@rimori/client 1.0.3 → 1.0.4

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.
Files changed (133) hide show
  1. package/README.md +51 -0
  2. package/dist/components/CRUDModal.js +0 -1
  3. package/dist/components/ai/Assistant.d.ts +9 -0
  4. package/dist/components/ai/Assistant.js +59 -0
  5. package/dist/components/ai/Avatar.d.ts +11 -0
  6. package/dist/components/ai/Avatar.js +39 -0
  7. package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  8. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +38 -0
  9. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  10. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  11. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  12. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +86 -0
  13. package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  14. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +180 -0
  15. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  16. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +45 -0
  17. package/dist/components/ai/utils.d.ts +6 -0
  18. package/dist/components/ai/utils.js +14 -0
  19. package/dist/components/audio/Playbutton.js +4 -5
  20. package/dist/components/avatar/Assistant.d.ts +9 -0
  21. package/dist/components/avatar/Assistant.js +59 -0
  22. package/dist/components/avatar/Avatar.d.ts +12 -0
  23. package/dist/components/avatar/Avatar.js +42 -0
  24. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  25. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +38 -0
  26. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  27. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  28. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  29. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +84 -0
  30. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  31. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +180 -0
  32. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  33. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +45 -0
  34. package/dist/components/avatar/utils.d.ts +6 -0
  35. package/dist/components/avatar/utils.js +14 -0
  36. package/dist/components.d.ts +9 -0
  37. package/dist/components.js +10 -0
  38. package/dist/controller/AIController.d.ts +4 -3
  39. package/dist/controller/AIController.js +32 -8
  40. package/dist/controller/ObjectController.d.ts +2 -2
  41. package/dist/controller/ObjectController.js +4 -5
  42. package/dist/controller/SettingsController.d.ts +2 -1
  43. package/dist/controller/SettingsController.js +9 -0
  44. package/dist/controller/SharedContentController.js +6 -6
  45. package/dist/core.d.ts +9 -0
  46. package/dist/core.js +10 -0
  47. package/dist/hooks/UseChatHook.js +2 -2
  48. package/dist/index.d.ts +3 -2
  49. package/dist/index.js +4 -2
  50. package/dist/plugin/PluginController.d.ts +4 -12
  51. package/dist/plugin/PluginController.js +43 -70
  52. package/dist/plugin/RimoriClient.d.ts +85 -32
  53. package/dist/plugin/RimoriClient.js +98 -77
  54. package/dist/plugin/fromRimori/EventBus.d.ts +98 -0
  55. package/dist/plugin/fromRimori/EventBus.js +240 -0
  56. package/dist/providers/PluginProvider.d.ts +1 -0
  57. package/dist/providers/PluginProvider.js +10 -12
  58. package/dist/worker/WorkerSetup.d.ts +6 -0
  59. package/dist/worker/WorkerSetup.js +79 -0
  60. package/package.json +16 -3
  61. package/src/components/CRUDModal.tsx +1 -3
  62. package/src/components/ai/Assistant.tsx +96 -0
  63. package/src/components/ai/Avatar.tsx +61 -0
  64. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +64 -0
  65. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +75 -0
  66. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +91 -0
  67. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +192 -0
  68. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +56 -0
  69. package/src/components/ai/utils.ts +23 -0
  70. package/src/components/audio/Playbutton.tsx +4 -5
  71. package/src/components.ts +10 -0
  72. package/src/controller/AIController.ts +84 -60
  73. package/src/controller/ObjectController.ts +4 -6
  74. package/src/controller/SettingsController.ts +9 -1
  75. package/src/controller/SharedContentController.ts +6 -6
  76. package/src/core.ts +10 -0
  77. package/src/hooks/UseChatHook.ts +2 -2
  78. package/src/index.ts +4 -2
  79. package/src/plugin/PluginController.ts +46 -76
  80. package/src/plugin/RimoriClient.ts +147 -85
  81. package/src/plugin/fromRimori/EventBus.ts +301 -0
  82. package/src/plugin/fromRimori/readme.md +2 -0
  83. package/src/providers/PluginProvider.tsx +12 -14
  84. package/src/worker/WorkerSetup.ts +80 -0
  85. package/dist/CRUDModal.d.ts +0 -16
  86. package/dist/CRUDModal.js +0 -31
  87. package/dist/MarkdownEditor.d.ts +0 -8
  88. package/dist/MarkdownEditor.js +0 -46
  89. package/dist/audio/Playbutton.d.ts +0 -14
  90. package/dist/audio/Playbutton.js +0 -73
  91. package/dist/components/hooks/UseChatHook.d.ts +0 -15
  92. package/dist/components/hooks/UseChatHook.js +0 -21
  93. package/dist/controller/PluginController.d.ts +0 -14
  94. package/dist/controller/PluginController.js +0 -30
  95. package/dist/plugin/AIController copy.d.ts +0 -22
  96. package/dist/plugin/AIController copy.js +0 -68
  97. package/dist/plugin/AIController.d.ts +0 -22
  98. package/dist/plugin/AIController.js +0 -68
  99. package/dist/plugin/ObjectController.d.ts +0 -34
  100. package/dist/plugin/ObjectController.js +0 -77
  101. package/dist/plugin/SettingController.d.ts +0 -13
  102. package/dist/plugin/SettingController.js +0 -55
  103. package/dist/plugin/VoiceController.d.ts +0 -2
  104. package/dist/plugin/VoiceController.js +0 -27
  105. package/dist/providers/EventEmitter.d.ts +0 -11
  106. package/dist/providers/EventEmitter.js +0 -41
  107. package/dist/providers/EventEmitterContext.d.ts +0 -6
  108. package/dist/providers/EventEmitterContext.js +0 -19
  109. package/dist/utils/DifficultyConverter.d.ts +0 -3
  110. package/dist/utils/DifficultyConverter.js +0 -7
  111. package/dist/utils/constants.d.ts +0 -4
  112. package/dist/utils/constants.js +0 -12
  113. package/dist/utils/plugin/Client.d.ts +0 -72
  114. package/dist/utils/plugin/Client.js +0 -118
  115. package/dist/utils/plugin/PluginController.d.ts +0 -36
  116. package/dist/utils/plugin/PluginController.js +0 -119
  117. package/dist/utils/plugin/PluginUtils.d.ts +0 -2
  118. package/dist/utils/plugin/PluginUtils.js +0 -23
  119. package/dist/utils/plugin/RimoriClient.d.ts +0 -72
  120. package/dist/utils/plugin/RimoriClient.js +0 -118
  121. package/dist/utils/plugin/ThemeSetter.d.ts +0 -1
  122. package/dist/utils/plugin/ThemeSetter.js +0 -13
  123. package/dist/utils/plugin/WhereClauseBuilder.d.ts +0 -24
  124. package/dist/utils/plugin/WhereClauseBuilder.js +0 -79
  125. package/dist/utils/plugin/providers/EventEmitter.d.ts +0 -11
  126. package/dist/utils/plugin/providers/EventEmitter.js +0 -41
  127. package/dist/utils/plugin/providers/EventEmitterContext.d.ts +0 -6
  128. package/dist/utils/plugin/providers/EventEmitterContext.js +0 -19
  129. package/dist/utils/plugin/providers/PluginProvider.d.ts +0 -8
  130. package/dist/utils/plugin/providers/PluginProvider.js +0 -49
  131. package/src/providers/EventEmitter.ts +0 -48
  132. package/src/providers/EventEmitterContext.tsx +0 -27
  133. package/src/utils/constants.ts +0 -18
