cozy-search 2.3.2 → 2.4.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/README.md CHANGED
@@ -59,9 +59,16 @@ of verbs (cozy-home and cozy-drive use `ALL`).
59
59
 
60
60
  ### RAG indexing setup
61
61
 
62
- Call `setupRagIndexing(client)` once per session at startup (before
63
- `ensureProvisionedAssistants` if your app provisions assistants from the
64
- `rag.assistants.autoprovision` flag). It makes sure the instance's two
62
+ Opening the assistant (`AssistantView` or `AssistantDialog`) calls
63
+ `autoprovisionAssistants(client)` once per session: when the
64
+ `cozy.assistant.autoprovision` flag lists assistants, it runs
65
+ `setupRagIndexing(client)` then `ensureProvisionedAssistants(client, entries)`.
66
+ A host app that wants this done at startup, before the assistant is
67
+ opened, can call `autoprovisionAssistants(client)` itself (or the
68
+ `useAssistantsAutoprovision` hook): every call shares the first one's
69
+ promise, so the two never race.
70
+
71
+ `setupRagIndexing(client)` makes sure the instance's two
65
72
  `rag-index` triggers exist (one on `io.cozy.files`, one on
66
73
  `io.cozy.ai.chat.assistants`) and gives the root folder to any assistant
67
74
  that has no knowledge base folder yet — the stack's `rag-index` worker
@@ -76,7 +83,7 @@ never throws: on a stack whose `rag-index` worker is still reserved, the
76
83
  additionally creates one `io.cozy.accounts` document per provisioned
77
84
  assistant, and the `dirName` folder in `io.cozy.files`.
78
85
 
79
- An entry of `rag.assistants.autoprovision` can carry `"default": true`
86
+ An entry of `cozy.assistant.autoprovision` can carry `"default": true`
80
87
  (the first flagged entry wins if there are several). Every NEW
81
88
  conversation then starts on that assistant once its document exists —
82
89
  from the session after it was provisioned onward. Existing conversations
