Skip to content

Commit a11dba5

Browse files
authored
feat: better tools.prefix typings (#65)
1 parent d2731ee commit a11dba5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/blink/src/agent/tools.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ export function toolWithApproval<INPUT, OUTPUT>(
6363
return tool;
6464
}
6565

66+
type ToolSetWithPrefix<TOOLS extends ToolSet, PREFIX extends string> = {
67+
[K in keyof TOOLS as `${PREFIX}${K & string}`]: K extends string
68+
? TOOLS[K]
69+
: never;
70+
};
71+
6672
/**
6773
* Tools are helpers for managing tools.
6874
*/
@@ -253,12 +259,15 @@ export const tools = Object.freeze({
253259
* @param prefix The prefix to add to the tools.
254260
* @returns The prefixed tool set.
255261
*/
256-
prefix(tools: ToolSet, prefix: string): ToolSet {
262+
prefix<PREFIX extends string, TOOLS extends ToolSet>(
263+
tools: TOOLS,
264+
prefix: PREFIX
265+
): ToolSetWithPrefix<TOOLS, PREFIX> {
257266
const prefixed: ToolSet = {};
258267
for (const [key, tool] of Object.entries(tools)) {
259268
prefixed[`${prefix}${key}`] = tool;
260269
}
261-
return prefixed;
270+
return prefixed as ToolSetWithPrefix<TOOLS, PREFIX>;
262271
},
263272
});
264273

packages/slack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blink-sdk/slack",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"author": {
55
"name": "Coder",
66
"email": "support@blink.so",

0 commit comments

Comments
 (0)