@@ -1,25 +1,95 @@
1
1
  import { PluginController } from "./PluginController";
2
2
  import { SupabaseClient } from "@supabase/supabase-js";
3
+ import { EventBusMessage, EventPayload } from "./fromRimori/EventBus";
3
4
  import { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types";
4
5
  import { PostgrestQueryBuilder, PostgrestFilterBuilder } from "@supabase/postgrest-js";
5
6
  import { BasicAssignment } from "../controller/SharedContentController";
6
7
  import { Message, Tool, OnLLMResponse } from "../controller/AIController";
7
8
  import { ObjectRequest } from "../controller/ObjectController";
8
9
  import { Plugin } from "../controller/SidePluginController";
9
- export declare class RimoriClient {
10
- private static instance;
11
- private superbase;
12
- private plugin;
10
+ import { UserInfo } from "../controller/SettingsController";
11
+ import { EventHandler } from "./fromRimori/EventBus";
12
+ interface Db {
13
+ from: {
14
+ <TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>;
15
+ <ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
16
+ };
17
+ rpc: <Fn extends GenericSchema['Functions'][string], FnName extends string & keyof GenericSchema['Functions']>(functionName: FnName, args?: Fn["Args"], options?: {
18
+ head?: boolean;
19
+ get?: boolean;
20
+ count?: "exact" | "planned" | "estimated";
21
+ }) => PostgrestFilterBuilder<GenericSchema, Fn["Returns"] extends any[] ? Fn["Returns"][number] extends Record<string, unknown> ? Fn["Returns"][number] : never : never, Fn["Returns"], string, null>;
13
22
  functions: SupabaseClient["functions"];
14
23
  storage: SupabaseClient["storage"];
24
+ }
25
+ interface PluginInterface {
15
26
  pluginId: string;
16
27
  tablePrefix: string;
28
+ setSettings: (settings: any) => Promise<void>;
29
+ /**
30
+ * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
31
+ * @param defaultSettings The default settings to use if no settings are found.
32
+ * @param genericSettings The type of settings to get.
33
+ * @returns The settings for the plugin.
34
+ */
35
+ getSettings: <T extends object>(defaultSettings: T) => Promise<T>;
36
+ /**
37
+ * Fetches all installed plugins.
38
+ * @returns A promise that resolves to an array of plugins
39
+ */
40
+ getInstalled: () => Promise<Plugin[]>;
41
+ getUserInfo: () => Promise<UserInfo>;
42
+ }
43
+ export declare class RimoriClient {
44
+ private static instance;
45
+ private superbase;
46
+ private pluginController;
17
47
  private settingsController;
18
48
  private sharedContentController;
49
+ private supabaseUrl;
50
+ db: Db;
51
+ plugin: PluginInterface;
19
52
  private constructor();
53
+ event: {
54
+ /**
55
+ * Emit an event to Rimori or a plugin.
56
+ * The topic schema is:
57
+ * {pluginId}.{eventId}
58
+ * Check out the event bus documentation for more information.
59
+ * For triggering events from Rimori like context menu actions use the "global" keyword.
60
+ * @param topic The topic to emit the event on.
61
+ * @param data The data to emit.
62
+ * @param eventId The event id.
63
+ */
64
+ emit: (topic: string, data: any, eventId?: number) => void;
65
+ /**
66
+ * Request an event.
67
+ * @param topic The topic to request the event on.
68
+ * @param data The data to request.
69
+ * @returns The response from the event.
70
+ */
71
+ request: <T>(topic: string, data?: any) => Promise<EventBusMessage<T>>;
72
+ /**
73
+ * Subscribe to an event.
74
+ * @param topic The topic to subscribe to.
75
+ * @param callback The callback to call when the event is emitted.
76
+ */
77
+ on: <T = EventPayload>(topic: string, callback: EventHandler<T>) => void;
78
+ /**
79
+ * Subscribe to an event once.
80
+ * @param topic The topic to subscribe to.
81
+ * @param callback The callback to call when the event is emitted.
82
+ */
83
+ once: <T = EventPayload>(topic: string, callback: EventHandler<T>) => void;
84
+ /**
85
+ * Respond to an event.
86
+ * @param topic The topic to respond to.
87
+ * @param data The data to respond with.
88
+ */
89
+ respond: <T = EventPayload>(topic: string, data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => void;
90
+ };
20
91
  static getInstance(pluginController: PluginController): Promise<RimoriClient>;
21
- from<TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>;
22
- from<ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
92
+ private from;
23
93
  /**
24
94
  * Perform a function call.
25
95
  *
@@ -43,33 +113,15 @@ export declare class RimoriClient {
43
113
  * `"estimated"`: Uses exact count for low numbers and planned count for high
44
114
  * numbers.
45
115
  */
46
- rpc<Fn extends GenericSchema['Functions'][string], FnName extends string & keyof GenericSchema['Functions']>(functionName: FnName, args?: Fn['Args'], options?: {
47
- head?: boolean;
48
- get?: boolean;
49
- count?: 'exact' | 'planned' | 'estimated';
50
- }): PostgrestFilterBuilder<GenericSchema, Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : never : never, Fn['Returns'], string, null>;
116
+ private rpc;
51
117
  private getTableName;
52
- subscribe(eventName: string, callback: (_id: number, data: any) => void): void;
53
- request<T>(eventName: string, data?: any): Promise<T>;
54
- emit(eventName: string, data: any): void;
55
- /**
56
- * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
57
- * @param defaultSettings The default settings to use if no settings are found.
58
- * @param genericSettings The type of settings to get.
59
- * @returns The settings for the plugin.
60
- */
61
- getSettings<T extends object>(defaultSettings: T, genericSettings?: "user" | "system"): Promise<T>;
62
- setSettings(settings: any, genericSettings?: "user" | "system"): Promise<void>;
63
- getAIResponse(messages: Message[], tools?: Tool[]): Promise<string>;
64
- getAIResponseStream(messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]): Promise<void>;
65
- getVoiceResponse(text: string, voice?: string, speed?: number, language?: string): Promise<Blob>;
66
- getVoiceToTextResponse(file: Blob): Promise<string>;
67
- /**
68
- * Fetches all installed plugins.
69
- * @returns A promise that resolves to an array of plugins
70
- */
71
- getPlugins(): Promise<Plugin[]>;
72
- generateObject(request: ObjectRequest): Promise<any>;
118
+ llm: {
119
+ getText: (messages: Message[], tools?: Tool[]) => Promise<string>;
120
+ getSteamedText: (messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]) => Promise<void>;
121
+ getVoice: (text: string, voice?: string, speed?: number, language?: string) => Promise<Blob>;
122
+ getTextFromVoice: (file: Blob) => Promise<string>;
123
+ getObject: (request: ObjectRequest) => Promise<any>;
124
+ };
73
125
  /**
74
126
  * Fetch new shared content.
75
127
  * @param type The type of shared content to fetch. E.g. assignments, exercises, etc.
@@ -96,3 +148,4 @@ export declare class RimoriClient {
96
148
  completeSharedContent(type: string, assignmentId: string): Promise<void>;
97
149
  triggerSidebarAction(pluginId: string, actionKey: string, text?: string): void;
98
150
  }
151
+ export {};
@@ -13,28 +13,109 @@ import { SharedContentController } from "../controller/SharedContentController";
13
13
  import { streamChatGPT, generateText } from "../controller/AIController";
14
14
  import { generateObject as generateObjectFunction } from "../controller/ObjectController";
15
15
  import { getPlugins } from "../controller/SidePluginController";
16
+ import { EventBus } from "./fromRimori/EventBus";
16
17
  export class RimoriClient {
17
18
  constructor(options) {
19
+ this.event = {
20
+ /**
21
+ * Emit an event to Rimori or a plugin.
22
+ * The topic schema is:
23
+ * {pluginId}.{eventId}
24
+ * Check out the event bus documentation for more information.
25
+ * For triggering events from Rimori like context menu actions use the "global" keyword.
26
+ * @param topic The topic to emit the event on.
27
+ * @param data The data to emit.
28
+ * @param eventId The event id.
29
+ */
30
+ emit: (topic, data, eventId) => {
31
+ const globalTopic = this.pluginController.getGlobalEventTopic(topic);
32
+ EventBus.emit(this.plugin.pluginId, globalTopic, data, eventId);
33
+ },
34
+ /**
35
+ * Request an event.
36
+ * @param topic The topic to request the event on.
37
+ * @param data The data to request.
38
+ * @returns The response from the event.
39
+ */
40
+ request: (topic, data) => {
41
+ const globalTopic = this.pluginController.getGlobalEventTopic(topic);
42
+ return EventBus.request(this.plugin.pluginId, globalTopic, data);
43
+ },
44
+ /**
45
+ * Subscribe to an event.
46
+ * @param topic The topic to subscribe to.
47
+ * @param callback The callback to call when the event is emitted.
48
+ */
49
+ on: (topic, callback) => {
50
+ EventBus.on(this.pluginController.getGlobalEventTopic(topic), callback);
51
+ },
52
+ /**
53
+ * Subscribe to an event once.
54
+ * @param topic The topic to subscribe to.
55
+ * @param callback The callback to call when the event is emitted.
56
+ */
57
+ once: (topic, callback) => {
58
+ EventBus.once(this.pluginController.getGlobalEventTopic(topic), callback);
59
+ },
60
+ /**
61
+ * Respond to an event.
62
+ * @param topic The topic to respond to.
63
+ * @param data The data to respond with.
64
+ */
65
+ respond: (topic, data) => {
66
+ EventBus.respond(this.plugin.pluginId, this.pluginController.getGlobalEventTopic(topic), data);
67
+ }
68
+ };
69
+ this.llm = {
70
+ getText: (messages, tools) => __awaiter(this, void 0, void 0, function* () {
71
+ const token = yield this.pluginController.getToken();
72
+ return generateText(this.supabaseUrl, messages, tools || [], token).then(response => response.messages[0].content[0].text);
73
+ }),
74
+ getSteamedText: (messages, onMessage, tools) => __awaiter(this, void 0, void 0, function* () {
75
+ const token = yield this.pluginController.getToken();
76
+ streamChatGPT(this.supabaseUrl, messages, tools || [], onMessage, token);
77
+ }),
78
+ getVoice: (text_1, ...args_1) => __awaiter(this, [text_1, ...args_1], void 0, function* (text, voice = "alloy", speed = 1, language) {
79
+ return getTTSResponse(this.pluginController.getSupabaseUrl(), { input: text, voice, speed, language }, yield this.pluginController.getToken());
80
+ }),
81
+ getTextFromVoice: (file) => {
82
+ return getSTTResponse(this.superbase, file);
83
+ },
84
+ getObject: (request) => __awaiter(this, void 0, void 0, function* () {
85
+ const token = yield this.pluginController.getToken();
86
+ return generateObjectFunction(this.pluginController.getSupabaseUrl(), request, token);
87
+ }),
88
+ // getSteamedObject: this.generateObjectStream,
89
+ };
18
90
  this.superbase = options.supabase;
19
- this.pluginId = options.pluginId;
20
- this.plugin = options.pluginController;
21
- this.tablePrefix = options.tablePrefix;
22
- this.storage = this.superbase.storage;
23
- this.functions = this.superbase.functions;
91
+ this.pluginController = options.pluginController;
24
92
  this.settingsController = new SettingsController(options.supabase, options.pluginId);
25
93
  this.sharedContentController = new SharedContentController(this);
94
+ this.supabaseUrl = this.pluginController.getSupabaseUrl();
26
95
  this.rpc = this.rpc.bind(this);
27
96
  this.from = this.from.bind(this);
28
- this.emit = this.emit.bind(this);
29
- this.request = this.request.bind(this);
30
- this.subscribe = this.subscribe.bind(this);
31
- this.getSettings = this.getSettings.bind(this);
32
- this.setSettings = this.setSettings.bind(this);
33
- this.getAIResponse = this.getAIResponse.bind(this);
34
- this.generateObject = this.generateObject.bind(this);
35
- this.getVoiceResponse = this.getVoiceResponse.bind(this);
36
- this.getAIResponseStream = this.getAIResponseStream.bind(this);
37
- this.getVoiceToTextResponse = this.getVoiceToTextResponse.bind(this);
97
+ this.db = {
98
+ rpc: this.rpc,
99
+ from: this.from,
100
+ storage: this.superbase.storage,
101
+ functions: this.superbase.functions,
102
+ };
103
+ this.plugin = {
104
+ pluginId: options.pluginId,
105
+ tablePrefix: options.tablePrefix,
106
+ setSettings: (settings) => __awaiter(this, void 0, void 0, function* () {
107
+ yield this.settingsController.setSettings(settings);
108
+ }),
109
+ getSettings: (defaultSettings) => __awaiter(this, void 0, void 0, function* () {
110
+ return yield this.settingsController.getSettings(defaultSettings);
111
+ }),
112
+ getInstalled: () => __awaiter(this, void 0, void 0, function* () {
113
+ return getPlugins(this.superbase);
114
+ }),
115
+ getUserInfo: () => __awaiter(this, void 0, void 0, function* () {
116
+ return this.settingsController.getUserInfo();
117
+ })
118
+ };
38
119
  }
