@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.mjs
CHANGED
|
@@ -9,6 +9,8 @@ var AlquimiaSDK = class {
|
|
|
9
9
|
this.sessionId = null;
|
|
10
10
|
// Internal subscription id from infer (`taskid` on the wire).
|
|
11
11
|
this.streamId = null;
|
|
12
|
+
// W3C traceparent for the current turn, so infer and stream share one trace.
|
|
13
|
+
this.traceParent = null;
|
|
12
14
|
this.tools = [];
|
|
13
15
|
this.extraInstructions = null;
|
|
14
16
|
this.assistantConfig = null;
|
|
@@ -129,11 +131,12 @@ var AlquimiaSDK = class {
|
|
|
129
131
|
const result = (await this.axiosInstance.post(inferUrl, initMessage, {
|
|
130
132
|
headers: {
|
|
131
133
|
"Content-Type": "application/json",
|
|
132
|
-
"x-trace-parent": traceParent
|
|
134
|
+
...traceParent && { "x-trace-parent": traceParent },
|
|
133
135
|
...adapterHeaders,
|
|
134
136
|
...this.buildIdentityHeaders()
|
|
135
137
|
}
|
|
136
138
|
})).data;
|
|
139
|
+
this.traceParent = traceParent ?? null;
|
|
137
140
|
this.streamId = result.taskid ?? null;
|
|
138
141
|
this.attachmentResponses = result.attachments ?? [];
|
|
139
142
|
this.attachments = [];
|
|
@@ -233,7 +236,10 @@ var AlquimiaSDK = class {
|
|
|
233
236
|
if (!this.streamId) {
|
|
234
237
|
throw new Error("Stream ID not initialized. Call sendMessage() first");
|
|
235
238
|
}
|
|
236
|
-
|
|
239
|
+
const url = this.adapter.resolveStreamUrl(this.streamId);
|
|
240
|
+
if (!this.traceParent) return url;
|
|
241
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
242
|
+
return `${url}${separator}trace_parent=${encodeURIComponent(this.traceParent)}`;
|
|
237
243
|
}
|
|
238
244
|
getStreamId() {
|
|
239
245
|
return this.streamId;
|
|
@@ -486,7 +492,9 @@ function frameToRecord(frame) {
|
|
|
486
492
|
control_id: frame.control_id ?? null,
|
|
487
493
|
data: frame.data,
|
|
488
494
|
status,
|
|
489
|
-
date_submitted: typeof frame.date_submitted === "string" ? frame.date_submitted : ""
|
|
495
|
+
date_submitted: typeof frame.date_submitted === "string" ? frame.date_submitted : "",
|
|
496
|
+
entry_hash: frame.entry_hash ?? null,
|
|
497
|
+
previous_hash: frame.previous_hash ?? null
|
|
490
498
|
};
|
|
491
499
|
}
|
|
492
500
|
|
|
@@ -642,6 +650,25 @@ var coreCatalog = {
|
|
|
642
650
|
};
|
|
643
651
|
|
|
644
652
|
// src/genui/actions.ts
|
|
653
|
+
var DISMISS_ACTION = "userDismissedSurface";
|
|
654
|
+
function buildDismissResult(surfaceId, userMessage) {
|
|
655
|
+
const said = typeof userMessage === "string" ? userMessage.trim() : "";
|
|
656
|
+
return {
|
|
657
|
+
action: DISMISS_ACTION,
|
|
658
|
+
surfaceId,
|
|
659
|
+
componentId: "",
|
|
660
|
+
data: {},
|
|
661
|
+
...said ? { userMessage: said } : {}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
function buildSurfaceResult(action) {
|
|
665
|
+
return {
|
|
666
|
+
action: action.action,
|
|
667
|
+
surfaceId: action.surfaceId,
|
|
668
|
+
componentId: action.componentId,
|
|
669
|
+
data: action.payload ?? {}
|
|
670
|
+
};
|
|
671
|
+
}
|
|
645
672
|
var URL_LIKE = /^\s*([a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
646
673
|
function assertSafeActionName(name) {
|
|
647
674
|
if (typeof name !== "string" || name.length === 0) {
|
|
@@ -676,7 +703,15 @@ var surfaceShape = z3.object({
|
|
|
676
703
|
});
|
|
677
704
|
var UAX31_ID = /^[\p{XID_Start}_][\p{XID_Continue}]*$/u;
|
|
678
705
|
function validateProps(node, def2) {
|
|
679
|
-
const {
|
|
706
|
+
const {
|
|
707
|
+
id,
|
|
708
|
+
component: _component,
|
|
709
|
+
children: _children,
|
|
710
|
+
child: _child,
|
|
711
|
+
binding: _binding,
|
|
712
|
+
action: _action,
|
|
713
|
+
...props
|
|
714
|
+
} = node;
|
|
680
715
|
const parsed = def2.schema.safeParse(props);
|
|
681
716
|
if (parsed.success) return { ok: true, value: parsed.data, errors: [] };
|
|
682
717
|
return {
|
|
@@ -813,7 +848,9 @@ function buildGenuiClause(manifest, allowlist) {
|
|
|
813
848
|
`Components: ${names.join(", ")}.`,
|
|
814
849
|
`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.`,
|
|
815
850
|
"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`).",
|
|
816
|
-
"To collect input, add a Button with an action { name, wantResponse: true }
|
|
851
|
+
"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.",
|
|
852
|
+
"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.",
|
|
853
|
+
'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.',
|
|
817
854
|
"IMPORTANT: the rendered surface IS your reply \u2014 do NOT reproduce its content as text, markdown, or ASCII; a one-line intro at most.",
|
|
818
855
|
"Prefer plain text for simple replies."
|
|
819
856
|
].join(" ");
|
|
@@ -1239,15 +1276,44 @@ function useAlquimia(config) {
|
|
|
1239
1276
|
control_id: controlId,
|
|
1240
1277
|
tool_name: "render_ui",
|
|
1241
1278
|
status: "success",
|
|
1242
|
-
|
|
1279
|
+
// Includes componentId, so the agent can tell which element was acted on when
|
|
1280
|
+
// several share one action name (a grid of option cards, say).
|
|
1281
|
+
result: buildSurfaceResult(action)
|
|
1243
1282
|
});
|
|
1244
1283
|
},
|
|
1245
1284
|
[completeToolExecution]
|
|
1246
1285
|
);
|
|
1286
|
+
const genuiDismiss = useCallback2(
|
|
1287
|
+
(userMessage) => {
|
|
1288
|
+
if (!pendingClientTool || pendingClientTool.toolName !== "render_ui") return;
|
|
1289
|
+
const { controlId } = pendingClientTool;
|
|
1290
|
+
const said = typeof userMessage === "string" ? userMessage.trim() : "";
|
|
1291
|
+
const item = genuiSurfaces.find((s) => s.controlId === controlId);
|
|
1292
|
+
setGenuiSurfaces(
|
|
1293
|
+
(prev) => prev.map(
|
|
1294
|
+
(s) => s.controlId === controlId ? { ...s, submitted: true, dismissedWith: said || void 0 } : s
|
|
1295
|
+
)
|
|
1296
|
+
);
|
|
1297
|
+
if (said) setInput("");
|
|
1298
|
+
void completeToolExecution(controlId, {
|
|
1299
|
+
control_id: controlId,
|
|
1300
|
+
tool_name: "render_ui",
|
|
1301
|
+
status: "success",
|
|
1302
|
+
result: buildDismissResult(item?.surface.surfaceId ?? "", said)
|
|
1303
|
+
});
|
|
1304
|
+
},
|
|
1305
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1306
|
+
[pendingClientTool, genuiSurfaces, completeToolExecution]
|
|
1307
|
+
);
|
|
1247
1308
|
const genuiAwaitingUser = !!(pendingClientTool && pendingClientTool.toolName === "render_ui" && genuiSurfaces.some(
|
|
1248
1309
|
(s) => s.controlId === pendingClientTool.controlId && s.surface.components.some((c) => c.action?.wantResponse === true)
|
|
1249
1310
|
));
|
|
1250
|
-
const genui = config.genui ? {
|
|
1311
|
+
const genui = config.genui ? {
|
|
1312
|
+
surfaces: genuiSurfaces,
|
|
1313
|
+
onAgentAction: genuiOnAgentAction,
|
|
1314
|
+
awaitingUser: genuiAwaitingUser,
|
|
1315
|
+
dismiss: genuiDismiss
|
|
1316
|
+
} : void 0;
|
|
1251
1317
|
return {
|
|
1252
1318
|
sdk,
|
|
1253
1319
|
activeTool,
|
|
@@ -1308,14 +1374,14 @@ function ratingReducer(state, action) {
|
|
|
1308
1374
|
return state;
|
|
1309
1375
|
}
|
|
1310
1376
|
}
|
|
1311
|
-
function useRatings({ assistantId, sendRating, topicId }) {
|
|
1377
|
+
function useRatings({ assistantId, sendRating, topicId, onError }) {
|
|
1312
1378
|
const [isLoading, setIsLoading] = useState2(false);
|
|
1313
1379
|
const [hasReviewed, setHasReviewed] = useState2(false);
|
|
1314
1380
|
const [state, dispatch] = useReducer2(ratingReducer, initialState);
|
|
1315
1381
|
const setRatingStars = (rating) => {
|
|
1316
1382
|
dispatch({ type: "SET_RATING_STARS", payload: rating });
|
|
1317
1383
|
};
|
|
1318
|
-
const
|
|
1384
|
+
const _setRatingThumbs = (rating) => {
|
|
1319
1385
|
dispatch({ type: "SET_RATING_THUMBS", payload: rating });
|
|
1320
1386
|
};
|
|
1321
1387
|
const setRatingComment = (comment) => {
|
|
@@ -1338,7 +1404,9 @@ function useRatings({ assistantId, sendRating, topicId }) {
|
|
|
1338
1404
|
const response = await sendRating(ratingObj);
|
|
1339
1405
|
if (!response.success) {
|
|
1340
1406
|
setIsLoading(false);
|
|
1341
|
-
|
|
1407
|
+
const error = new Error(response.error?.message ?? "Failed to send rating");
|
|
1408
|
+
onHandleRateSuccess(false, error.message);
|
|
1409
|
+
onError?.("useRatings", error);
|
|
1342
1410
|
return;
|
|
1343
1411
|
}
|
|
1344
1412
|
if (key === "score") {
|
|
@@ -1351,7 +1419,9 @@ function useRatings({ assistantId, sendRating, topicId }) {
|
|
|
1351
1419
|
onHandleRateSuccess(true);
|
|
1352
1420
|
} catch (err) {
|
|
1353
1421
|
setIsLoading(false);
|
|
1354
|
-
|
|
1422
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
1423
|
+
onHandleRateSuccess(false, error.message);
|
|
1424
|
+
onError?.("useRatings", error);
|
|
1355
1425
|
}
|
|
1356
1426
|
};
|
|
1357
1427
|
return {
|