@@ -21,6 +21,8 @@ var _Conversation = _interopRequireDefault(require("../Conversations/Conversatio
21
21
 
22
22
  var _CozyAssistantRuntimeProvider = _interopRequireDefault(require("../CozyAssistantRuntimeProvider"));
23
23
 
24
+ var _useAssistantsAutoprovision = require("../KnowledgeBase/useAssistantsAutoprovision");
25
+
24
26
  var _SearchConversation = _interopRequireDefault(require("../Search/SearchConversation"));
25
27
 
26
28
  var _Sidebar = _interopRequireDefault(require("../Sidebar"));
@@ -43,6 +45,7 @@ var AssistantContainer = function AssistantContainer() {
43
45
  var _useAssistant = (0, _AssistantProvider.useAssistant)(),
44
46
  isOpenSearchConversation = _useAssistant.isOpenSearchConversation;
45
47
 
48
+ (0, _useAssistantsAutoprovision.useAssistantsAutoprovision)();
46
49
  return /*#__PURE__*/_react.default.createElement("div", {
47
50
  className: (0, _classnames.default)('u-flex u-ov-hidden u-h-100', styles['assistant-container'])
48
51
  }, /*#__PURE__*/_react.default.createElement(_Sidebar.default, {
@@ -0,0 +1,10 @@
1
+ export function resetAutoprovisionForTests(): void;
2
+ export function autoprovisionAssistants(client: import("cozy-client").CozyClient): Promise<null | {
3
+ setup: object;
4
+ created: string[];
5
+ ensured: string[];
6
+ skipped: {
7
+ id: string;
8
+ reason: string;
9
+ }[];
10
+ }>;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.resetAutoprovisionForTests = exports.autoprovisionAssistants = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
+
16
+ var _cozyFlags = _interopRequireDefault(require("cozy-flags"));
17
+
18
+ var _provisioning = require("./provisioning");
19
+
20
+ var _ragIndexing = require("./ragIndexing");
21
+
22
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
+
26
+ var warn = function warn() {
27
+ var _console;
28
+
29
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
+ args[_key] = arguments[_key];
31
+ }
32
+
33
+ // eslint-disable-next-line no-console
34
+ (_console = console).warn.apply(_console, ['cozy-search autoprovision:'].concat(args));
35
+ };
36
+
37
+ var pending = null;
38
+
39
+ var resetAutoprovisionForTests = function resetAutoprovisionForTests() {
40
+ pending = null;
41
+ };
42
+
43
+ exports.resetAutoprovisionForTests = resetAutoprovisionForTests;
44
+
45
+ var run = /*#__PURE__*/function () {
46
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client) {
47
+ var entries, setup, result;
48
+ return _regenerator.default.wrap(function _callee$(_context) {
49
+ while (1) {
50
+ switch (_context.prev = _context.next) {
51
+ case 0:
52
+ entries = (0, _cozyFlags.default)(_provisioning.AUTOPROVISION_FLAG);
53
+
54
+ if (!(!Array.isArray(entries) || entries.length === 0)) {
55
+ _context.next = 3;
56
+ break;
57
+ }
58
+
59
+ return _context.abrupt("return", null);
60
+
61
+ case 3:
62
+ _context.next = 5;
63
+ return (0, _ragIndexing.setupRagIndexing)(client);
64
+
65
+ case 5:
66
+ setup = _context.sent;
67
+ _context.next = 8;
68
+ return (0, _provisioning.ensureProvisionedAssistants)(client, entries);
69
+
70
+ case 8:
71
+ result = _context.sent;
72
+
73
+ if (result.skipped.length > 0) {
74
+ warn('skipped entries', result.skipped);
75
+ }
76
+
77
+ return _context.abrupt("return", _objectSpread({
78
+ setup: setup
79
+ }, result));
80
+
81
+ case 11:
82
+ case "end":
83
+ return _context.stop();
84
+ }
85
+ }
86
+ }, _callee);
87
+ }));
88
+
89
+ return function run(_x) {
90
+ return _ref.apply(this, arguments);
91
+ };
92
+ }();
93
+ /**
94
+ * Sets up the rag-index triggers, then provisions the assistants listed in
95
+ * the autoprovision flag. Runs once per session: every call shares the
96
+ * first one's promise, so the assistant UI and the host app's startup can
97
+ * both trigger it without racing each other. Never rejects.
98
+ * @param {import('cozy-client').CozyClient} client - The cozy client.
99
+ * @returns {Promise<null|{setup: object, created: string[], ensured: string[], skipped: {id: string, reason: string}[]}>} Null when the flag lists nothing.
100
+ */
101
+
102
+
103
+ var autoprovisionAssistants = function autoprovisionAssistants(client) {
104
+ if (!pending) {
105
+ pending = run(client).catch(function (error) {
106
+ warn('failed', error);
107
+ return null;
108
+ });
109
+ }
110
+
111
+ return pending;
112
+ };
113
+
114
+ exports.autoprovisionAssistants = autoprovisionAssistants;
@@ -0,0 +1,115 @@
1
+ import flag from 'cozy-flags'
2
+
3
+ import {
4
+ autoprovisionAssistants,
5
+ resetAutoprovisionForTests
6
+ } from './autoprovision'
7
+ import { ensureProvisionedAssistants } from './provisioning'
8
+ import { setupRagIndexing } from './ragIndexing'
9
+
10
+ jest.mock('cozy-flags', () => jest.fn())
11
+ jest.mock('./provisioning', () => ({
12
+ AUTOPROVISION_FLAG: 'cozy.assistant.autoprovision',
13
+ ensureProvisionedAssistants: jest.fn()
14
+ }))
15
+ jest.mock('./ragIndexing', () => ({ setupRagIndexing: jest.fn() }))
16
+
17
+ const client = { id: 'client' }
18
+ const entries = [{ name: 'Docs', dirName: 'Docs' }]
19
+ let warnSpy
20
+
21
+ describe('autoprovisionAssistants', () => {
22
+ beforeEach(() => {
23
+ resetAutoprovisionForTests()
24
+ flag.mockReset()
25
+
26
+ warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {})
27
+ setupRagIndexing
28
+ .mockReset()
29
+ .mockResolvedValue({ triggers: [], migrated: [], errors: [] })
30
+ ensureProvisionedAssistants
31
+ .mockReset()
32
+ .mockResolvedValue({ created: ['docs'], ensured: [], skipped: [] })
33
+ })
34
+
35
+ afterEach(() => {
36
+ warnSpy.mockRestore()
37
+ })
38
+
39
+ it('does nothing without flag entries', async () => {
40
+ flag.mockReturnValue(null)
41
+ await expect(autoprovisionAssistants(client)).resolves.toBeNull()
42
+ expect(flag).toHaveBeenCalledWith('cozy.assistant.autoprovision')
43
+ expect(setupRagIndexing).not.toHaveBeenCalled()
44
+ expect(ensureProvisionedAssistants).not.toHaveBeenCalled()
45
+ })
46
+
47
+ it('sets up the indexing, then provisions the flag entries', async () => {
48
+ flag.mockReturnValue(entries)
49
+ const result = await autoprovisionAssistants(client)
50
+
51
+ expect(setupRagIndexing).toHaveBeenCalledWith(client)
52
+ expect(ensureProvisionedAssistants).toHaveBeenCalledWith(client, entries)
53
+ expect(setupRagIndexing.mock.invocationCallOrder[0]).toBeLessThan(
54
+ ensureProvisionedAssistants.mock.invocationCallOrder[0]
55
+ )
56
+ expect(result).toEqual({
57
+ setup: { triggers: [], migrated: [], errors: [] },
58
+ created: ['docs'],
59
+ ensured: [],
60
+ skipped: []
61
+ })
62
+ })
63
+
64
+ it('runs once per session, sharing the promise', async () => {
65
+ flag.mockReturnValue(entries)
66
+ const first = autoprovisionAssistants(client)
67
+ const second = autoprovisionAssistants(client)
68
+ expect(second).toBe(first)
69
+ await first
70
+ await autoprovisionAssistants(client)
71
+
72
+ expect(setupRagIndexing).toHaveBeenCalledTimes(1)
73
+ expect(ensureProvisionedAssistants).toHaveBeenCalledTimes(1)
74
+ })
75
+
76
+ it('still provisions when the setup reported errors', async () => {
77
+ flag.mockReturnValue(entries)
78
+ setupRagIndexing.mockResolvedValue({
79
+ triggers: [],
80
+ migrated: [],
81
+ errors: [new Error('forbidden')]
82
+ })
83
+ const result = await autoprovisionAssistants(client)
84
+
85
+ expect(ensureProvisionedAssistants).toHaveBeenCalledTimes(1)
86
+ expect(result.setup.errors).toHaveLength(1)
87
+ })
88
+
89
+ it('logs the skipped entries', async () => {
90
+ flag.mockReturnValue(entries)
91
+ ensureProvisionedAssistants.mockResolvedValue({
92
+ created: [],
93
+ ensured: [],
94
+ skipped: [{ id: 'docs', reason: 'nope' }]
95
+ })
96
+ await autoprovisionAssistants(client)
97
+
98
+ expect(warnSpy).toHaveBeenCalledWith(
99
+ 'cozy-search autoprovision:',
100
+ 'skipped entries',
101
+ [{ id: 'docs', reason: 'nope' }]
102
+ )
103
+ })
104
+
105
+ it('never rejects', async () => {
106
+ flag.mockReturnValue(entries)
107
+ setupRagIndexing.mockRejectedValue(new Error('boom'))
108
+ await expect(autoprovisionAssistants(client)).resolves.toBeNull()
109
+ expect(warnSpy).toHaveBeenCalledWith(
110
+ 'cozy-search autoprovision:',
111
+ 'failed',
112
+ expect.any(Error)
113
+ )
114
+ })
115
+ })
@@ -1,4 +1,4 @@
1
- export const AUTOPROVISION_FLAG: "rag.assistants.autoprovision";
1
+ export const AUTOPROVISION_FLAG: "cozy.assistant.autoprovision";
2
2
  export function assistantIdFromName(name: any): string;
3
3
  export function getDefaultProvisionedAssistantId(): string | null;
4
4
  export function isMagicFolderId(dirId: any): boolean;
@@ -27,7 +27,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
27
27
 
28
28
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
29
29
 
30
- var AUTOPROVISION_FLAG = 'rag.assistants.autoprovision';
30
+ var AUTOPROVISION_FLAG = 'cozy.assistant.autoprovision';
31
31
  exports.AUTOPROVISION_FLAG = AUTOPROVISION_FLAG;
32
32
  var ASSISTANTS_DOCTYPE = 'io.cozy.ai.chat.assistants';
33
33
  var APPS_DOCTYPE = 'io.cozy.apps';
@@ -390,7 +390,7 @@ var validate = function validate(entry) {
390
390
  };
391
391
  };