39
120
  static getInstance(pluginController) {
40
121
  return __awaiter(this, void 0, void 0, function* () {
@@ -75,67 +156,7 @@ export class RimoriClient {
75
156
  return this.superbase.rpc(this.getTableName(functionName), args, options);
76
157
  }
77
158
  getTableName(type) {
78
- return this.tablePrefix + "_" + type;
79
- }
80
- subscribe(eventName, callback) {
81
- this.plugin.subscribe(eventName, callback);
82
- }
83
- request(eventName, data) {
84
- return this.plugin.request(eventName, data);
85
- }
86
- emit(eventName, data) {
87
- this.plugin.emit(eventName, data);
88
- }
89
- /**
90
- * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
91
- * @param defaultSettings The default settings to use if no settings are found.
92
- * @param genericSettings The type of settings to get.
93
- * @returns The settings for the plugin.
94
- */
95
- getSettings(defaultSettings, genericSettings) {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- return this.settingsController.getSettings(defaultSettings, genericSettings);
98
- });
99
- }
100
- setSettings(settings, genericSettings) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- yield this.settingsController.setSettings(settings, genericSettings);
103
- });
104
- }
105
- getAIResponse(messages, tools) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const token = yield this.plugin.getToken();
108
- return generateText(messages, tools || [], token).then(response => response.messages[0].content[0].text);
109
- });
110
- }
111
- getAIResponseStream(messages, onMessage, tools) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const token = yield this.plugin.getToken();
114
- streamChatGPT(messages, tools || [], onMessage, token);
115
- });
116
- }
117
- getVoiceResponse(text_1) {
118
- return __awaiter(this, arguments, void 0, function* (text, voice = "alloy", speed = 1, language) {
119
- return getTTSResponse(this.plugin.getSupabaseUrl(), { input: text, voice, speed, language }, yield this.plugin.getToken());
120
- });
121
- }
122
- getVoiceToTextResponse(file) {
123
- return getSTTResponse(this.superbase, file);
124
- }
125
- /**
126
- * Fetches all installed plugins.
127
- * @returns A promise that resolves to an array of plugins
128
- */
129
- getPlugins() {
130
- return __awaiter(this, void 0, void 0, function* () {
131
- return getPlugins(this.superbase);
132
- });
133
- }
134
- generateObject(request) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- const token = yield this.plugin.getToken();
137
- return generateObjectFunction(request, token);
138
- });
159
+ return this.plugin.tablePrefix + "_" + type;
139
160
  }
