cozy-client 60.19.0 → 60.21.0
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/ai.js +200 -0
- package/dist/models/assistant.js +316 -0
- package/dist/models/index.js +9 -1
- package/package.json +4 -4
- package/types/models/ai.d.ts +149 -0
- package/types/models/assistant.d.ts +20 -0
- package/types/models/index.d.ts +3 -1
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.
|
|
3129
|
+
CozyClient.version = "60.21.0";
|
|
3130
3130
|
|
|
3131
3131
|
_microee.default.mixin(CozyClient);
|
|
3132
3132
|
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.chatCompletion = exports.extractText = 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
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {object} FileMetadata
|
|
24
|
+
* @property {string} name - File name
|
|
25
|
+
* @property {string} mime - File MIME type
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {object} ChatMessage
|
|
30
|
+
* @property {string} role - Role of the message sender (e.g., 'system', 'user', 'assistant')
|
|
31
|
+
* @property {string} content - Content of the message
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {object} ChatCompletionMessage
|
|
36
|
+
* @property {string} content - Message content
|
|
37
|
+
* @property {string} role - Message role
|
|
38
|
+
* @property {*} [tool_calls] - Tool calls (if any)
|
|
39
|
+
* @property {*} [function_call] - Function call (if any)
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {object} ChatCompletionChoice
|
|
44
|
+
* @property {string} finish_reason - Reason for finishing
|
|
45
|
+
* @property {number} index - Choice index
|
|
46
|
+
* @property {ChatCompletionMessage} message - Message content
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {object} ChatCompletionUsage
|
|
51
|
+
* @property {number} completion_tokens - Number of tokens in completion
|
|
52
|
+
* @property {number} prompt_tokens - Number of tokens in prompt
|
|
53
|
+
* @property {number} total_tokens - Total tokens used
|
|
54
|
+
* @property {*} [completion_tokens_details] - Completion tokens details
|
|
55
|
+
* @property {*} [prompt_tokens_details] - Prompt tokens details
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @typedef {object} ChatCompletionResponse
|
|
60
|
+
* @property {string} id - Completion ID
|
|
61
|
+
* @property {number} created - Creation timestamp
|
|
62
|
+
* @property {string|null} model - Model used (may be null)
|
|
63
|
+
* @property {string} object - Object type
|
|
64
|
+
* @property {string|null} system_fingerprint - System fingerprint
|
|
65
|
+
* @property {ChatCompletionChoice[]} choices - Array of completion choices
|
|
66
|
+
* @property {ChatCompletionUsage} usage - Token usage statistics
|
|
67
|
+
* @property {string|null} [service_tier] - Service tier
|
|
68
|
+
* @property {*} [prompt_logprobs] - Prompt log probabilities
|
|
69
|
+
* @property {string} [extra] - Extra data (e.g., sources)
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {object} ChatCompletionOptions
|
|
74
|
+
* @property {boolean} [stream=false] - Whether to stream the response
|
|
75
|
+
* @property {string} [model] - Optional model to use
|
|
76
|
+
* @property {number} [temperature] - Temperature for randomness (0-2)
|
|
77
|
+
* @property {number} [top_p] - Top-p sampling
|
|
78
|
+
* @property {number} [max_tokens] - Maximum tokens to generate
|
|
79
|
+
* @property {number} [presence_penalty] - Presence penalty
|
|
80
|
+
* @property {number} [frequency_penalty] - Frequency penalty
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Extract text from a file using AI tools
|
|
85
|
+
*
|
|
86
|
+
* @param {CozyClient} client - Instance of CozyClient
|
|
87
|
+
* @param {Blob} fileBlob - File content as Blob
|
|
88
|
+
* @param {FileMetadata} fileMetadata - File metadata (name, mime)
|
|
89
|
+
* @returns {Promise<string>} Extracted text content
|
|
90
|
+
*/
|
|
91
|
+
var extractText = /*#__PURE__*/function () {
|
|
92
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, fileBlob, fileMetadata) {
|
|
93
|
+
var formData, response, _response$text, errorText, result;
|
|
94
|
+
|
|
95
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
96
|
+
while (1) {
|
|
97
|
+
switch (_context.prev = _context.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
formData = new FormData();
|
|
100
|
+
formData.append('file', fileBlob, fileMetadata.name);
|
|
101
|
+
formData.append('tool', JSON.stringify({
|
|
102
|
+
name: 'extractText'
|
|
103
|
+
}));
|
|
104
|
+
formData.append('metadata', JSON.stringify({
|
|
105
|
+
mime: fileMetadata.mime,
|
|
106
|
+
name: fileMetadata.name
|
|
107
|
+
}));
|
|
108
|
+
_context.next = 6;
|
|
109
|
+
return client.stackClient.fetch('POST', '/ai/v1/tools/execute', formData, {
|
|
110
|
+
body: formData
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
case 6:
|
|
114
|
+
response = _context.sent;
|
|
115
|
+
|
|
116
|
+
if (response.ok) {
|
|
117
|
+
_context.next = 12;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_context.next = 10;
|
|
122
|
+
return (_response$text = response.text) === null || _response$text === void 0 ? void 0 : _response$text.call(response);
|
|
123
|
+
|
|
124
|
+
case 10:
|
|
125
|
+
errorText = _context.sent;
|
|
126
|
+
throw new Error("Failed to extract text: ".concat(response.statusText, ". ").concat(errorText));
|
|
127
|
+
|
|
128
|
+
case 12:
|
|
129
|
+
_context.next = 14;
|
|
130
|
+
return response.json();
|
|
131
|
+
|
|
132
|
+
case 14:
|
|
133
|
+
result = _context.sent;
|
|
134
|
+
return _context.abrupt("return", result.message);
|
|
135
|
+
|
|
136
|
+
case 16:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context.stop();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}, _callee);
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
return function extractText(_x, _x2, _x3) {
|
|
145
|
+
return _ref.apply(this, arguments);
|
|
146
|
+
};
|
|
147
|
+
}();
|
|
148
|
+
/**
|
|
149
|
+
* Generate AI chat completion
|
|
150
|
+
*
|
|
151
|
+
* @param {CozyClient} client - Instance of CozyClient
|
|
152
|
+
* @param {ChatMessage[]} messages - Array of message objects with role and content
|
|
153
|
+
* @param {ChatCompletionOptions} [options={}] - Additional options
|
|
154
|
+
* @returns {Promise<ChatCompletionResponse>} AI response following OpenAI chat completion format
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
exports.extractText = extractText;
|
|
159
|
+
|
|
160
|
+
var chatCompletion = /*#__PURE__*/function () {
|
|
161
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(client, messages) {
|
|
162
|
+
var options,
|
|
163
|
+
requestBody,
|
|
164
|
+
response,
|
|
165
|
+
_args2 = arguments;
|
|
166
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
167
|
+
while (1) {
|
|
168
|
+
switch (_context2.prev = _context2.next) {
|
|
169
|
+
case 0:
|
|
170
|
+
options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
|
|
171
|
+
requestBody = _objectSpread({
|
|
172
|
+
messages: messages
|
|
173
|
+
}, options);
|
|
174
|
+
_context2.prev = 2;
|
|
175
|
+
_context2.next = 5;
|
|
176
|
+
return client.stackClient.fetchJSON('POST', '/ai/v1/chat/completions', requestBody);
|
|
177
|
+
|
|
178
|
+
case 5:
|
|
179
|
+
response = _context2.sent;
|
|
180
|
+
return _context2.abrupt("return", response);
|
|
181
|
+
|
|
182
|
+
case 9:
|
|
183
|
+
_context2.prev = 9;
|
|
184
|
+
_context2.t0 = _context2["catch"](2);
|
|
185
|
+
throw new Error("Failed to generate chat completion: ".concat(_context2.t0.message));
|
|
186
|
+
|
|
187
|
+
case 12:
|
|
188
|
+
case "end":
|
|
189
|
+
return _context2.stop();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}, _callee2, null, [[2, 9]]);
|
|
193
|
+
}));
|
|
194
|
+
|
|
195
|
+
return function chatCompletion(_x4, _x5) {
|
|
196
|
+
return _ref2.apply(this, arguments);
|
|
197
|
+
};
|
|
198
|
+
}();
|
|
199
|
+
|
|
200
|
+
exports.chatCompletion = chatCompletion;
|
|
@@ -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;
|
package/dist/models/index.js
CHANGED
|
@@ -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.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
|
|
|
@@ -82,6 +82,14 @@ exports.geo = geo;
|
|
|
82
82
|
var doctypes = _interopRequireWildcard(require("./doctypes"));
|
|
83
83
|
|
|
84
84
|
exports.doctypes = doctypes;
|
|
85
|
+
|
|
86
|
+
var ai = _interopRequireWildcard(require("./ai"));
|
|
87
|
+
|
|
88
|
+
exports.ai = ai;
|
|
89
|
+
|
|
90
|
+
var assistant = _interopRequireWildcard(require("./assistant"));
|
|
91
|
+
|
|
92
|
+
exports.assistant = assistant;
|
|
85
93
|
// For backward compatibility before 9.0.0
|
|
86
94
|
var triggers = trigger;
|
|
87
95
|
exports.triggers = triggers;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.21.0",
|
|
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/
|
|
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.
|
|
22
|
+
"cozy-stack-client": "^60.21.0",
|
|
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": "
|
|
77
|
+
"gitHead": "a832efcd3a152a0ea11f5a736abcd3ece28cf181"
|
|
78
78
|
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export function extractText(client: CozyClient, fileBlob: Blob, fileMetadata: FileMetadata): Promise<string>;
|
|
2
|
+
export function chatCompletion(client: CozyClient, messages: ChatMessage[], options?: ChatCompletionOptions): Promise<ChatCompletionResponse>;
|
|
3
|
+
export type FileMetadata = {
|
|
4
|
+
/**
|
|
5
|
+
* - File name
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* - File MIME type
|
|
10
|
+
*/
|
|
11
|
+
mime: string;
|
|
12
|
+
};
|
|
13
|
+
export type ChatMessage = {
|
|
14
|
+
/**
|
|
15
|
+
* - Role of the message sender (e.g., 'system', 'user', 'assistant')
|
|
16
|
+
*/
|
|
17
|
+
role: string;
|
|
18
|
+
/**
|
|
19
|
+
* - Content of the message
|
|
20
|
+
*/
|
|
21
|
+
content: string;
|
|
22
|
+
};
|
|
23
|
+
export type ChatCompletionMessage = {
|
|
24
|
+
/**
|
|
25
|
+
* - Message content
|
|
26
|
+
*/
|
|
27
|
+
content: string;
|
|
28
|
+
/**
|
|
29
|
+
* - Message role
|
|
30
|
+
*/
|
|
31
|
+
role: string;
|
|
32
|
+
/**
|
|
33
|
+
* - Tool calls (if any)
|
|
34
|
+
*/
|
|
35
|
+
tool_calls?: any;
|
|
36
|
+
/**
|
|
37
|
+
* - Function call (if any)
|
|
38
|
+
*/
|
|
39
|
+
function_call?: any;
|
|
40
|
+
};
|
|
41
|
+
export type ChatCompletionChoice = {
|
|
42
|
+
/**
|
|
43
|
+
* - Reason for finishing
|
|
44
|
+
*/
|
|
45
|
+
finish_reason: string;
|
|
46
|
+
/**
|
|
47
|
+
* - Choice index
|
|
48
|
+
*/
|
|
49
|
+
index: number;
|
|
50
|
+
/**
|
|
51
|
+
* - Message content
|
|
52
|
+
*/
|
|
53
|
+
message: ChatCompletionMessage;
|
|
54
|
+
};
|
|
55
|
+
export type ChatCompletionUsage = {
|
|
56
|
+
/**
|
|
57
|
+
* - Number of tokens in completion
|
|
58
|
+
*/
|
|
59
|
+
completion_tokens: number;
|
|
60
|
+
/**
|
|
61
|
+
* - Number of tokens in prompt
|
|
62
|
+
*/
|
|
63
|
+
prompt_tokens: number;
|
|
64
|
+
/**
|
|
65
|
+
* - Total tokens used
|
|
66
|
+
*/
|
|
67
|
+
total_tokens: number;
|
|
68
|
+
/**
|
|
69
|
+
* - Completion tokens details
|
|
70
|
+
*/
|
|
71
|
+
completion_tokens_details?: any;
|
|
72
|
+
/**
|
|
73
|
+
* - Prompt tokens details
|
|
74
|
+
*/
|
|
75
|
+
prompt_tokens_details?: any;
|
|
76
|
+
};
|
|
77
|
+
export type ChatCompletionResponse = {
|
|
78
|
+
/**
|
|
79
|
+
* - Completion ID
|
|
80
|
+
*/
|
|
81
|
+
id: string;
|
|
82
|
+
/**
|
|
83
|
+
* - Creation timestamp
|
|
84
|
+
*/
|
|
85
|
+
created: number;
|
|
86
|
+
/**
|
|
87
|
+
* - Model used (may be null)
|
|
88
|
+
*/
|
|
89
|
+
model: string | null;
|
|
90
|
+
/**
|
|
91
|
+
* - Object type
|
|
92
|
+
*/
|
|
93
|
+
object: string;
|
|
94
|
+
/**
|
|
95
|
+
* - System fingerprint
|
|
96
|
+
*/
|
|
97
|
+
system_fingerprint: string | null;
|
|
98
|
+
/**
|
|
99
|
+
* - Array of completion choices
|
|
100
|
+
*/
|
|
101
|
+
choices: ChatCompletionChoice[];
|
|
102
|
+
/**
|
|
103
|
+
* - Token usage statistics
|
|
104
|
+
*/
|
|
105
|
+
usage: ChatCompletionUsage;
|
|
106
|
+
/**
|
|
107
|
+
* - Service tier
|
|
108
|
+
*/
|
|
109
|
+
service_tier?: string | null;
|
|
110
|
+
/**
|
|
111
|
+
* - Prompt log probabilities
|
|
112
|
+
*/
|
|
113
|
+
prompt_logprobs?: any;
|
|
114
|
+
/**
|
|
115
|
+
* - Extra data (e.g., sources)
|
|
116
|
+
*/
|
|
117
|
+
extra?: string;
|
|
118
|
+
};
|
|
119
|
+
export type ChatCompletionOptions = {
|
|
120
|
+
/**
|
|
121
|
+
* - Whether to stream the response
|
|
122
|
+
*/
|
|
123
|
+
stream?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* - Optional model to use
|
|
126
|
+
*/
|
|
127
|
+
model?: string;
|
|
128
|
+
/**
|
|
129
|
+
* - Temperature for randomness (0-2)
|
|
130
|
+
*/
|
|
131
|
+
temperature?: number;
|
|
132
|
+
/**
|
|
133
|
+
* - Top-p sampling
|
|
134
|
+
*/
|
|
135
|
+
top_p?: number;
|
|
136
|
+
/**
|
|
137
|
+
* - Maximum tokens to generate
|
|
138
|
+
*/
|
|
139
|
+
max_tokens?: number;
|
|
140
|
+
/**
|
|
141
|
+
* - Presence penalty
|
|
142
|
+
*/
|
|
143
|
+
presence_penalty?: number;
|
|
144
|
+
/**
|
|
145
|
+
* - Frequency penalty
|
|
146
|
+
*/
|
|
147
|
+
frequency_penalty?: number;
|
|
148
|
+
};
|
|
149
|
+
import CozyClient from "../CozyClient";
|
|
@@ -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";
|
package/types/models/index.d.ts
CHANGED
|
@@ -19,4 +19,6 @@ import * as paper from "./paper";
|
|
|
19
19
|
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
|
+
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 };
|