cozy-client 60.20.0 → 60.21.1

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.
@@ -3126,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
3126
3126
  CozyClient.hooks = CozyClient.hooks || {};
3127
3127
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3128
3128
 
3129
- CozyClient.version = "60.20.0";
3129
+ CozyClient.version = "60.21.1";
3130
3130
 
3131
3131
  _microee.default.mixin(CozyClient);
3132
3132
 
@@ -0,0 +1,316 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.editAssistant = exports.deleteAssistant = exports.createAssistant = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _CozyClient = _interopRequireDefault(require("../CozyClient"));
17
+
18
+ var _dsl = require("../queries/dsl");
19
+
20
+ var _logger = _interopRequireDefault(require("../logger"));
21
+
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
23
+
24
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
25
+
26
+ /**
27
+ * Creates a new assistant with the provided data.
28
+ *
29
+ * @param {CozyClient} client - An instance of CozyClient
30
+ * @param {object} assistantData - Data for the new assistant
31
+ * @param {string} assistantData.name - Name of the assistant
32
+ * @param {string} assistantData.prompt - Prompt for the assistant
33
+ * @param {string} [assistantData.icon] - Optional icon for the assistant
34
+ * @param {boolean} assistantData.isCustomModel - Indicates if it's a custom model
35
+ * @param {string} assistantData.model - Model identifier
36
+ * @param {string} assistantData.baseUrl - Provider's base URL
37
+ * @param {string} assistantData.apiKey - API key for authentication
38
+ * @returns {Promise<void>} - A promise that resolves when the assistant is created
39
+ * @throws {Error} - Throws an error if the creation fails
40
+ */
41
+ var createAssistant = /*#__PURE__*/function () {
42
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, assistantData) {
43
+ var createdAccountId, account, response, assistant;
44
+ return _regenerator.default.wrap(function _callee$(_context) {
45
+ while (1) {
46
+ switch (_context.prev = _context.next) {
47
+ case 0:
48
+ createdAccountId = null;
49
+ _context.prev = 1;
50
+ account = {
51
+ _type: 'io.cozy.accounts',
52
+ auth: {
53
+ login: assistantData.model,
54
+ password: assistantData.apiKey
55
+ },
56
+ data: {
57
+ baseUrl: assistantData.baseUrl
58
+ }
59
+ };
60
+ _context.next = 5;
61
+ return client.save(account);
62
+
63
+ case 5:
64
+ response = _context.sent;
65
+
66
+ if (!(!response.data || !response.data._id)) {
67
+ _context.next = 8;
68
+ break;
69
+ }
70
+
71
+ throw new Error('Failed to create account for assistant');
72
+
73
+ case 8:
74
+ createdAccountId = response.data._id;
75
+ assistant = {
76
+ _type: 'io.cozy.ai.chat.assistants',
77
+ name: assistantData.name,
78
+ prompt: assistantData.prompt,
79
+ icon: assistantData.icon || null,
80
+ isCustomModel: assistantData.isCustomModel,
81
+ relationships: {
82
+ provider: {
83
+ data: {
84
+ _type: 'io.cozy.accounts',
85
+ _id: createdAccountId
86
+ }
87
+ }
88
+ }
89
+ };
90
+ _context.next = 12;
91
+ return client.save(assistant);
92
+
93
+ case 12:
94
+ _context.next = 26;
95
+ break;
96
+
97
+ case 14:
98
+ _context.prev = 14;
99
+ _context.t0 = _context["catch"](1);
100
+
101
+ if (!createdAccountId) {
102
+ _context.next = 25;
103
+ break;
104
+ }
105
+
106
+ _context.prev = 17;
107
+ _context.next = 20;
108
+ return client.stackClient.collection('io.cozy.accounts').destroy({
109
+ _id: createdAccountId
110
+ });
111
+
112
+ case 20:
113
+ _context.next = 25;
114
+ break;
115
+
116
+ case 22:
117
+ _context.prev = 22;
118
+ _context.t1 = _context["catch"](17);
119
+
120
+ _logger.default.warn('Failed to cleanup orphaned account:', _context.t1);
121
+
122
+ case 25:
123
+ throw new Error("Failed to create assistant: ".concat(_context.t0.message));
124
+
125
+ case 26:
126
+ case "end":
127
+ return _context.stop();
128
+ }
129
+ }
130
+ }, _callee, null, [[1, 14], [17, 22]]);
131
+ }));
132
+
133
+ return function createAssistant(_x, _x2) {
134
+ return _ref.apply(this, arguments);
135
+ };
136
+ }();
137
+ /**
138
+ * Deletes an assistant by its ID.
139
+ *
140
+ * @param {CozyClient} client - An instance of CozyClient
141
+ * @param {string} assistantId - The ID of the assistant to delete
142
+ * @returns {Promise<void>} - A promise that resolves when the assistant is deleted
143
+ * @throws {Error} - Throws an error if the deletion fails
144
+ */
145
+
146
+
147
+ exports.createAssistant = createAssistant;
148
+
149
+ var deleteAssistant = /*#__PURE__*/function () {
150
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(client, assistantId) {
151
+ var _existedAssistant$inc, existedAssistant, assistantInstance, provider;
152
+
153
+ return _regenerator.default.wrap(function _callee2$(_context2) {
154
+ while (1) {
155
+ switch (_context2.prev = _context2.next) {
156
+ case 0:
157
+ _context2.prev = 0;
158
+ _context2.next = 3;
159
+ return client.query((0, _dsl.Q)('io.cozy.ai.chat.assistants').getById(assistantId).include(['provider']));
160
+
161
+ case 3:
162
+ existedAssistant = _context2.sent;
163
+ assistantInstance = existedAssistant.data;
164
+ provider = (_existedAssistant$inc = existedAssistant.included) === null || _existedAssistant$inc === void 0 ? void 0 : _existedAssistant$inc[0];
165
+ _context2.next = 8;
166
+ return client.stackClient.collection('io.cozy.ai.chat.assistants').destroy({
167
+ _id: assistantId,
168
+ _rev: assistantInstance._rev
169
+ });
170
+
171
+ case 8:
172
+ if (!(provider !== null && provider !== void 0 && provider._id && provider !== null && provider !== void 0 && provider._rev)) {
173
+ _context2.next = 11;
174
+ break;
175
+ }
176
+
177
+ _context2.next = 11;
178
+ return client.stackClient.collection('io.cozy.accounts').destroy({
179
+ _id: provider._id,
180
+ _rev: provider._rev
181
+ });
182
+
183
+ case 11:
184
+ _context2.next = 16;
185
+ break;
186
+
187
+ case 13:
188
+ _context2.prev = 13;
189
+ _context2.t0 = _context2["catch"](0);
190
+ throw new Error("Failed to delete assistant: ".concat(_context2.t0.message));
191
+
192
+ case 16:
193
+ case "end":
194
+ return _context2.stop();
195
+ }
196
+ }
197
+ }, _callee2, null, [[0, 13]]);
198
+ }));
199
+
200
+ return function deleteAssistant(_x3, _x4) {
201
+ return _ref2.apply(this, arguments);
202
+ };
203
+ }();
204
+ /**
205
+ * Edit assistant with the provided data.
206
+ *
207
+ * @param {CozyClient} client - An instance of CozyClient
208
+ * @param {string} assistantId - ID of existed assistant
209
+ * @param {object} assistantData - Data for the new assistant
210
+ * @param {string} assistantData.name - Name of the assistant
211
+ * @param {string} assistantData.prompt - Prompt for the assistant
212
+ * @param {string} [assistantData.icon] - Optional icon for the assistant
213
+ * @param {boolean} assistantData.isCustomModel - Indicates if it's a custom model
214
+ * @param {string} assistantData.model - Model identifier
215
+ * @param {string} assistantData.baseUrl - Provider's base URL
216
+ * @param {string} [assistantData.apiKey] - API key for authentication
217
+ * @returns {Promise<void>} - A promise that resolves when the assistant is edited
218
+ * @throws {Error} - Throws an error if the edition fails
219
+ */
220
+
221
+
222
+ exports.deleteAssistant = deleteAssistant;
223
+
224
+ var editAssistant = /*#__PURE__*/function () {
225
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(client, assistantId, assistantData) {
226
+ var _existedAssistant$inc2, existedAssistant, existedAssistantData, provider, account, response, assistant;
227
+
228
+ return _regenerator.default.wrap(function _callee3$(_context3) {
229
+ while (1) {
230
+ switch (_context3.prev = _context3.next) {
231
+ case 0:
232
+ _context3.prev = 0;
233
+ _context3.next = 3;
234
+ return client.query((0, _dsl.Q)('io.cozy.ai.chat.assistants').getById(assistantId).include(['provider']));
235
+
236
+ case 3:
237
+ existedAssistant = _context3.sent;
238
+
239
+ if (existedAssistant) {
240
+ _context3.next = 6;
241
+ break;
242
+ }
243
+
244
+ throw new Error('Assistant not found');
245
+
246
+ case 6:
247
+ existedAssistantData = existedAssistant.data;
248
+ provider = existedAssistant === null || existedAssistant === void 0 ? void 0 : (_existedAssistant$inc2 = existedAssistant.included) === null || _existedAssistant$inc2 === void 0 ? void 0 : _existedAssistant$inc2[0];
249
+
250
+ if (provider) {
251
+ _context3.next = 10;
252
+ break;
253
+ }
254
+
255
+ throw new Error('Provider account not found for assistant');
256
+
257
+ case 10:
258
+ account = _objectSpread(_objectSpread({}, provider), {}, {
259
+ auth: _objectSpread(_objectSpread({}, provider.auth || {}), {}, {
260
+ login: assistantData.model
261
+ }),
262
+ data: _objectSpread(_objectSpread({}, provider.data || {}), {}, {
263
+ baseUrl: assistantData.baseUrl
264
+ })
265
+ });
266
+
267
+ if (assistantData.apiKey) {
268
+ account.auth.password = assistantData.apiKey;
269
+ }
270
+
271
+ _context3.next = 14;
272
+ return client.save(account);
273
+
274
+ case 14:
275
+ response = _context3.sent;
276
+
277
+ if (!(!response.data || !response.data._id)) {
278
+ _context3.next = 17;
279
+ break;
280
+ }
281
+
282
+ throw new Error('Failed to edit account for assistant');
283
+
284
+ case 17:
285
+ assistant = _objectSpread(_objectSpread({}, existedAssistantData), {}, {
286
+ name: assistantData.name,
287
+ prompt: assistantData.prompt,
288
+ icon: assistantData.icon || null,
289
+ isCustomModel: assistantData.isCustomModel
290
+ });
291
+ _context3.next = 20;
292
+ return client.save(assistant);
293
+
294
+ case 20:
295
+ _context3.next = 25;
296
+ break;
297
+
298
+ case 22:
299
+ _context3.prev = 22;
300
+ _context3.t0 = _context3["catch"](0);
301
+ throw new Error("Failed to edit assistant: ".concat(_context3.t0.message));
302
+
303
+ case 25:
304
+ case "end":
305
+ return _context3.stop();
306
+ }
307
+ }
308
+ }, _callee3, null, [[0, 22]]);
309
+ }));
310
+
311
+ return function editAssistant(_x5, _x6, _x7) {
312
+ return _ref3.apply(this, arguments);
313
+ };
314
+ }();
315
+
316
+ exports.editAssistant = editAssistant;
@@ -1223,7 +1223,7 @@ var copy = /*#__PURE__*/function () {
1223
1223
  _context9.next = 19;
1224
1224
  return client.collection(_const.DOCTYPE_FILES, {
1225
1225
  driveId: driveId
1226
- }).copy(file._id, undefined, destination._id);
1226
+ }).copy(file._id, file.name, destination._id);
1227
1227
 
