@rimori/client 2.5.18 → 2.5.19

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/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export { Translator } from './controller/TranslationController';
15
15
  export type { TriggerAction } from './plugin/module/ExerciseModule';
16
16
  export type { Message, ToolInvocation } from './plugin/module/AIModule';
17
17
  export type { Theme, ApplicationMode } from './plugin/module/PluginModule';
18
- export type { UserInfo, Language, UserRole, ExplicitUndefined } from './plugin/module/PluginModule';
18
+ export type { UserInfo, Language, UserRole, ExplicitUndefined, BasePluginSettings } from './plugin/module/PluginModule';
19
19
  export type { SharedContent, BasicSharedContent, ContentStatus } from './plugin/module/SharedContentController';
20
20
  export type { MacroAccomplishmentPayload, MicroAccomplishmentPayload } from './controller/AccomplishmentController';
21
21
  export { StorageModule } from './plugin/module/StorageModule';
@@ -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,
@@ -32,7 +32,7 @@ export class EventModule {
32
32
  const topicParts = preliminaryTopic.split('.');
33
33
  if (topicParts.length === 3) {
34
34
  if (!topicParts[0].startsWith('pl') && topicParts[0] !== 'global') {
35
- throw new Error("The event topic must start with the plugin id or 'global'.");
35
+ throw new Error(`Invalid event topic '${preliminaryTopic}'. The topic must start with the plugin id, 'self' or 'global'.`);
36
36
  }
37
37
  return preliminaryTopic;
38
38
  }
@@ -44,7 +44,7 @@ export declare class PluginModule {
44
44
  * @param defaultSettings The default settings to use if no settings are found.
45
45
  * @returns The settings for the plugin.
46
46
  */
47
- getSettings<T>(defaultSettings: ExplicitUndefined<T>): Promise<ExplicitUndefined<T>>;
47
+ getSettings<T extends BasePluginSettings>(defaultSettings: ExplicitUndefined<T>): Promise<ExplicitUndefined<T>>;
48
48
  /**
49
49
  * Get the current user info.
50
50
  * Note: For reactive updates in React components, use the userInfo from useRimori() hook instead.
@@ -110,6 +110,13 @@ export type LearningReason = (typeof LEARNING_REASONS)[number];
110
110
  export type ExplicitUndefined<T> = {
111
111
  [K in Exclude<keyof T, never>]-?: {} extends Pick<T, K> ? T[K] | undefined : T[K];
112
112
  };
113
+ /**
114
+ * All plugin settings must include is_inited so rimori-main can detect
115
+ * plugins whose one-time worker init did not complete and re-trigger them.
116
+ */
117
+ export type BasePluginSettings = {
118
+ is_inited: boolean;
119
+ };
113
120
  export interface UserInfo {
114
121
  /**
115
122
  * The user's unique ID
@@ -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",
3
+ "version": "2.5.19",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {