@rimori/client 2.5.14 → 2.5.15
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/modules.js
ADDED
|
@@ -29,7 +29,7 @@ export class RimoriClient {
|
|
|
29
29
|
};
|
|
30
30
|
this.rimoriInfo = info;
|
|
31
31
|
this.sharedContent = new SharedContentController(supabase, this);
|
|
32
|
-
this.ai = new AIModule(
|
|
32
|
+
this.ai = new AIModule(info.backendUrl, () => this.rimoriInfo.token);
|
|
33
33
|
this.event = new EventModule(info.pluginId);
|
|
34
34
|
this.db = new DbModule(supabase, controller, info);
|
|
35
35
|
this.plugin = new PluginModule(supabase, controller, info, this.ai);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Tool } from '../../fromRimori/PluginTypes';
|
|
2
|
-
import { RimoriCommunicationHandler, RimoriInfo } from '../CommunicationHandler';
|
|
3
2
|
import { Language } from '../../controller/SettingsController';
|
|
4
3
|
export type OnStreamedObjectResult<T = any> = (result: T, isLoading: boolean) => void;
|
|
5
4
|
type PrimitiveType = 'string' | 'number' | 'boolean';
|
|
@@ -21,7 +20,7 @@ interface ObjectToolParameter {
|
|
|
21
20
|
* The value is the parameter of the tool.
|
|
22
21
|
*
|
|
23
22
|
*/
|
|
24
|
-
export type
|
|
23
|
+
export type AIObjectTool = {
|
|
25
24
|
[key: string]: ObjectToolParameter;
|
|
26
25
|
};
|
|
27
26
|
export interface ToolInvocation {
|
|
@@ -40,7 +39,7 @@ export interface ObjectRequest {
|
|
|
40
39
|
/**
|
|
41
40
|
* The tools that the AI can use.
|
|
42
41
|
*/
|
|
43
|
-
tool:
|
|
42
|
+
tool: AIObjectTool;
|
|
44
43
|
/**
|
|
45
44
|
* High level instructions for the AI to follow. Behaviour, tone, restrictions, etc.
|
|
46
45
|
* Example: "Act like a recipe writer."
|
|
@@ -57,10 +56,9 @@ export interface ObjectRequest {
|
|
|
57
56
|
* Provides access to text generation, voice synthesis, and object generation.
|
|
58
57
|
*/
|
|
59
58
|
export declare class AIModule {
|
|
60
|
-
private
|
|
59
|
+
private getToken;
|
|
61
60
|
private backendUrl;
|
|
62
|
-
|
|
63
|
-
constructor(communicationHandler: RimoriCommunicationHandler, info: RimoriInfo);
|
|
61
|
+
constructor(backendUrl: string, getToken: () => string);
|
|
64
62
|
/**
|
|
65
63
|
* Generate text from messages using AI.
|
|
66
64
|
* @param messages The messages to generate text from.
|
|
@@ -78,7 +76,7 @@ export declare class AIModule {
|
|
|
78
76
|
* @param cache Whether to cache the result (default: false).
|
|
79
77
|
* @param model The model to use for generation.
|
|
80
78
|
*/
|
|
81
|
-
getSteamedText(messages: Message[], onMessage: OnLLMResponse, tools?: Tool[], cache?: boolean, model?: string): Promise<void>;
|
|
79
|
+
getSteamedText(messages: Message[], onMessage: OnLLMResponse, tools?: Tool[], cache?: boolean, model?: string, knowledgeId?: string): Promise<void>;
|
|
82
80
|
/**
|
|
83
81
|
* Generate voice audio from text using AI.
|
|
84
82
|
* @param text The text to convert to voice.
|
|
@@ -110,11 +108,12 @@ export declare class AIModule {
|
|
|
110
108
|
*/
|
|
111
109
|
getObject<T = any>(params: {
|
|
112
110
|
systemPrompt: string;
|
|
113
|
-
responseSchema:
|
|
111
|
+
responseSchema: AIObjectTool;
|
|
114
112
|
userPrompt?: string;
|
|
115
113
|
cache?: boolean;
|
|
116
114
|
tools?: Tool[];
|
|
117
115
|
model?: string;
|
|
116
|
+
knowledgeId?: string;
|
|
118
117
|
}): Promise<T>;
|
|
119
118
|
/**
|
|
120
119
|
* Generate a streamed structured object from a request using AI.
|
|
@@ -126,15 +125,17 @@ export declare class AIModule {
|
|
|
126
125
|
* @param request.cache Whether to cache the result (default: false).
|
|
127
126
|
* @param request.tools The tools to use for generation.
|
|
128
127
|
* @param request.model The model to use for generation.
|
|
128
|
+
* @param request.knowledgeId Optional knowledge entry ID to ground AI content in real facts.
|
|
129
129
|
*/
|
|
130
130
|
getStreamedObject<T = any>(params: {
|
|
131
131
|
systemPrompt: string;
|
|
132
|
-
responseSchema:
|
|
132
|
+
responseSchema: AIObjectTool;
|
|
133
133
|
userPrompt?: string;
|
|
134
134
|
onResult: OnStreamedObjectResult<T>;
|
|
135
135
|
cache?: boolean;
|
|
136
136
|
tools?: Tool[];
|
|
137
137
|
model?: string;
|
|
138
|
+
knowledgeId?: string;
|
|
138
139
|
}): Promise<void>;
|
|
139
140
|
private streamObject;
|
|
140
141
|
private sendToolResult;
|
|
@@ -12,13 +12,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
* Provides access to text generation, voice synthesis, and object generation.
|
|
13
13
|
*/
|
|
14
14
|
export class AIModule {
|
|
15
|
-
constructor(
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.communicationHandler = communicationHandler;
|
|
19
|
-
this.communicationHandler.onUpdate((updatedInfo) => {
|
|
20
|
-
this.token = updatedInfo.token;
|
|
21
|
-
});
|
|
15
|
+
constructor(backendUrl, getToken) {
|
|
16
|
+
this.backendUrl = backendUrl;
|
|
17
|
+
this.getToken = getToken;
|
|
22
18
|
}
|
|
23
19
|
/**
|
|
24
20
|
* Generate text from messages using AI.
|
|
@@ -53,13 +49,14 @@ export class AIModule {
|
|
|
53
49
|
* @param model The model to use for generation.
|
|
54
50
|
*/
|
|
55
51
|
getSteamedText(messages_1, onMessage_1, tools_1) {
|
|
56
|
-
return __awaiter(this, arguments, void 0, function* (messages, onMessage, tools, cache = false, model) {
|
|
52
|
+
return __awaiter(this, arguments, void 0, function* (messages, onMessage, tools, cache = false, model, knowledgeId) {
|
|
57
53
|
const messageId = Math.random().toString(36).substring(3);
|
|
58
54
|
const { result } = yield this.streamObject({
|
|
59
55
|
cache,
|
|
60
56
|
tools,
|
|
61
57
|
model,
|
|
62
58
|
messages,
|
|
59
|
+
knowledgeId,
|
|
63
60
|
responseSchema: {
|
|
64
61
|
result: {
|
|
65
62
|
type: 'string',
|
|
@@ -85,7 +82,7 @@ export class AIModule {
|
|
|
85
82
|
method: 'POST',
|
|
86
83
|
headers: {
|
|
87
84
|
'Content-Type': 'application/json',
|
|
88
|
-
Authorization: `Bearer ${this.
|
|
85
|
+
Authorization: `Bearer ${this.getToken()}`,
|
|
89
86
|
},
|
|
90
87
|
body: JSON.stringify({ input: text, voice, speed, language, cache }),
|
|
91
88
|
}).then((r) => r.blob());
|
|
@@ -106,7 +103,7 @@ export class AIModule {
|
|
|
106
103
|
}
|
|
107
104
|
return yield fetch(`${this.backendUrl}/voice/stt`, {
|
|
108
105
|
method: 'POST',
|
|
109
|
-
headers: { Authorization: `Bearer ${this.
|
|
106
|
+
headers: { Authorization: `Bearer ${this.getToken()}` },
|
|
110
107
|
body: formData,
|
|
111
108
|
})
|
|
112
109
|
.then((r) => r.json())
|
|
@@ -136,13 +133,14 @@ export class AIModule {
|
|
|
136
133
|
*/
|
|
137
134
|
getObject(params) {
|
|
138
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
const { systemPrompt, responseSchema, userPrompt, cache = false, tools = [], model = undefined } = params;
|
|
136
|
+
const { systemPrompt, responseSchema, userPrompt, cache = false, tools = [], model = undefined, knowledgeId, } = params;
|
|
140
137
|
return yield this.streamObject({
|
|
141
138
|
responseSchema,
|
|
142
139
|
messages: this.getChatMessage(systemPrompt, userPrompt),
|
|
143
140
|
cache,
|
|
144
141
|
tools,
|
|
145
142
|
model,
|
|
143
|
+
knowledgeId,
|
|
146
144
|
});
|
|
147
145
|
});
|
|
148
146
|
}
|
|
@@ -156,10 +154,11 @@ export class AIModule {
|
|
|
156
154
|
* @param request.cache Whether to cache the result (default: false).
|
|
157
155
|
* @param request.tools The tools to use for generation.
|
|
158
156
|
* @param request.model The model to use for generation.
|
|
157
|
+
* @param request.knowledgeId Optional knowledge entry ID to ground AI content in real facts.
|
|
159
158
|
*/
|
|
160
159
|
getStreamedObject(params) {
|
|
161
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const { systemPrompt, responseSchema, userPrompt, onResult, cache = false, tools = [], model = undefined } = params;
|
|
161
|
+
const { systemPrompt, responseSchema, userPrompt, onResult, cache = false, tools = [], model = undefined, knowledgeId, } = params;
|
|
163
162
|
yield this.streamObject({
|
|
164
163
|
responseSchema,
|
|
165
164
|
messages: this.getChatMessage(systemPrompt, userPrompt),
|
|
@@ -167,12 +166,13 @@ export class AIModule {
|
|
|
167
166
|
cache,
|
|
168
167
|
tools,
|
|
169
168
|
model,
|
|
169
|
+
knowledgeId,
|
|
170
170
|
});
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
streamObject(params) {
|
|
174
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
const { messages, responseSchema, onResult = () => null, cache = false, tools = [], model = undefined } = params;
|
|
175
|
+
const { messages, responseSchema, onResult = () => null, cache = false, tools = [], model = undefined, knowledgeId, } = params;
|
|
176
176
|
const chatMessages = messages.map((message, index) => (Object.assign(Object.assign({}, message), { id: `${index + 1}` })));
|
|
177
177
|
const response = yield fetch(`${this.backendUrl}/ai/llm`, {
|
|
178
178
|
body: JSON.stringify({
|
|
@@ -182,9 +182,10 @@ export class AIModule {
|
|
|
182
182
|
responseSchema,
|
|
183
183
|
messages: chatMessages,
|
|
184
184
|
model,
|
|
185
|
+
knowledge_id: knowledgeId,
|
|
185
186
|
}),
|
|
186
187
|
method: 'POST',
|
|
187
|
-
headers: { Authorization: `Bearer ${this.
|
|
188
|
+
headers: { Authorization: `Bearer ${this.getToken()}`, 'Content-Type': 'application/json' },
|
|
188
189
|
});
|
|
189
190
|
if (!response.ok) {
|
|
190
191
|
throw new Error(`Failed to stream object: ${response.status} ${response.statusText}`);
|
|
@@ -260,7 +261,7 @@ export class AIModule {
|
|
|
260
261
|
toolCallId,
|
|
261
262
|
result: result !== null && result !== void 0 ? result : '[DONE]',
|
|
262
263
|
}),
|
|
263
|
-
headers: { Authorization: `Bearer ${this.
|
|
264
|
+
headers: { Authorization: `Bearer ${this.getToken()} `, 'Content-Type': 'application/json' },
|
|
264
265
|
});
|
|
265
266
|
});
|
|
266
267
|
}
|