140
161
  /**
141
162
  * Fetch new shared content.
@@ -171,6 +192,6 @@ export class RimoriClient {
171
192
  });
172
193
  }
173
194
  triggerSidebarAction(pluginId, actionKey, text) {
174
- this.emit("triggerSidebarAction", { pluginId, actionKey, text });
195
+ this.event.emit("global.sidebar.triggerAction", { pluginId, actionKey, text });
175
196
  }
176
197
  }
@@ -0,0 +1,98 @@
1
+ export type EventPayload = Record<string, any>;
2
+ /**
3
+ * Interface representing a message sent through the EventBus
4
+ *
5
+ * Debug capabilities:
6
+ * - System-wide debugging: Send an event to "global.system.requestDebug"
7
+ * Example: `EventBus.emit("yourPluginId", "global.system.requestDebug");`
8
+ */
9
+ export interface EventBusMessage<T = EventPayload> {
10
+ timestamp: string;
11
+ eventId: number;
12
+ sender: string;
13
+ topic: string;
14
+ data: T;
15
+ debug: boolean;
16
+ }
17
+ export type EventHandler<T = EventPayload> = (event: EventBusMessage<T>) => void | Promise<void>;
18
+ export declare class EventBusHandler {
19
+ private listeners;
20
+ private responseResolvers;
21
+ private static instance;
22
+ private debugEnabled;
23
+ private evName;
24
+ private constructor();
25
+ static getInstance(name?: string): EventBusHandler;
26
+ private createEvent;
27
+ /**
28
+ * Emits an event to the event bus. Can be a new event or a response to a request.
29
+ * @param sender - The sender of the event.
30
+ * @param topic - The topic of the event.
31
+ * @param data - The data of the event.
32
+ * @param eventId - The event id of the event.
33
+ *
34
+ * The topic format is: **pluginId.area.action**
35
+ *
36
+ * Example topics:
37
+ * - pl1234.card.requestHard
38
+ * - pl1234.card.requestNew
39
+ * - pl1234.card.requestAll
40
+ * - pl1234.card.create
41
+ * - pl1234.card.update
42
+ * - pl1234.card.delete
43
+ * - pl1234.card.triggerBackup
44
+ */
45
+ emit<T = EventPayload>(sender: string, topic: string, data?: T, eventId?: number): void;
46
+ private emitInternal;
47
+ /**
48
+ * Subscribes to an event on the event bus.
49
+ * @param topics - The topic of the event.
50
+ * @param handler - The handler to be called when the event is emitted.
51
+ * @param ignoreSender - The senders to ignore.
52
+ * @returns The ids of the listeners.
53
+ */
54
+ on<T = EventPayload>(topics: string | string[], handler: EventHandler<T>, ignoreSender?: string[]): string[];
55
+ /**
56
+ * Subscribes to an event, processes the data and emits a response on the event bus.
57
+ * @param sender - The sender of the event.
58
+ * @param topic - The topic of the event.
59
+ * @param handler - The handler to be called when the event is received. The handler returns the data to be emitted. Can be a static object or a function.
60
+ * @returns The ids of the listeners.
61
+ */
62
+ respond(sender: string, topic: string, handler: EventPayload | ((data: EventBusMessage) => EventPayload | Promise<EventPayload>)): string[];
63
+ /**
64
+ * Subscribes to an event on the event bus. The handler will be called once and then removed.
65
+ * @param topic - The topic of the event.
66
+ * @param handler - The handler to be called when the event is emitted.
67
+ */
68
+ once<T = EventPayload>(topic: string, handler: EventHandler<T>): void;
69
+ /**
70
+ * Unsubscribes from an event on the event bus.
71
+ * @param listenerIds - The ids of the listeners to unsubscribe from.
72
+ */
73
+ off(listenerIds: string | string[]): void;
74
+ private toArray;
75
+ /**
76
+ * Requests data from the event bus.
77
+ * @param sender - The sender of the event.
78
+ * @param topic - The topic of the event.
79
+ * @param data - The data of the event.
80
+ * @returns A promise that resolves to the event.
81
+ */
82
+ request<T = EventPayload>(sender: string, topic: string, data?: EventPayload): Promise<EventBusMessage<T>>;
83
+ /**
84
+ * Gets the matching handlers for an event.
85
+ * @param topic - The topic of the event.
86
+ * @returns A set of handlers that match the event type.
87
+ */
88
+ private getMatchingHandlers;
89
+ /**
90
+ * Validates the topic of an event.
91
+ * @param topic - The topic of the event.
92
+ * @returns True if the topic is valid, false otherwise.
93
+ */
94
+ private validateTopic;
95
+ private logIfDebug;
96
+ private logAndThrowError;
97
+ }
98
+ export declare const EventBus: EventBusHandler;