@alquimia-ai/tools 2.3.0 → 2.5.0
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 +6 -0
- package/dist/actions/index.d.mts +2 -2
- package/dist/actions/index.d.ts +2 -2
- package/dist/actions/index.js +1 -1
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/index.mjs +1 -1
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions-BjDPJdyA.d.mts +57 -0
- package/dist/actions-CP1d4Ye1.d.ts +57 -0
- package/dist/adapters/index.d.mts +2 -2
- package/dist/adapters/index.d.ts +2 -2
- package/dist/adapters/index.js.map +1 -1
- package/dist/genui/index.d.mts +3 -3
- package/dist/genui/index.d.ts +3 -3
- package/dist/genui/index.js +34 -2
- package/dist/genui/index.js.map +1 -1
- package/dist/genui/index.mjs +34 -2
- package/dist/genui/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +11 -10
- package/dist/hooks/index.d.ts +11 -10
- package/dist/hooks/index.js +81 -11
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +81 -11
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/next/index.js +19 -5
- package/dist/next/index.js.map +1 -1
- package/dist/next/index.mjs +19 -5
- package/dist/next/index.mjs.map +1 -1
- package/dist/providers/index.d.mts +4 -4
- package/dist/providers/index.d.ts +4 -4
- package/dist/providers/index.js +111 -110
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +111 -110
- package/dist/providers/index.mjs.map +1 -1
- package/dist/{providers-BJTXCtI3.d.ts → providers-DiR9cgyo.d.mts} +8 -8
- package/dist/{providers-0Gi78uNQ.d.mts → providers-b5_yMyMo.d.ts} +8 -8
- package/dist/proxy.d.mts +4 -4
- package/dist/proxy.d.ts +4 -4
- package/dist/proxy.js +19 -5
- package/dist/proxy.js.map +1 -1
- package/dist/proxy.mjs +19 -5
- package/dist/proxy.mjs.map +1 -1
- package/dist/sdk/index.d.mts +4 -3
- package/dist/sdk/index.d.ts +4 -3
- package/dist/sdk/index.js +8 -2
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/index.mjs +8 -2
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/services/index.d.mts +3 -3
- package/dist/services/index.d.ts +3 -3
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs.map +1 -1
- package/dist/type-DqX3-9QS.d.mts +312 -0
- package/dist/type-xksRnBUW.d.ts +312 -0
- package/dist/types/index.d.mts +78 -302
- package/dist/types/index.d.ts +78 -302
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/types-C-6fgK1_.d.mts +111 -0
- package/dist/types-C-6fgK1_.d.ts +111 -0
- package/dist/{types-DnfWUE9V.d.mts → types-CMVbyEv8.d.mts} +3 -2
- package/dist/{types-DnfWUE9V.d.ts → types-CMVbyEv8.d.ts} +3 -2
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/worklog/index.d.mts +5 -2
- package/dist/worklog/index.d.ts +5 -2
- package/dist/worklog/index.js +3 -1
- package/dist/worklog/index.js.map +1 -1
- package/dist/worklog/index.mjs +3 -1
- package/dist/worklog/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/actions-BebMyGqF.d.ts +0 -16
- package/dist/actions-Ca3ro-hX.d.mts +0 -16
- package/dist/types-Dvu9y4WM.d.mts +0 -53
- package/dist/types-Dvu9y4WM.d.ts +0 -53
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { AlquimiaSDK } from '../sdk/index.mjs';
|
|
3
3
|
import { AlquimiaAdapter } from '../adapters/index.mjs';
|
|
4
|
-
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-
|
|
5
|
-
import { GenuiSurfaceItem, AlquimiaMessage, ToolEvent, AIMessageChunk, RatingData } from '../
|
|
4
|
+
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-DiR9cgyo.mjs';
|
|
5
|
+
import { G as GenuiSurfaceItem, e as AlquimiaMessage, u as ToolEvent, a as AIMessageChunk, R as RatingData } from '../type-DqX3-9QS.mjs';
|
|
6
|
+
import { T as ToolExecutionResponse } from '../types-CMVbyEv8.mjs';
|
|
7
|
+
import { a as WorklogState } from '../types-C-6fgK1_.mjs';
|
|
6
8
|
import { createMessageId } from '../utils/index.mjs';
|
|
7
|
-
import { W as WorklogState } from '../types-Dvu9y4WM.mjs';
|
|
8
|
-
import { T as ToolExecutionResponse } from '../types-DnfWUE9V.mjs';
|
|
9
9
|
import { C as CatalogManifest } from '../registry-Bcu_ZYL1.mjs';
|
|
10
|
-
import { U as UIAction } from '../actions-
|
|
10
|
+
import { U as UIAction } from '../actions-BjDPJdyA.mjs';
|
|
11
11
|
import '@elastic/apm-rum';
|
|
12
12
|
import 'ai';
|
|
13
13
|
import 'zod';
|
|
@@ -49,6 +49,7 @@ declare function useAlquimia(config: UseAlquimiaConfig): {
|
|
|
49
49
|
surfaces: GenuiSurfaceItem[];
|
|
50
50
|
onAgentAction: (controlId: string) => (action: UIAction) => void;
|
|
51
51
|
awaitingUser: boolean;
|
|
52
|
+
dismiss: (userMessage?: string) => void;
|
|
52
53
|
} | undefined;
|
|
53
54
|
cleanMessages: () => void;
|
|
54
55
|
createMessageId: typeof createMessageId;
|
|
@@ -73,7 +74,7 @@ declare function useAlquimia(config: UseAlquimiaConfig): {
|
|
|
73
74
|
messages: AlquimiaMessage[];
|
|
74
75
|
populateMessages: (messages: AlquimiaMessage[]) => void;
|
|
75
76
|
processMessageChunk: (messageId: string, chunk: string, error_code?: string, error_detail?: string, taskid?: string, additionalInfo?: string, loading?: boolean, tooler?: ToolEvent[], thinkings?: any[]) => void;
|
|
76
|
-
sendMessage: (message: string, callBack: (
|
|
77
|
+
sendMessage: (message: string, callBack: (_chunk: AIMessageChunk) => void, traceParentId?: string, sessionId?: string) => Promise<void>;
|
|
77
78
|
sessionId: string | null;
|
|
78
79
|
setActiveTool: react.Dispatch<any>;
|
|
79
80
|
setSessionId: react.Dispatch<react.SetStateAction<string | null>>;
|
|
@@ -92,11 +93,11 @@ declare function useAlquimia(config: UseAlquimiaConfig): {
|
|
|
92
93
|
interface UseRatingsParams {
|
|
93
94
|
assistantId: string;
|
|
94
95
|
topicId: string;
|
|
95
|
-
sendRating: (
|
|
96
|
-
onError?: (
|
|
96
|
+
sendRating: (_ratingData: RatingData) => Promise<any>;
|
|
97
|
+
onError?: (_componentName: string, _error: Error) => void;
|
|
97
98
|
}
|
|
98
|
-
declare function useRatings({ assistantId, sendRating, topicId }: UseRatingsParams): {
|
|
99
|
-
handleRate: (key: string, value: any | string, onHandleRateSuccess: (
|
|
99
|
+
declare function useRatings({ assistantId, sendRating, topicId, onError }: UseRatingsParams): {
|
|
100
|
+
handleRate: (key: string, value: any | string, onHandleRateSuccess: (_success: boolean, _err?: string) => void) => Promise<void>;
|
|
100
101
|
ratingStars: number;
|
|
101
102
|
ratingThumbs: "" | "thumbsUp" | "thumbsDown";
|
|
102
103
|
ratingComment: string;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { AlquimiaSDK } from '../sdk/index.js';
|
|
3
3
|
import { AlquimiaAdapter } from '../adapters/index.js';
|
|
4
|
-
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-
|
|
5
|
-
import { GenuiSurfaceItem, AlquimiaMessage, ToolEvent, AIMessageChunk, RatingData } from '../
|
|
4
|
+
import { W as WhisperProvider, S as StableDiffusionProvider, C as CharacterizationProvider, R as RatingsProvider, L as LoggerProvider } from '../providers-b5_yMyMo.js';
|
|
5
|
+
import { G as GenuiSurfaceItem, e as AlquimiaMessage, u as ToolEvent, a as AIMessageChunk, R as RatingData } from '../type-xksRnBUW.js';
|
|
6
|
+
import { T as ToolExecutionResponse } from '../types-CMVbyEv8.js';
|
|
7
|
+
import { a as WorklogState } from '../types-C-6fgK1_.js';
|
|
6
8
|
import { createMessageId } from '../utils/index.js';
|
|
7
|
-
import { W as WorklogState } from '../types-Dvu9y4WM.js';
|
|
8
|
-
import { T as ToolExecutionResponse } from '../types-DnfWUE9V.js';
|
|
9
9
|
import { C as CatalogManifest } from '../registry-Bcu_ZYL1.js';
|
|
10
|
-
import { U as UIAction } from '../actions-
|
|
10
|
+
import { U as UIAction } from '../actions-CP1d4Ye1.js';
|
|
11
11
|
import '@elastic/apm-rum';
|
|
12
12
|
import 'ai';
|
|
13
13
|
import 'zod';
|
|
@@ -49,6 +49,7 @@ declare function useAlquimia(config: UseAlquimiaConfig): {
|
|
|
49
49
|
surfaces: GenuiSurfaceItem[];
|
|
50
50
|
onAgentAction: (controlId: string) => (action: UIAction) => void;
|
|
51
51
|
awaitingUser: boolean;
|
|
52
|
+
dismiss: (userMessage?: string) => void;
|
|
52
53
|
} | undefined;
|
|
53
54
|
cleanMessages: () => void;
|
|
54
55
|
createMessageId: typeof createMessageId;
|
|
@@ -73,7 +74,7 @@ declare function useAlquimia(config: UseAlquimiaConfig): {
|
|
|
73
74
|
messages: AlquimiaMessage[];
|
|
74
75
|
populateMessages: (messages: AlquimiaMessage[]) => void;
|
|
75
76
|
processMessageChunk: (messageId: string, chunk: string, error_code?: string, error_detail?: string, taskid?: string, additionalInfo?: string, loading?: boolean, tooler?: ToolEvent[], thinkings?: any[]) => void;
|
|
76
|
-
sendMessage: (message: string, callBack: (
|
|
77
|
+
sendMessage: (message: string, callBack: (_chunk: AIMessageChunk) => void, traceParentId?: string, sessionId?: string) => Promise<void>;
|
|
77
78
|
sessionId: string | null;
|
|
78
79
|
setActiveTool: react.Dispatch<any>;
|
|
79
80
|
setSessionId: react.Dispatch<react.SetStateAction<string | null>>;
|
|
@@ -92,11 +93,11 @@ declare function useAlquimia(config: UseAlquimiaConfig): {
|
|
|
92
93
|
interface UseRatingsParams {
|
|
93
94
|
assistantId: string;
|
|
94
95
|
topicId: string;
|
|
95
|
-
sendRating: (
|
|
96
|
-
onError?: (
|
|
96
|
+
sendRating: (_ratingData: RatingData) => Promise<any>;
|
|
97
|
+
onError?: (_componentName: string, _error: Error) => void;
|
|
97
98
|
}
|
|
98
|
-
declare function useRatings({ assistantId, sendRating, topicId }: UseRatingsParams): {
|
|
99
|
-
handleRate: (key: string, value: any | string, onHandleRateSuccess: (
|
|
99
|
+
declare function useRatings({ assistantId, sendRating, topicId, onError }: UseRatingsParams): {
|
|
100
|
+
handleRate: (key: string, value: any | string, onHandleRateSuccess: (_success: boolean, _err?: string) => void) => Promise<void>;
|
|
100
101
|
ratingStars: number;
|
|
101
102
|
ratingThumbs: "" | "thumbsUp" | "thumbsDown";
|
|
102
103
|
ratingComment: string;
|
package/dist/hooks/index.js
CHANGED
|
@@ -46,6 +46,8 @@ var AlquimiaSDK = class {
|
|
|
46
46
|
this.sessionId = null;
|
|
47
47
|
// Internal subscription id from infer (`taskid` on the wire).
|
|
48
48
|
this.streamId = null;
|
|
49
|
+
// W3C traceparent for the current turn, so infer and stream share one trace.
|
|
50
|
+
this.traceParent = null;
|
|
49
51
|
this.tools = [];
|
|
50
52
|
this.extraInstructions = null;
|
|
51
53
|
this.assistantConfig = null;
|
|
@@ -166,11 +168,12 @@ var AlquimiaSDK = class {
|
|
|
166
168
|
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
167
169
|
headers: {
|
|
168
170
|
"Content-Type": "application/json",
|
|
169
|
-
"x-trace-parent": traceParent
|
|
171
|
+
...traceParent && { "x-trace-parent": traceParent },
|
|
170
172
|
...adapterHeaders,
|
|
171
173
|
...this.buildIdentityHeaders()
|
|
172
174
|
}
|
|
173
175
|
})).data;
|
|
176
|
+
this.traceParent = traceParent ?? null;
|
|
174
177
|
this.streamId = result.taskid ?? null;
|
|
175
178
|
this.attachmentResponses = result.attachments ?? [];
|
|
176
179
|
this.attachments = [];
|
|
@@ -270,7 +273,10 @@ var AlquimiaSDK = class {
|
|
|
270
273
|
if (!this.streamId) {
|
|
271
274
|
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
272
275
|
}
|
|
273
|
-
|
|
276
|
+
const url = this.adapter.resolveStreamUrl(this.streamId);
|
|
277
|
+
if (!this.traceParent) return url;
|
|
278
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
279
|
+
return `${url}${separator}trace_parent=${encodeURIComponent(this.traceParent)}`;
|
|
274
280
|
}
|
|
275
281
|
getStreamId() {
|
|
276
282
|
return this.streamId;
|
|
@@ -523,7 +529,9 @@ function frameToRecord(frame) {
|
|
|
523
529
|
control_id: frame.control_id ?? null,
|
|
524
530
|
data: frame.data,
|
|
525
531
|
status,
|
|
526
|
-
date_submitted: typeof frame.date_submitted === "string" ? frame.date_submitted : ""
|
|
532
|
+
date_submitted: typeof frame.date_submitted === "string" ? frame.date_submitted : "",
|
|
533
|
+
entry_hash: frame.entry_hash ?? null,
|
|
534
|
+
previous_hash: frame.previous_hash ?? null
|
|
527
535
|
};
|
|
528
536
|
}
|
|
529
537
|
|
|
@@ -679,6 +687,25 @@ var coreCatalog = {
|
|
|
679
687
|
};
|
|
680
688
|
|
|
681
689
|
// src/genui/actions.ts
|
|
690
|
+
var DISMISS_ACTION = "userDismissedSurface";
|
|
691
|
+
function buildDismissResult(surfaceId, userMessage) {
|
|
692
|
+
const said = typeof userMessage === "string" ? userMessage.trim() : "";
|
|
693
|
+
return {
|
|
694
|
+
action: DISMISS_ACTION,
|
|
695
|
+
surfaceId,
|
|
696
|
+
componentId: "",
|
|
697
|
+
data: {},
|
|
698
|
+
...said ? { userMessage: said } : {}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
function buildSurfaceResult(action) {
|
|
702
|
+
return {
|
|
703
|
+
action: action.action,
|
|
704
|
+
surfaceId: action.surfaceId,
|
|
705
|
+
componentId: action.componentId,
|
|
706
|
+
data: action.payload ?? {}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
682
709
|
var URL_LIKE = /^\s*([a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
683
710
|
function assertSafeActionName(name) {
|
|
684
711
|
if (typeof name !== "string" || name.length === 0) {
|
|
@@ -713,7 +740,15 @@ var surfaceShape = import_zod3.z.object({
|
|
|
713
740
|
});
|
|
714
741
|
var UAX31_ID = /^[\p{XID_Start}_][\p{XID_Continue}]*$/u;
|
|
715
742
|
function validateProps(node, def2) {
|
|
716
|
-
const {
|
|
743
|
+
const {
|
|
744
|
+
id,
|
|
745
|
+
component: _component,
|
|
746
|
+
children: _children,
|
|
747
|
+
child: _child,
|
|
748
|
+
binding: _binding,
|
|
749
|
+
action: _action,
|
|
750
|
+
...props
|
|
751
|
+
} = node;
|
|
717
752
|
const parsed = def2.schema.safeParse(props);
|
|
718
753
|
if (parsed.success) return { ok: true, value: parsed.data, errors: [] };
|
|
719
754
|
return {
|
|
@@ -850,7 +885,9 @@ function buildGenuiClause(manifest, allowlist) {
|
|
|
850
885
|
`Components: ${names.join(", ")}.`,
|
|
851
886
|
`Style each component via the semantic vocabulary (never CSS, colors, or HTML): tone (${TONES.join("/")}), size (${SIZES.join("/")}), emphasis (low/medium/high), align (start/center/end), density (compact/comfortable), plus a component-specific variant where offered.`,
|
|
852
887
|
"Data components MUST carry their data: Chart takes `data` (an array of row objects) + `series` (keys to plot) + `x` (the category key); Table takes `rows` (array of row objects) + `columns` ([{ key, header }] matching the row keys); List takes `items` (array); Stat takes `label`+`value`; KeyValue takes `data` (an object). Put the data inline on the component (or in dataModel referenced via `binding`).",
|
|
853
|
-
"To collect input, add a Button with an action { name, wantResponse: true }
|
|
888
|
+
"To collect input, add a Button with an action { name, wantResponse: true }. You get back { action, surfaceId, componentId, data } \u2014 `data` is the collected data model and `componentId` is the id of the component that was acted on. A surface with no such button is display-only.",
|
|
889
|
+
"When you render several options to choose from (a grid of cards, each with its own button), give every option component a MEANINGFUL id (e.g. flight-NH107, hotel-memmo-alfama): `componentId` tells you which one the user picked, so never ask them to repeat a choice they already made.",
|
|
890
|
+
'The user may ignore an interactive surface and just type instead. You then receive action "userDismissedSurface" with their words in `userMessage` \u2014 treat it as their reply, answer it directly, and do not re-render the same surface or scold them for not using it.',
|
|
854
891
|
"IMPORTANT: the rendered surface IS your reply \u2014 do NOT reproduce its content as text, markdown, or ASCII; a one-line intro at most.",
|
|
855
892
|
"Prefer plain text for simple replies."
|
|
856
893
|
].join(" ");
|
|
@@ -1276,15 +1313,44 @@ function useAlquimia(config) {
|
|
|
1276
1313
|
control_id: controlId,
|
|
1277
1314
|
tool_name: "render_ui",
|
|
1278
1315
|
status: "success",
|
|
1279
|
-
|
|
1316
|
+
// Includes componentId, so the agent can tell which element was acted on when
|
|
1317
|
+
// several share one action name (a grid of option cards, say).
|
|
1318
|
+
result: buildSurfaceResult(action)
|
|
1280
1319
|
});
|
|
1281
1320
|
},
|
|
1282
1321
|
[completeToolExecution]
|
|
1283
1322
|
);
|
|
1323
|
+
const genuiDismiss = (0, import_react2.useCallback)(
|
|
1324
|
+
(userMessage) => {
|
|
1325
|
+
if (!pendingClientTool || pendingClientTool.toolName !== "render_ui") return;
|
|
1326
|
+
const { controlId } = pendingClientTool;
|
|
1327
|
+
const said = typeof userMessage === "string" ? userMessage.trim() : "";
|
|
1328
|
+
const item = genuiSurfaces.find((s) => s.controlId === controlId);
|
|
1329
|
+
setGenuiSurfaces(
|
|
1330
|
+
(prev) => prev.map(
|
|
1331
|
+
(s) => s.controlId === controlId ? { ...s, submitted: true, dismissedWith: said || void 0 } : s
|
|
1332
|
+
)
|
|
1333
|
+
);
|
|
1334
|
+
if (said) setInput("");
|
|
1335
|
+
void completeToolExecution(controlId, {
|
|
1336
|
+
control_id: controlId,
|
|
1337
|
+
tool_name: "render_ui",
|
|
1338
|
+
status: "success",
|
|
1339
|
+
result: buildDismissResult(item?.surface.surfaceId ?? "", said)
|
|
1340
|
+
});
|
|
1341
|
+
},
|
|
1342
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1343
|
+
[pendingClientTool, genuiSurfaces, completeToolExecution]
|
|
1344
|
+
);
|
|
1284
1345
|
const genuiAwaitingUser = !!(pendingClientTool && pendingClientTool.toolName === "render_ui" && genuiSurfaces.some(
|
|
1285
1346
|
(s) => s.controlId === pendingClientTool.controlId && s.surface.components.some((c) => c.action?.wantResponse === true)
|
|
1286
1347
|
));
|
|
1287
|
-
const genui = config.genui ? {
|
|
1348
|
+
const genui = config.genui ? {
|
|
1349
|
+
surfaces: genuiSurfaces,
|
|
1350
|
+
onAgentAction: genuiOnAgentAction,
|
|
1351
|
+
awaitingUser: genuiAwaitingUser,
|
|
1352
|
+
dismiss: genuiDismiss
|
|
1353
|
+
} : void 0;
|
|
1288
1354
|
return {
|
|
1289
1355
|
sdk,
|
|
1290
1356
|
activeTool,
|
|
@@ -1345,14 +1411,14 @@ function ratingReducer(state, action) {
|
|
|
1345
1411
|
return state;
|
|
1346
1412
|
}
|
|
1347
1413
|
}
|
|
1348
|
-
function useRatings({ assistantId, sendRating, topicId }) {
|
|
1414
|
+
function useRatings({ assistantId, sendRating, topicId, onError }) {
|
|
1349
1415
|
const [isLoading, setIsLoading] = (0, import_react3.useState)(false);
|
|
1350
1416
|
const [hasReviewed, setHasReviewed] = (0, import_react3.useState)(false);
|
|
1351
1417
|
const [state, dispatch] = (0, import_react3.useReducer)(ratingReducer, initialState);
|
|
1352
1418
|
const setRatingStars = (rating) => {
|
|
1353
1419
|
dispatch({ type: "SET_RATING_STARS", payload: rating });
|
|
1354
1420
|
};
|
|
1355
|
-
const
|
|
1421
|
+
const _setRatingThumbs = (rating) => {
|
|
1356
1422
|
dispatch({ type: "SET_RATING_THUMBS", payload: rating });
|
|
1357
1423
|
};
|
|
1358
1424
|
const setRatingComment = (comment) => {
|
|
@@ -1375,7 +1441,9 @@ function useRatings({ assistantId, sendRating, topicId }) {
|
|
|
1375
1441
|
const response = await sendRating(ratingObj);
|
|
1376
1442
|
if (!response.success) {
|
|
1377
1443
|
setIsLoading(false);
|
|
1378
|
-
|
|
1444
|
+
const error = new Error(response.error?.message ?? "Failed to send rating");
|
|
1445
|
+
onHandleRateSuccess(false, error.message);
|
|
1446
|
+
onError?.("useRatings", error);
|
|
1379
1447
|
return;
|
|
1380
1448
|
}
|
|
1381
1449
|
if (key === "score") {
|
|
@@ -1388,7 +1456,9 @@ function useRatings({ assistantId, sendRating, topicId }) {
|
|
|
1388
1456
|
onHandleRateSuccess(true);
|
|
1389
1457
|
} catch (err) {
|
|
1390
1458
|
setIsLoading(false);
|
|
1391
|
-
|
|
1459
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
1460
|
+
onHandleRateSuccess(false, error.message);
|
|
1461
|
+
onError?.("useRatings", error);
|
|
1392
1462
|
}
|
|
1393
1463
|
};
|
|
1394
1464
|
return {
|