pi-llama-cpp 0.12.0 → 0.14.0

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.
Files changed (68) hide show
  1. package/README.md +20 -9
  2. package/package.json +3 -3
  3. package/src/api/client.ts +25 -0
  4. package/src/constants.ts +8 -5
  5. package/src/enums/status.ts +0 -1
  6. package/src/interfaces/endpoints/models.ts +1 -1
  7. package/src/interfaces/settings.ts +3 -2
  8. package/src/interfaces/sortBy.ts +4 -0
  9. package/src/managers/command/models.ts +247 -0
  10. package/src/managers/command.ts +29 -459
  11. package/src/managers/events.ts +2 -2
  12. package/src/managers/server.ts +29 -5
  13. package/src/managers/settings.ts +12 -88
  14. package/src/models/baseModel.ts +27 -10
  15. package/src/models/legacyModel.ts +2 -2
  16. package/src/models/routerModel.ts +2 -2
  17. package/src/models/singleModel.ts +1 -1
  18. package/src/server.ts +35 -48
  19. package/src/sse/client.ts +113 -59
  20. package/src/sse/fetch.ts +43 -0
  21. package/src/sse/manager.ts +9 -27
  22. package/src/sse/types.ts +0 -4
  23. package/src/ui/dialog/base.ts +118 -0
  24. package/src/ui/dialog/confirm.ts +45 -0
  25. package/src/ui/dialog/factory.ts +111 -0
  26. package/src/ui/dialog/input.ts +63 -0
  27. package/src/ui/dialog/options.ts +23 -0
  28. package/src/ui/editors/editorOptions.ts +43 -0
  29. package/src/ui/editors/itemBuilder.ts +47 -0
  30. package/src/ui/editors/listEditor.ts +291 -0
  31. package/src/ui/editors/override/entry.ts +24 -0
  32. package/src/ui/editors/override/entryEditor.ts +166 -0
  33. package/src/ui/editors/override/fields.ts +294 -0
  34. package/src/ui/editors/override/handlers.ts +118 -0
  35. package/src/ui/editors/override/itemBuilder.ts +42 -0
  36. package/src/ui/editors/override/overrideList.ts +127 -0
  37. package/src/ui/editors/server/builder.ts +60 -0
  38. package/src/ui/editors/server/fields.ts +84 -0
  39. package/src/ui/editors/server/handlers.ts +32 -0
  40. package/src/ui/editors/server/itemBuilder.ts +68 -0
  41. package/src/ui/editors/server/serverEditor.ts +161 -0
  42. package/src/ui/editors/server/utils.ts +45 -0
  43. package/src/ui/editors/server/wizard.ts +110 -0
  44. package/src/ui/editors/settingField.ts +37 -0
  45. package/src/ui/editors/settingsListFactory.ts +33 -0
  46. package/src/ui/settings/index.ts +237 -0
  47. package/src/ui/strings.ts +8 -4
  48. package/src/utils/health.ts +48 -0
  49. package/src/utils/serverIds.ts +21 -0
  50. package/src/utils/settingsStore.ts +1 -1
  51. package/src/utils/urlResolver.ts +129 -0
  52. package/src/utils/urls.ts +33 -13
  53. package/tests/commandManager.test.ts +38 -7
  54. package/tests/dialog.test.ts +95 -2
  55. package/tests/health.test.ts +116 -0
  56. package/tests/legacyModel.test.ts +34 -28
  57. package/tests/overrides.test.ts +123 -68
  58. package/tests/routerModel.test.ts +67 -68
  59. package/tests/server.test.ts +47 -16
  60. package/tests/serverManager.test.ts +4 -4
  61. package/tests/settings.test.ts +10 -8
  62. package/tests/singleModel.test.ts +12 -12
  63. package/tests/sseManager.test.ts +6 -24
  64. package/src/ui/dialog.ts +0 -287
  65. package/src/ui/overrideEntryEditor.ts +0 -119
  66. package/src/ui/overrideSettingsList.ts +0 -682
  67. package/src/ui/serverListEditor.ts +0 -32
  68. package/src/ui/serverSettingsList.ts +0 -466
