@rimori/client 2.5.18-next.0 → 2.5.18-next.2

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.
@@ -91,7 +91,7 @@ export declare class AIModule {
91
91
  * @param cache Whether to cache the result (default: false).
92
92
  * @param model The model to use for generation.
93
93
  */
94
- getSteamedText(messages: Message[], onMessage: OnLLMResponse, tools?: Tool[], cache?: boolean, model?: string, knowledgeId?: string): Promise<void>;
94
+ getSteamedText(messages: Message[], onMessage: OnLLMResponse, tools?: Tool[], cache?: boolean, model?: string, knowledgeId?: string): Promise<string>;
95
95
  /**
96
96
  * Generate voice audio from text using AI.
97
97
  * @param text The text to convert to voice.
@@ -151,7 +151,7 @@ export declare class AIModule {
151
151
  tools?: Tool[];
152
152
  model?: string;
153
153
  knowledgeId?: string;
154
- }): Promise<void>;
154
+ }): Promise<T>;
155
155
  private streamObject;
156
156
  private sendToolResult;
157
157
  }
@@ -108,6 +108,7 @@ export class AIModule {
108
108
  onResult: ({ result }) => onMessage(messageId, result, false),
109
109
  });
110
110
  onMessage(messageId, result, true);
111
+ return result;
111
112
  });
112
113
  }
113
114
  /**
@@ -208,7 +209,7 @@ export class AIModule {
208
209
  getStreamedObject(params) {
209
210
  return __awaiter(this, void 0, void 0, function* () {
210
211
  const { systemPrompt, responseSchema, userPrompt, onResult, cache = false, tools = [], model = undefined, knowledgeId, } = params;
211
- yield this.streamObject({
212
+ return yield this.streamObject({
212
213
  responseSchema,
213
214
  messages: this.getChatMessage(systemPrompt, userPrompt),
214
215
  onResult,
@@ -2,6 +2,7 @@ import { RimoriClient } from '../plugin/RimoriClient';
2
2
  /**
3
3
  * Sets up the web worker for the plugin to be able receive and send messages to Rimori.
4
4
  * @param pluginId - The id of the plugin to setup the worker for.
5
- * @param init - The function containing the initialization logic.
5
+ * @param init - The function containing the initialization logic. The init must be completed within 5s. For long running tasks use the init event (e.g. onboarding.triggerInitPlugin) or run the work async.
6
+ * @returns A promise that resolves when the worker is setup.
6
7
  */
7
8
  export declare function setupWorker(pluginId: string, init: (client: RimoriClient) => void | Promise<void>): Promise<void>;
@@ -12,7 +12,8 @@ import { EventBusHandler } from '../fromRimori/EventBus';
12
12
  /**
13
13
  * Sets up the web worker for the plugin to be able receive and send messages to Rimori.
14
14
  * @param pluginId - The id of the plugin to setup the worker for.
15
- * @param init - The function containing the initialization logic.
15
+ * @param init - The function containing the initialization logic. The init must be completed within 5s. For long running tasks use the init event (e.g. onboarding.triggerInitPlugin) or run the work async.
16
+ * @returns A promise that resolves when the worker is setup.
16
17
  */
17
18
  export function setupWorker(pluginId, init) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -27,10 +28,15 @@ export function setupWorker(pluginId, init) {
27
28
  };
28
29
  // Assign the mock to globalThis.
29
30
  Object.assign(globalThis, { window: mockWindow });
30
- EventBusHandler.getInstance('Worker EventBus');
31
+ EventBusHandler.getInstance('Worker ' + pluginId + ' EventBus');
31
32
  const rimoriClient = yield RimoriClient.getInstance(pluginId);
32
33
  console.debug('[Worker] RimoriClient initialized.');
33
- yield init(rimoriClient);
34
+ const timoutError = new Error('[Worker ' +
35
+ pluginId +
36
+ '] Worker setup must complete within 5s. Use init event (e.g. onboarding.triggerInitPlugin) or run work async.');
37
+ const initPromise = Promise.resolve(init(rimoriClient));
38
+ const timeout = new Promise((_, reject) => setTimeout(() => reject(timoutError), 5000));
39
+ yield Promise.race([initPromise, timeout]);
34
40
  console.debug('[Worker] Worker initialized.');
35
41
  rimoriClient.event.emit('self.rimori.triggerInitFinished');
36
42
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/client",
3
- "version": "2.5.18-next.0",
3
+ "version": "2.5.18-next.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {