@inferencesh/sdk 0.6.10 → 0.6.13

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 (75) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/actions.js +3 -3
  3. package/dist/agent/actions.test.js +231 -1
  4. package/dist/agent/api.test.js +18 -1
  5. package/dist/api/agents.d.ts +10 -0
  6. package/dist/api/agents.js +17 -3
  7. package/dist/api/agents.test.js +500 -0
  8. package/dist/api/api-keys.d.ts +24 -0
  9. package/dist/api/api-keys.js +26 -0
  10. package/dist/api/api-keys.test.d.ts +1 -0
  11. package/dist/api/api-keys.test.js +44 -0
  12. package/dist/api/apps.js +1 -1
  13. package/dist/api/apps.test.js +71 -3
  14. package/dist/api/chats.d.ts +14 -0
  15. package/dist/api/chats.js +18 -0
  16. package/dist/api/chats.test.js +52 -0
  17. package/dist/api/engines.d.ts +12 -0
  18. package/dist/api/engines.js +18 -0
  19. package/dist/api/engines.test.js +78 -0
  20. package/dist/api/files.test.js +183 -0
  21. package/dist/api/flow-runs.test.js +42 -0
  22. package/dist/api/flows.d.ts +4 -0
  23. package/dist/api/flows.js +6 -0
  24. package/dist/api/flows.test.js +75 -0
  25. package/dist/api/integrations.d.ts +41 -0
  26. package/dist/api/integrations.js +56 -0
  27. package/dist/api/integrations.test.d.ts +1 -0
  28. package/dist/api/integrations.test.js +109 -0
  29. package/dist/api/knowledge.d.ts +112 -0
  30. package/dist/api/knowledge.js +163 -0
  31. package/dist/api/knowledge.test.d.ts +1 -0
  32. package/dist/api/knowledge.test.js +238 -0
  33. package/dist/api/mcp-servers.d.ts +45 -0
  34. package/dist/api/mcp-servers.js +62 -0
  35. package/dist/api/mcp-servers.test.d.ts +1 -0
  36. package/dist/api/mcp-servers.test.js +98 -0
  37. package/dist/api/projects.d.ts +29 -0
  38. package/dist/api/projects.js +38 -0
  39. package/dist/api/projects.test.d.ts +1 -0
  40. package/dist/api/projects.test.js +61 -0
  41. package/dist/api/search.d.ts +21 -0
  42. package/dist/api/search.js +20 -0
  43. package/dist/api/search.test.d.ts +1 -0
  44. package/dist/api/search.test.js +39 -0
  45. package/dist/api/secrets.d.ts +29 -0
  46. package/dist/api/secrets.js +38 -0
  47. package/dist/api/secrets.test.d.ts +1 -0
  48. package/dist/api/secrets.test.js +61 -0
  49. package/dist/api/sessions.test.js +12 -0
  50. package/dist/api/tasks.d.ts +13 -1
  51. package/dist/api/tasks.js +18 -0
  52. package/dist/api/tasks.test.js +171 -0
  53. package/dist/api/teams.d.ts +71 -0
  54. package/dist/api/teams.js +92 -0
  55. package/dist/api/teams.test.d.ts +1 -0
  56. package/dist/api/teams.test.js +139 -0
  57. package/dist/client.test.js +112 -1
  58. package/dist/http/client.d.ts +5 -0
  59. package/dist/http/client.js +42 -23
  60. package/dist/http/client.test.js +245 -0
  61. package/dist/http/errors.test.js +13 -0
  62. package/dist/index.d.ts +25 -0
  63. package/dist/index.js +25 -0
  64. package/dist/proxy/hono.test.d.ts +1 -0
  65. package/dist/proxy/hono.test.js +90 -0
  66. package/dist/proxy/nextjs.test.d.ts +1 -0
  67. package/dist/proxy/nextjs.test.js +125 -0
  68. package/dist/proxy/remix.test.d.ts +1 -0
  69. package/dist/proxy/remix.test.js +66 -0
  70. package/dist/proxy/svelte.test.d.ts +1 -0
  71. package/dist/proxy/svelte.test.js +69 -0
  72. package/dist/tool-builder.test.js +11 -1
  73. package/dist/types.d.ts +110 -5
  74. package/dist/types.js +58 -2
  75. package/package.json +6 -6
