@inferencesh/sdk 0.6.10 → 0.6.12
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/README.md +1 -1
- package/dist/agent/actions.js +3 -3
- package/dist/agent/actions.test.js +6 -0
- package/dist/api/agents.d.ts +10 -0
- package/dist/api/agents.js +17 -3
- package/dist/api/agents.test.js +215 -0
- package/dist/api/api-keys.d.ts +24 -0
- package/dist/api/api-keys.js +26 -0
- package/dist/api/api-keys.test.d.ts +1 -0
- package/dist/api/api-keys.test.js +44 -0
- package/dist/api/apps.js +1 -1
- package/dist/api/apps.test.js +71 -3
- package/dist/api/chats.d.ts +14 -0
- package/dist/api/chats.js +18 -0
- package/dist/api/chats.test.js +52 -0
- package/dist/api/engines.d.ts +12 -0
- package/dist/api/engines.js +18 -0
- package/dist/api/engines.test.js +78 -0
- package/dist/api/files.test.js +183 -0
- package/dist/api/flow-runs.test.js +42 -0
- package/dist/api/flows.d.ts +4 -0
- package/dist/api/flows.js +6 -0
- package/dist/api/flows.test.js +75 -0
- package/dist/api/integrations.d.ts +41 -0
- package/dist/api/integrations.js +56 -0
- package/dist/api/integrations.test.d.ts +1 -0
- package/dist/api/integrations.test.js +109 -0
- package/dist/api/knowledge.d.ts +112 -0
- package/dist/api/knowledge.js +163 -0
- package/dist/api/knowledge.test.d.ts +1 -0
- package/dist/api/knowledge.test.js +94 -0
- package/dist/api/mcp-servers.d.ts +45 -0
- package/dist/api/mcp-servers.js +62 -0
- package/dist/api/mcp-servers.test.d.ts +1 -0
- package/dist/api/mcp-servers.test.js +64 -0
- package/dist/api/projects.d.ts +29 -0
- package/dist/api/projects.js +38 -0
- package/dist/api/projects.test.d.ts +1 -0
- package/dist/api/projects.test.js +52 -0
- package/dist/api/search.d.ts +21 -0
- package/dist/api/search.js +20 -0
- package/dist/api/search.test.d.ts +1 -0
- package/dist/api/search.test.js +39 -0
- package/dist/api/secrets.d.ts +29 -0
- package/dist/api/secrets.js +38 -0
- package/dist/api/secrets.test.d.ts +1 -0
- package/dist/api/secrets.test.js +61 -0
- package/dist/api/tasks.d.ts +13 -1
- package/dist/api/tasks.js +18 -0
- package/dist/api/tasks.test.js +134 -0
- package/dist/api/teams.d.ts +71 -0
- package/dist/api/teams.js +92 -0
- package/dist/api/teams.test.d.ts +1 -0
- package/dist/api/teams.test.js +79 -0
- package/dist/http/client.d.ts +5 -0
- package/dist/http/client.js +42 -23
- package/dist/http/client.test.js +245 -0
- package/dist/http/errors.test.js +13 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +25 -0
- package/dist/tool-builder.test.js +11 -1
- package/dist/types.d.ts +110 -5
- package/dist/types.js +58 -2
- package/package.json +4 -4
package/dist/api/chats.test.js
CHANGED
|
@@ -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
|
});
|
package/dist/api/engines.d.ts
CHANGED
|
@@ -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;
|
package/dist/api/engines.js
CHANGED
|
@@ -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);
|
package/dist/api/engines.test.js
CHANGED
|
@@ -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
|
});
|
package/dist/api/files.test.js
CHANGED
|
@@ -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
|
});
|
package/dist/api/flows.d.ts
CHANGED
|
@@ -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
|
*/
|
package/dist/api/flows.test.js
CHANGED
|
@@ -40,4 +40,79 @@ describe('FlowsAPI', () => {
|
|
|
40
40
|
expect(createEventSource).toHaveBeenCalledWith('/flows/flow-5/stream');
|
|
41
41
|
createEventSource.mockRestore();
|
|
42
42
|
});
|
|
43
|
+
it('should POST /flows/list for list()', async () => {
|
|
44
|
+
const page = { items: [{ id: 'flow-1' }], next_cursor: null };
|
|
45
|
+
mockJsonResponse(page);
|
|
46
|
+
const result = await api().list({ limit: 10 });
|
|
47
|
+
expect(result).toEqual(page);
|
|
48
|
+
const [url, init] = mockFetch.mock.calls[0];
|
|
49
|
+
expect(url).toContain('/flows/list');
|
|
50
|
+
expect(init.method).toBe('POST');
|
|
51
|
+
});
|
|
52
|
+
it('should GET /flows/{id} for get()', async () => {
|
|
53
|
+
const flow = { id: 'flow-1', name: 'Demo' };
|
|
54
|
+
mockJsonResponse(flow);
|
|
55
|
+
const result = await api().get('flow-1');
|
|
56
|
+
expect(result).toEqual(flow);
|
|
57
|
+
const [url, init] = mockFetch.mock.calls[0];
|
|
58
|
+
expect(url).toContain('/flows/flow-1');
|
|
59
|
+
expect(init.method).toBe('GET');
|
|
60
|
+
});
|
|
61
|
+
it('should POST /flows/{id} for update()', async () => {
|
|
62
|
+
const flow = { id: 'flow-1', name: 'Renamed' };
|
|
63
|
+
mockJsonResponse(flow);
|
|
64
|
+
const result = await api().update('flow-1', { name: 'Renamed' });
|
|
65
|
+
expect(result).toEqual(flow);
|
|
66
|
+
const [, init] = mockFetch.mock.calls[0];
|
|
67
|
+
expect(JSON.parse(init.body)).toEqual({ name: 'Renamed' });
|
|
68
|
+
});
|
|
69
|
+
it('should POST visibility for updateVisibility()', async () => {
|
|
70
|
+
const flow = { id: 'flow-1', visibility: 'public' };
|
|
71
|
+
mockJsonResponse(flow);
|
|
72
|
+
const result = await api().updateVisibility('flow-1', 'public');
|
|
73
|
+
expect(result).toEqual(flow);
|
|
74
|
+
const [url, init] = mockFetch.mock.calls[0];
|
|
75
|
+
expect(url).toContain('/flows/flow-1/visibility');
|
|
76
|
+
expect(JSON.parse(init.body)).toEqual({ visibility: 'public' });
|
|
77
|
+
});
|
|
78
|
+
it('should DELETE /flows/{id} for delete()', async () => {
|
|
79
|
+
mockJsonResponse(null);
|
|
80
|
+
await api().delete('flow-1');
|
|
81
|
+
const [url, init] = mockFetch.mock.calls[0];
|
|
82
|
+
expect(url).toContain('/flows/flow-1');
|
|
83
|
+
expect(init.method).toBe('DELETE');
|
|
84
|
+
});
|
|
85
|
+
it('should POST /flows/{id}/duplicate for duplicate()', async () => {
|
|
86
|
+
const flow = { id: 'flow-copy' };
|
|
87
|
+
mockJsonResponse(flow);
|
|
88
|
+
const result = await api().duplicate('flow-1');
|
|
89
|
+
expect(result).toEqual(flow);
|
|
90
|
+
const [url] = mockFetch.mock.calls[0];
|
|
91
|
+
expect(url).toContain('/flows/flow-1/duplicate');
|
|
92
|
+
});
|
|
93
|
+
it('should POST /flows/{id}/versions/list for listVersions()', async () => {
|
|
94
|
+
const versions = { items: [{ id: 'ver-1' }], next_cursor: null };
|
|
95
|
+
mockJsonResponse(versions);
|
|
96
|
+
const result = await api().listVersions('flow-1');
|
|
97
|
+
expect(result).toEqual(versions);
|
|
98
|
+
const [url] = mockFetch.mock.calls[0];
|
|
99
|
+
expect(url).toContain('/flows/flow-1/versions/list');
|
|
100
|
+
});
|
|
101
|
+
it('should POST transfer with team_id for transferOwnership()', async () => {
|
|
102
|
+
const flow = { id: 'flow-1' };
|
|
103
|
+
mockJsonResponse(flow);
|
|
104
|
+
await api().transferOwnership('flow-1', 'team-42');
|
|
105
|
+
const [, init] = mockFetch.mock.calls[0];
|
|
106
|
+
expect(JSON.parse(init.body)).toEqual({ team_id: 'team-42' });
|
|
107
|
+
});
|
|
108
|
+
it('should POST /flows/{id}/visibility for updateVisibility()', async () => {
|
|
109
|
+
const flow = { id: 'flow-1', visibility: 'public' };
|
|
110
|
+
mockJsonResponse(flow);
|
|
111
|
+
const result = await api().updateVisibility('flow-1', 'public');
|
|
112
|
+
expect(result).toEqual(flow);
|
|
113
|
+
const [url, init] = mockFetch.mock.calls[0];
|
|
114
|
+
expect(url).toContain('/flows/flow-1/visibility');
|
|
115
|
+
expect(init.method).toBe('POST');
|
|
116
|
+
expect(JSON.parse(init.body)).toEqual({ visibility: 'public' });
|
|
117
|
+
});
|
|
43
118
|
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HttpClient } from '../http/client';
|
|
2
|
+
import { IntegrationDTO, IntegrationConfigDTO, IntegrationConnectRequest, IntegrationConnectResponse, CursorListRequest, CursorListResponse } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Integrations API
|
|
5
|
+
*/
|
|
6
|
+
export declare class IntegrationsAPI {
|
|
7
|
+
private readonly http;
|
|
8
|
+
constructor(http: HttpClient);
|
|
9
|
+
/**
|
|
10
|
+
* List integrations with cursor-based pagination
|
|
11
|
+
*/
|
|
12
|
+
list(params?: Partial<CursorListRequest>): Promise<CursorListResponse<IntegrationDTO>>;
|
|
13
|
+
/**
|
|
14
|
+
* Get available integrations
|
|
15
|
+
*/
|
|
16
|
+
listAvailable(): Promise<IntegrationConfigDTO[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Get integration configs
|
|
19
|
+
*/
|
|
20
|
+
getConfigs(): Promise<IntegrationConfigDTO[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Get capabilities
|
|
23
|
+
*/
|
|
24
|
+
getCapabilities(): Promise<unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Check requirements
|
|
27
|
+
*/
|
|
28
|
+
checkRequirements(data: unknown): Promise<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Connect an integration
|
|
31
|
+
*/
|
|
32
|
+
connect(data: IntegrationConnectRequest): Promise<IntegrationConnectResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Get an integration by provider key
|
|
35
|
+
*/
|
|
36
|
+
get(provider: string): Promise<IntegrationDTO>;
|
|
37
|
+
/**
|
|
38
|
+
* Disconnect an integration
|
|
39
|
+
*/
|
|
40
|
+
disconnect(provider: string): Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integrations API
|
|
3
|
+
*/
|
|
4
|
+
export class IntegrationsAPI {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* List integrations with cursor-based pagination
|
|
10
|
+
*/
|
|
11
|
+
async list(params) {
|
|
12
|
+
return this.http.request('post', '/integrations/list', { data: params });
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get available integrations
|
|
16
|
+
*/
|
|
17
|
+
async listAvailable() {
|
|
18
|
+
return this.http.request('get', '/integrations/available');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get integration configs
|
|
22
|
+
*/
|
|
23
|
+
async getConfigs() {
|
|
24
|
+
return this.http.request('get', '/integrations/configs');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get capabilities
|
|
28
|
+
*/
|
|
29
|
+
async getCapabilities() {
|
|
30
|
+
return this.http.request('get', '/integrations/capabilities');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check requirements
|
|
34
|
+
*/
|
|
35
|
+
async checkRequirements(data) {
|
|
36
|
+
return this.http.request('post', '/integrations/check', { data });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Connect an integration
|
|
40
|
+
*/
|
|
41
|
+
async connect(data) {
|
|
42
|
+
return this.http.request('post', '/integrations', { data });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get an integration by provider key
|
|
46
|
+
*/
|
|
47
|
+
async get(provider) {
|
|
48
|
+
return this.http.request('get', `/integrations/${provider}`);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Disconnect an integration
|
|
52
|
+
*/
|
|
53
|
+
async disconnect(provider) {
|
|
54
|
+
return this.http.request('delete', `/integrations/${provider}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|