cozy-client 60.18.0 → 60.20.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/index.js +5 -1
- package/package.json +3 -3
- package/types/models/ai.d.ts +149 -0
- package/types/models/index.d.ts +2 -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.20.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;
|
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.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,10 @@ 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;
|
|
85
89
|
// For backward compatibility before 9.0.0
|
|
86
90
|
var triggers = trigger;
|
|
87
91
|
exports.triggers = triggers;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.20.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -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.19.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": "52ae03c0c91e430cb47b8a750d565076db2d559b"
|
|
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";
|
package/types/models/index.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ 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
|
+
export { trigger, instance, applications, file, folder, konnectorFolder, note, account, permission, utils, contact, document, timeseries, sharing, dacc, paper, user, geo, doctypes, ai };
|