@@ -48,12 +48,13 @@ describe('AppsAPI', () => {
48
48
  const [, init] = mockFetch.mock.calls[0];
49
49
  expect(JSON.parse(init.body)).toEqual({ license: 'key-abc' });
50
50
  });
51
- it('should POST version_id for setCurrentVersion()', async () => {
51
+ it('should PUT /apps/{id}/versions/{versionId}/current for setCurrentVersion()', async () => {
52
52
  const app = { id: 'app-1', current_version_id: 'ver-2' };
53
53
  mockJsonResponse(app);
54
54
  await api().setCurrentVersion('app-1', 'ver-2');
55
- const [, init] = mockFetch.mock.calls[0];
56
- expect(JSON.parse(init.body)).toEqual({ version_id: 'ver-2' });
55
+ const [url, init] = mockFetch.mock.calls[0];
56
+ expect(url).toContain('/apps/app-1/versions/ver-2/current');
57
+ expect(init.method).toBe('PUT');
57
58
  });
58
59
  it('should POST /apps/{id}/duplicate for duplicate()', async () => {
59
60
  const app = { id: 'app-copy' };
@@ -64,4 +65,71 @@ describe('AppsAPI', () => {
64
65
  expect(url).toContain('/apps/app-1/duplicate');
65
66
  expect(init.method).toBe('POST');
66
67
  });
68
+ it('should GET /apps/{id} for get()', async () => {
69
+ const app = { id: 'app-1', name: 'demo' };
70
+ mockJsonResponse(app);
71
+ const result = await api().get('app-1');
72
+ expect(result).toEqual(app);
73
+ const [url, init] = mockFetch.mock.calls[0];
74
+ expect(url).toContain('/apps/app-1');
75
+ expect(init.method).toBe('GET');
76
+ });
77
+ it('should GET versioned app for getByVersionId()', async () => {
78
+ const app = { id: 'app-1', version_id: 'ver-1' };
79
+ mockJsonResponse(app);
80
+ const result = await api().getByVersionId('app-1', 'ver-1');
81
+ expect(result).toEqual(app);
82
+ const [url] = mockFetch.mock.calls[0];
83
+ expect(url).toContain('/apps/app-1/versions/ver-1');
84
+ });
85
+ it('should POST /apps for create()', async () => {
86
+ const app = { id: 'app-new', name: 'New App' };
87
+ mockJsonResponse(app);
88
+ const result = await api().create({ name: 'New App' });
89
+ expect(result).toEqual(app);
90
+ const [url, init] = mockFetch.mock.calls[0];
91
+ expect(url).toContain('/apps');
92
+ expect(init.method).toBe('POST');
93
+ expect(JSON.parse(init.body)).toEqual({ name: 'New App' });
94
+ });
95
+ it('should POST /apps/{id} for update()', async () => {
96
+ const app = { id: 'app-1', description: 'updated' };
97
+ mockJsonResponse(app);
98
+ const result = await api().update('app-1', { description: 'updated' });
99
+ expect(result).toEqual(app);
100
+ const [url, init] = mockFetch.mock.calls[0];
101
+ expect(url).toContain('/apps/app-1');
102
+ expect(JSON.parse(init.body)).toEqual({ description: 'updated' });
103
+ });
104
+ it('should DELETE /apps/{id} for delete()', async () => {
105
+ mockJsonResponse(null);
106
+ await api().delete('app-1');
107
+ const [url, init] = mockFetch.mock.calls[0];
108
+ expect(url).toContain('/apps/app-1');
109
+ expect(init.method).toBe('DELETE');
110
+ });
111
+ it('should POST /apps/{id}/versions/list for listVersions()', async () => {
112
+ const versions = { items: [{ id: 'ver-1' }], next_cursor: null };
113
+ mockJsonResponse(versions);
114
+ const result = await api().listVersions('app-1', { limit: 20 });
115
+ expect(result).toEqual(versions);
116
+ const [url, init] = mockFetch.mock.calls[0];
117
+ expect(url).toContain('/apps/app-1/versions/list');
118
+ expect(JSON.parse(init.body)).toEqual({ limit: 20 });
119
+ });
120
+ it('should POST visibility for updateVisibility()', async () => {
121
+ const app = { id: 'app-1', visibility: 'private' };
122
+ mockJsonResponse(app);
123
+ await api().updateVisibility('app-1', 'private');
124
+ const [, init] = mockFetch.mock.calls[0];
125
+ expect(JSON.parse(init.body)).toEqual({ visibility: 'private' });
126
+ });
127
+ it('should GET /apps/{id}/license for getLicense()', async () => {
128
+ const license = { app_id: 'app-1', license: 'MIT' };
129
+ mockJsonResponse(license);
130
+ const result = await api().getLicense('app-1');
131
+ expect(result).toEqual(license);
132
+ const [url] = mockFetch.mock.calls[0];
133
+ expect(url).toContain('/apps/app-1/license');
134
+ });
67
135
  });
@@ -26,5 +26,19 @@ export declare class ChatsAPI {
26
26
  * Get chat trace (for debugging/observability)
27
27
  */
28
28
  getTrace(chatId: string): Promise<ChatTraceDTO>;
29
+ /**
30
+ * Get chat status
31
+ */
32
+ getStatus(chatId: string): Promise<{
33
+ status: string;
34
+ }>;
35
+ /**
36
+ * Stop chat generation
37
+ */
38
+ stop(chatId: string): Promise<void>;
39
+ /**
40
+ * Stream chat updates
41
+ */
42
+ stream(chatId: string): Promise<import("eventsource").EventSource | null>;
29
43
  }
30
44
  export declare function createChatsAPI(http: HttpClient): ChatsAPI;
package/dist/api/chats.js CHANGED
@@ -35,6 +35,24 @@ export class ChatsAPI {
35
35
  async getTrace(chatId) {
36
36
  return this.http.request('get', `/chats/${chatId}/trace`);
37
37
  }
38
+ /**
39
+ * Get chat status
40
+ */
41
+ async getStatus(chatId) {
42
+ return this.http.request('get', `/chats/${chatId}/status`);
43
+ }
44
+ /**
45
+ * Stop chat generation
46
+ */
47
+ async stop(chatId) {
48
+ return this.http.request('post', `/chats/${chatId}/stop`);
49
+ }
50
+ /**
51
+ * Stream chat updates
52
+ */
53
+ stream(chatId) {
54
+ return this.http.createEventSource(`/chats/${chatId}/stream`);
55
+ }
38
56
  }
39
57
  export function createChatsAPI(http) {
40
58
  return new ChatsAPI(http);
@@ -30,4 +30,56 @@ describe('ChatsAPI', () => {
30
30
  expect(url).toContain('/chats/chat-9');
31
31
  expect(init.method).toBe('DELETE');
32
32
  });
33
+ it('should POST /chats/list for list()', async () => {
34
+ const page = { items: [{ id: 'chat-1' }], next_cursor: null };
35
+ mockJsonResponse(page);
36
+ const result = await api().list({ limit: 25 });
37
+ expect(result).toEqual(page);
38
+ const [url, init] = mockFetch.mock.calls[0];
39
+ expect(url).toContain('/chats/list');
40
+ expect(init.method).toBe('POST');
41
+ expect(JSON.parse(init.body)).toEqual({ limit: 25 });
42
+ });
43
+ it('should GET /chats/{id} for get()', async () => {
44
+ const chat = { id: 'chat-1', status: 'open' };
45
+ mockJsonResponse(chat);
46
+ const result = await api().get('chat-1');
47
+ expect(result).toEqual(chat);
48
+ const [url, init] = mockFetch.mock.calls[0];
49
+ expect(url).toContain('/chats/chat-1');
50
+ expect(init.method).toBe('GET');
51
+ });
52
+ it('should POST /chats/{id} for update()', async () => {
53
+ const chat = { id: 'chat-1', name: 'Renamed' };
54
+ mockJsonResponse(chat);
55
+ const result = await api().update('chat-1', { name: 'Renamed' });
56
+ expect(result).toEqual(chat);
57
+ const [, init] = mockFetch.mock.calls[0];
58
+ expect(JSON.parse(init.body)).toEqual({ name: 'Renamed' });
59
+ });
60
+ it('should GET /chats/{id}/status for getStatus()', async () => {
61
+ mockJsonResponse({ status: 'busy' });
62
+ const result = await api().getStatus('chat-1');
63
+ expect(result).toEqual({ status: 'busy' });
64
+ const [url, init] = mockFetch.mock.calls[0];
65
+ expect(url).toContain('/chats/chat-1/status');
66
+ expect(init.method).toBe('GET');
67
+ });
68
+ it('should POST /chats/{id}/stop for stop()', async () => {
69
+ mockJsonResponse(null);
70
+ await api().stop('chat-1');
71
+ const [url, init] = mockFetch.mock.calls[0];
72
+ expect(url).toContain('/chats/chat-1/stop');
73
+ expect(init.method).toBe('POST');
74
+ });
75
+ it('should open SSE on /chats/{id}/stream for stream()', async () => {
76
+ const http = new HttpClient({ apiKey: 'test-key' });
77
+ const createEventSource = jest
78
+ .spyOn(http, 'createEventSource')
79
+ .mockResolvedValue(null);
80
+ const chats = new ChatsAPI(http);
81
+ await chats.stream('chat-42');
82
+ expect(createEventSource).toHaveBeenCalledWith('/chats/chat-42/stream');
83
+ createEventSource.mockRestore();
84
+ });
33
85
  });
@@ -53,5 +53,17 @@ export declare class EnginesAPI {
53
53
  * Transfer engine ownership
54
54
  */
55
55
  transferOwnership(engineId: string, newTeamId: string): Promise<Engine>;
56
+ /**
57
+ * Extend engine duration
58
+ */
59
+ extend(engineId: string): Promise<void>;
60
+ /**
61
+ * Drain an engine
62
+ */
63
+ drain(engineId: string): Promise<void>;
64
+ /**
65
+ * Update an engine binary (drain + restart with new version)
66
+ */
67
+ updateBinary(engineId: string): Promise<void>;
56
68
  }
57
69
  export declare function createEnginesAPI(http: HttpClient): EnginesAPI;
@@ -71,6 +71,24 @@ export class EnginesAPI {
71
71
  async transferOwnership(engineId, newTeamId) {
72
72
  return this.http.request('post', `/engines/${engineId}/transfer`, { data: { team_id: newTeamId } });
73
73
  }
74
+ /**
75
+ * Extend engine duration
76
+ */
77
+ async extend(engineId) {
78
+ return this.http.request('post', `/engines/${engineId}/extend`);
79
+ }
80
+ /**
81
+ * Drain an engine
82
+ */
83
+ async drain(engineId) {
84
+ return this.http.request('post', `/engines/${engineId}/drain`);
85
+ }
86
+ /**
87
+ * Update an engine binary (drain + restart with new version)
88
+ */
89
+ async updateBinary(engineId) {
90
+ return this.http.request('post', `/engines/${engineId}/update`);
91
+ }
74
92
  }
75
93
  export function createEnginesAPI(http) {
76
94
  return new EnginesAPI(http);
@@ -52,4 +52,82 @@ describe('EnginesAPI', () => {
52
52
  expect(createEventSource).toHaveBeenCalledWith('/engines/eng-7/stream');
53
53
  createEventSource.mockRestore();
54
54
  });
55
+ it('should POST /engines/list for list()', async () => {
56
+ const page = { items: [{ id: 'eng-1' }], next_cursor: null };
57
+ mockJsonResponse(page);
58
+ const result = await api().list();
59
+ expect(result).toEqual(page);
60
+ const [url, init] = mockFetch.mock.calls[0];
61
+ expect(url).toContain('/engines/list');
62
+ expect(init.method).toBe('POST');
63
+ });
64
+ it('should GET /engines/{id} for get()', async () => {
65
+ const engine = { id: 'eng-1' };
66
+ mockJsonResponse(engine);
67
+ const result = await api().get('eng-1');
68
+ expect(result).toEqual(engine);
69
+ const [url, init] = mockFetch.mock.calls[0];
70
+ expect(url).toContain('/engines/eng-1');
71
+ expect(init.method).toBe('GET');
72
+ });
73
+ it('should POST /engines for create()', async () => {
74
+ const engine = { id: 'eng-new', name: 'worker' };
75
+ mockJsonResponse(engine);
76
+ const result = await api().create({ name: 'worker' });
77
+ expect(result).toEqual(engine);
78
+ const [url, init] = mockFetch.mock.calls[0];
79
+ expect(url).toContain('/engines');
80
+ expect(init.method).toBe('POST');
81
+ expect(JSON.parse(init.body)).toEqual({ name: 'worker' });
82
+ });
83
+ it('should POST /engines/{id} for update()', async () => {
84
+ const engine = { id: 'eng-1', name: 'updated' };
85
+ mockJsonResponse(engine);
86
+ const result = await api().update('eng-1', { name: 'updated' });
87
+ expect(result).toEqual(engine);
88
+ const [, init] = mockFetch.mock.calls[0];
89
+ expect(JSON.parse(init.body)).toEqual({ name: 'updated' });
90
+ });
91
+ it('should DELETE /engines/{id} for delete()', async () => {
92
+ mockJsonResponse(null);
93
+ await api().delete('eng-1');
94
+ const [url, init] = mockFetch.mock.calls[0];
95
+ expect(url).toContain('/engines/eng-1');
96
+ expect(init.method).toBe('DELETE');
97
+ });
98
+ it('should POST visibility for updateVisibility()', async () => {
99
+ const engine = { id: 'eng-1', visibility: 'team' };
100
+ mockJsonResponse(engine);
101
+ await api().updateVisibility('eng-1', 'team');
102
+ const [, init] = mockFetch.mock.calls[0];
103
+ expect(JSON.parse(init.body)).toEqual({ visibility: 'team' });
104
+ });
105
+ it('should POST transfer with team_id for transferOwnership()', async () => {
106
+ const engine = { id: 'eng-1' };
107
+ mockJsonResponse(engine);
108
+ await api().transferOwnership('eng-1', 'team-7');
109
+ const [, init] = mockFetch.mock.calls[0];
110
+ expect(JSON.parse(init.body)).toEqual({ team_id: 'team-7' });
111
+ });
112
+ it('should POST /engines/{id}/extend for extend()', async () => {
113
+ mockJsonResponse(null);
114
+ await api().extend('eng-1');
115
+ const [url, init] = mockFetch.mock.calls[0];
116
+ expect(url).toContain('/engines/eng-1/extend');
117
+ expect(init.method).toBe('POST');
118
+ });
119
+ it('should POST /engines/{id}/drain for drain()', async () => {
120
+ mockJsonResponse(null);
121
+ await api().drain('eng-1');
122
+ const [url, init] = mockFetch.mock.calls[0];
123
+ expect(url).toContain('/engines/eng-1/drain');
124
+ expect(init.method).toBe('POST');
125
+ });
126
+ it('should POST /engines/{id}/update for updateBinary()', async () => {
127
+ mockJsonResponse(null);
128
+ await api().updateBinary('eng-1');
129
+ const [url, init] = mockFetch.mock.calls[0];
130
+ expect(url).toContain('/engines/eng-1/update');
131
+ expect(init.method).toBe('POST');
132
+ });
55
133
  });
