@kognitivedev/tools 0.2.4 → 0.2.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.
@@ -0,0 +1 @@
1
+ $ vitest run
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @kognitivedev/tools
2
2
 
3
+ ## 0.2.7
4
+
5
+ ### Patch Changes
6
+
7
+ - release
8
+
9
+ - Updated dependencies []:
10
+ - @kognitivedev/shared@0.2.7
11
+
12
+ ## 0.2.6
13
+
14
+ ### Patch Changes
15
+
16
+ - release
17
+
18
+ - Updated dependencies []:
19
+ - @kognitivedev/shared@0.2.6
20
+
21
+ ## 0.2.5
22
+
23
+ ### Patch Changes
24
+
25
+ - release
26
+
27
+ - Updated dependencies []:
28
+ - @kognitivedev/shared@0.2.5
29
+
3
30
  ## 0.2.4
4
31
 
5
32
  ### Patch Changes
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const zod_1 = require("zod");
5
+ const index_1 = require("../index");
6
+ (0, vitest_1.describe)("AI SDK adapter", () => {
7
+ (0, vitest_1.it)("passes resource context and emit callbacks through", async () => {
8
+ const emit = vitest_1.vi.fn();
9
+ const tool = (0, index_1.createTool)({
10
+ id: "search",
11
+ description: "Search",
12
+ inputSchema: zod_1.z.object({ query: zod_1.z.string() }),
13
+ execute: async (input, ctx) => {
14
+ ctx.emit("progress", { query: input.query });
15
+ return { value: input.query, projectId: ctx.resourceId.projectId };
16
+ },
17
+ toModelOutput: (output) => JSON.stringify(output),
18
+ });
19
+ const sdkTool = (0, index_1.toAISDKTool)(tool, {
20
+ resourceId: { projectId: "proj-1", userId: "user-1" },
21
+ onEmit: (toolId, event, data) => emit(toolId, event, data),
22
+ });
23
+ if (!(sdkTool === null || sdkTool === void 0 ? void 0 : sdkTool.execute))
24
+ throw new Error("Missing execute handler for sdk tool");
25
+ const result = await sdkTool.execute({ query: "hello" }, {});
26
+ (0, vitest_1.expect)(result).toBe(JSON.stringify({ value: "hello", projectId: "proj-1" }));
27
+ (0, vitest_1.expect)(emit).toHaveBeenCalledWith("search", "progress", { query: "hello" });
28
+ });
29
+ (0, vitest_1.it)("builds a ToolSet from multiple tools", () => {
30
+ const tool = (0, index_1.createTool)({
31
+ id: "echo",
32
+ description: "Echo",
33
+ inputSchema: zod_1.z.object({}),
34
+ execute: async () => "ok",
35
+ });
36
+ const toolSet = (0, index_1.toAISDKTools)([tool], { resourceId: { projectId: "proj-2" } });
37
+ (0, vitest_1.expect)(toolSet).toHaveProperty("echo");
38
+ });
39
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kognitivedev/tools",
3
- "version": "0.2.4",
3
+ "version": "0.2.7",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {
@@ -13,7 +13,7 @@
13
13
  "test": "vitest run"
14
14
  },
15
15
  "dependencies": {
16
- "@kognitivedev/shared": "workspace:*"
16
+ "@kognitivedev/shared": "^0.2.7"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "ai": ">=5.0.0",
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect, vi } from "vitest";
2
+ import { z } from "zod";
3
+ import { createTool, toAISDKTool, toAISDKTools } from "../index";
4
+
5
+ describe("AI SDK adapter", () => {
6
+ it("passes resource context and emit callbacks through", async () => {
7
+ const emit = vi.fn();
8
+ const tool = createTool({
9
+ id: "search",
10
+ description: "Search",
11
+ inputSchema: z.object({ query: z.string() }),
12
+ execute: async (input, ctx) => {
13
+ ctx.emit("progress", { query: input.query });
14
+ return { value: input.query, projectId: ctx.resourceId.projectId };
15
+ },
16
+ toModelOutput: (output) => JSON.stringify(output),
17
+ });
18
+
19
+ const sdkTool = toAISDKTool(tool, {
20
+ resourceId: { projectId: "proj-1", userId: "user-1" },
21
+ onEmit: (toolId, event, data) => emit(toolId, event, data),
22
+ });
23
+
24
+ if (!sdkTool?.execute) throw new Error("Missing execute handler for sdk tool");
25
+ const result = await sdkTool.execute({ query: "hello" }, {} as any);
26
+ expect(result).toBe(JSON.stringify({ value: "hello", projectId: "proj-1" }));
27
+ expect(emit).toHaveBeenCalledWith("search", "progress", { query: "hello" });
28
+ });
29
+
30
+ it("builds a ToolSet from multiple tools", () => {
31
+ const tool = createTool({
32
+ id: "echo",
33
+ description: "Echo",
34
+ inputSchema: z.object({}),
35
+ execute: async () => "ok",
36
+ });
37
+
38
+ const toolSet = toAISDKTools([tool], { resourceId: { projectId: "proj-2" } });
39
+ expect(toolSet).toHaveProperty("echo");
40
+ });
41
+ });