@rimori/client 2.5.28-next.5 → 2.5.28-next.7
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 +1 -1
- package/dist/plugin/module/AIModule.d.ts +30 -49
- package/dist/plugin/module/AIModule.js +26 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -140,7 +140,7 @@ Helpers:
|
|
|
140
140
|
The `client.ai` controller surfaces AI capabilities:
|
|
141
141
|
|
|
142
142
|
- `getText(messages, tools?)` – chat completion (string result).
|
|
143
|
-
- `
|
|
143
|
+
- `getStreamedText(messages, onMessage, tools?)` – streamed responses.
|
|
144
144
|
- `getObject(request)` – structured JSON generation.
|
|
145
145
|
- `getVoice(text, voice?, speed?, language?)` – text-to-speech (returns `Blob`).
|
|
146
146
|
- `getTextFromVoice(file)` – speech-to-text transcription.
|
|
@@ -35,24 +35,6 @@ export interface Message {
|
|
|
35
35
|
toolCalls?: ToolInvocation[];
|
|
36
36
|
}
|
|
37
37
|
export type OnLLMResponse = (id: string, response: string, finished: boolean, toolInvocations?: ToolInvocation[]) => void;
|
|
38
|
-
export interface ObjectRequest {
|
|
39
|
-
/**
|
|
40
|
-
* The tools that the AI can use.
|
|
41
|
-
*/
|
|
42
|
-
tool: AIObjectTool;
|
|
43
|
-
/**
|
|
44
|
-
* High level instructions for the AI to follow. Behaviour, tone, restrictions, etc.
|
|
45
|
-
* Example: "Act like a recipe writer."
|
|
46
|
-
*/
|
|
47
|
-
/** @deprecated Use server-side prompt definitions (prompt + variables) instead of building requests client-side. */
|
|
48
|
-
behaviour?: string;
|
|
49
|
-
/**
|
|
50
|
-
* The specific instruction for the AI to follow.
|
|
51
|
-
* Example: "Generate a recipe using chicken, rice and vegetables."
|
|
52
|
-
*/
|
|
53
|
-
/** @deprecated Use server-side prompt definitions (prompt + variables) instead of building requests client-side. */
|
|
54
|
-
instructions: string;
|
|
55
|
-
}
|
|
56
38
|
/**
|
|
57
39
|
* Controller for AI-related operations.
|
|
58
40
|
* Provides access to text generation, voice synthesis, and object generation.
|
|
@@ -88,24 +70,41 @@ export declare class AIModule {
|
|
|
88
70
|
setOnRateLimited(cb: (exercisesRemaining: number) => void): void;
|
|
89
71
|
/**
|
|
90
72
|
* Generate text from messages using AI.
|
|
91
|
-
* @param messages The messages to generate text from.
|
|
92
|
-
* @param tools Optional tools to use for generation.
|
|
93
|
-
* @param cache Whether to cache the result (default: false).
|
|
94
|
-
* @param model The model to use for generation.
|
|
73
|
+
* @param params.messages The messages to generate text from.
|
|
74
|
+
* @param params.tools Optional tools to use for generation.
|
|
75
|
+
* @param params.cache Whether to cache the result (default: false).
|
|
76
|
+
* @param params.model The model to use for generation.
|
|
77
|
+
* @param params.prompt Server-side prompt name (e.g. 'writing.analysis').
|
|
78
|
+
* @param params.variables Variables for the server-side prompt template.
|
|
95
79
|
* @returns The generated text.
|
|
96
80
|
*/
|
|
97
|
-
getText(
|
|
81
|
+
getText(params: {
|
|
82
|
+
messages: Message[];
|
|
83
|
+
tools?: Tool[];
|
|
84
|
+
cache?: boolean;
|
|
85
|
+
model?: string;
|
|
86
|
+
prompt?: string;
|
|
87
|
+
variables?: Record<string, any>;
|
|
88
|
+
}): Promise<string>;
|
|
98
89
|
/**
|
|
99
90
|
* Stream text generation from messages using AI.
|
|
100
|
-
* @param messages The messages to generate text from.
|
|
101
|
-
* @param onMessage Callback for each message chunk.
|
|
102
|
-
* @param tools Optional tools to use for generation.
|
|
103
|
-
* @param cache Whether to cache the result (default: false).
|
|
104
|
-
* @param model The model to use for generation.
|
|
91
|
+
* @param params.messages The messages to generate text from.
|
|
92
|
+
* @param params.onMessage Callback for each message chunk.
|
|
93
|
+
* @param params.tools Optional tools to use for generation.
|
|
94
|
+
* @param params.cache Whether to cache the result (default: false).
|
|
95
|
+
* @param params.model The model to use for generation.
|
|
96
|
+
* @param params.prompt Server-side prompt name (e.g. 'writing.analysis').
|
|
97
|
+
* @param params.variables Variables for the server-side prompt template.
|
|
105
98
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
getStreamedText(params: {
|
|
100
|
+
messages: Message[];
|
|
101
|
+
onMessage: OnLLMResponse;
|
|
102
|
+
tools?: Tool[];
|
|
103
|
+
cache?: boolean;
|
|
104
|
+
model?: string;
|
|
105
|
+
prompt?: string;
|
|
106
|
+
variables?: Record<string, any>;
|
|
107
|
+
}): Promise<string>;
|
|
109
108
|
/**
|
|
110
109
|
* Generate voice audio from text using AI.
|
|
111
110
|
* @param text The text to convert to voice.
|
|
@@ -123,8 +122,6 @@ export declare class AIModule {
|
|
|
123
122
|
* @returns The transcribed text.
|
|
124
123
|
*/
|
|
125
124
|
getTextFromVoice(file: Blob, language?: Language): Promise<string>;
|
|
126
|
-
/** @deprecated Used by legacy client-side prompt path. Will be removed once all plugins migrate to server-side prompt definitions. */
|
|
127
|
-
private getChatMessage;
|
|
128
125
|
/**
|
|
129
126
|
* Generate a structured object from a request using AI.
|
|
130
127
|
* @param request.cache Whether to cache the result (default: false).
|
|
@@ -135,17 +132,9 @@ export declare class AIModule {
|
|
|
135
132
|
* @returns The generated object.
|
|
136
133
|
*/
|
|
137
134
|
getObject<T = any>(params: {
|
|
138
|
-
/** @deprecated Use prompt + variables instead of client-side system prompts. */
|
|
139
|
-
systemPrompt?: string;
|
|
140
|
-
/** @deprecated Use prompt + variables instead. Schema is loaded server-side from the prompt definition. */
|
|
141
|
-
responseSchema?: AIObjectTool;
|
|
142
|
-
/** @deprecated Use prompt + variables instead of client-side user prompts. */
|
|
143
|
-
userPrompt?: string;
|
|
144
135
|
cache?: boolean;
|
|
145
136
|
tools?: Tool[];
|
|
146
137
|
model?: string;
|
|
147
|
-
/** @deprecated Use uuid variable with resolver 'knowledgeEntry' in prompt definitions instead. */
|
|
148
|
-
knowledgeId?: string;
|
|
149
138
|
prompt?: string;
|
|
150
139
|
variables?: Record<string, any>;
|
|
151
140
|
}): Promise<T>;
|
|
@@ -159,18 +148,10 @@ export declare class AIModule {
|
|
|
159
148
|
* @param request.variables Variables for the server-side prompt template.
|
|
160
149
|
*/
|
|
161
150
|
getStreamedObject<T = any>(params: {
|
|
162
|
-
/** @deprecated Use prompt + variables instead of client-side system prompts. */
|
|
163
|
-
systemPrompt?: string;
|
|
164
|
-
/** @deprecated Use prompt + variables instead. Schema is loaded server-side from the prompt definition. */
|
|
165
|
-
responseSchema?: AIObjectTool;
|
|
166
|
-
/** @deprecated Use prompt + variables instead of client-side user prompts. */
|
|
167
|
-
userPrompt?: string;
|
|
168
151
|
onResult: OnStreamedObjectResult<T>;
|
|
169
152
|
cache?: boolean;
|
|
170
153
|
tools?: Tool[];
|
|
171
154
|
model?: string;
|
|
172
|
-
/** @deprecated Use uuid variable with resolver 'knowledgeEntry' in prompt definitions instead. */
|
|
173
|
-
knowledgeId?: string;
|
|
174
155
|
prompt?: string;
|
|
175
156
|
variables?: Record<string, any>;
|
|
176
157
|
}): Promise<T>;
|
|
@@ -75,42 +75,47 @@ export class AIModule {
|
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Generate text from messages using AI.
|
|
78
|
-
* @param messages The messages to generate text from.
|
|
79
|
-
* @param tools Optional tools to use for generation.
|
|
80
|
-
* @param cache Whether to cache the result (default: false).
|
|
81
|
-
* @param model The model to use for generation.
|
|
78
|
+
* @param params.messages The messages to generate text from.
|
|
79
|
+
* @param params.tools Optional tools to use for generation.
|
|
80
|
+
* @param params.cache Whether to cache the result (default: false).
|
|
81
|
+
* @param params.model The model to use for generation.
|
|
82
|
+
* @param params.prompt Server-side prompt name (e.g. 'writing.analysis').
|
|
83
|
+
* @param params.variables Variables for the server-side prompt template.
|
|
82
84
|
* @returns The generated text.
|
|
83
85
|
*/
|
|
84
|
-
getText(
|
|
85
|
-
return __awaiter(this,
|
|
86
|
+
getText(params) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const { messages, tools, cache = false, model, prompt, variables } = params;
|
|
86
89
|
const { result } = yield this.streamObject({
|
|
87
90
|
cache,
|
|
88
91
|
tools,
|
|
89
92
|
model,
|
|
90
93
|
messages,
|
|
94
|
+
prompt,
|
|
95
|
+
variables,
|
|
91
96
|
});
|
|
92
97
|
return result;
|
|
93
98
|
});
|
|
94
99
|
}
|
|
95
100
|
/**
|
|
96
101
|
* Stream text generation from messages using AI.
|
|
97
|
-
* @param messages The messages to generate text from.
|
|
98
|
-
* @param onMessage Callback for each message chunk.
|
|
99
|
-
* @param tools Optional tools to use for generation.
|
|
100
|
-
* @param cache Whether to cache the result (default: false).
|
|
101
|
-
* @param model The model to use for generation.
|
|
102
|
+
* @param params.messages The messages to generate text from.
|
|
103
|
+
* @param params.onMessage Callback for each message chunk.
|
|
104
|
+
* @param params.tools Optional tools to use for generation.
|
|
105
|
+
* @param params.cache Whether to cache the result (default: false).
|
|
106
|
+
* @param params.model The model to use for generation.
|
|
107
|
+
* @param params.prompt Server-side prompt name (e.g. 'writing.analysis').
|
|
108
|
+
* @param params.variables Variables for the server-side prompt template.
|
|
102
109
|
*/
|
|
103
|
-
|
|
104
|
-
return __awaiter(this,
|
|
105
|
-
|
|
106
|
-
knowledgeId, prompt, variables) {
|
|
110
|
+
getStreamedText(params) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const { messages, onMessage, tools, cache = false, model, prompt, variables, } = params;
|
|
107
113
|
const messageId = Math.random().toString(36).substring(3);
|
|
108
114
|
const { result } = yield this.streamObject({
|
|
109
115
|
cache,
|
|
110
116
|
tools,
|
|
111
117
|
model,
|
|
112
118
|
messages,
|
|
113
|
-
knowledgeId,
|
|
114
119
|
prompt,
|
|
115
120
|
variables,
|
|
116
121
|
onResult: ({ result }) => onMessage(messageId, result, false),
|
|
@@ -179,14 +184,6 @@ export class AIModule {
|
|
|
179
184
|
});
|
|
180
185
|
});
|
|
181
186
|
}
|
|
182
|
-
/** @deprecated Used by legacy client-side prompt path. Will be removed once all plugins migrate to server-side prompt definitions. */
|
|
183
|
-
getChatMessage(systemPrompt, userPrompt) {
|
|
184
|
-
const messages = [{ role: 'system', content: systemPrompt }];
|
|
185
|
-
if (userPrompt) {
|
|
186
|
-
messages.push({ role: 'user', content: userPrompt });
|
|
187
|
-
}
|
|
188
|
-
return messages;
|
|
189
|
-
}
|
|
190
187
|
/**
|
|
191
188
|
* Generate a structured object from a request using AI.
|
|
192
189
|
* @param request.cache Whether to cache the result (default: false).
|
|
@@ -198,14 +195,12 @@ export class AIModule {
|
|
|
198
195
|
*/
|
|
199
196
|
getObject(params) {
|
|
200
197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
const {
|
|
198
|
+
const { cache = false, tools = [], model = undefined, prompt, variables } = params;
|
|
202
199
|
return yield this.streamObject({
|
|
203
|
-
|
|
204
|
-
messages: systemPrompt ? this.getChatMessage(systemPrompt, userPrompt) : [],
|
|
200
|
+
messages: [],
|
|
205
201
|
cache,
|
|
206
202
|
tools,
|
|
207
203
|
model,
|
|
208
|
-
knowledgeId,
|
|
209
204
|
prompt,
|
|
210
205
|
variables,
|
|
211
206
|
});
|
|
@@ -222,15 +217,13 @@ export class AIModule {
|
|
|
222
217
|
*/
|
|
223
218
|
getStreamedObject(params) {
|
|
224
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
const {
|
|
220
|
+
const { onResult, cache = false, tools = [], model = undefined, prompt, variables } = params;
|
|
226
221
|
return yield this.streamObject({
|
|
227
|
-
|
|
228
|
-
messages: systemPrompt ? this.getChatMessage(systemPrompt, userPrompt) : [],
|
|
222
|
+
messages: [],
|
|
229
223
|
onResult,
|
|
230
224
|
cache,
|
|
231
225
|
tools,
|
|
232
226
|
model,
|
|
233
|
-
knowledgeId,
|
|
234
227
|
prompt,
|
|
235
228
|
variables,
|
|
236
229
|
});
|
|
@@ -239,7 +232,7 @@ export class AIModule {
|
|
|
239
232
|
streamObject(params) {
|
|
240
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
241
234
|
var _a, _b, _c, _d, _e;
|
|
242
|
-
const { messages,
|
|
235
|
+
const { messages, onResult = () => null, cache = false, tools = [], model = undefined, prompt, variables, } = params;
|
|
243
236
|
const chatMessages = messages.map((message, index) => (Object.assign(Object.assign({}, message), { id: `${index + 1}` })));
|
|
244
237
|
const payload = {
|
|
245
238
|
cache,
|
|
@@ -247,15 +240,11 @@ export class AIModule {
|
|
|
247
240
|
stream: true,
|
|
248
241
|
messages: chatMessages,
|
|
249
242
|
model,
|
|
250
|
-
knowledge_id: knowledgeId,
|
|
251
243
|
session_token_id: (_a = this.sessionTokenId) !== null && _a !== void 0 ? _a : undefined,
|
|
252
244
|
};
|
|
253
245
|
if (prompt) {
|
|
254
246
|
payload.prompt = { name: this.resolvePromptName(prompt), variables: variables !== null && variables !== void 0 ? variables : {} };
|
|
255
247
|
}
|
|
256
|
-
if (responseSchema) {
|
|
257
|
-
payload.responseSchema = responseSchema;
|
|
258
|
-
}
|
|
259
248
|
const response = yield fetch(`${this.backendUrl}/ai/llm`, {
|
|
260
249
|
body: JSON.stringify(payload),
|
|
261
250
|
method: 'POST',
|