cozy-client 60.22.0 → 60.22.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.
- package/dist/CozyClient.js +1 -1
- package/dist/models/assistant.js +92 -66
- package/package.json +2 -2
- package/types/models/assistant.d.ts +28 -14
package/dist/CozyClient.js
CHANGED
|
@@ -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.22.
|
|
3129
|
+
CozyClient.version = "60.22.1";
|
|
3130
3130
|
|
|
3131
3131
|
_microee.default.mixin(CozyClient);
|
|
3132
3132
|
|
package/dist/models/assistant.js
CHANGED
|
@@ -23,21 +23,28 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
23
23
|
|
|
24
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
25
|
|
|
26
|
+
var ASSISTANT_DOCTYPE = 'io.cozy.ai.chat.assistants';
|
|
27
|
+
var ACCOUNT_DOCTYPE = 'io.cozy.accounts';
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} Assistant
|
|
30
|
+
* @property {string} name - Name of the assistant
|
|
31
|
+
* @property {string} prompt - Prompt for the assistant
|
|
32
|
+
* @property {string} [icon] - Optional icon for the assistant
|
|
33
|
+
* @property {string} model - Model identifier
|
|
34
|
+
* @property {string} baseUrl - Provider's base URL
|
|
35
|
+
* @property {string} [apiKey] - API key for authentication
|
|
36
|
+
* @property {string} providerId - ID of the provider
|
|
37
|
+
*/
|
|
38
|
+
|
|
26
39
|
/**
|
|
27
40
|
* Creates a new assistant with the provided data.
|
|
28
41
|
*
|
|
29
42
|
* @param {CozyClient} client - An instance of CozyClient
|
|
30
|
-
* @param {
|
|
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
|
|
43
|
+
* @param {Assistant} assistantData - Data for the new assistant
|
|
38
44
|
* @returns {Promise<void>} - A promise that resolves when the assistant is created
|
|
39
45
|
* @throws {Error} - Throws an error if the creation fails
|
|
40
46
|
*/
|
|
47
|
+
|
|
41
48
|
var createAssistant = /*#__PURE__*/function () {
|
|
42
49
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, assistantData) {
|
|
43
50
|
var createdAccountId, account, response, assistant;
|
|
@@ -48,86 +55,96 @@ var createAssistant = /*#__PURE__*/function () {
|
|
|
48
55
|
createdAccountId = null;
|
|
49
56
|
_context.prev = 1;
|
|
50
57
|
account = {
|
|
51
|
-
_type:
|
|
58
|
+
_type: ACCOUNT_DOCTYPE,
|
|
52
59
|
auth: {
|
|
53
|
-
login: assistantData.model
|
|
54
|
-
password: assistantData.apiKey
|
|
60
|
+
login: assistantData.model
|
|
55
61
|
},
|
|
56
|
-
|
|
57
|
-
baseUrl: assistantData.baseUrl
|
|
58
|
-
}
|
|
62
|
+
account_type: assistantData.providerId
|
|
59
63
|
};
|
|
60
|
-
|
|
64
|
+
|
|
65
|
+
if (assistantData.baseUrl) {
|
|
66
|
+
account.data = {
|
|
67
|
+
baseUrl: assistantData.baseUrl
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (assistantData.apiKey) {
|
|
72
|
+
account.auth.password = assistantData.apiKey;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_context.next = 7;
|
|
61
76
|
return client.save(account);
|
|
62
77
|
|
|
63
|
-
case
|
|
78
|
+
case 7:
|
|
64
79
|
response = _context.sent;
|
|
65
80
|
|
|
66
81
|
if (!(!response.data || !response.data._id)) {
|
|
67
|
-
_context.next =
|
|
82
|
+
_context.next = 10;
|
|
68
83
|
break;
|
|
69
84
|
}
|
|
70
85
|
|
|
71
86
|
throw new Error('Failed to create account for assistant');
|
|
72
87
|
|
|
73
|
-
case
|
|
88
|
+
case 10:
|
|
74
89
|
createdAccountId = response.data._id;
|
|
75
90
|
assistant = {
|
|
76
|
-
_type:
|
|
91
|
+
_type: ASSISTANT_DOCTYPE,
|
|
77
92
|
name: assistantData.name,
|
|
78
93
|
prompt: assistantData.prompt,
|
|
79
94
|
icon: assistantData.icon || null,
|
|
80
|
-
isCustomModel: assistantData.isCustomModel,
|
|
81
95
|
relationships: {
|
|
82
96
|
provider: {
|
|
83
97
|
data: {
|
|
84
|
-
_type:
|
|
85
|
-
_id: createdAccountId
|
|
98
|
+
_type: ACCOUNT_DOCTYPE,
|
|
99
|
+
_id: createdAccountId,
|
|
100
|
+
metadata: {
|
|
101
|
+
providerId: assistantData.providerId
|
|
102
|
+
}
|
|
86
103
|
}
|
|
87
104
|
}
|
|
88
105
|
}
|
|
89
106
|
};
|
|
90
|
-
_context.next =
|
|
107
|
+
_context.next = 14;
|
|
91
108
|
return client.save(assistant);
|
|
92
109
|
|
|
93
|
-
case
|
|
94
|
-
_context.next =
|
|
110
|
+
case 14:
|
|
111
|
+
_context.next = 28;
|
|
95
112
|
break;
|
|
96
113
|
|
|
97
|
-
case
|
|
98
|
-
_context.prev =
|
|
114
|
+
case 16:
|
|
115
|
+
_context.prev = 16;
|
|
99
116
|
_context.t0 = _context["catch"](1);
|
|
100
117
|
|
|
101
118
|
if (!createdAccountId) {
|
|
102
|
-
_context.next =
|
|
119
|
+
_context.next = 27;
|
|
103
120
|
break;
|
|
104
121
|
}
|
|
105
122
|
|
|
106
|
-
_context.prev =
|
|
107
|
-
_context.next =
|
|
123
|
+
_context.prev = 19;
|
|
124
|
+
_context.next = 22;
|
|
108
125
|
return client.stackClient.collection('io.cozy.accounts').destroy({
|
|
109
126
|
_id: createdAccountId
|
|
110
127
|
});
|
|
111
128
|
|
|
112
|
-
case
|
|
113
|
-
_context.next =
|
|
129
|
+
case 22:
|
|
130
|
+
_context.next = 27;
|
|
114
131
|
break;
|
|
115
132
|
|
|
116
|
-
case
|
|
117
|
-
_context.prev =
|
|
118
|
-
_context.t1 = _context["catch"](
|
|
133
|
+
case 24:
|
|
134
|
+
_context.prev = 24;
|
|
135
|
+
_context.t1 = _context["catch"](19);
|
|
119
136
|
|
|
120
137
|
_logger.default.warn('Failed to cleanup orphaned account:', _context.t1);
|
|
121
138
|
|
|
122
|
-
case
|
|
139
|
+
case 27:
|
|
123
140
|
throw new Error("Failed to create assistant: ".concat(_context.t0.message));
|
|
124
141
|
|
|
125
|
-
case
|
|
142
|
+
case 28:
|
|
126
143
|
case "end":
|
|
127
144
|
return _context.stop();
|
|
128
145
|
}
|
|
129
146
|
}
|
|
130
|
-
}, _callee, null, [[1,
|
|
147
|
+
}, _callee, null, [[1, 16], [19, 24]]);
|
|
131
148
|
}));
|
|
132
149
|
|
|
133
150
|
return function createAssistant(_x, _x2) {
|
|
@@ -156,14 +173,14 @@ var deleteAssistant = /*#__PURE__*/function () {
|
|
|
156
173
|
case 0:
|
|
157
174
|
_context2.prev = 0;
|
|
158
175
|
_context2.next = 3;
|
|
159
|
-
return client.query((0, _dsl.Q)(
|
|
176
|
+
return client.query((0, _dsl.Q)(ASSISTANT_DOCTYPE).getById(assistantId).include(['provider']));
|
|
160
177
|
|
|
161
178
|
case 3:
|
|
162
179
|
existedAssistant = _context2.sent;
|
|
163
180
|
assistantInstance = existedAssistant.data;
|
|
164
181
|
provider = (_existedAssistant$inc = existedAssistant.included) === null || _existedAssistant$inc === void 0 ? void 0 : _existedAssistant$inc[0];
|
|
165
182
|
_context2.next = 8;
|
|
166
|
-
return client.stackClient.collection(
|
|
183
|
+
return client.stackClient.collection(ASSISTANT_DOCTYPE).destroy({
|
|
167
184
|
_id: assistantId,
|
|
168
185
|
_rev: assistantInstance._rev
|
|
169
186
|
});
|
|
@@ -175,7 +192,7 @@ var deleteAssistant = /*#__PURE__*/function () {
|
|
|
175
192
|
}
|
|
176
193
|
|
|
177
194
|
_context2.next = 11;
|
|
178
|
-
return client.stackClient.collection(
|
|
195
|
+
return client.stackClient.collection(ACCOUNT_DOCTYPE).destroy({
|
|
179
196
|
_id: provider._id,
|
|
180
197
|
_rev: provider._rev
|
|
181
198
|
});
|
|
@@ -206,14 +223,7 @@ var deleteAssistant = /*#__PURE__*/function () {
|
|
|
206
223
|
*
|
|
207
224
|
* @param {CozyClient} client - An instance of CozyClient
|
|
208
225
|
* @param {string} assistantId - ID of existed assistant
|
|
209
|
-
* @param {
|
|
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
|
|
226
|
+
* @param {Assistant} assistantData - Data for the editted assistant
|
|
217
227
|
* @returns {Promise<void>} - A promise that resolves when the assistant is edited
|
|
218
228
|
* @throws {Error} - Throws an error if the edition fails
|
|
219
229
|
*/
|
|
@@ -223,7 +233,7 @@ exports.deleteAssistant = deleteAssistant;
|
|
|
223
233
|
|
|
224
234
|
var editAssistant = /*#__PURE__*/function () {
|
|
225
235
|
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(client, assistantId, assistantData) {
|
|
226
|
-
var _existedAssistant$inc2, existedAssistant, existedAssistantData, provider, account, response, assistant;
|
|
236
|
+
var _existedAssistant$inc2, _existedAssistantData, _existedAssistantData2, _existedAssistantData3, _existedAssistantData4, _existedAssistantData5, existedAssistant, existedAssistantData, provider, account, _account$data, _account$auth, response, assistant;
|
|
227
237
|
|
|
228
238
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
229
239
|
while (1) {
|
|
@@ -231,7 +241,7 @@ var editAssistant = /*#__PURE__*/function () {
|
|
|
231
241
|
case 0:
|
|
232
242
|
_context3.prev = 0;
|
|
233
243
|
_context3.next = 3;
|
|
234
|
-
return client.query((0, _dsl.Q)(
|
|
244
|
+
return client.query((0, _dsl.Q)(ASSISTANT_DOCTYPE).getById(assistantId).include(['provider']));
|
|
235
245
|
|
|
236
246
|
case 3:
|
|
237
247
|
existedAssistant = _context3.sent;
|
|
@@ -259,53 +269,69 @@ var editAssistant = /*#__PURE__*/function () {
|
|
|
259
269
|
auth: _objectSpread(_objectSpread({}, provider.auth || {}), {}, {
|
|
260
270
|
login: assistantData.model
|
|
261
271
|
}),
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
})
|
|
272
|
+
account_type: assistantData.providerId,
|
|
273
|
+
data: _objectSpread({}, provider.data || {})
|
|
265
274
|
});
|
|
266
275
|
|
|
276
|
+
if (assistantData.baseUrl) {
|
|
277
|
+
account.data.baseUrl = assistantData.baseUrl;
|
|
278
|
+
} else {
|
|
279
|
+
(_account$data = account.data) === null || _account$data === void 0 ? true : delete _account$data.baseUrl;
|
|
280
|
+
} // Only update the password if a new API key is explicitly provided
|
|
281
|
+
|
|
282
|
+
|
|
267
283
|
if (assistantData.apiKey) {
|
|
268
284
|
account.auth.password = assistantData.apiKey;
|
|
285
|
+
} else if (!assistantData.baseUrl) {
|
|
286
|
+
(_account$auth = account.auth) === null || _account$auth === void 0 ? true : delete _account$auth.password;
|
|
269
287
|
}
|
|
270
288
|
|
|
271
|
-
_context3.next =
|
|
289
|
+
_context3.next = 15;
|
|
272
290
|
return client.save(account);
|
|
273
291
|
|
|
274
|
-
case
|
|
292
|
+
case 15:
|
|
275
293
|
response = _context3.sent;
|
|
276
294
|
|
|
277
295
|
if (!(!response.data || !response.data._id)) {
|
|
278
|
-
_context3.next =
|
|
296
|
+
_context3.next = 18;
|
|
279
297
|
break;
|
|
280
298
|
}
|
|
281
299
|
|
|
282
300
|
throw new Error('Failed to edit account for assistant');
|
|
283
301
|
|
|
284
|
-
case
|
|
302
|
+
case 18:
|
|
285
303
|
assistant = _objectSpread(_objectSpread({}, existedAssistantData), {}, {
|
|
286
304
|
name: assistantData.name,
|
|
287
305
|
prompt: assistantData.prompt,
|
|
288
306
|
icon: assistantData.icon || null,
|
|
289
|
-
|
|
307
|
+
relationships: {
|
|
308
|
+
provider: {
|
|
309
|
+
data: _objectSpread(_objectSpread({}, (existedAssistantData === null || existedAssistantData === void 0 ? void 0 : (_existedAssistantData = existedAssistantData.relationships) === null || _existedAssistantData === void 0 ? void 0 : (_existedAssistantData2 = _existedAssistantData.provider) === null || _existedAssistantData2 === void 0 ? void 0 : _existedAssistantData2.data) || {}), {}, {
|
|
310
|
+
metadata: _objectSpread(_objectSpread({}, (existedAssistantData === null || existedAssistantData === void 0 ? void 0 : (_existedAssistantData3 = existedAssistantData.relationships) === null || _existedAssistantData3 === void 0 ? void 0 : (_existedAssistantData4 = _existedAssistantData3.provider) === null || _existedAssistantData4 === void 0 ? void 0 : (_existedAssistantData5 = _existedAssistantData4.data) === null || _existedAssistantData5 === void 0 ? void 0 : _existedAssistantData5.metadata) || {}), {}, {
|
|
311
|
+
providerId: assistantData.providerId
|
|
312
|
+
})
|
|
313
|
+
})
|
|
314
|
+
}
|
|
315
|
+
}
|
|
290
316
|
});
|
|
291
|
-
_context3.next =
|
|
317
|
+
_context3.next = 21;
|
|
292
318
|
return client.save(assistant);
|
|
293
319
|
|
|
294
|
-
case
|
|
295
|
-
_context3.next =
|
|
320
|
+
case 21:
|
|
321
|
+
_context3.next = 26;
|
|
296
322
|
break;
|
|
297
323
|
|
|
298
|
-
case
|
|
299
|
-
_context3.prev =
|
|
324
|
+
case 23:
|
|
325
|
+
_context3.prev = 23;
|
|
300
326
|
_context3.t0 = _context3["catch"](0);
|
|
301
327
|
throw new Error("Failed to edit assistant: ".concat(_context3.t0.message));
|
|
302
328
|
|
|
303
|
-
case
|
|
329
|
+
case 26:
|
|
304
330
|
case "end":
|
|
305
331
|
return _context3.stop();
|
|
306
332
|
}
|
|
307
333
|
}
|
|
308
|
-
}, _callee3, null, [[0,
|
|
334
|
+
}, _callee3, null, [[0, 23]]);
|
|
309
335
|
}));
|
|
310
336
|
|
|
311
337
|
return function editAssistant(_x5, _x6, _x7) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.22.
|
|
3
|
+
"version": "60.22.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-native-ios11-devicecheck": "^0.0.3"
|
|
75
75
|
},
|
|
76
76
|
"sideEffects": false,
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "b1d8d07e1152cda660cadab7531d71fc637e8e81"
|
|
78
78
|
}
|
|
@@ -1,20 +1,34 @@
|
|
|
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>;
|
|
1
|
+
export function createAssistant(client: CozyClient, assistantData: Assistant): Promise<void>;
|
|
10
2
|
export function deleteAssistant(client: CozyClient, assistantId: string): Promise<void>;
|
|
11
|
-
export function editAssistant(client: CozyClient, assistantId: string, assistantData:
|
|
3
|
+
export function editAssistant(client: CozyClient, assistantId: string, assistantData: Assistant): Promise<void>;
|
|
4
|
+
export type Assistant = {
|
|
5
|
+
/**
|
|
6
|
+
* - Name of the assistant
|
|
7
|
+
*/
|
|
12
8
|
name: string;
|
|
9
|
+
/**
|
|
10
|
+
* - Prompt for the assistant
|
|
11
|
+
*/
|
|
13
12
|
prompt: string;
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/**
|
|
14
|
+
* - Optional icon for the assistant
|
|
15
|
+
*/
|
|
16
|
+
icon?: string;
|
|
17
|
+
/**
|
|
18
|
+
* - Model identifier
|
|
19
|
+
*/
|
|
16
20
|
model: string;
|
|
21
|
+
/**
|
|
22
|
+
* - Provider's base URL
|
|
23
|
+
*/
|
|
17
24
|
baseUrl: string;
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
/**
|
|
26
|
+
* - API key for authentication
|
|
27
|
+
*/
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
/**
|
|
30
|
+
* - ID of the provider
|
|
31
|
+
*/
|
|
32
|
+
providerId: string;
|
|
33
|
+
};
|
|
20
34
|
import CozyClient from "../CozyClient";
|