@ottocode/web-sdk 0.1.213 → 0.1.216

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 (138) hide show
  1. package/dist/components/git/GitSidebar.js +1 -1
  2. package/dist/components/git/GitSidebar.js.map +1 -1
  3. package/dist/components/index.d.ts +3 -0
  4. package/dist/components/index.d.ts.map +1 -1
  5. package/dist/components/index.js +4 -0
  6. package/dist/components/index.js.map +1 -1
  7. package/dist/components/messages/ToolApprovalCard.d.ts +2 -2
  8. package/dist/components/messages/ToolApprovalCard.d.ts.map +1 -1
  9. package/dist/components/messages/ToolApprovalCard.js +6 -2
  10. package/dist/components/messages/ToolApprovalCard.js.map +1 -1
  11. package/dist/components/messages/renderers/shared/ImagePreview.js +1 -1
  12. package/dist/components/messages/renderers/shared/ImagePreview.js.map +1 -1
  13. package/dist/components/research/ResearchSidebar.js +1 -1
  14. package/dist/components/research/ResearchSidebar.js.map +1 -1
  15. package/dist/components/sessions/SessionListContainer.d.ts.map +1 -1
  16. package/dist/components/sessions/SessionListContainer.js +6 -9
  17. package/dist/components/sessions/SessionListContainer.js.map +1 -1
  18. package/dist/components/skills/SkillViewerPanel.d.ts +2 -0
  19. package/dist/components/skills/SkillViewerPanel.d.ts.map +1 -0
  20. package/dist/components/skills/SkillViewerPanel.js +89 -0
  21. package/dist/components/skills/SkillViewerPanel.js.map +1 -0
  22. package/dist/components/skills/SkillsSidebar.d.ts +2 -0
  23. package/dist/components/skills/SkillsSidebar.d.ts.map +1 -0
  24. package/dist/components/skills/SkillsSidebar.js +59 -0
  25. package/dist/components/skills/SkillsSidebar.js.map +1 -0
  26. package/dist/components/skills/SkillsSidebarToggle.d.ts +2 -0
  27. package/dist/components/skills/SkillsSidebarToggle.d.ts.map +1 -0
  28. package/dist/components/skills/SkillsSidebarToggle.js +12 -0
  29. package/dist/components/skills/SkillsSidebarToggle.js.map +1 -0
  30. package/dist/components/skills/index.d.ts +4 -0
  31. package/dist/components/skills/index.d.ts.map +1 -0
  32. package/dist/components/skills/index.js +4 -0
  33. package/dist/components/skills/index.js.map +1 -0
  34. package/dist/components/terminals/TerminalViewer.d.ts +2 -1
  35. package/dist/components/terminals/TerminalViewer.d.ts.map +1 -1
  36. package/dist/components/terminals/TerminalViewer.js +81 -3
  37. package/dist/components/terminals/TerminalViewer.js.map +1 -1
  38. package/dist/components/terminals/TerminalsPanel.d.ts.map +1 -1
  39. package/dist/components/terminals/TerminalsPanel.js +1 -3
  40. package/dist/components/terminals/TerminalsPanel.js.map +1 -1
  41. package/dist/hooks/index.d.ts +1 -0
  42. package/dist/hooks/index.d.ts.map +1 -1
  43. package/dist/hooks/index.js +1 -0
  44. package/dist/hooks/index.js.map +1 -1
  45. package/dist/hooks/useAuthStatus.d.ts.map +1 -1
  46. package/dist/hooks/useConfig.d.ts.map +1 -1
  47. package/dist/hooks/useFileBrowser.d.ts.map +1 -1
  48. package/dist/hooks/useFileMention.js +4 -4
  49. package/dist/hooks/useFileMention.js.map +1 -1
  50. package/dist/hooks/useFiles.d.ts +2 -2
  51. package/dist/hooks/useMCP.d.ts +23 -11
  52. package/dist/hooks/useMCP.d.ts.map +1 -1
  53. package/dist/hooks/useMCP.js +68 -50
  54. package/dist/hooks/useMCP.js.map +1 -1
  55. package/dist/hooks/useSkills.d.ts +12 -0
  56. package/dist/hooks/useSkills.d.ts.map +1 -0
  57. package/dist/hooks/useSkills.js +54 -0
  58. package/dist/hooks/useSkills.js.map +1 -0
  59. package/dist/hooks/useTerminals.js +2 -2
  60. package/dist/hooks/useTerminals.js.map +1 -1
  61. package/dist/lib/api-client/approval.d.ts +18 -0
  62. package/dist/lib/api-client/approval.d.ts.map +1 -0
  63. package/dist/lib/api-client/approval.js +25 -0
  64. package/dist/lib/api-client/approval.js.map +1 -0
  65. package/dist/lib/api-client/auth.d.ts +74 -0
  66. package/dist/lib/api-client/auth.d.ts.map +1 -0
  67. package/dist/lib/api-client/auth.js +111 -0
  68. package/dist/lib/api-client/auth.js.map +1 -0
  69. package/dist/lib/api-client/branches.d.ts +10 -0
  70. package/dist/lib/api-client/branches.d.ts.map +1 -0
  71. package/dist/lib/api-client/branches.js +45 -0
  72. package/dist/lib/api-client/branches.js.map +1 -0
  73. package/dist/lib/api-client/config.d.ts +41 -0
  74. package/dist/lib/api-client/config.d.ts.map +1 -0
  75. package/dist/lib/api-client/config.js +38 -0
  76. package/dist/lib/api-client/config.js.map +1 -0
  77. package/dist/lib/api-client/files.d.ts +29 -0
  78. package/dist/lib/api-client/files.d.ts.map +1 -0
  79. package/dist/lib/api-client/files.js +35 -0
  80. package/dist/lib/api-client/files.js.map +1 -0
  81. package/dist/lib/api-client/git.d.ts +32 -0
  82. package/dist/lib/api-client/git.d.ts.map +1 -0
  83. package/dist/lib/api-client/git.js +154 -0
  84. package/dist/lib/api-client/git.js.map +1 -0
  85. package/dist/lib/api-client/index.d.ts +292 -0
  86. package/dist/lib/api-client/index.d.ts.map +1 -0
  87. package/dist/lib/api-client/index.js +85 -0
  88. package/dist/lib/api-client/index.js.map +1 -0
  89. package/dist/lib/api-client/sessions.d.ts +43 -0
  90. package/dist/lib/api-client/sessions.d.ts.map +1 -0
  91. package/dist/lib/api-client/sessions.js +108 -0
  92. package/dist/lib/api-client/sessions.js.map +1 -0
  93. package/dist/lib/api-client/setu.d.ts +59 -0
  94. package/dist/lib/api-client/setu.d.ts.map +1 -0
  95. package/dist/lib/api-client/setu.js +112 -0
  96. package/dist/lib/api-client/setu.js.map +1 -0
  97. package/dist/lib/api-client/skills.d.ts +35 -0
  98. package/dist/lib/api-client/skills.d.ts.map +1 -0
  99. package/dist/lib/api-client/skills.js +31 -0
  100. package/dist/lib/api-client/skills.js.map +1 -0
  101. package/dist/lib/api-client/utils.d.ts +8 -0
  102. package/dist/lib/api-client/utils.d.ts.map +1 -0
  103. package/dist/lib/api-client/utils.js +65 -0
  104. package/dist/lib/api-client/utils.js.map +1 -0
  105. package/dist/stores/fileBrowserStore.d.ts.map +1 -1
  106. package/dist/stores/fileBrowserStore.js +6 -0
  107. package/dist/stores/fileBrowserStore.js.map +1 -1
  108. package/dist/stores/gitStore.d.ts.map +1 -1
  109. package/dist/stores/gitStore.js +2 -0
  110. package/dist/stores/gitStore.js.map +1 -1
  111. package/dist/stores/index.d.ts +1 -0
  112. package/dist/stores/index.d.ts.map +1 -1
  113. package/dist/stores/index.js +1 -0
  114. package/dist/stores/index.js.map +1 -1
  115. package/dist/stores/mcpStore.d.ts.map +1 -1
  116. package/dist/stores/mcpStore.js +3 -0
  117. package/dist/stores/mcpStore.js.map +1 -1
  118. package/dist/stores/researchStore.d.ts.map +1 -1
  119. package/dist/stores/researchStore.js +3 -0
  120. package/dist/stores/researchStore.js.map +1 -1
  121. package/dist/stores/sessionFilesStore.d.ts.map +1 -1
  122. package/dist/stores/sessionFilesStore.js +3 -0
  123. package/dist/stores/sessionFilesStore.js.map +1 -1
  124. package/dist/stores/settingsStore.d.ts.map +1 -1
  125. package/dist/stores/settingsStore.js +2 -0
  126. package/dist/stores/settingsStore.js.map +1 -1
  127. package/dist/stores/skillsStore.d.ts +23 -0
  128. package/dist/stores/skillsStore.d.ts.map +1 -0
  129. package/dist/stores/skillsStore.js +46 -0
  130. package/dist/stores/skillsStore.js.map +1 -0
  131. package/dist/stores/tunnelStore.d.ts.map +1 -1
  132. package/dist/stores/tunnelStore.js +3 -0
  133. package/dist/stores/tunnelStore.js.map +1 -1
  134. package/package.json +6 -6
  135. package/dist/lib/api-client.d.ts +0 -288
  136. package/dist/lib/api-client.d.ts.map +0 -1
  137. package/dist/lib/api-client.js +0 -936
  138. package/dist/lib/api-client.js.map +0 -1