@@ -14,6 +14,32 @@ describe('FilesAPI', () => {
14
14
  jest.clearAllMocks();
15
15
  });
16
16
  const api = () => new FilesAPI(new HttpClient({ apiKey: 'test-key' }));
17
+ it('should POST /files/list for list()', async () => {
18
+ const page = { items: [{ id: 'file-1' }], next_cursor: null };
19
+ mockJsonResponse(page);
20
+ const result = await api().list({ limit: 10 });
21
+ expect(result).toEqual(page);
22
+ const [url, init] = mockFetch.mock.calls[0];
23
+ expect(url).toContain('/files/list');
24
+ expect(init.method).toBe('POST');
25
+ expect(JSON.parse(init.body)).toEqual({ limit: 10 });
26
+ });
27
+ it('should GET /files/{id} for get()', async () => {
28
+ const file = { id: 'file-1', uri: 'inf://files/abc' };
29
+ mockJsonResponse(file);
30
+ const result = await api().get('file-1');
31
+ expect(result).toEqual(file);
32
+ const [url, init] = mockFetch.mock.calls[0];
33
+ expect(url).toContain('/files/file-1');
34
+ expect(init.method).toBe('GET');
35
+ });
36
+ it('should DELETE /files/{id} for delete()', async () => {
37
+ mockJsonResponse(null);
38
+ await api().delete('file-1');
39
+ const [url, init] = mockFetch.mock.calls[0];
40
+ expect(url).toContain('/files/file-1');
41
+ expect(init.method).toBe('DELETE');
42
+ });
17
43
  describe('processInput', () => {
18
44
  it('should not treat short plain strings as base64 file uploads', async () => {
19
45
  const result = await api().processInput({ key: 'key1', note: 'hello' });
@@ -38,12 +64,169 @@ describe('FilesAPI', () => {
38
64
  expect(result.image).toBe('inf://files/abc');
39
65
  expect(mockFetch).toHaveBeenCalledTimes(2);
40
66
  });
67
+ it('should upload top-level Blob values', async () => {
68
+ const fileRecord = {
69
+ id: 'file-blob',
70
+ uri: 'inf://files/blob',
71
+ upload_url: 'https://upload.example.com/put',
72
+ content_type: 'image/png',
73
+ };
74
+ mockJsonResponse([fileRecord]);
75
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
76
+ const blob = new Blob(['png-bytes'], { type: 'image/png' });
77
+ const result = await api().processInput(blob);
78
+ expect(result).toBe('inf://files/blob');
79
+ expect(mockFetch).toHaveBeenCalledTimes(2);
80
+ });
81
+ it('should process arrays recursively', async () => {
82
+ const fileRecord = {
83
+ id: 'file-arr',
84
+ uri: 'inf://files/arr',
85
+ upload_url: 'https://upload.example.com/put',
86
+ content_type: 'image/png',
87
+ };
88
+ mockJsonResponse([fileRecord]);
89
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
90
+ const input = ['plain', 'data:image/png;base64,iVBORw0KGgo='];
91
+ const result = (await api().processInput(input));
92
+ expect(result[0]).toBe('plain');
93
+ expect(result[1]).toBe('inf://files/arr');
94
+ });
95
+ it('should upload long raw base64 strings', async () => {
96
+ const fileRecord = {
97
+ id: 'file-b64',
98
+ uri: 'inf://files/b64',
99
+ upload_url: 'https://upload.example.com/put',
100
+ content_type: 'application/octet-stream',
101
+ };
102
+ mockJsonResponse([fileRecord]);
103
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
104
+ const rawBase64 = 'A'.repeat(64);
105
+ const result = await api().processInput(rawBase64);
106
+ expect(result).toBe('inf://files/b64');
107
+ expect(mockFetch).toHaveBeenCalledTimes(2);
108
+ });
41
109
  });
42
110
  describe('upload', () => {
43
111
  it('should reject invalid data URI format when uploading content', async () => {
44
112
  mockJsonResponse([{ id: 'file-x', uri: '', upload_url: 'https://upload.example.com/put' }]);
45
113
  await expect(api().upload('data:invalid')).rejects.toThrow('Invalid data URI format');
46
114
  });
115
+ it('should decode URL-encoded (non-base64) data URIs', async () => {
116
+ const fileRecord = {
117
+ id: 'file-3',
118
+ uri: 'inf://files/url-encoded',
119
+ upload_url: 'https://upload.example.com/put',
120
+ content_type: 'text/plain',
121
+ };
122
+ mockJsonResponse([fileRecord]);
123
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
124
+ const result = await api().upload('data:text/plain,Hello%20World');
125
+ expect(result.uri).toBe('inf://files/url-encoded');
126
+ const putCall = mockFetch.mock.calls[1];
127
+ expect(putCall[1]?.headers).toMatchObject({ 'Content-Type': 'text/plain' });
128
+ });
129
+ it('should default media type to text/plain for data URIs without explicit type', async () => {
130
+ const fileRecord = {
131
+ id: 'file-4',
132
+ uri: 'inf://files/default-mt',
133
+ upload_url: 'https://upload.example.com/put',
134
+ content_type: 'text/plain',
135
+ };
136
+ mockJsonResponse([fileRecord]);
137
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
138
+ await api().upload('data:;base64,SGVsbG8=');
139
+ const putCall = mockFetch.mock.calls[1];
140
+ expect(putCall[1]?.headers).toMatchObject({ 'Content-Type': 'text/plain' });
141
+ });
142
+ it('should throw when server does not return upload_url', async () => {
143
+ mockJsonResponse([{ id: 'file-x', uri: '', upload_url: undefined }]);
144
+ await expect(api().upload('data:text/plain,hello')).rejects.toThrow('No upload URL provided by the server');
145
+ });
146
+ it('should throw when PUT to upload_url fails', async () => {
147
+ const fileRecord = {
148
+ id: 'file-5',
149
+ uri: 'inf://files/fail-put',
150
+ upload_url: 'https://upload.example.com/put',
151
+ content_type: 'text/plain',
152
+ };
153
+ mockJsonResponse([fileRecord]);
154
+ mockFetch.mockResolvedValueOnce({
155
+ ok: false,
156
+ status: 500,
157
+ statusText: 'Internal Server Error',
158
+ });
159
+ await expect(api().upload('data:text/plain,hello')).rejects.toThrow('Failed to upload file content');
160
+ });
161
+ it('should upload Blob content with inferred content type and size', async () => {
162
+ const fileRecord = {
163
+ id: 'file-blob',
164
+ uri: 'inf://files/blob-direct',
165
+ upload_url: 'https://upload.example.com/put',
166
+ content_type: 'image/jpeg',
167
+ };
168
+ mockJsonResponse([fileRecord]);
169
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
170
+ const blob = new Blob(['jpeg-bytes'], { type: 'image/jpeg' });
171
+ const result = await api().upload(blob, { filename: 'photo.jpg' });
172
+ expect(result.uri).toBe('inf://files/blob-direct');
173
+ const [, createInit] = mockFetch.mock.calls[0];
174
+ const createBody = JSON.parse(createInit.body);
175
+ expect(createBody.files[0]).toMatchObject({
176
+ filename: 'photo.jpg',
177
+ content_type: 'image/jpeg',
178
+ size: blob.size,
179
+ });
180
+ const [, putInit] = mockFetch.mock.calls[1];
181
+ expect(putInit.method).toBe('PUT');
182
+ expect(putInit.body).toBe(blob);
183
+ expect(putInit.headers).toMatchObject({ 'Content-Type': 'image/jpeg' });
184
+ });
185
+ it('should extract filename from File objects when options.filename is omitted', async () => {
186
+ const fileRecord = {
187
+ id: 'file-named',
188
+ uri: 'inf://files/named',
189
+ upload_url: 'https://upload.example.com/put',
190
+ content_type: 'application/pdf',
191
+ };
192
+ mockJsonResponse([fileRecord]);
193
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
194
+ const file = new File(['pdf-bytes'], 'report.pdf', { type: 'application/pdf' });
195
+ await api().upload(file);
196
+ const [, createInit] = mockFetch.mock.calls[0];
197
+ const createBody = JSON.parse(createInit.body);
198
+ expect(createBody.files[0].filename).toBe('report.pdf');
199
+ expect(createBody.files[0].content_type).toBe('application/pdf');
200
+ });
201
+ it('should use explicit contentType when Blob type is empty', async () => {
202
+ const fileRecord = {
203
+ id: 'file-octet',
204
+ uri: 'inf://files/octet',
205
+ upload_url: 'https://upload.example.com/put',
206
+ content_type: 'application/octet-stream',
207
+ };
208
+ mockJsonResponse([fileRecord]);
209
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
210
+ const blob = new Blob(['raw']);
211
+ await api().upload(blob, { contentType: 'application/octet-stream' });
212
+ const [, createInit] = mockFetch.mock.calls[0];
213
+ const createBody = JSON.parse(createInit.body);
214
+ expect(createBody.files[0].content_type).toBe('application/octet-stream');
215
+ });
216
+ it('should upload clean base64 strings without a data URI prefix', async () => {
217
+ const fileRecord = {
218
+ id: 'file-b64-direct',
219
+ uri: 'inf://files/b64-direct',
220
+ upload_url: 'https://upload.example.com/put',
221
+ content_type: 'text/plain',
222
+ };
223
+ mockJsonResponse([fileRecord]);
224
+ mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
225
+ const result = await api().upload('SGVsbG8=', { contentType: 'text/plain' });
226
+ expect(result.uri).toBe('inf://files/b64-direct');
227
+ const [, putInit] = mockFetch.mock.calls[1];
228
+ expect(putInit.headers).toMatchObject({ 'Content-Type': 'text/plain' });
229
+ });
47
230
  it('should decode URL-safe base64 in data URIs', async () => {
48
231
  const fileRecord = {
49
232
  id: 'file-2',
@@ -52,4 +52,46 @@ describe('FlowRunsAPI', () => {
52
52
  expect(createEventSource).toHaveBeenCalledWith('/flowruns/fr-42/tasks/stream');
53
53
  createEventSource.mockRestore();
54
54
  });
55
+ it('should POST /flowruns/list for list()', async () => {
56
+ const page = { items: [{ id: 'fr-1' }], next_cursor: null };
57
+ mockJsonResponse(page);
58
+ const result = await api().list({ limit: 10 });
59
+ expect(result).toEqual(page);
60
+ const [url, init] = mockFetch.mock.calls[0];
61
+ expect(url).toContain('/flowruns/list');
62
+ expect(init.method).toBe('POST');
63
+ });
64
+ it('should GET /flowruns/{id} for get()', async () => {
65
+ const flowRun = { id: 'fr-1' };
66
+ mockJsonResponse(flowRun);
67
+ const result = await api().get('fr-1');
68
+ expect(result).toEqual(flowRun);
69
+ const [url, init] = mockFetch.mock.calls[0];
70
+ expect(url).toContain('/flowruns/fr-1');
71
+ expect(init.method).toBe('GET');
72
+ });
73
+ it('should POST /flowruns/{id}/clone for clone()', async () => {
74
+ const flowRun = { id: 'fr-clone' };
75
+ mockJsonResponse(flowRun);
76
+ const result = await api().clone('fr-1');
77
+ expect(result).toEqual(flowRun);
78
+ const [url, init] = mockFetch.mock.calls[0];
79
+ expect(url).toContain('/flowruns/fr-1/clone');
80
+ expect(init.method).toBe('POST');
81
+ });
82
+ it('should POST /flowruns/{id} for update()', async () => {
83
+ const flowRun = { id: 'fr-1', fail_on_error: false };
84
+ mockJsonResponse(flowRun);
85
+ const result = await api().update('fr-1', { fail_on_error: false });
86
+ expect(result).toEqual(flowRun);
87
+ const [, init] = mockFetch.mock.calls[0];
88
+ expect(JSON.parse(init.body)).toEqual({ fail_on_error: false });
89
+ });
90
+ it('should POST visibility for updateVisibility()', async () => {
91
+ const flowRun = { id: 'fr-1', visibility: 'public' };
92
+ mockJsonResponse(flowRun);
93
+ await api().updateVisibility('fr-1', 'public');
94
+ const [, init] = mockFetch.mock.calls[0];
95
+ expect(JSON.parse(init.body)).toEqual({ visibility: 'public' });
96
+ });
55
97
  });
@@ -22,6 +22,10 @@ export declare class FlowsAPI {
22
22
  * Update a flow
23
23
  */
24
24
  update(flowId: string, data: Partial<Flow>): Promise<Flow>;
25
+ /**
26
+ * Update flow visibility
27
+ */
28
+ updateVisibility(flowId: string, visibility: string): Promise<Flow>;
25
29
  /**
26
30
  * Delete a flow
27
31
  */
package/dist/api/flows.js CHANGED
@@ -29,6 +29,12 @@ export class FlowsAPI {
29
29
  async update(flowId, data) {
30
30
  return this.http.request('post', `/flows/${flowId}`, { data });
31
31
  }
32
+ /**
33
+ * Update flow visibility
34
+ */
35
+ async updateVisibility(flowId, visibility) {
36
+ return this.http.request('post', `/flows/${flowId}/visibility`, { data: { visibility } });
37
+ }
32
38
  /**
33
39
  * Delete a flow
34
40
  */