@@ -1,4 +1,5 @@
1
1
  import { beforeEach, describe, expect, it } from "vitest";
2
+ import { FALLBACK_CTX } from "../src/constants";
2
3
  import { Mode } from "../src/enums/mode";
3
4
  import { DataProperty } from "../src/interfaces/endpoints/models";
4
5
  import { RouterModel } from "../src/models/routerModel";
@@ -20,12 +21,21 @@ beforeEach(() => {
20
21
  mockRpc.mockClear();
21
22
  });
22
23
 
23
- describe("RouterModel context size extraction", () => {
24
- it("should extract --ctx-size value", () => {
24
+ describe("RouterModel context size (via toProviderConfig)", () => {
25
+ /** Mocks for an unloaded model: capabilities detection fails (text-only),
26
+ * then the status probe fails so context size falls back to CLI args. */
27
+ const mockUnloaded = () => {
28
+ mockRpc.mockRejectedValueOnce(new Error("props not available")); // capabilities: /props
29
+ mockRpc.mockResolvedValueOnce({ data: [] }); // capabilities: /v1/models
30
+ mockRpc.mockRejectedValueOnce(new Error("props not available")); // status: /props
31
+ };
32
+
33
+ it("should extract --ctx-size when unloaded", async () => {
34
+ mockUnloaded();
25
35
  const model = new RouterModel(
26
36
  createModel({
27
37
  status: {
28
- value: "loaded",
38
+ value: "unloaded",
29
39
  args: [
30
40
  "--model",
31
41
  "gguf",
@@ -40,16 +50,17 @@ describe("RouterModel context size extraction", () => {
40
50
  createMockServer(),
41
51
  );
42
52
 
43
- // Access the private method via any
44
- const extractFrom = (model as any).extractFrom.bind(model);
45
- expect(extractFrom("--ctx-size")).toBe(4096);
53
+ const { contextWindow } = await model.toProviderConfig();
54
+
55
+ expect(contextWindow).toBe(4096);
46
56
  });
47
57
 
48
- it("should extract --fit-ctx value when --ctx-size is not present", () => {
58
+ it("should fall back to --fit-ctx when --ctx-size is not present", async () => {
59
+ mockUnloaded();
49
60
  const model = new RouterModel(
50
61
  createModel({
51
62
  status: {
52
- value: "loaded",
63
+ value: "unloaded",
53
64
  args: ["--model", "gguf", "--fit-ctx", "8192"],
54
65
  preset: "default",
55
66
  },
@@ -57,91 +68,87 @@ describe("RouterModel context size extraction", () => {
57
68
  createMockServer(),
58
69
  );
59
70
 
60
- const extractFrom = (model as any).extractFrom.bind(model);
61
- expect(extractFrom("--fit-ctx")).toBe(8192);
71
+ const { contextWindow } = await model.toProviderConfig();
72
+
73
+ expect(contextWindow).toBe(8192);
62
74
  });
63
75
 
64
- it("should return null when argument is not found", () => {
76
+ it("should prefer --ctx-size over --fit-ctx", async () => {
77
+ mockUnloaded();
65
78
  const model = new RouterModel(
66
79
  createModel({
67
80
  status: {
68
- value: "loaded",
69
- args: ["--model", "gguf", "--batch-size", "512"],
81
+ value: "unloaded",
82
+ args: ["--model", "gguf", "--ctx-size", "4096", "--fit-ctx", "8192"],
70
83
  preset: "default",
71
84
  },
72
85
  }),
73
86
  createMockServer(),
74
87
  );
75
88
 
76
- const extractFrom = (model as any).extractFrom.bind(model);
77
- expect(extractFrom("--ctx-size")).toBeNull();
78
- expect(extractFrom("--fit-ctx")).toBeNull();
89
+ const { contextWindow } = await model.toProviderConfig();
90
+
91
+ expect(contextWindow).toBe(4096);
79
92
  });
80
93
 
81
- it("should return null when argument has no following value", () => {
94
+ it("should fall back to FALLBACK_CTX when no size argument is present", async () => {
95
+ mockUnloaded();
82
96
  const model = new RouterModel(
83
97
  createModel({
84
98
  status: {
85
- value: "loaded",
86
- args: ["--model", "gguf", "--ctx-size"],
99
+ value: "unloaded",
100
+ args: ["--model", "gguf", "--batch-size", "512"],
87
101
  preset: "default",
88
102
  },
89
103
  }),
90
104
  createMockServer(),
91
105
  );
92
106
 
93
- const extractFrom = (model as any).extractFrom.bind(model);
94
- expect(extractFrom("--ctx-size")).toBeNull();
107
+ const { contextWindow } = await model.toProviderConfig();
108
+
109
+ expect(contextWindow).toBe(FALLBACK_CTX);
95
110
  });
96
111
 
97
- it("should return null when argument value is not a valid number", () => {
112
+ it("should fall back to FALLBACK_CTX when the argument has no following value", async () => {
113
+ mockUnloaded();
98
114
  const model = new RouterModel(
99
115
  createModel({
100
116
  status: {
101
- value: "loaded",
102
- args: ["--model", "gguf", "--ctx-size", "not-a-number"],
117
+ value: "unloaded",
118
+ args: ["--model", "gguf", "--ctx-size"],
103
119
  preset: "default",
104
120
  },
105
121
  }),
106
122
  createMockServer(),
107
123
  );
108
124
 
109
- const extractFrom = (model as any).extractFrom.bind(model);
110
- expect(extractFrom("--ctx-size")).toBeNull();
111
- });
125
+ const { contextWindow } = await model.toProviderConfig();
112
126
 
113
- it("should prefer --ctx-size over --fit-ctx when loaded", async () => {
114
- // First call: getStatus() -> fetchModelProps
115
- mockRpc.mockResolvedValueOnce({ is_sleeping: false });
116
- // Second call: super.getContextSize() -> fetchModels with meta.n_ctx
117
- mockRpc.mockResolvedValueOnce({
118
- data: [
119
- {
120
- id: "test-model",
121
- meta: { n_ctx: 4096 },
122
- },
123
- ],
124
- });
127
+ expect(contextWindow).toBe(FALLBACK_CTX);
128
+ });
125
129
 
130
+ it("should fall back to FALLBACK_CTX when the argument value is not a valid number", async () => {
131
+ mockUnloaded();
126
132
  const model = new RouterModel(
127
133
  createModel({
128
134
  status: {
129
- value: "loaded",
130
- args: ["--model", "gguf", "--ctx-size", "4096", "--fit-ctx", "8192"],
135
+ value: "unloaded",
136
+ args: ["--model", "gguf", "--ctx-size", "not-a-number"],
131
137
  preset: "default",
132
138
  },
133
139
  }),
134
140
  createMockServer(),
135
141
  );
136
142
 
137
- const ctxSize = await model.getContextSize();
138
- expect(ctxSize).toBe(4096);
143
+ const { contextWindow } = await model.toProviderConfig();
144
+
145
+ expect(contextWindow).toBe(FALLBACK_CTX);
139
146
  });
140
147
 
141
- it("should return n_ctx from meta when loaded without context size args", async () => {
142
- // First call: getStatus() -> fetchModelProps
143
- mockRpc.mockResolvedValueOnce({ is_sleeping: false });
144
- // Second call: super.getContextSize() -> fetchModels with meta.n_ctx
148
+ it("should return n_ctx from meta when loaded", async () => {
149
+ mockRpc.mockResolvedValueOnce({ modalities: { vision: false } }); // capabilities: /props
150
+ mockRpc.mockResolvedValueOnce({ is_sleeping: false }); // status: /props
151
+ // super.getContextSize() -> fetchModels with meta.n_ctx
145
152
  mockRpc.mockResolvedValueOnce({
146
153
  data: [
147
154
  {
@@ -151,30 +158,22 @@ describe("RouterModel context size extraction", () => {
151
158
  ],
152
159
  });
153
160
 
154
- const model = new RouterModel(
155
- createModel({
156
- status: {
157
- value: "loaded",
158
- args: ["--model", "gguf"],
159
- preset: "default",
160
- },
161
- }),
162
- createMockServer(),
163
- );
161
+ const model = new RouterModel(createModel(), createMockServer());
162
+
163
+ const { contextWindow } = await model.toProviderConfig();
164
164
 
165
- const ctxSize = await model.getContextSize();
166
- expect(ctxSize).toBe(4096);
165
+ expect(contextWindow).toBe(4096);
167
166
  });
168
167
  });
169
168
 
170
- describe("RouterModel capabilities detection", () => {
169
+ describe("RouterModel capabilities detection (via toProviderConfig)", () => {
171
170
  it("should detect image capability when modalities.vision is true", async () => {
172
171
  mockRpc.mockResolvedValueOnce({ modalities: { vision: true } });
173
172
 
174
173
  const model = new RouterModel(createModel(), createMockServer());
175
- const capabilities = await model.getCapabilities();
174
+ const { input } = await model.toProviderConfig();
176
175
 
177
- expect(capabilities).toEqual(["text", "image"]);
176
+ expect(input).toEqual(["text", "image"]);
178
177
  expect(mockRpc).toHaveBeenCalledWith(
179
178
  "/props?model=test-model&autoload=false",
180
179
  );
@@ -187,9 +186,9 @@ describe("RouterModel capabilities detection", () => {
187
186
  mockRpc.mockResolvedValueOnce({ data: [] });
188
187
 
189
188
  const model = new RouterModel(createModel(), createMockServer());
190
- const capabilities = await model.getCapabilities();
189
+ const { input } = await model.toProviderConfig();
191
190
 
192
- expect(capabilities).toEqual(["text"]);
191
+ expect(input).toEqual(["text"]);
193
192
  });
194
193
 
195
194
  it("should detect text-only capability when only text in input_modalities", async () => {
@@ -215,9 +214,9 @@ describe("RouterModel capabilities detection", () => {
215
214
  });
216
215
 
217
216
  const model = new RouterModel(createModel(), createMockServer());
218
- const capabilities = await model.getCapabilities();
217
+ const { input } = await model.toProviderConfig();
219
218
 
220
- expect(capabilities).toEqual(["text"]);
219
+ expect(input).toEqual(["text"]);
221
220
  });
222
221
 
223
222
  it("should return text when model not found in /models response", async () => {
@@ -239,9 +238,9 @@ describe("RouterModel capabilities detection", () => {
239
238
  });
240
239
 
241
240
  const model = new RouterModel(createModel(), createMockServer());
242
- const capabilities = await model.getCapabilities();
241
+ const { input } = await model.toProviderConfig();
243
242
 
244
- expect(capabilities).toEqual(["text"]);
243
+ expect(input).toEqual(["text"]);
245
244
  });
246
245
  });
247
246
 
@@ -1,4 +1,4 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
2
  import { POLLING_TIMEOUT, SERVER_TIMEOUT } from "../src/constants";
3
3
  import { ServerStatus } from "../src/enums/serverStatus";
4
4
  import type { LlamaSettingsManager } from "../src/managers/settings";
@@ -35,6 +35,26 @@ describe("Server providerName", () => {
35
35
  });
36
36
  });
37
37
 
38
+ describe("Server apiBaseUrl", () => {
39
+ it("should append the ENDPOINT_PREFIX to baseUrl", () => {
40
+ const server = new Server(settings, { baseUrl: "http://127.0.0.1:8080" });
41
+ expect(server.apiBaseUrl).toBe("http://127.0.0.1:8080/v1");
42
+ });
43
+
44
+ it("should not double the prefix when baseUrl already ends with it", () => {
45
+ const server = new Server(settings, {
46
+ baseUrl: "http://127.0.0.1:8080/v1",
47
+ });
48
+ expect(server.apiBaseUrl).toBe("http://127.0.0.1:8080/v1");
49
+ });
50
+
51
+ it("should keep baseUrl untouched for provider identity", () => {
52
+ const server = new Server(settings, { baseUrl: "http://127.0.0.1:8080" });
53
+ expect(server.baseUrl).toBe("http://127.0.0.1:8080");
54
+ expect(server.providerId).toBe("llama-server=http://127.0.0.1:8080");
55
+ });
56
+ });
57
+
38
58
  describe("Server fetchModels", () => {
39
59
  it("should call the /models endpoint", async () => {
40
60
  mockRpc.mockResolvedValueOnce({
@@ -87,18 +107,6 @@ describe("Server fetchModelProps", () => {
87
107
  });
88
108
  });
89
109
 
90
- describe("Server fetchServerHealth", () => {
91
- it("should call the /health endpoint", async () => {
92
- mockRpc.mockResolvedValueOnce({ status: "ok" });
93
-
94
- const server = createMockServer();
95
- const result = await server.fetchServerHealth();
96
-
97
- expect(result).toEqual({ status: "ok" });
98
- expect(mockRpc).toHaveBeenCalledWith("/health");
99
- });
100
- });
101
-
102
110
  describe("Server fetchServerProps", () => {
103
111
  it("should call the /props endpoint without model", async () => {
104
112
  mockRpc.mockResolvedValueOnce({
@@ -195,8 +203,18 @@ describe("Server timeouts", async () => {
195
203
  });
196
204
 
197
205
  describe("Server isReady", () => {
206
+ // `isReady` delegates to the shared health probe (`utils/health`), which
207
+ // uses plain `fetch` instead of the ApiClient — stub it per test.
208
+ const stubFetch = (impl: () => Promise<unknown>) => {
209
+ vi.stubGlobal("fetch", vi.fn(impl));
210
+ };
211
+
212
+ afterEach(() => {
213
+ vi.unstubAllGlobals();
214
+ });
215
+
198
216
  it("should return READY when health status is ok", async () => {
199
- mockRpc.mockResolvedValueOnce({ status: "ok" });
217
+ stubFetch(async () => ({ json: async () => ({ status: "ok" }) }));
200
218
 
201
219
  const server = createMockServer();
202
220
  const status = await server.isReady(1000);
@@ -205,7 +223,9 @@ describe("Server isReady", () => {
205
223
  });
206
224
 
207
225
  it("should return UNREACHABLE when health check fails", async () => {
208
- mockRpc.mockRejectedValueOnce(new Error("connection refused"));
226
+ stubFetch(async () => {
227
+ throw new Error("connection refused");
228
+ });
209
229
 
210
230
  const server = createMockServer();
211
231
  const status = await server.isReady(1000);
@@ -214,11 +234,22 @@ describe("Server isReady", () => {
214
234
  });
215
235
 
216
236
  it("should return UNREACHABLE when health status is not ok", async () => {
217
- mockRpc.mockResolvedValueOnce({ status: "error" });
237
+ stubFetch(async () => ({ json: async () => ({ status: "error" }) }));
218
238
 
219
239
  const server = createMockServer();
220
240
  const status = await server.isReady(1000);
221
241
 
222
242
  expect(status).toBe(ServerStatus.UNREACHABLE);
223
243
  });
244
+
245
+ it("should return TIMEOUT when the health check aborts", async () => {
246
+ stubFetch(async () => {
247
+ throw new DOMException("The operation timed out.", "TimeoutError");
248
+ });
249
+
250
+ const server = createMockServer();
251
+ const status = await server.isReady(1000);
252
+
253
+ expect(status).toBe(ServerStatus.TIMEOUT);
254
+ });
224
255
  });
@@ -69,7 +69,7 @@ describe("ServerManager", () => {
69
69
  "llama-server=http://127.0.0.1:8080",
70
70
  {
71
71
  name: "Llama.cpp (http://127.0.0.1:8080)",
72
- baseUrl: "http://127.0.0.1:8080",
72
+ baseUrl: "http://127.0.0.1:8080/v1",
73
73
  api: "openai-completions",
74
74
  apiKey: "key-1",
75
75
  models: [{ id: "test-model" }],
@@ -79,7 +79,7 @@ describe("ServerManager", () => {
79
79
  "llama-server=http://127.0.0.1:8081",
80
80
  {
81
81
  name: "Llama.cpp (http://127.0.0.1:8081)",
82
- baseUrl: "http://127.0.0.1:8081",
82
+ baseUrl: "http://127.0.0.1:8081/v1",
83
83
  api: "openai-completions",
84
84
  apiKey: "key-2",
85
85
  models: [{ id: "test-model" }],
@@ -133,7 +133,7 @@ describe("ServerManager", () => {
133
133
 
134
134
  expect(mockPi.registerProvider).toHaveBeenCalledWith(
135
135
  "llama-server=http://127.0.0.1:8081",
136
- expect.objectContaining({ baseUrl: "http://127.0.0.1:8081" }),
136
+ expect.objectContaining({ baseUrl: "http://127.0.0.1:8081/v1" }),
137
137
  );
138
138
  expect(manager.servers).toHaveLength(2);
139
139
  const models = await manager.getAllModels();
@@ -184,7 +184,7 @@ describe("ServerManager", () => {
184
184
  );
185
185
  expect(mockPi.registerProvider).toHaveBeenCalledWith(
186
186
  "llama-server=http://127.0.0.1:9090",
187
- expect.objectContaining({ baseUrl: "http://127.0.0.1:9090" }),
187
+ expect.objectContaining({ baseUrl: "http://127.0.0.1:9090/v1" }),
188
188
  );
189
189
  expect(manager.servers[0]?.providerId).toBe(
190
190
  "llama-server=http://127.0.0.1:9090",
@@ -1065,18 +1065,20 @@ describe("Server with overrides", () => {
1065
1065
  },
1066
1066
  });
1067
1067
 
1068
- expect(server.getOverrides()).toEqual({
1069
- "model-a": { cost: { input: 0.2, output: 0.6 } },
1070
- "model-b": { cost: { input: 0.1, output: 0.3, cacheRead: 0.01 } },
1068
+ expect(server.findOverrideForModel("model-a")).toEqual({
1069
+ cost: { input: 0.2, output: 0.6 },
1070
+ });
1071
+ expect(server.findOverrideForModel("model-b")).toEqual({
1072
+ cost: { input: 0.1, output: 0.3, cacheRead: 0.01 },
1071
1073
  });
1072
1074
  });
1073
1075
 
1074
- it("should return empty object when no overrides are provided", () => {
1076
+ it("should return undefined for findOverrideForModel when no overrides are provided", () => {
1075
1077
  const server = new Server(settings, {
1076
1078
  baseUrl: "http://127.0.0.1:8080",
1077
1079
  });
1078
1080
 
1079
- expect(server.getOverrides()).toEqual({});
1081
+ expect(server.findOverrideForModel("any-model")).toBeUndefined();
1080
1082
  });
1081
1083
  });
1082
1084
 
@@ -1118,10 +1120,10 @@ describe("resolveServers passes overrides", () => {
1118
1120
  const result = await settings.resolveServers();
1119
1121
 
1120
1122
  expect(result).toHaveLength(2);
1121
- expect(result[0].getOverrides()).toEqual({
1122
- "model-x": { cost: { input: 0.5, output: 1.0 } },
1123
+ expect(result[0].findOverrideForModel("model-x")).toEqual({
1124
+ cost: { input: 0.5, output: 1.0 },
1123
1125
  });
1124
- expect(result[1].getOverrides()).toEqual({});
1126
+ expect(result[1].findOverrideForModel("any-model")).toBeUndefined();
1125
1127
  });
1126
1128
  });
1127
1129
 
@@ -29,23 +29,23 @@ describe("SingleModel mode", () => {
29
29
  });
30
30
  });
31
31
 
32
- describe("SingleModel capabilities", () => {
32
+ describe("SingleModel capabilities (via toProviderConfig)", () => {
33
33
  it("should detect image capability when multimodal is in capabilities", async () => {
34
34
  mockRpc.mockResolvedValueOnce({ modalities: { vision: true } });
35
35
 
36
36
  const model = createModel();
37
- const capabilities = await model.getCapabilities();
37
+ const { input } = await model.toProviderConfig();
38
38
 
39
- expect(capabilities).toEqual(["text", "image"]);
39
+ expect(input).toEqual(["text", "image"]);
40
40
  });
41
41
 
42
42
  it("should detect text-only capability when multimodal is not in capabilities", async () => {
43
43
  mockRpc.mockResolvedValueOnce({ modalities: { vision: false } });
44
44
 
45
45
  const model = createModel();
46
- const capabilities = await model.getCapabilities();
46
+ const { input } = await model.toProviderConfig();
47
47
 
48
- expect(capabilities).toEqual(["text"]);
48
+ expect(input).toEqual(["text"]);
49
49
  });
50
50
 
51
51
  it("should fall back to the models endpoint when auth fails", async () => {
@@ -59,9 +59,9 @@ describe("SingleModel capabilities", () => {
59
59
  }); // /v1/models retry in SingleModel's catch
60
60
 
61
61
  const model = createModel();
62
- const capabilities = await model.getCapabilities();
62
+ const { input } = await model.toProviderConfig();
63
63
 
64
- expect(capabilities).toEqual(["text", "image"]);
64
+ expect(input).toEqual(["text", "image"]);
65
65
  });
66
66
 
67
67
  it("should fall back to text-only when the models endpoint reports no multimodal", async () => {
@@ -75,9 +75,9 @@ describe("SingleModel capabilities", () => {
75
75
  }); // /v1/models retry in SingleModel's catch
76
76
 
77
77
  const model = createModel();
78
- const capabilities = await model.getCapabilities();
78
+ const { input } = await model.toProviderConfig();
79
79
 
80
- expect(capabilities).toEqual(["text"]);
80
+ expect(input).toEqual(["text"]);
81
81
  });
82
82
  });
83
83
 
@@ -104,16 +104,16 @@ describe("SingleModel getStatus", () => {
104
104
  });
105
105
  });
106
106
 
107
- describe("SingleModel getContextSize", () => {
107
+ describe("SingleModel context size (via toProviderConfig)", () => {
108
108
  it("should return n_ctx from /v1/models endpoint meta", async () => {
109
109
  mockRpc.mockResolvedValue({
110
110
  data: [{ id: "test", meta: { n_ctx: 8192 } }],
111
111
  });
112
112
 
113
113
  const model = createModel();
114
- const ctxSize = await model.getContextSize();
114
+ const { contextWindow } = await model.toProviderConfig();
115
115
 
116
- expect(ctxSize).toBe(8192);
116
+ expect(contextWindow).toBe(8192);
117
117
  expect(mockRpc).toHaveBeenCalledWith("/v1/models");
118
118
  });
119
119
  });
@@ -16,29 +16,15 @@ const createManager = (
16
16
  pollingTimeout,
17
17
  serverTimeout,
18
18
  }),
19
- "",
20
19
  );
21
20
 
22
- describe("SSEManager timeouts", async () => {
23
- it("should expose the timeouts of its server", async () => {
24
- const manager = createManager(5678, 1234);
25
-
26
- expect(await manager.getPollingTimeout()).toBe(5678);
27
- expect(await manager.getServerTimeout()).toBe(1234);
28
- });
29
- });
30
-
31
21
  describe("SSEManager subscribeToStatus", () => {
32
22
  it("should reject after the server's pollingTimeout, not the constant", async () => {
33
23
  vi.useFakeTimers();
24
+ // Never-resolving fetch: the connection stays open but no events arrive
34
25
  vi.stubGlobal(
35
- "EventSource",
36
- class StubEventSource {
37
- onopen = null;
38
- onerror = null;
39
- onmessage = null;
40
- close() {}
41
- },
26
+ "fetch",
27
+ vi.fn(async () => new Promise<Response>(() => {})),
42
28
  );
43
29
 
44
30
  try {
@@ -60,14 +46,10 @@ describe("SSEManager subscribeToStatus", () => {
60
46
 
61
47
  it("should resolve when a terminal status arrives before the timeout", async () => {
62
48
  vi.useFakeTimers();
49
+ // Never-resolving fetch: events are dispatched manually below
63
50
  vi.stubGlobal(
64
- "EventSource",
65
- class StubEventSource {
66
- onopen = null;
67
- onerror = null;
68
- onmessage = null;
69
- close() {}
70
- },
51
+ "fetch",
52
+ vi.fn(async () => new Promise<Response>(() => {})),
71
53
  );
72
54
 
73
55
  try {