@@ -1,936 +0,0 @@
1
- import { client, createSession as apiCreateSession, listMessages as apiListMessages, createMessage as apiCreateMessage, abortSession as apiAbortSession, getConfig as apiGetConfig, getProviderModels as apiGetProviderModels, listFiles as apiListFiles, getGitStatus as apiGetGitStatus, getGitDiff as apiGetGitDiff, getGitBranch as apiGetGitBranch, stageFiles as apiStageFiles, unstageFiles as apiUnstageFiles, restoreFiles as apiRestoreFiles, deleteFiles as apiDeleteFiles, commitChanges as apiCommitChanges, generateCommitMessage as apiGenerateCommitMessage, pushCommits as apiPushCommits, pullChanges as apiPullChanges, } from '@ottocode/api';
2
- import { API_BASE_URL } from './config';
3
- /**
4
- * Extract error message from API error response
5
- * Handles both string errors and structured error objects
6
- */
7
- function extractErrorMessage(error) {
8
- if (!error) {
9
- return 'Unknown error';
10
- }
11
- // If it's a string, return it
12
- if (typeof error === 'string') {
13
- return error;
14
- }
15
- // If it's an error object with our standardized structure
16
- if (error && typeof error === 'object') {
17
- const errObj = error;
18
- // New standardized format: { error: { message, type, ... } }
19
- if (errObj.error && typeof errObj.error === 'object') {
20
- const innerError = errObj.error;
21
- if (typeof innerError.message === 'string') {
22
- return innerError.message;
23
- }
24
- }
25
- // Legacy format: { error: "message" }
26
- if (typeof errObj.error === 'string') {
27
- return errObj.error;
28
- }
29
- // Direct message property
30
- if (typeof errObj.message === 'string') {
31
- return errObj.message;
32
- }
33
- // Try to JSON stringify if it's a complex object
34
- try {
35
- return JSON.stringify(error);
36
- }
37
- catch {
38
- return 'Error occurred (unable to parse)';
39
- }
40
- }
41
- return 'Unknown error';
42
- }
43
- /**
44
- * Configure the API client with the correct base URL
45
- * This should be called once at application startup
46
- */
47
- export function configureApiClient() {
48
- const win = window;
49
- const baseURL = win.OTTO_SERVER_URL || API_BASE_URL;
50
- client.setConfig({
51
- baseURL,
52
- });
53
- }
54
- // Configure the client immediately when this module is imported
55
- configureApiClient();
56
- // Type conversion helpers
57
- function convertSession(apiSession) {
58
- return {
59
- ...apiSession,
60
- title: apiSession.title ?? null,
61
- createdAt: typeof apiSession.createdAt === 'string'
62
- ? new Date(apiSession.createdAt).getTime()
63
- : apiSession.createdAt,
64
- lastActiveAt: typeof apiSession.lastActiveAt === 'string'
65
- ? new Date(apiSession.lastActiveAt).getTime()
66
- : apiSession.lastActiveAt,
67
- };
68
- }
69
- function convertMessage(apiMessage) {
70
- return {
71
- ...apiMessage,
72
- createdAt: typeof apiMessage.createdAt === 'string'
73
- ? new Date(apiMessage.createdAt).getTime()
74
- : apiMessage.createdAt,
75
- completedAt: apiMessage.completedAt
76
- ? typeof apiMessage.completedAt === 'string'
77
- ? new Date(apiMessage.completedAt).getTime()
78
- : apiMessage.completedAt
79
- : null,
80
- };
81
- }
82
- class ApiClient {
83
- get baseUrl() {
84
- // Always check for injected URL at runtime
85
- const win = window;
86
- if (win.OTTO_SERVER_URL) {
87
- return win.OTTO_SERVER_URL;
88
- }
89
- return API_BASE_URL;
90
- }
91
- // Session methods using new API
92
- async getSessions() {
93
- const page = await this.getSessionsPage({ limit: 200 });
94
- return page.items;
95
- }
96
- async getSessionsPage(params = {}) {
97
- const { limit = 50, offset = 0 } = params;
98
- const url = `${this.baseUrl}/v1/sessions?limit=${limit}&offset=${offset}`;
99
- const res = await fetch(url);
100
- if (!res.ok) {
101
- throw new Error(`Failed to fetch sessions: ${res.statusText}`);
102
- }
103
- const data = (await res.json());
104
- return {
105
- items: (data.items || []).map((s) => convertSession(s)),
106
- hasMore: data.hasMore,
107
- nextOffset: data.nextOffset,
108
- };
109
- }
110
- async createSession(data) {
111
- const response = await apiCreateSession({
112
- body: data,
113
- });
114
- if (response.error) {
115
- throw new Error(extractErrorMessage(response.error));
116
- }
117
- if (!response.data) {
118
- throw new Error('No data returned from create session');
119
- }
120
- return convertSession(response.data);
121
- }
122
- async updateSession(sessionId, data) {
123
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}`, {
124
- method: 'PATCH',
125
- headers: {
126
- 'Content-Type': 'application/json',
127
- },
128
- body: JSON.stringify(data),
129
- });
130
- if (!response.ok) {
131
- const errorData = await response
132
- .json()
133
- .catch(() => ({ error: 'Failed to update session' }));
134
- throw new Error(extractErrorMessage(errorData));
135
- }
136
- const sessionData = await response.json();
137
- return convertSession(sessionData);
138
- }
139
- async deleteSession(sessionId) {
140
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}`, {
141
- method: 'DELETE',
142
- headers: {
143
- 'Content-Type': 'application/json',
144
- },
145
- });
146
- if (!response.ok) {
147
- const errorData = await response
148
- .json()
149
- .catch(() => ({ error: 'Failed to delete session' }));
150
- throw new Error(extractErrorMessage(errorData));
151
- }
152
- return await response.json();
153
- }
154
- async abortSession(sessionId) {
155
- const response = await apiAbortSession({
156
- path: { sessionId },
157
- });
158
- if (response.error) {
159
- throw new Error(extractErrorMessage(response.error));
160
- }
161
- return response.data;
162
- }
163
- async abortMessage(sessionId, messageId) {
164
- const baseUrl = this.baseUrl;
165
- const response = await fetch(`${baseUrl}/v1/sessions/${sessionId}/abort`, {
166
- method: 'DELETE',
167
- headers: { 'Content-Type': 'application/json' },
168
- body: JSON.stringify({ messageId }),
169
- });
170
- if (!response.ok) {
171
- throw new Error('Failed to abort message');
172
- }
173
- return response.json();
174
- }
175
- async getQueueState(sessionId) {
176
- const baseUrl = this.baseUrl;
177
- const response = await fetch(`${baseUrl}/v1/sessions/${sessionId}/queue`);
178
- if (!response.ok) {
179
- throw new Error('Failed to get queue state');
180
- }
181
- return response.json();
182
- }
183
- async removeFromQueue(sessionId, messageId) {
184
- const baseUrl = this.baseUrl;
185
- const response = await fetch(`${baseUrl}/v1/sessions/${sessionId}/queue/${messageId}`, { method: 'DELETE' });
186
- if (!response.ok) {
187
- throw new Error('Failed to remove from queue');
188
- }
189
- return response.json();
190
- }
191
- async getMessages(sessionId) {
192
- const response = await apiListMessages({
193
- path: { id: sessionId },
194
- });
195
- if (response.error) {
196
- throw new Error(extractErrorMessage(response.error));
197
- }
198
- return (response.data || []).map(convertMessage);
199
- }
200
- async sendMessage(sessionId, data) {
201
- const response = await apiCreateMessage({
202
- path: { id: sessionId },
203
- body: data,
204
- });
205
- if (response.error) {
206
- throw new Error(extractErrorMessage(response.error));
207
- }
208
- return response.data;
209
- }
210
- getStreamUrl(sessionId) {
211
- return `${this.baseUrl}/v1/sessions/${sessionId}/stream`;
212
- }
213
- // Config methods using new API
214
- async getConfig() {
215
- const response = await apiGetConfig();
216
- if (response.error) {
217
- throw new Error(extractErrorMessage(response.error));
218
- }
219
- return response.data;
220
- }
221
- async getModels(providerId) {
222
- const response = await apiGetProviderModels({
223
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
224
- path: { provider: providerId },
225
- });
226
- if (response.error) {
227
- throw new Error(extractErrorMessage(response.error));
228
- }
229
- return response.data;
230
- }
231
- async getAllModels() {
232
- const response = await fetch(`${this.baseUrl}/v1/config/models`, {
233
- method: 'GET',
234
- headers: {
235
- 'Content-Type': 'application/json',
236
- },
237
- });
238
- if (!response.ok) {
239
- const errorData = await response
240
- .json()
241
- .catch(() => ({ error: 'Failed to fetch models' }));
242
- throw new Error(extractErrorMessage(errorData));
243
- }
244
- return await response.json();
245
- }
246
- async updateDefaults(data) {
247
- const response = await fetch(`${this.baseUrl}/v1/config/defaults`, {
248
- method: 'PATCH',
249
- headers: {
250
- 'Content-Type': 'application/json',
251
- },
252
- body: JSON.stringify(data),
253
- });
254
- if (!response.ok) {
255
- const errorData = await response
256
- .json()
257
- .catch(() => ({ error: 'Failed to update defaults' }));
258
- throw new Error(extractErrorMessage(errorData));
259
- }
260
- return await response.json();
261
- }
262
- // Git methods using new API
263
- async initGitRepo() {
264
- const response = await fetch(`${this.baseUrl}/v1/git/init`, {
265
- method: 'POST',
266
- headers: { 'Content-Type': 'application/json' },
267
- body: JSON.stringify({}),
268
- });
269
- if (!response.ok) {
270
- const errorData = await response
271
- .json()
272
- .catch(() => ({ error: 'Failed to initialize git repository' }));
273
- throw new Error(extractErrorMessage(errorData));
274
- }
275
- const data = await response.json();
276
- return data.data;
277
- }
278
- async getGitStatus() {
279
- const response = await apiGetGitStatus();
280
- if (response.error) {
281
- throw new Error(extractErrorMessage(response.error));
282
- }
283
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
284
- return response.data?.data;
285
- }
286
- async getGitDiff(file, staged = false) {
287
- const response = await apiGetGitDiff({
288
- query: {
289
- file,
290
- staged: staged ? 'true' : 'false',
291
- },
292
- });
293
- if (response.error) {
294
- throw new Error(extractErrorMessage(response.error));
295
- }
296
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
297
- return response.data?.data;
298
- }
299
- async generateCommitMessage(sessionId) {
300
- const response = await apiGenerateCommitMessage({
301
- body: sessionId ? { sessionId } : {},
302
- });
303
- if (response.error) {
304
- throw new Error(extractErrorMessage(response.error));
305
- }
306
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
307
- return response.data?.data;
308
- }
309
- async stageFiles(files) {
310
- const response = await apiStageFiles({
311
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
312
- body: { files },
313
- });
314
- if (response.error) {
315
- throw new Error(extractErrorMessage(response.error));
316
- }
317
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
318
- return response.data?.data;
319
- }
320
- async unstageFiles(files) {
321
- const response = await apiUnstageFiles({
322
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
323
- body: { files },
324
- });
325
- if (response.error) {
326
- throw new Error(extractErrorMessage(response.error));
327
- }
328
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
329
- return response.data?.data;
330
- }
331
- async restoreFiles(files) {
332
- const response = await apiRestoreFiles({
333
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
334
- body: { files },
335
- });
336
- if (response.error) {
337
- throw new Error(extractErrorMessage(response.error));
338
- }
339
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
340
- return response.data?.data;
341
- }
342
- async deleteFiles(files) {
343
- const response = await apiDeleteFiles({
344
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
345
- body: { files },
346
- });
347
- if (response.error) {
348
- throw new Error(extractErrorMessage(response.error));
349
- }
350
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
351
- return response.data?.data;
352
- }
353
- async commitChanges(message) {
354
- const response = await apiCommitChanges({
355
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
356
- body: { message },
357
- });
358
- if (response.error) {
359
- throw new Error(extractErrorMessage(response.error));
360
- }
361
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
362
- return response.data?.data;
363
- }
364
- async getGitBranch() {
365
- const response = await apiGetGitBranch();
366
- if (response.error) {
367
- throw new Error(extractErrorMessage(response.error));
368
- }
369
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
370
- return response.data?.data;
371
- }
372
- async pushCommits() {
373
- const response = await apiPushCommits({
374
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
375
- body: {},
376
- });
377
- if (response.error) {
378
- throw new Error(extractErrorMessage(response.error));
379
- }
380
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
381
- return response.data?.data;
382
- }
383
- async pullChanges() {
384
- const response = await apiPullChanges({
385
- // biome-ignore lint/suspicious/noExplicitAny: API type mismatch between client and server
386
- body: {},
387
- });
388
- if (response.error) {
389
- throw new Error(extractErrorMessage(response.error));
390
- }
391
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
392
- return response.data?.data;
393
- }
394
- async getRemotes() {
395
- const response = await fetch(`${this.baseUrl}/v1/git/remotes`, {
396
- method: 'GET',
397
- headers: { 'Content-Type': 'application/json' },
398
- });
399
- if (!response.ok) {
400
- const errorData = await response
401
- .json()
402
- .catch(() => ({ error: 'Failed to list remotes' }));
403
- throw new Error(extractErrorMessage(errorData));
404
- }
405
- const data = await response.json();
406
- return data.data.remotes;
407
- }
408
- async addRemote(name, url) {
409
- const response = await fetch(`${this.baseUrl}/v1/git/remotes`, {
410
- method: 'POST',
411
- headers: { 'Content-Type': 'application/json' },
412
- body: JSON.stringify({ name, url }),
413
- });
414
- if (!response.ok) {
415
- const errorData = await response
416
- .json()
417
- .catch(() => ({ error: 'Failed to add remote' }));
418
- throw new Error(extractErrorMessage(errorData));
419
- }
420
- const data = await response.json();
421
- return data.data;
422
- }
423
- async removeRemote(name) {
424
- const response = await fetch(`${this.baseUrl}/v1/git/remotes`, {
425
- method: 'DELETE',
426
- headers: { 'Content-Type': 'application/json' },
427
- body: JSON.stringify({ name }),
428
- });
429
- if (!response.ok) {
430
- const errorData = await response
431
- .json()
432
- .catch(() => ({ error: 'Failed to remove remote' }));
433
- throw new Error(extractErrorMessage(errorData));
434
- }
435
- const data = await response.json();
436
- return data.data;
437
- }
438
- async listFiles() {
439
- const response = await apiListFiles();
440
- if (response.error) {
441
- throw new Error(extractErrorMessage(response.error));
442
- }
443
- return response.data;
444
- }
445
- async getFileTree(dirPath = '.') {
446
- const response = await fetch(`${this.baseUrl}/v1/files/tree?path=${encodeURIComponent(dirPath)}`, {
447
- method: 'GET',
448
- headers: { 'Content-Type': 'application/json' },
449
- });
450
- if (!response.ok) {
451
- const errorData = await response
452
- .json()
453
- .catch(() => ({ error: 'Failed to fetch file tree' }));
454
- throw new Error(extractErrorMessage(errorData));
455
- }
456
- return await response.json();
457
- }
458
- async readFileContent(filePath) {
459
- const response = await fetch(`${this.baseUrl}/v1/files/read?path=${encodeURIComponent(filePath)}`, {
460
- method: 'GET',
461
- headers: { 'Content-Type': 'application/json' },
462
- });
463
- if (!response.ok) {
464
- const errorData = await response
465
- .json()
466
- .catch(() => ({ error: 'Failed to read file' }));
467
- throw new Error(extractErrorMessage(errorData));
468
- }
469
- return await response.json();
470
- }
471
- async getGitDiffFullFile(file, staged = false) {
472
- const params = new URLSearchParams({
473
- file,
474
- staged: staged ? 'true' : 'false',
475
- fullFile: 'true',
476
- });
477
- const response = await fetch(`${this.baseUrl}/v1/git/diff?${params.toString()}`, {
478
- method: 'GET',
479
- headers: { 'Content-Type': 'application/json' },
480
- });
481
- if (!response.ok) {
482
- const errorData = await response
483
- .json()
484
- .catch(() => ({ error: 'Failed to get full file diff' }));
485
- throw new Error(extractErrorMessage(errorData));
486
- }
487
- const json = await response.json();
488
- // biome-ignore lint/suspicious/noExplicitAny: API response structure mismatch
489
- return json?.data;
490
- }
491
- async getSessionFiles(sessionId) {
492
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/files`, {
493
- method: 'GET',
494
- headers: {
495
- 'Content-Type': 'application/json',
496
- },
497
- });
498
- if (!response.ok) {
499
- const errorData = await response
500
- .json()
501
- .catch(() => ({ error: 'Failed to fetch session files' }));
502
- throw new Error(extractErrorMessage(errorData));
503
- }
504
- return await response.json();
505
- }
506
- async createBranch(sessionId, data) {
507
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/branch`, {
508
- method: 'POST',
509
- headers: {
510
- 'Content-Type': 'application/json',
511
- },
512
- body: JSON.stringify(data),
513
- });
514
- if (!response.ok) {
515
- const errorData = await response
516
- .json()
517
- .catch(() => ({ error: 'Failed to create branch' }));
518
- throw new Error(extractErrorMessage(errorData));
519
- }
520
- return await response.json();
521
- }
522
- async listBranches(sessionId) {
523
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/branches`, {
524
- method: 'GET',
525
- headers: {
526
- 'Content-Type': 'application/json',
527
- },
528
- });
529
- if (!response.ok) {
530
- const errorData = await response
531
- .json()
532
- .catch(() => ({ error: 'Failed to list branches' }));
533
- throw new Error(extractErrorMessage(errorData));
534
- }
535
- return await response.json();
536
- }
537
- async getParentSession(sessionId) {
538
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/parent`, {
539
- method: 'GET',
540
- headers: {
541
- 'Content-Type': 'application/json',
542
- },
543
- });
544
- if (!response.ok) {
545
- const errorData = await response
546
- .json()
547
- .catch(() => ({ error: 'Failed to get parent session' }));
548
- throw new Error(extractErrorMessage(errorData));
549
- }
550
- return await response.json();
551
- }
552
- async getSetuBalance() {
553
- try {
554
- const response = await fetch(`${this.baseUrl}/v1/setu/balance`, {
555
- method: 'GET',
556
- headers: {
557
- 'Content-Type': 'application/json',
558
- },
559
- });
560
- if (!response.ok) {
561
- return null;
562
- }
563
- return await response.json();
564
- }
565
- catch {
566
- return null;
567
- }
568
- }
569
- async getSetuWallet() {
570
- try {
571
- const response = await fetch(`${this.baseUrl}/v1/setu/wallet`, {
572
- method: 'GET',
573
- headers: {
574
- 'Content-Type': 'application/json',
575
- },
576
- });
577
- if (!response.ok) {
578
- return { configured: false };
579
- }
580
- return await response.json();
581
- }
582
- catch {
583
- return { configured: false };
584
- }
585
- }
586
- async getSetuUsdcBalance(network = 'mainnet') {
587
- try {
588
- const response = await fetch(`${this.baseUrl}/v1/setu/usdc-balance?network=${network}`, {
589
- method: 'GET',
590
- headers: {
591
- 'Content-Type': 'application/json',
592
- },
593
- });
594
- if (!response.ok) {
595
- return null;
596
- }
597
- return await response.json();
598
- }
599
- catch {
600
- return null;
601
- }
602
- }
603
- async getShareStatus(sessionId) {
604
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/share`, {
605
- method: 'GET',
606
- headers: {
607
- 'Content-Type': 'application/json',
608
- },
609
- });
610
- if (!response.ok) {
611
- return { shared: false };
612
- }
613
- return await response.json();
614
- }
615
- async shareSession(sessionId) {
616
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/share`, {
617
- method: 'POST',
618
- headers: {
619
- 'Content-Type': 'application/json',
620
- },
621
- });
622
- if (!response.ok) {
623
- const errorData = await response
624
- .json()
625
- .catch(() => ({ error: 'Failed to share session' }));
626
- throw new Error(extractErrorMessage(errorData));
627
- }
628
- return await response.json();
629
- }
630
- async syncSession(sessionId) {
631
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/share`, {
632
- method: 'PUT',
633
- headers: {
634
- 'Content-Type': 'application/json',
635
- },
636
- });
637
- if (!response.ok) {
638
- const errorData = await response
639
- .json()
640
- .catch(() => ({ error: 'Failed to sync session' }));
641
- throw new Error(extractErrorMessage(errorData));
642
- }
643
- return await response.json();
644
- }
645
- async approveToolCall(sessionId, callId, approved) {
646
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/approval`, {
647
- method: 'POST',
648
- headers: { 'Content-Type': 'application/json' },
649
- body: JSON.stringify({ callId, approved }),
650
- });
651
- if (!response.ok) {
652
- throw new Error('Failed to send tool approval');
653
- }
654
- return await response.json();
655
- }
656
- async getPendingApprovals(sessionId) {
657
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/approval/pending`, {
658
- method: 'GET',
659
- headers: { 'Content-Type': 'application/json' },
660
- });
661
- if (!response.ok) {
662
- return { ok: false, pending: [] };
663
- }
664
- return await response.json();
665
- }
666
- async getPolarTopupEstimate(amount) {
667
- try {
668
- const response = await fetch(`${this.baseUrl}/v1/setu/topup/polar/estimate?amount=${amount}`, {
669
- method: 'GET',
670
- headers: { 'Content-Type': 'application/json' },
671
- });
672
- if (!response.ok) {
673
- return null;
674
- }
675
- return await response.json();
676
- }
677
- catch {
678
- return null;
679
- }
680
- }
681
- async createPolarCheckout(amount, successUrl) {
682
- const response = await fetch(`${this.baseUrl}/v1/setu/topup/polar`, {
683
- method: 'POST',
684
- headers: { 'Content-Type': 'application/json' },
685
- body: JSON.stringify({ amount, successUrl }),
686
- });
687
- if (!response.ok) {
688
- const errorData = await response
689
- .json()
690
- .catch(() => ({ error: 'Failed to create checkout' }));
691
- throw new Error(extractErrorMessage(errorData));
692
- }
693
- return await response.json();
694
- }
695
- async selectTopupMethod(sessionId, method) {
696
- const response = await fetch(`${this.baseUrl}/v1/setu/topup/select`, {
697
- method: 'POST',
698
- headers: { 'Content-Type': 'application/json' },
699
- body: JSON.stringify({ sessionId, method }),
700
- });
701
- if (!response.ok) {
702
- const errorData = await response
703
- .json()
704
- .catch(() => ({ error: 'Failed to select topup method' }));
705
- throw new Error(extractErrorMessage(errorData));
706
- }
707
- return await response.json();
708
- }
709
- async cancelTopup(sessionId, reason) {
710
- const response = await fetch(`${this.baseUrl}/v1/setu/topup/cancel`, {
711
- method: 'POST',
712
- headers: { 'Content-Type': 'application/json' },
713
- body: JSON.stringify({ sessionId, reason }),
714
- });
715
- if (!response.ok) {
716
- const errorData = await response
717
- .json()
718
- .catch(() => ({ error: 'Failed to cancel topup' }));
719
- throw new Error(extractErrorMessage(errorData));
720
- }
721
- return await response.json();
722
- }
723
- async getPendingTopup(sessionId) {
724
- try {
725
- const response = await fetch(`${this.baseUrl}/v1/setu/topup/pending?sessionId=${sessionId}`, {
726
- method: 'GET',
727
- headers: { 'Content-Type': 'application/json' },
728
- });
729
- if (!response.ok) {
730
- return { hasPending: false };
731
- }
732
- return await response.json();
733
- }
734
- catch {
735
- return { hasPending: false };
736
- }
737
- }
738
- async getPolarTopupStatus(checkoutId) {
739
- try {
740
- const response = await fetch(`${this.baseUrl}/v1/setu/topup/polar/status?checkoutId=${checkoutId}`, {
741
- method: 'GET',
742
- headers: { 'Content-Type': 'application/json' },
743
- });
744
- if (!response.ok) {
745
- return null;
746
- }
747
- return await response.json();
748
- }
749
- catch {
750
- return null;
751
- }
752
- }
753
- async retryMessage(sessionId, messageId) {
754
- const response = await fetch(`${this.baseUrl}/v1/sessions/${sessionId}/messages/${messageId}/retry`, {
755
- method: 'POST',
756
- headers: { 'Content-Type': 'application/json' },
757
- });
758
- if (!response.ok) {
759
- const errorData = await response
760
- .json()
761
- .catch(() => ({ error: 'Failed to retry message' }));
762
- throw new Error(extractErrorMessage(errorData));
763
- }
764
- return await response.json();
765
- }
766
- async getAuthStatus() {
767
- const response = await fetch(`${this.baseUrl}/v1/auth/status`, {
768
- method: 'GET',
769
- headers: { 'Content-Type': 'application/json' },
770
- });
771
- if (!response.ok) {
772
- const errorData = await response
773
- .json()
774
- .catch(() => ({ error: 'Failed to get auth status' }));
775
- throw new Error(extractErrorMessage(errorData));
776
- }
777
- return await response.json();
778
- }
779
- async setupSetuWallet() {
780
- const response = await fetch(`${this.baseUrl}/v1/auth/setu/setup`, {
781
- method: 'POST',
782
- headers: { 'Content-Type': 'application/json' },
783
- });
784
- if (!response.ok) {
785
- const errorData = await response
786
- .json()
787
- .catch(() => ({ error: 'Failed to setup wallet' }));
788
- throw new Error(extractErrorMessage(errorData));
789
- }
790
- return await response.json();
791
- }
792
- async importSetuWallet(privateKey) {
793
- const response = await fetch(`${this.baseUrl}/v1/auth/setu/import`, {
794
- method: 'POST',
795
- headers: { 'Content-Type': 'application/json' },
796
- body: JSON.stringify({ privateKey }),
797
- });
798
- if (!response.ok) {
799
- const errorData = await response
800
- .json()
801
- .catch(() => ({ error: 'Failed to import wallet' }));
802
- throw new Error(extractErrorMessage(errorData));
803
- }
804
- return await response.json();
805
- }
806
- async exportSetuWallet() {
807
- const response = await fetch(`${this.baseUrl}/v1/auth/setu/export`, {
808
- method: 'GET',
809
- headers: { 'Content-Type': 'application/json' },
810
- });
811
- if (!response.ok) {
812
- const errorData = await response
813
- .json()
814
- .catch(() => ({ error: 'Failed to export wallet' }));
815
- throw new Error(extractErrorMessage(errorData));
816
- }
817
- return await response.json();
818
- }
819
- async addProvider(provider, apiKey) {
820
- const response = await fetch(`${this.baseUrl}/v1/auth/${provider}`, {
821
- method: 'POST',
822
- headers: { 'Content-Type': 'application/json' },
823
- body: JSON.stringify({ apiKey }),
824
- });
825
- if (!response.ok) {
826
- const errorData = await response
827
- .json()
828
- .catch(() => ({ error: 'Failed to add provider' }));
829
- throw new Error(extractErrorMessage(errorData));
830
- }
831
- return await response.json();
832
- }
833
- async removeProvider(provider) {
834
- const response = await fetch(`${this.baseUrl}/v1/auth/${provider}`, {
835
- method: 'DELETE',
836
- headers: { 'Content-Type': 'application/json' },
837
- });
838
- if (!response.ok) {
839
- const errorData = await response
840
- .json()
841
- .catch(() => ({ error: 'Failed to remove provider' }));
842
- throw new Error(extractErrorMessage(errorData));
843
- }
844
- return await response.json();
845
- }
846
- async completeOnboarding() {
847
- const response = await fetch(`${this.baseUrl}/v1/auth/onboarding/complete`, {
848
- method: 'POST',
849
- headers: { 'Content-Type': 'application/json' },
850
- });
851
- if (!response.ok) {
852
- const errorData = await response
853
- .json()
854
- .catch(() => ({ error: 'Failed to complete onboarding' }));
855
- throw new Error(extractErrorMessage(errorData));
856
- }
857
- return await response.json();
858
- }
859
- getOAuthStartUrl(provider, mode) {
860
- const baseUrl = `${this.baseUrl}/v1/auth/${provider}/oauth/start`;
861
- if (mode) {
862
- return `${baseUrl}?mode=${mode}`;
863
- }
864
- return baseUrl;
865
- }
866
- async getOAuthUrl(provider, mode) {
867
- const response = await fetch(`${this.baseUrl}/v1/auth/${provider}/oauth/url`, {
868
- method: 'POST',
869
- headers: { 'Content-Type': 'application/json' },
870
- body: JSON.stringify({ mode }),
871
- });
872
- if (!response.ok) {
873
- const errorData = await response
874
- .json()
875
- .catch(() => ({ error: 'Failed to get OAuth URL' }));
876
- throw new Error(extractErrorMessage(errorData));
877
- }
878
- return await response.json();
879
- }
880
- async exchangeOAuthCode(provider, code, sessionId) {
881
- const response = await fetch(`${this.baseUrl}/v1/auth/${provider}/oauth/exchange`, {
882
- method: 'POST',
883
- headers: { 'Content-Type': 'application/json' },
884
- body: JSON.stringify({ code, sessionId }),
885
- });
886
- if (!response.ok) {
887
- const errorData = await response
888
- .json()
889
- .catch(() => ({ error: 'Failed to exchange OAuth code' }));
890
- throw new Error(extractErrorMessage(errorData));
891
- }
892
- return await response.json();
893
- }
894
- async startCopilotDeviceFlow() {
895
- const response = await fetch(`${this.baseUrl}/v1/auth/copilot/device/start`, {
896
- method: 'POST',
897
- headers: { 'Content-Type': 'application/json' },
898
- });
899
- if (!response.ok) {
900
- const errorData = await response
901
- .json()
902
- .catch(() => ({ error: 'Failed to start Copilot device flow' }));
903
- throw new Error(extractErrorMessage(errorData));
904
- }
905
- return await response.json();
906
- }
907
- async getProviderUsage(provider) {
908
- const response = await fetch(`${this.baseUrl}/v1/provider-usage/${provider}`, {
909
- method: 'GET',
910
- headers: { 'Content-Type': 'application/json' },
911
- });
912
- if (!response.ok) {
913
- const errorData = await response
914
- .json()
915
- .catch(() => ({ error: 'Failed to fetch usage' }));
916
- throw new Error(extractErrorMessage(errorData));
917
- }
918
- return await response.json();
919
- }
920
- async pollCopilotDeviceFlow(sessionId) {
921
- const response = await fetch(`${this.baseUrl}/v1/auth/copilot/device/poll`, {
922
- method: 'POST',
923
- headers: { 'Content-Type': 'application/json' },
924
- body: JSON.stringify({ sessionId }),
925
- });
926
- if (!response.ok) {
927
- const errorData = await response
928
- .json()
929
- .catch(() => ({ error: 'Poll failed' }));
930
- throw new Error(extractErrorMessage(errorData));
931
- }
932
- return await response.json();
933
- }
934
- }
935
- export const apiClient = new ApiClient();
936
- //# sourceMappingURL=api-client.js.map