1228
1228
  case 19:
1229
1229
  resp = _context9.sent;
@@ -5,7 +5,7 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.ai = exports.doctypes = exports.geo = exports.user = exports.paper = exports.dacc = exports.sharing = exports.timeseries = exports.document = exports.contact = exports.utils = exports.permission = exports.note = exports.account = exports.konnectorFolder = exports.folder = exports.file = exports.applications = exports.instance = exports.trigger = exports.accounts = exports.triggers = void 0;
8
+ exports.assistant = exports.ai = exports.doctypes = exports.geo = exports.user = exports.paper = exports.dacc = exports.sharing = exports.timeseries = exports.document = exports.contact = exports.utils = exports.permission = exports.note = exports.account = exports.konnectorFolder = exports.folder = exports.file = exports.applications = exports.instance = exports.trigger = exports.accounts = exports.triggers = void 0;
9
9
 
10
10
  var trigger = _interopRequireWildcard(require("./trigger"));
11
11
 
@@ -86,6 +86,10 @@ exports.doctypes = doctypes;
86
86
  var ai = _interopRequireWildcard(require("./ai"));
87
87
 
88
88
  exports.ai = ai;
89
+
90
+ var assistant = _interopRequireWildcard(require("./assistant"));
91
+
92
+ exports.assistant = assistant;
89
93
  // For backward compatibility before 9.0.0