392
392
  /**
393
- * Provisions the assistants described by the rag.assistants.autoprovision
393
+ * Provisions the assistants described by the cozy.assistant.autoprovision
394
394
  * flag. Idempotent: an existing assistant is left alone, or gets the flag's
395
395
  * folder back when it lost it or fell back to the root. Two entries whose
396
396
  * names derive to the same id would fight over one assistant: the second
@@ -42,7 +42,8 @@ const makeClient = ({
42
42
  query: jest.fn(async definition => {
43
43
  if (definition.doctype === 'io.cozy.ai.chat.assistants') {
44
44
  const doc = assistants[definition.id]
45
- if (!doc) throw notFound()
45
+ // cozy-client answers a 404 on getById with a null document.
46
+ if (!doc) return { data: null }
46
47
  return { data: doc }
47
48
  }
48
49
  throw new Error(`unexpected query ${definition.doctype}`)
@@ -398,7 +399,7 @@ describe('ensureProvisionedAssistants', () => {
398
399
  client.query.mockImplementation(async definition => {
399
400
  if (definition.doctype === 'io.cozy.ai.chat.assistants') {
400
401
  queries += 1
401
- if (queries === 1) throw notFound()
402
+ if (queries === 1) return { data: null }
402
403
  return {
403
404
  data: {
404
405
  _id: 'docs',
@@ -484,6 +485,6 @@ describe('getDefaultProvisionedAssistantId', () => {
484
485
  { name: 'Autre', dirName: 'Autre', default: true }
485
486
  ])
486
487
  expect(getDefaultProvisionedAssistantId()).toBe('mes-documents')
487
- expect(flag).toHaveBeenCalledWith('rag.assistants.autoprovision')
488
+ expect(flag).toHaveBeenCalledWith('cozy.assistant.autoprovision')
488
489
  })
489
490
  })
@@ -0,0 +1 @@
1
+ export function useAssistantsAutoprovision(): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAssistantsAutoprovision = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _cozyClient = require("cozy-client");
11
+
12
+ var _autoprovision = require("./autoprovision");
13
+
14
+ /**
15
+ * Provisions the flagged assistants when the assistant UI opens, so an
16
+ * instance gets them even if the host app did not do it at startup.
17
+ */
18
+ var useAssistantsAutoprovision = function useAssistantsAutoprovision() {
19
+ var client = (0, _cozyClient.useClient)();
20
+ (0, _react.useEffect)(function () {
21
+ if (client) (0, _autoprovision.autoprovisionAssistants)(client);
22
+ }, [client]);
23
+ };
24
+
25
+ exports.useAssistantsAutoprovision = useAssistantsAutoprovision;
@@ -0,0 +1,33 @@
1
+ import { renderHook } from '@testing-library/react-hooks/dom'
2
+
3
+ import { useClient } from 'cozy-client'
4
+
5
+ import { autoprovisionAssistants } from './autoprovision'
6
+ import { useAssistantsAutoprovision } from './useAssistantsAutoprovision'
7
+
8
+ jest.mock('cozy-client', () => ({ useClient: jest.fn() }))
9
+ jest.mock('./autoprovision', () => ({ autoprovisionAssistants: jest.fn() }))
10
+
11
+ describe('useAssistantsAutoprovision', () => {
12
+ beforeEach(() => {
13
+ useClient.mockReset()
14
+ autoprovisionAssistants.mockReset().mockResolvedValue(null)
15
+ })
16
+
17
+ it('provisions with the client on mount', () => {
18
+ const client = { id: 'client' }
19
+ useClient.mockReturnValue(client)
20
+ const { rerender } = renderHook(() => useAssistantsAutoprovision())
21
+ rerender()
22
+
23
+ expect(autoprovisionAssistants).toHaveBeenCalledTimes(1)
24
+ expect(autoprovisionAssistants).toHaveBeenCalledWith(client)
25
+ })
26
+
27
+ it('waits for a client', () => {
28
+ useClient.mockReturnValue(null)
29
+ renderHook(() => useAssistantsAutoprovision())
30
+
31
+ expect(autoprovisionAssistants).not.toHaveBeenCalled()
32
+ })
33
+ })
@@ -86,7 +86,7 @@ var DeleteAssistantDialog = function DeleteAssistantDialog(_ref) {
86
86
  isDeleting = _useState2[0],
87
87
  setIsDeleting = _useState2[1];
88
88
 
89
- var assistantQuery = (0, _queries.buildAssistantByIdQuery)(assistantIdInAction);
89
+ var assistantQuery = (0, _queries.buildAssistantByIdWithProviderQuery)(assistantIdInAction);
90
90
 
91
91
  var _ref2 = (0, _cozyClient.useQuery)(assistantQuery.definition, assistantQuery.options) || {},
92
92
  assistant = _ref2.data,
@@ -120,13 +120,13 @@ var EditAssistantDialog = function EditAssistantDialog(_ref) {
120
120
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
121
121
  var _assistant$relationsh, _assistant$relationsh2, _assistant$relationsh3, _assistant$relationsh4, _provider$data, _provider$auth, _provider$data2, _provider$auth2, _provider$auth3, _provider$data3, _provider$auth4;
122
122
 
123
- var _buildAssistantByIdQu, definition, options, response, assistant, provider, providerId, model, selectProviderDefault;
123
+ var _buildAssistantByIdWi, definition, options, response, assistant, provider, providerId, model, selectProviderDefault;
124
124
 
125
125
  return _regenerator.default.wrap(function _callee$(_context) {
126
126
  while (1) {
127
127
  switch (_context.prev = _context.next) {
128
128
  case 0:
129
- _buildAssistantByIdQu = (0, _queries.buildAssistantByIdQuery)(assistantIdInAction), definition = _buildAssistantByIdQu.definition, options = _buildAssistantByIdQu.options;
129
+ _buildAssistantByIdWi = (0, _queries.buildAssistantByIdWithProviderQuery)(assistantIdInAction), definition = _buildAssistantByIdWi.definition, options = _buildAssistantByIdWi.options;
130
130
  _context.next = 3;
131
131
  return client.query(definition(), {
132
132
  as: options.as
@@ -43,6 +43,15 @@ export function buildAssistantByIdQuery(id: any): {
43
43
  enabled: boolean;
44
44
  };
45
45
  };
46
+ export function buildAssistantByIdWithProviderQuery(id: any): {
47
+ definition: () => import("cozy-client").QueryDefinition;
48
+ options: {
49
+ as: string;
50
+ fetchPolicy: Function;
51
+ singleDocData: boolean;
52
+ enabled: boolean;
53
+ };
54
+ };
46
55
  export function buildFileByIdQuery(fileId: any): {
47
56
  definition: () => import("cozy-client").QueryDefinition;
48
57
  options: {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.buildMyselfQuery = exports.buildFilesByIds = exports.buildFileByIdQuery = exports.buildChatConversationsQuery = exports.buildChatConversationQueryById = exports.buildAssistantsQuery = exports.buildAssistantByIdQuery = exports.buildAllAssistantsQuery = exports.FILES_DOCTYPE = exports.EMAIL_DOCTYPE = exports.CHAT_EVENTS_DOCTYPE = exports.CHAT_CONVERSATIONS_DOCTYPE = exports.ASSISTANTS_DOCTYPE = exports.ACCOUNTS_DOCTYPE = void 0;
6
+ exports.buildMyselfQuery = exports.buildFilesByIds = exports.buildFileByIdQuery = exports.buildChatConversationsQuery = exports.buildChatConversationQueryById = exports.buildAssistantsQuery = exports.buildAssistantByIdWithProviderQuery = exports.buildAssistantByIdQuery = exports.buildAllAssistantsQuery = exports.FILES_DOCTYPE = exports.EMAIL_DOCTYPE = exports.CHAT_EVENTS_DOCTYPE = exports.CHAT_CONVERSATIONS_DOCTYPE = exports.ASSISTANTS_DOCTYPE = exports.ACCOUNTS_DOCTYPE = void 0;
7
7
 
8
8
  var _cozyClient = require("cozy-client");
9
9
 
@@ -23,8 +23,7 @@ exports.ACCOUNTS_DOCTYPE = ACCOUNTS_DOCTYPE;
23
23
  var EMAIL_DOCTYPE = 'com.linagora.email';
24
24
  exports.EMAIL_DOCTYPE = EMAIL_DOCTYPE;
25
25
 
26
- var defaultFetchPolicy = _cozyClient.fetchPolicies.olderThan(86400); // 24 hours
27
-
26
+ var defaultFetchPolicy = _cozyClient.fetchPolicies.olderThan(5 * 60 * 1000);
28
27
 
29
28
  var buildFilesByIds = function buildFilesByIds(ids, enabled) {
30
29
  return {
@@ -78,14 +77,16 @@ var buildAssistantsQuery = function buildAssistantsQuery() {
78
77
  fetchPolicy: defaultFetchPolicy
79
78
  }
80
79
  };
81
- };
80
+ }; // The bare assistant document. On a missing id cozy-client resolves to
81
+ // `{ data: null }` rather than throwing, which callers can rely on.
82
+
82
83
 
83
84
  exports.buildAssistantsQuery = buildAssistantsQuery;
84
85
 
85
86
  var buildAssistantByIdQuery = function buildAssistantByIdQuery(id) {
86
87
  return {
87
88
  definition: function definition() {
88
- return (0, _cozyClient.Q)('io.cozy.ai.chat.assistants').getById(id).include(['provider']);
89
+ return (0, _cozyClient.Q)('io.cozy.ai.chat.assistants').getById(id);
89
90
  },
90
91
  options: {
91
92
  as: 'io.cozy.ai.chat.assistants/' + id,
@@ -94,10 +95,29 @@ var buildAssistantByIdQuery = function buildAssistantByIdQuery(id) {
94
95
  enabled: !!id
95
96
  }
96
97
  };
97
- };
98
+ }; // The assistant with its provider account in `included`. Only for ids known
99
+ // to exist: resolving the include on a missing document throws a TypeError
100
+ // in cozy-client instead of yielding a null document.
101
+
98
102
 
99
103
  exports.buildAssistantByIdQuery = buildAssistantByIdQuery;
100
104
 
105
+ var buildAssistantByIdWithProviderQuery = function buildAssistantByIdWithProviderQuery(id) {
106
+ return {
107
+ definition: function definition() {
108
+ return (0, _cozyClient.Q)('io.cozy.ai.chat.assistants').getById(id).include(['provider']);
109
+ },
110
+ options: {
111
+ as: 'io.cozy.ai.chat.assistants/' + id + '/with-provider',
112
+ fetchPolicy: defaultFetchPolicy,
113
+ singleDocData: true,
114
+ enabled: !!id
115
+ }
116
+ };
117
+ };
118
+
119
+ exports.buildAssistantByIdWithProviderQuery = buildAssistantByIdWithProviderQuery;
120
+
101
121
  var buildFileByIdQuery = function buildFileByIdQuery(fileId) {
102
122
  return {
103
123
  definition: function definition() {
package/dist/index.d.ts CHANGED
@@ -11,3 +11,5 @@ export { StreamBridge, createCozyRealtimeChatAdapter } from './components/adapte
11
11
  export { default as AssistantView } from './components/Views/AssistantView';
12
12
  export { assistantIdFromName, AUTOPROVISION_FLAG, ensureProvisionedAssistants, getDefaultProvisionedAssistantId } from './components/KnowledgeBase/provisioning';
13
13
  export { setupRagIndexing } from './components/KnowledgeBase/ragIndexing';
14
+ export { autoprovisionAssistants } from './components/KnowledgeBase/autoprovision';
15
+ export { useAssistantsAutoprovision } from './components/KnowledgeBase/useAssistantsAutoprovision';
package/dist/index.js CHANGED
@@ -83,6 +83,12 @@ Object.defineProperty(exports, "assistantIdFromName", {
83
83
  return _provisioning.assistantIdFromName;
84
84
  }
85
85
  });
86
+ Object.defineProperty(exports, "autoprovisionAssistants", {
87
+ enumerable: true,
88
+ get: function get() {
89
+ return _autoprovision.autoprovisionAssistants;
90
+ }
91
+ });
86
92
  Object.defineProperty(exports, "createCozyRealtimeChatAdapter", {
87
93
  enumerable: true,
88
94
  get: function get() {
@@ -107,6 +113,12 @@ Object.defineProperty(exports, "setupRagIndexing", {
107
113
  return _ragIndexing.setupRagIndexing;
108
114
  }
109
115
  });
116
+ Object.defineProperty(exports, "useAssistantsAutoprovision", {
117
+ enumerable: true,
118
+ get: function get() {
119
+ return _useAssistantsAutoprovision.useAssistantsAutoprovision;
120
+ }
121
+ });
110
122
 
111
123
  var _AssistantLink = _interopRequireDefault(require("./components/Search/AssistantLink"));
112
124
 
@@ -132,4 +144,8 @@ var _AssistantView = _interopRequireDefault(require("./components/Views/Assistan
132
144
 
133
145
  var _provisioning = require("./components/KnowledgeBase/provisioning");
134
146
 
135
- var _ragIndexing = require("./components/KnowledgeBase/ragIndexing");
147
+ var _ragIndexing = require("./components/KnowledgeBase/ragIndexing");
148
+
149
+ var _autoprovision = require("./components/KnowledgeBase/autoprovision");
150
+
151
+ var _useAssistantsAutoprovision = require("./components/KnowledgeBase/useAssistantsAutoprovision");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cozy-search",
3
3
  "description": "UI components about search bar and IA assistant",
4
- "version": "2.3.2",
4
+ "version": "2.4.0",
5
5
  "author": {
6
6
  "name": "Cozy Cloud",
7
7
  "url": "https://github.com/cozy"
@@ -96,5 +96,5 @@
96
96
  "lint": "cd .. && yarn eslint --ext js,jsx,ts packages/cozy-search"
97
97
  },
98
98
  "types": "dist/index.d.ts",
99
- "gitHead": "96598a165eae6c8eef3da4b6451af1dfdb8801a0"
99
+ "gitHead": "c1957ceb37bd485a80d871abc3d583238ef4f2e7"
100
100
  }