@inferencesh/sdk 0.6.15 → 0.6.19
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/agent/provider.d.ts +2 -1
- package/dist/api/apps.d.ts +4 -0
- package/dist/api/apps.js +6 -0
- package/dist/api/index.d.ts +3 -3
- package/dist/http/index.d.ts +3 -3
- package/dist/index.d.ts +9 -9
- package/dist/types.d.ts +30 -4
- package/dist/types.js +4 -0
- package/package.json +8 -5
- package/dist/agent/actions.test.d.ts +0 -1
- package/dist/agent/actions.test.js +0 -820
- package/dist/agent/api.test.d.ts +0 -1
- package/dist/agent/api.test.js +0 -246
- package/dist/agent/reducer.test.d.ts +0 -1
- package/dist/agent/reducer.test.js +0 -131
- package/dist/agent/types.test.d.ts +0 -1
- package/dist/agent/types.test.js +0 -75
- package/dist/api/agents.test.d.ts +0 -1
- package/dist/api/agents.test.js +0 -1014
- package/dist/api/api-keys.test.d.ts +0 -1
- package/dist/api/api-keys.test.js +0 -44
- package/dist/api/apps.test.d.ts +0 -1
- package/dist/api/apps.test.js +0 -135
- package/dist/api/chats.test.d.ts +0 -1
- package/dist/api/chats.test.js +0 -85
- package/dist/api/engines.test.d.ts +0 -1
- package/dist/api/engines.test.js +0 -133
- package/dist/api/files.test.d.ts +0 -1
- package/dist/api/files.test.js +0 -256
- package/dist/api/flow-runs.test.d.ts +0 -1
- package/dist/api/flow-runs.test.js +0 -97
- package/dist/api/flows.test.d.ts +0 -1
- package/dist/api/flows.test.js +0 -118
- package/dist/api/integrations.test.d.ts +0 -1
- package/dist/api/integrations.test.js +0 -109
- package/dist/api/knowledge.test.d.ts +0 -1
- package/dist/api/knowledge.test.js +0 -238
- package/dist/api/mcp-servers.test.d.ts +0 -1
- package/dist/api/mcp-servers.test.js +0 -98
- package/dist/api/projects.test.d.ts +0 -1
- package/dist/api/projects.test.js +0 -61
- package/dist/api/search.test.d.ts +0 -1
- package/dist/api/search.test.js +0 -50
- package/dist/api/secrets.test.d.ts +0 -1
- package/dist/api/secrets.test.js +0 -61
- package/dist/api/sessions.test.d.ts +0 -1
- package/dist/api/sessions.test.js +0 -61
- package/dist/api/tasks.test.d.ts +0 -1
- package/dist/api/tasks.test.js +0 -381
- package/dist/api/teams.test.d.ts +0 -1
- package/dist/api/teams.test.js +0 -139
- package/dist/client.test.d.ts +0 -1
- package/dist/client.test.js +0 -446
- package/dist/http/client.test.d.ts +0 -1
- package/dist/http/client.test.js +0 -435
- package/dist/http/errors.test.d.ts +0 -1
- package/dist/http/errors.test.js +0 -66
- package/dist/http/poll.test.d.ts +0 -1
- package/dist/http/poll.test.js +0 -146
- package/dist/http/streamable.test.d.ts +0 -4
- package/dist/http/streamable.test.js +0 -510
- package/dist/integration.test.d.ts +0 -9
- package/dist/integration.test.js +0 -107
- package/dist/proxy/express.test.d.ts +0 -1
- package/dist/proxy/express.test.js +0 -106
- package/dist/proxy/hono.test.d.ts +0 -1
- package/dist/proxy/hono.test.js +0 -90
- package/dist/proxy/index.test.d.ts +0 -1
- package/dist/proxy/index.test.js +0 -173
- package/dist/proxy/nextjs.test.d.ts +0 -1
- package/dist/proxy/nextjs.test.js +0 -125
- package/dist/proxy/remix.test.d.ts +0 -1
- package/dist/proxy/remix.test.js +0 -66
- package/dist/proxy/svelte.test.d.ts +0 -1
- package/dist/proxy/svelte.test.js +0 -69
- package/dist/sessions.integration.test.d.ts +0 -13
- package/dist/sessions.integration.test.js +0 -310
- package/dist/stream.test.d.ts +0 -1
- package/dist/stream.test.js +0 -363
- package/dist/streamable.integration.test.d.ts +0 -11
- package/dist/streamable.integration.test.js +0 -150
- package/dist/tool-builder.test.d.ts +0 -1
- package/dist/tool-builder.test.js +0 -407
- package/dist/utils.test.d.ts +0 -1
- package/dist/utils.test.js +0 -43
package/dist/api/tasks.test.js
DELETED
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from '../http/client';
|
|
2
|
-
import { TaskStatusCancelled, TaskStatusCompleted, TaskStatusFailed, TaskStatusRunning, } from '../types';
|
|
3
|
-
import { TasksAPI } from './tasks';
|
|
4
|
-
const mockFetch = jest.fn();
|
|
5
|
-
global.fetch = mockFetch;
|
|
6
|
-
function mockJsonResponse(body) {
|
|
7
|
-
mockFetch.mockResolvedValueOnce({
|
|
8
|
-
ok: true,
|
|
9
|
-
status: 200,
|
|
10
|
-
text: () => Promise.resolve(JSON.stringify(body)),
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function makeTask(overrides = {}) {
|
|
14
|
-
return {
|
|
15
|
-
id: 'task-1',
|
|
16
|
-
status: TaskStatusRunning,
|
|
17
|
-
created_at: '2026-01-01T00:00:00Z',
|
|
18
|
-
updated_at: '2026-01-01T00:00:00Z',
|
|
19
|
-
input: { prompt: 'hi' },
|
|
20
|
-
output: null,
|
|
21
|
-
logs: [],
|
|
22
|
-
session_id: 'sess-1',
|
|
23
|
-
...overrides,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
describe('TasksAPI.run (polling mode)', () => {
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
jest.clearAllMocks();
|
|
29
|
-
});
|
|
30
|
-
const api = () => new TasksAPI(new HttpClient({
|
|
31
|
-
apiKey: 'test-key',
|
|
32
|
-
stream: false,
|
|
33
|
-
pollIntervalMs: 20,
|
|
34
|
-
}));
|
|
35
|
-
it('should resolve when status polling detects completion', async () => {
|
|
36
|
-
const runningTask = makeTask();
|
|
37
|
-
const completedTask = makeTask({ status: TaskStatusCompleted, output: { ok: true } });
|
|
38
|
-
mockJsonResponse(runningTask);
|
|
39
|
-
mockJsonResponse({ status: TaskStatusRunning });
|
|
40
|
-
mockJsonResponse({ status: TaskStatusCompleted });
|
|
41
|
-
mockJsonResponse(completedTask);
|
|
42
|
-
const onUpdate = jest.fn();
|
|
43
|
-
const result = await api().run({ app: 'test-app', input: {} }, { prompt: 'hi' }, { wait: true, stream: false, onUpdate });
|
|
44
|
-
expect(result.status).toBe(TaskStatusCompleted);
|
|
45
|
-
expect(onUpdate).toHaveBeenCalledWith(expect.objectContaining({ id: 'task-1', status: TaskStatusCompleted }));
|
|
46
|
-
});
|
|
47
|
-
it('should reject when polling detects a failed task', async () => {
|
|
48
|
-
const runningTask = makeTask();
|
|
49
|
-
const failedTask = makeTask({ status: TaskStatusFailed, error: 'model error' });
|
|
50
|
-
mockJsonResponse(runningTask);
|
|
51
|
-
mockJsonResponse({ status: TaskStatusRunning });
|
|
52
|
-
mockJsonResponse({ status: TaskStatusFailed });
|
|
53
|
-
mockJsonResponse(failedTask);
|
|
54
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true, stream: false })).rejects.toThrow('model error');
|
|
55
|
-
});
|
|
56
|
-
it('should reject when polling detects a cancelled task', async () => {
|
|
57
|
-
const runningTask = makeTask();
|
|
58
|
-
const cancelledTask = makeTask({ status: TaskStatusCancelled });
|
|
59
|
-
mockJsonResponse(runningTask);
|
|
60
|
-
mockJsonResponse({ status: TaskStatusRunning });
|
|
61
|
-
mockJsonResponse({ status: TaskStatusCancelled });
|
|
62
|
-
mockJsonResponse(cancelledTask);
|
|
63
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true, stream: false })).rejects.toThrow('task cancelled');
|
|
64
|
-
});
|
|
65
|
-
it('should reject when full task fetch fails after status change', async () => {
|
|
66
|
-
const runningTask = makeTask();
|
|
67
|
-
mockJsonResponse(runningTask);
|
|
68
|
-
mockJsonResponse({ status: TaskStatusRunning });
|
|
69
|
-
mockJsonResponse({ status: TaskStatusCompleted });
|
|
70
|
-
mockFetch.mockRejectedValueOnce(new Error('network down'));
|
|
71
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true, stream: false })).rejects.toThrow('network down');
|
|
72
|
-
});
|
|
73
|
-
it('should reject when status polling fails', async () => {
|
|
74
|
-
const runningTask = makeTask();
|
|
75
|
-
mockJsonResponse(runningTask);
|
|
76
|
-
mockFetch.mockRejectedValueOnce(new Error('status endpoint down'));
|
|
77
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true, stream: false })).rejects.toThrow('status endpoint down');
|
|
78
|
-
});
|
|
79
|
-
it('should not refetch full task when poll status is unchanged', async () => {
|
|
80
|
-
const runningTask = makeTask();
|
|
81
|
-
const completedTask = makeTask({ status: TaskStatusCompleted, output: { ok: true } });
|
|
82
|
-
mockJsonResponse(runningTask);
|
|
83
|
-
mockJsonResponse({ status: TaskStatusRunning });
|
|
84
|
-
mockJsonResponse({ status: TaskStatusRunning });
|
|
85
|
-
mockJsonResponse({ status: TaskStatusCompleted });
|
|
86
|
-
mockJsonResponse(completedTask);
|
|
87
|
-
await api().run({ app: 'test-app', input: {} }, {}, { wait: true, stream: false });
|
|
88
|
-
const fullTaskGets = mockFetch.mock.calls.filter(([url, init]) => String(url).includes('/tasks/task-1') &&
|
|
89
|
-
!String(url).includes('/status') &&
|
|
90
|
-
init.method === 'GET');
|
|
91
|
-
expect(fullTaskGets).toHaveLength(1);
|
|
92
|
-
});
|
|
93
|
-
it('should parse string terminal statuses from the status endpoint', async () => {
|
|
94
|
-
const runningTask = makeTask();
|
|
95
|
-
const completedTask = makeTask({ status: TaskStatusCompleted });
|
|
96
|
-
mockJsonResponse(runningTask);
|
|
97
|
-
mockJsonResponse({ status: TaskStatusRunning });
|
|
98
|
-
mockJsonResponse({ status: 'completed' });
|
|
99
|
-
mockJsonResponse(completedTask);
|
|
100
|
-
const result = await api().run({ app: 'test-app', input: {} }, {}, { wait: true, stream: false });
|
|
101
|
-
expect(result.status).toBe(TaskStatusCompleted);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
function mockNdjsonStream(chunks) {
|
|
105
|
-
let chunkIndex = 0;
|
|
106
|
-
const mockReader = {
|
|
107
|
-
read: jest.fn().mockImplementation(async () => {
|
|
108
|
-
if (chunkIndex >= chunks.length) {
|
|
109
|
-
return { done: true, value: undefined };
|
|
110
|
-
}
|
|
111
|
-
return { done: false, value: new TextEncoder().encode(chunks[chunkIndex++]) };
|
|
112
|
-
}),
|
|
113
|
-
releaseLock: jest.fn(),
|
|
114
|
-
};
|
|
115
|
-
return {
|
|
116
|
-
ok: true,
|
|
117
|
-
status: 200,
|
|
118
|
-
body: { getReader: () => mockReader },
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
describe('TasksAPI.run (general)', () => {
|
|
122
|
-
beforeEach(() => {
|
|
123
|
-
jest.clearAllMocks();
|
|
124
|
-
});
|
|
125
|
-
const streamingApi = () => new TasksAPI(new HttpClient({ apiKey: 'test-key', stream: true }));
|
|
126
|
-
it('should return immediately when wait is false', async () => {
|
|
127
|
-
const task = makeTask();
|
|
128
|
-
mockJsonResponse(task);
|
|
129
|
-
const result = await streamingApi().run({ app: 'test-app', input: {} }, { prompt: 'hi' }, { wait: false });
|
|
130
|
-
expect(result.id).toBe('task-1');
|
|
131
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe('TasksAPI.run (streaming mode)', () => {
|
|
135
|
-
beforeEach(() => {
|
|
136
|
-
jest.clearAllMocks();
|
|
137
|
-
});
|
|
138
|
-
const api = () => new TasksAPI(new HttpClient({ apiKey: 'test-key', stream: true }));
|
|
139
|
-
function setupStreamMocks(ndjsonChunks, initialTask = makeTask()) {
|
|
140
|
-
mockFetch.mockImplementation((url) => {
|
|
141
|
-
if (url.includes('/apps/run')) {
|
|
142
|
-
return Promise.resolve({
|
|
143
|
-
ok: true,
|
|
144
|
-
status: 200,
|
|
145
|
-
text: () => Promise.resolve(JSON.stringify(initialTask)),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
return Promise.resolve(mockNdjsonStream(ndjsonChunks));
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
it('should resolve when NDJSON stream reports completion', async () => {
|
|
152
|
-
setupStreamMocks([
|
|
153
|
-
`${JSON.stringify({ status: TaskStatusRunning, id: 'task-1' })}\n`,
|
|
154
|
-
`${JSON.stringify({ status: TaskStatusCompleted, id: 'task-1', output: { ok: true } })}\n`,
|
|
155
|
-
]);
|
|
156
|
-
const onUpdate = jest.fn();
|
|
157
|
-
const result = await api().run({ app: 'test-app', input: {} }, { prompt: 'hi' }, { wait: true, onUpdate });
|
|
158
|
-
expect(result.status).toBe(TaskStatusCompleted);
|
|
159
|
-
expect(onUpdate).toHaveBeenCalled();
|
|
160
|
-
});
|
|
161
|
-
it('should reject when NDJSON stream reports failure', async () => {
|
|
162
|
-
setupStreamMocks([
|
|
163
|
-
`${JSON.stringify({ status: TaskStatusFailed, id: 'task-1', error: 'gpu OOM' })}\n`,
|
|
164
|
-
]);
|
|
165
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true })).rejects.toThrow('gpu OOM');
|
|
166
|
-
});
|
|
167
|
-
it('should reject when NDJSON stream reports cancellation', async () => {
|
|
168
|
-
setupStreamMocks([
|
|
169
|
-
`${JSON.stringify({ status: TaskStatusCancelled, id: 'task-1' })}\n`,
|
|
170
|
-
]);
|
|
171
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true })).rejects.toThrow('task cancelled');
|
|
172
|
-
});
|
|
173
|
-
it('should reject when partial stream reports failure', async () => {
|
|
174
|
-
setupStreamMocks([
|
|
175
|
-
`${JSON.stringify({
|
|
176
|
-
data: { status: TaskStatusFailed, id: 'task-1', error: 'partial fail' },
|
|
177
|
-
fields: ['status'],
|
|
178
|
-
})}\n`,
|
|
179
|
-
]);
|
|
180
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true })).rejects.toThrow('partial fail');
|
|
181
|
-
});
|
|
182
|
-
it('should reject when partial stream reports cancellation', async () => {
|
|
183
|
-
setupStreamMocks([
|
|
184
|
-
`${JSON.stringify({
|
|
185
|
-
data: { status: TaskStatusCancelled, id: 'task-1' },
|
|
186
|
-
fields: ['status'],
|
|
187
|
-
})}\n`,
|
|
188
|
-
]);
|
|
189
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true })).rejects.toThrow('task cancelled');
|
|
190
|
-
});
|
|
191
|
-
it('should reject when the NDJSON stream connection fails', async () => {
|
|
192
|
-
mockFetch.mockImplementation((url) => {
|
|
193
|
-
if (url.includes('/apps/run')) {
|
|
194
|
-
return Promise.resolve({
|
|
195
|
-
ok: true,
|
|
196
|
-
status: 200,
|
|
197
|
-
text: () => Promise.resolve(JSON.stringify(makeTask())),
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
return Promise.resolve({
|
|
201
|
-
ok: false,
|
|
202
|
-
status: 503,
|
|
203
|
-
text: () => Promise.resolve('service unavailable'),
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
await expect(api().run({ app: 'test-app', input: {} }, {}, { wait: true })).rejects.toThrow('HTTP 503');
|
|
207
|
-
});
|
|
208
|
-
it('should handle partial updates via onPartialUpdate', async () => {
|
|
209
|
-
setupStreamMocks([
|
|
210
|
-
`${JSON.stringify({
|
|
211
|
-
data: { status: TaskStatusCompleted, id: 'task-1', session_id: 'sess-1' },
|
|
212
|
-
fields: ['status'],
|
|
213
|
-
})}\n`,
|
|
214
|
-
]);
|
|
215
|
-
const onPartialUpdate = jest.fn();
|
|
216
|
-
const result = await api().run({ app: 'test-app', input: {} }, {}, { wait: true, onPartialUpdate });
|
|
217
|
-
expect(result.status).toBe(TaskStatusCompleted);
|
|
218
|
-
expect(onPartialUpdate).toHaveBeenCalledWith(expect.objectContaining({ id: 'task-1', status: TaskStatusCompleted }), ['status']);
|
|
219
|
-
});
|
|
220
|
-
it('should preserve session_id across partial stream updates that omit it', async () => {
|
|
221
|
-
setupStreamMocks([
|
|
222
|
-
`${JSON.stringify({
|
|
223
|
-
data: { status: TaskStatusRunning, id: 'task-1' },
|
|
224
|
-
fields: ['status'],
|
|
225
|
-
})}\n`,
|
|
226
|
-
`${JSON.stringify({
|
|
227
|
-
data: { status: TaskStatusCompleted, id: 'task-1', output: { ok: true } },
|
|
228
|
-
fields: ['status', 'output'],
|
|
229
|
-
})}\n`,
|
|
230
|
-
], makeTask({ session_id: 'sess-persist' }));
|
|
231
|
-
const onPartialUpdate = jest.fn();
|
|
232
|
-
const result = await api().run({ app: 'test-app', input: {} }, {}, { wait: true, onPartialUpdate });
|
|
233
|
-
expect(result.session_id).toBe('sess-persist');
|
|
234
|
-
expect(onPartialUpdate).toHaveBeenCalledWith(expect.objectContaining({ session_id: 'sess-persist', status: TaskStatusRunning }), ['status']);
|
|
235
|
-
expect(onPartialUpdate).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
236
|
-
session_id: 'sess-persist',
|
|
237
|
-
status: TaskStatusCompleted,
|
|
238
|
-
output: { ok: true },
|
|
239
|
-
}), ['status', 'output']);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
describe('TasksAPI.run (HTTP contract)', () => {
|
|
243
|
-
beforeEach(() => {
|
|
244
|
-
jest.clearAllMocks();
|
|
245
|
-
});
|
|
246
|
-
const api = () => new TasksAPI(new HttpClient({ apiKey: 'test-key' }));
|
|
247
|
-
it('should POST /apps/run with merged params and processedInput', async () => {
|
|
248
|
-
const task = makeTask();
|
|
249
|
-
mockJsonResponse(task);
|
|
250
|
-
const result = await api().run({ app: 'image-gen', version_id: 'ver-2', input: {} }, { prompt: 'sunset', width: 512 }, { wait: false });
|
|
251
|
-
expect(result).toEqual(task);
|
|
252
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
253
|
-
expect(url).toContain('/apps/run');
|
|
254
|
-
expect(init.method).toBe('POST');
|
|
255
|
-
expect(JSON.parse(init.body)).toEqual({
|
|
256
|
-
app: 'image-gen',
|
|
257
|
-
version_id: 'ver-2',
|
|
258
|
-
input: { prompt: 'sunset', width: 512 },
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
describe('TasksAPI.create', () => {
|
|
263
|
-
beforeEach(() => {
|
|
264
|
-
jest.clearAllMocks();
|
|
265
|
-
});
|
|
266
|
-
const api = () => new TasksAPI(new HttpClient({ apiKey: 'test-key' }));
|
|
267
|
-
it('should POST /apps/run for create()', async () => {
|
|
268
|
-
const task = makeTask();
|
|
269
|
-
mockJsonResponse(task);
|
|
270
|
-
const result = await api().create({ app: 'test-app', input: { prompt: 'hi' } });
|
|
271
|
-
expect(result).toEqual(task);
|
|
272
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
273
|
-
expect(url).toContain('/apps/run');
|
|
274
|
-
expect(init.method).toBe('POST');
|
|
275
|
-
expect(JSON.parse(init.body)).toEqual({
|
|
276
|
-
app: 'test-app',
|
|
277
|
-
input: { prompt: 'hi' },
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
describe('TasksAPI (CRUD and admin)', () => {
|
|
282
|
-
beforeEach(() => {
|
|
283
|
-
jest.clearAllMocks();
|
|
284
|
-
});
|
|
285
|
-
const api = () => new TasksAPI(new HttpClient({ apiKey: 'test-key' }));
|
|
286
|
-
it('should POST /tasks/list for list()', async () => {
|
|
287
|
-
const page = { items: [{ id: 'task-1' }], next_cursor: null };
|
|
288
|
-
mockJsonResponse(page);
|
|
289
|
-
const result = await api().list({ limit: 5 });
|
|
290
|
-
expect(result).toEqual(page);
|
|
291
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
292
|
-
expect(url).toContain('/tasks/list');
|
|
293
|
-
expect(init.method).toBe('POST');
|
|
294
|
-
expect(JSON.parse(init.body)).toEqual({ limit: 5 });
|
|
295
|
-
});
|
|
296
|
-
it('should GET /tasks/featured for listFeatured()', async () => {
|
|
297
|
-
const page = { items: [{ id: 'task-f' }], next_cursor: null };
|
|
298
|
-
mockJsonResponse(page);
|
|
299
|
-
const result = await api().listFeatured({ cursor: 'abc' });
|
|
300
|
-
expect(result).toEqual(page);
|
|
301
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
302
|
-
expect(url).toContain('/tasks/featured');
|
|
303
|
-
expect(init.method).toBe('GET');
|
|
304
|
-
});
|
|
305
|
-
it('should GET /tasks/{id} for get()', async () => {
|
|
306
|
-
const task = makeTask();
|
|
307
|
-
mockJsonResponse(task);
|
|
308
|
-
const result = await api().get('task-1');
|
|
309
|
-
expect(result).toEqual(task);
|
|
310
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
311
|
-
expect(url).toContain('/tasks/task-1');
|
|
312
|
-
expect(init.method).toBe('GET');
|
|
313
|
-
});
|
|
314
|
-
it('should DELETE /tasks/{id} for delete()', async () => {
|
|
315
|
-
mockJsonResponse(null);
|
|
316
|
-
await api().delete('task-1');
|
|
317
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
318
|
-
expect(url).toContain('/tasks/task-1');
|
|
319
|
-
expect(init.method).toBe('DELETE');
|
|
320
|
-
});
|
|
321
|
-
it('should POST /tasks/{id}/cancel for cancel()', async () => {
|
|
322
|
-
mockJsonResponse(null);
|
|
323
|
-
await api().cancel('task-1');
|
|
324
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
325
|
-
expect(url).toContain('/tasks/task-1/cancel');
|
|
326
|
-
expect(init.method).toBe('POST');
|
|
327
|
-
});
|
|
328
|
-
it('should POST visibility for updateVisibility()', async () => {
|
|
329
|
-
const task = makeTask({ visibility: 'public' });
|
|
330
|
-
mockJsonResponse(task);
|
|
331
|
-
const result = await api().updateVisibility('task-1', 'public');
|
|
332
|
-
expect(result).toEqual(task);
|
|
333
|
-
const [, init] = mockFetch.mock.calls[0];
|
|
334
|
-
expect(JSON.parse(init.body)).toEqual({ visibility: 'public' });
|
|
335
|
-
});
|
|
336
|
-
it('should POST is_featured for feature()', async () => {
|
|
337
|
-
const task = makeTask({ is_featured: true });
|
|
338
|
-
mockJsonResponse(task);
|
|
339
|
-
await api().feature('task-1', true);
|
|
340
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
341
|
-
expect(url).toContain('/tasks/task-1/featured');
|
|
342
|
-
expect(JSON.parse(init.body)).toEqual({ is_featured: true });
|
|
343
|
-
});
|
|
344
|
-
it('should open SSE on /tasks/{id}/stream for stream()', async () => {
|
|
345
|
-
const http = new HttpClient({ apiKey: 'test-key' });
|
|
346
|
-
const createEventSource = jest
|
|
347
|
-
.spyOn(http, 'createEventSource')
|
|
348
|
-
.mockResolvedValue(null);
|
|
349
|
-
const tasks = new TasksAPI(http);
|
|
350
|
-
await tasks.stream('task-42');
|
|
351
|
-
expect(createEventSource).toHaveBeenCalledWith('/tasks/task-42/stream');
|
|
352
|
-
createEventSource.mockRestore();
|
|
353
|
-
});
|
|
354
|
-
it('should GET /tasks/{id}/logs for getLogs()', async () => {
|
|
355
|
-
const logs = { logs: [{ message: 'started', timestamp: '2026-01-01T00:00:00Z' }] };
|
|
356
|
-
mockJsonResponse(logs);
|
|
357
|
-
const result = await api().getLogs('task-1');
|
|
358
|
-
expect(result).toEqual(logs);
|
|
359
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
360
|
-
expect(url).toContain('/tasks/task-1/logs');
|
|
361
|
-
expect(init.method).toBe('GET');
|
|
362
|
-
});
|
|
363
|
-
it('should GET /tasks/{id}/timings for getTimings()', async () => {
|
|
364
|
-
const timings = { total_ms: 1200, stages: [{ name: 'inference', ms: 900 }] };
|
|
365
|
-
mockJsonResponse(timings);
|
|
366
|
-
const result = await api().getTimings('task-1');
|
|
367
|
-
expect(result).toEqual(timings);
|
|
368
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
369
|
-
expect(url).toContain('/tasks/task-1/timings');
|
|
370
|
-
expect(init.method).toBe('GET');
|
|
371
|
-
});
|
|
372
|
-
it('should GET /tasks/{id}/telemetry for getTelemetry()', async () => {
|
|
373
|
-
const telemetry = [{ metric: 'gpu_util', value: 0.82 }];
|
|
374
|
-
mockJsonResponse(telemetry);
|
|
375
|
-
const result = await api().getTelemetry('task-1');
|
|
376
|
-
expect(result).toEqual(telemetry);
|
|
377
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
378
|
-
expect(url).toContain('/tasks/task-1/telemetry');
|
|
379
|
-
expect(init.method).toBe('GET');
|
|
380
|
-
});
|
|
381
|
-
});
|
package/dist/api/teams.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/api/teams.test.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from '../http/client';
|
|
2
|
-
import { TeamsAPI } from './teams';
|
|
3
|
-
const mockFetch = jest.fn();
|
|
4
|
-
global.fetch = mockFetch;
|
|
5
|
-
function mockJsonResponse(body) {
|
|
6
|
-
mockFetch.mockResolvedValueOnce({
|
|
7
|
-
ok: true,
|
|
8
|
-
status: 200,
|
|
9
|
-
text: () => Promise.resolve(JSON.stringify(body)),
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
describe('TeamsAPI', () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
jest.clearAllMocks();
|
|
15
|
-
});
|
|
16
|
-
const api = () => new TeamsAPI(new HttpClient({ apiKey: 'test-key' }));
|
|
17
|
-
it('should GET /me for me()', async () => {
|
|
18
|
-
const me = { user: { id: 'user-1' }, team: { id: 'team-1' } };
|
|
19
|
-
mockJsonResponse(me);
|
|
20
|
-
const result = await api().me();
|
|
21
|
-
expect(result).toEqual(me);
|
|
22
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
23
|
-
expect(url).toContain('/me');
|
|
24
|
-
expect(init.method).toBe('GET');
|
|
25
|
-
});
|
|
26
|
-
it('should GET /teams for list()', async () => {
|
|
27
|
-
const teams = [{ id: 'team-1', name: 'Acme' }];
|
|
28
|
-
mockJsonResponse(teams);
|
|
29
|
-
const result = await api().list();
|
|
30
|
-
expect(result).toEqual(teams);
|
|
31
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
32
|
-
expect(url).toContain('/teams');
|
|
33
|
-
expect(init.method).toBe('GET');
|
|
34
|
-
});
|
|
35
|
-
it('should POST /teams for create()', async () => {
|
|
36
|
-
const payload = { name: 'New Team', username: 'new-team' };
|
|
37
|
-
const team = { id: 'team-new', ...payload };
|
|
38
|
-
mockJsonResponse(team);
|
|
39
|
-
const result = await api().create(payload);
|
|
40
|
-
expect(result).toEqual(team);
|
|
41
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
42
|
-
expect(url).toContain('/teams');
|
|
43
|
-
expect(init.method).toBe('POST');
|
|
44
|
-
expect(JSON.parse(init.body)).toEqual(payload);
|
|
45
|
-
});
|
|
46
|
-
it('should GET /teams/check-username with username param for checkUsername()', async () => {
|
|
47
|
-
mockJsonResponse({ available: true });
|
|
48
|
-
const result = await api().checkUsername('acme-corp');
|
|
49
|
-
expect(result).toEqual({ available: true });
|
|
50
|
-
const [url] = mockFetch.mock.calls[0];
|
|
51
|
-
expect(url).toContain('/teams/check-username');
|
|
52
|
-
expect(url).toContain('username=acme-corp');
|
|
53
|
-
});
|
|
54
|
-
it('should POST role for updateMemberRole()', async () => {
|
|
55
|
-
const member = { user_id: 'user-2', role: 'admin' };
|
|
56
|
-
mockJsonResponse(member);
|
|
57
|
-
await api().updateMemberRole('team-1', 'user-2', 'admin');
|
|
58
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
59
|
-
expect(url).toContain('/teams/team-1/members/user-2/role');
|
|
60
|
-
expect(JSON.parse(init.body)).toEqual({ role: 'admin' });
|
|
61
|
-
});
|
|
62
|
-
it('should DELETE /teams/{id}/members/{userId} for removeMember()', async () => {
|
|
63
|
-
mockJsonResponse(null);
|
|
64
|
-
await api().removeMember('team-1', 'user-3');
|
|
65
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
66
|
-
expect(url).toContain('/teams/team-1/members/user-3');
|
|
67
|
-
expect(init.method).toBe('DELETE');
|
|
68
|
-
});
|
|
69
|
-
it('should POST /teams/{id}/invites for createInvite()', async () => {
|
|
70
|
-
const payload = { email: 'dev@example.com', role: 'member' };
|
|
71
|
-
const invite = { id: 'inv-1', ...payload };
|
|
72
|
-
mockJsonResponse(invite);
|
|
73
|
-
const result = await api().createInvite('team-1', payload);
|
|
74
|
-
expect(result).toEqual(invite);
|
|
75
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
76
|
-
expect(url).toContain('/teams/team-1/invites');
|
|
77
|
-
expect(JSON.parse(init.body)).toEqual(payload);
|
|
78
|
-
});
|
|
79
|
-
it('should GET /teams/{id} for get()', async () => {
|
|
80
|
-
const team = { id: 'team-1', name: 'Acme' };
|
|
81
|
-
mockJsonResponse(team);
|
|
82
|
-
const result = await api().get('team-1');
|
|
83
|
-
expect(result).toEqual(team);
|
|
84
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
85
|
-
expect(url).toContain('/teams/team-1');
|
|
86
|
-
expect(init.method).toBe('GET');
|
|
87
|
-
});
|
|
88
|
-
it('should POST /teams/{id} for update()', async () => {
|
|
89
|
-
const team = { id: 'team-1', name: 'Acme Updated' };
|
|
90
|
-
mockJsonResponse(team);
|
|
91
|
-
const result = await api().update('team-1', { name: 'Acme Updated' });
|
|
92
|
-
expect(result).toEqual(team);
|
|
93
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
94
|
-
expect(url).toContain('/teams/team-1');
|
|
95
|
-
expect(JSON.parse(init.body)).toEqual({ name: 'Acme Updated' });
|
|
96
|
-
});
|
|
97
|
-
it('should DELETE /teams/{id} for delete()', async () => {
|
|
98
|
-
mockJsonResponse(null);
|
|
99
|
-
await api().delete('team-1');
|
|
100
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
101
|
-
expect(url).toContain('/teams/team-1');
|
|
102
|
-
expect(init.method).toBe('DELETE');
|
|
103
|
-
});
|
|
104
|
-
it('should GET /teams/{id}/members for getMembers()', async () => {
|
|
105
|
-
const members = [{ user_id: 'user-1', role: 'owner' }];
|
|
106
|
-
mockJsonResponse(members);
|
|
107
|
-
const result = await api().getMembers('team-1');
|
|
108
|
-
expect(result).toEqual(members);
|
|
109
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
110
|
-
expect(url).toContain('/teams/team-1/members');
|
|
111
|
-
expect(init.method).toBe('GET');
|
|
112
|
-
});
|
|
113
|
-
it('should POST /teams/{id}/members for addMember()', async () => {
|
|
114
|
-
const payload = { user_id: 'user-4', role: 'member' };
|
|
115
|
-
const member = { ...payload };
|
|
116
|
-
mockJsonResponse(member);
|
|
117
|
-
const result = await api().addMember('team-1', payload);
|
|
118
|
-
expect(result).toEqual(member);
|
|
119
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
120
|
-
expect(url).toContain('/teams/team-1/members');
|
|
121
|
-
expect(JSON.parse(init.body)).toEqual(payload);
|
|
122
|
-
});
|
|
123
|
-
it('should GET /teams/{id}/invites for listInvites()', async () => {
|
|
124
|
-
const invites = [{ id: 'inv-1', email: 'dev@example.com' }];
|
|
125
|
-
mockJsonResponse(invites);
|
|
126
|
-
const result = await api().listInvites('team-1');
|
|
127
|
-
expect(result).toEqual(invites);
|
|
128
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
129
|
-
expect(url).toContain('/teams/team-1/invites');
|
|
130
|
-
expect(init.method).toBe('GET');
|
|
131
|
-
});
|
|
132
|
-
it('should DELETE /teams/{id}/invites/{inviteId} for revokeInvite()', async () => {
|
|
133
|
-
mockJsonResponse(null);
|
|
134
|
-
await api().revokeInvite('team-1', 'inv-9');
|
|
135
|
-
const [url, init] = mockFetch.mock.calls[0];
|
|
136
|
-
expect(url).toContain('/teams/team-1/invites/inv-9');
|
|
137
|
-
expect(init.method).toBe('DELETE');
|
|
138
|
-
});
|
|
139
|
-
});
|
package/dist/client.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|