90
94
  var triggers = trigger;
91
95
  exports.triggers = triggers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "60.20.0",
3
+ "version": "60.21.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "git+https://github.com/cozy/cozy-client.git"
14
+ "url": "git+https://github.com/linagora/cozy-client.git"
15
15
  },
16
16
  "dependencies": {
17
17
  "@cozy/minilog": "1.0.0",
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "^26.0.20",
20
20
  "@types/lodash": "^4.14.170",
21
21
  "btoa": "^1.2.1",
22
- "cozy-stack-client": "^60.19.0",
22
+ "cozy-stack-client": "^60.21.1",
23
23
  "date-fns": "^2.30.0",
24
24
  "fast-deep-equal": "^3.1.3",
25
25
  "json-stable-stringify": "^1.0.1",
@@ -74,5 +74,5 @@
74
74
  "react-native-ios11-devicecheck": "^0.0.3"
75
75
  },
76
76
  "sideEffects": false,
77
- "gitHead": "52ae03c0c91e430cb47b8a750d565076db2d559b"
77
+ "gitHead": "fde12fe912846e9e6c357330327de76022a62c88"
78
78
  }
@@ -0,0 +1,20 @@
1
+ export function createAssistant(client: CozyClient, assistantData: {
2
+ name: string;
3
+ prompt: string;
4
+ icon: string;
5
+ isCustomModel: boolean;
6
+ model: string;
7
+ baseUrl: string;
8
+ apiKey: string;
9
+ }): Promise<void>;
10
+ export function deleteAssistant(client: CozyClient, assistantId: string): Promise<void>;
11
+ export function editAssistant(client: CozyClient, assistantId: string, assistantData: {
12
+ name: string;
13
+ prompt: string;
14
+ icon: string;
15
+ isCustomModel: boolean;
16
+ model: string;
17
+ baseUrl: string;
18
+ apiKey: string;
19
+ }): Promise<void>;
20
+ import CozyClient from "../CozyClient";
@@ -20,4 +20,5 @@ import * as user from "./user";
20
20
  import * as geo from "./geo";
21
21
  import * as doctypes from "./doctypes";
22
22
  import * as ai from "./ai";
23
- export { trigger, instance, applications, file, folder, konnectorFolder, note, account, permission, utils, contact, document, timeseries, sharing, dacc, paper, user, geo, doctypes, ai };
23
+ import * as assistant from "./assistant";
24
+ export { trigger, instance, applications, file, folder, konnectorFolder, note, account, permission, utils, contact, document, timeseries, sharing, dacc, paper, user, geo, doctypes, ai, assistant };