@kognitivedev/tools 0.2.7 → 0.2.11

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.
@@ -1 +1,12 @@
1
1
  $ vitest run
2
+
3
+ RUN v3.2.4 /Users/vserifsaglam/work/memory-experiment/packages/tools
4
+
5
+ ✓ src/__tests__/adapters.test.ts (2 tests) 3ms
6
+ ✓ src/__tests__/tools.test.ts (14 tests) 7ms
7
+
8
+ Test Files 2 passed (2)
9
+ Tests 16 passed (16)
10
+ Start at 15:51:01
11
+ Duration 3.41s (transform 383ms, setup 0ms, collect 1.52s, tests 10ms, environment 0ms, prepare 1.21s)
12
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @kognitivedev/tools
2
2
 
3
+ ## 0.2.11
4
+
5
+ ### Patch Changes
6
+
7
+ - release
8
+
9
+ - Updated dependencies []:
10
+ - @kognitivedev/shared@0.2.11
11
+
12
+ ## 0.2.10
13
+
14
+ ### Patch Changes
15
+
16
+ - release
17
+
18
+ - Updated dependencies []:
19
+ - @kognitivedev/shared@0.2.10
20
+
21
+ ## 0.2.9
22
+
23
+ ### Patch Changes
24
+
25
+ - release
26
+
27
+ - Updated dependencies []:
28
+ - @kognitivedev/shared@0.2.9
29
+
30
+ ## 0.2.8
31
+
32
+ ### Patch Changes
33
+
34
+ - release
35
+
36
+ - Updated dependencies []:
37
+ - @kognitivedev/shared@0.2.8
38
+
3
39
  ## 0.2.7
4
40
 
5
41
  ### Patch Changes
@@ -12,18 +12,18 @@ const index_1 = require("../index");
12
12
  inputSchema: zod_1.z.object({ query: zod_1.z.string() }),
13
13
  execute: async (input, ctx) => {
14
14
  ctx.emit("progress", { query: input.query });
15
- return { value: input.query, projectId: ctx.resourceId.projectId };
15
+ return { value: input.query, userId: ctx.resourceId.userId };
16
16
  },
17
17
  toModelOutput: (output) => JSON.stringify(output),
18
18
  });
19
19
  const sdkTool = (0, index_1.toAISDKTool)(tool, {
20
- resourceId: { projectId: "proj-1", userId: "user-1" },
20
+ resourceId: { userId: "user-1" },
21
21
  onEmit: (toolId, event, data) => emit(toolId, event, data),
22
22
  });
23
23
  if (!(sdkTool === null || sdkTool === void 0 ? void 0 : sdkTool.execute))
24
24
  throw new Error("Missing execute handler for sdk tool");
25
25
  const result = await sdkTool.execute({ query: "hello" }, {});
26
- (0, vitest_1.expect)(result).toBe(JSON.stringify({ value: "hello", projectId: "proj-1" }));
26
+ (0, vitest_1.expect)(result).toBe(JSON.stringify({ value: "hello", userId: "user-1" }));
27
27
  (0, vitest_1.expect)(emit).toHaveBeenCalledWith("search", "progress", { query: "hello" });
28
28
  });
29
29
  (0, vitest_1.it)("builds a ToolSet from multiple tools", () => {
@@ -33,7 +33,7 @@ const index_1 = require("../index");
33
33
  inputSchema: zod_1.z.object({}),
34
34
  execute: async () => "ok",
35
35
  });
36
- const toolSet = (0, index_1.toAISDKTools)([tool], { resourceId: { projectId: "proj-2" } });
36
+ const toolSet = (0, index_1.toAISDKTools)([tool], { resourceId: { userId: "user-2" } });
37
37
  (0, vitest_1.expect)(toolSet).toHaveProperty("echo");
38
38
  });
39
39
  });
@@ -5,7 +5,7 @@ const zod_1 = require("zod");
5
5
  const index_1 = require("../index");
6
6
  const mockContext = {
7
7
  abortSignal: new AbortController().signal,
8
- resourceId: { projectId: "test" },
8
+ resourceId: { userId: "test-user" },
9
9
  emit: vitest_1.vi.fn(),
10
10
  };
11
11
  (0, vitest_1.describe)("createTool", () => {
@@ -28,7 +28,7 @@ export interface AISDKToolOptions {
28
28
  * import { streamText } from 'ai';
29
29
  *
30
30
  * const sdkTool = toAISDKTool(myTool, {
31
- * resourceId: { projectId: 'proj_1', userId: 'user_1' },
31
+ * resourceId: { userId: 'user_1' },
32
32
  * });
33
33
  * const result = await streamText({
34
34
  * model: openai('gpt-4o'),
@@ -9,7 +9,7 @@ function buildContext(toolId, options) {
9
9
  var _a, _b;
10
10
  return {
11
11
  abortSignal: (_a = options.abortSignal) !== null && _a !== void 0 ? _a : new AbortController().signal,
12
- resourceId: (_b = options.resourceId) !== null && _b !== void 0 ? _b : { projectId: "default" },
12
+ resourceId: (_b = options.resourceId) !== null && _b !== void 0 ? _b : {},
13
13
  memory: options.memory,
14
14
  emit: (event, data) => {
15
15
  var _a;
@@ -28,7 +28,7 @@ function buildContext(toolId, options) {
28
28
  * import { streamText } from 'ai';
29
29
  *
30
30
  * const sdkTool = toAISDKTool(myTool, {
31
- * resourceId: { projectId: 'proj_1', userId: 'user_1' },
31
+ * resourceId: { userId: 'user_1' },
32
32
  * });
33
33
  * const result = await streamText({
34
34
  * model: openai('gpt-4o'),
package/dist/types.d.ts CHANGED
@@ -43,7 +43,10 @@ export interface ToolDefinition<TInput = any, TOutput = any> {
43
43
  * Transform tool output before sending to the model.
44
44
  * Useful for large outputs — keep full result in application, send summary to model.
45
45
  */
46
- toModelOutput?: (output: TOutput) => string;
46
+ toModelOutput?: (output: TOutput) => string | Array<{
47
+ type: string;
48
+ [key: string]: unknown;
49
+ }>;
47
50
  }
48
51
  /**
49
52
  * A created tool instance with its definition and metadata.
@@ -62,7 +65,10 @@ export interface Tool<TInput = any, TOutput = any> {
62
65
  /** Approval requirement. */
63
66
  requireApproval?: boolean | ((input: TInput) => boolean);
64
67
  /** Output transformation for model context. */
65
- toModelOutput?: (output: TOutput) => string;
68
+ toModelOutput?: (output: TOutput) => string | Array<{
69
+ type: string;
70
+ [key: string]: unknown;
71
+ }>;
66
72
  }
67
73
  /**
68
74
  * Request for human approval of a tool execution.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kognitivedev/tools",
3
- "version": "0.2.7",
3
+ "version": "0.2.11",
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": "^0.2.7"
16
+ "@kognitivedev/shared": "^0.2.11"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "ai": ">=5.0.0",
@@ -11,19 +11,19 @@ describe("AI SDK adapter", () => {
11
11
  inputSchema: z.object({ query: z.string() }),
12
12
  execute: async (input, ctx) => {
13
13
  ctx.emit("progress", { query: input.query });
14
- return { value: input.query, projectId: ctx.resourceId.projectId };
14
+ return { value: input.query, userId: ctx.resourceId.userId };
15
15
  },
16
16
  toModelOutput: (output) => JSON.stringify(output),
17
17
  });
18
18
 
19
19
  const sdkTool = toAISDKTool(tool, {
20
- resourceId: { projectId: "proj-1", userId: "user-1" },
20
+ resourceId: { userId: "user-1" },
21
21
  onEmit: (toolId, event, data) => emit(toolId, event, data),
22
22
  });
23
23
 
24
24
  if (!sdkTool?.execute) throw new Error("Missing execute handler for sdk tool");
25
25
  const result = await sdkTool.execute({ query: "hello" }, {} as any);
26
- expect(result).toBe(JSON.stringify({ value: "hello", projectId: "proj-1" }));
26
+ expect(result).toBe(JSON.stringify({ value: "hello", userId: "user-1" }));
27
27
  expect(emit).toHaveBeenCalledWith("search", "progress", { query: "hello" });
28
28
  });
29
29
 
@@ -35,7 +35,7 @@ describe("AI SDK adapter", () => {
35
35
  execute: async () => "ok",
36
36
  });
37
37
 
38
- const toolSet = toAISDKTools([tool], { resourceId: { projectId: "proj-2" } });
38
+ const toolSet = toAISDKTools([tool], { resourceId: { userId: "user-2" } });
39
39
  expect(toolSet).toHaveProperty("echo");
40
40
  });
41
41
  });
@@ -5,7 +5,7 @@ import type { ToolContext } from "../types";
5
5
 
6
6
  const mockContext: ToolContext = {
7
7
  abortSignal: new AbortController().signal,
8
- resourceId: { projectId: "test" },
8
+ resourceId: { userId: "test-user" },
9
9
  emit: vi.fn(),
10
10
  };
11
11
 
@@ -22,7 +22,7 @@ export interface AISDKToolOptions {
22
22
  function buildContext(toolId: string, options: AISDKToolOptions): ToolContext {
23
23
  return {
24
24
  abortSignal: options.abortSignal ?? new AbortController().signal,
25
- resourceId: options.resourceId ?? { projectId: "default" },
25
+ resourceId: options.resourceId ?? {},
26
26
  memory: options.memory,
27
27
  emit: (event, data) => {
28
28
  options.onEmit?.(toolId, event, data);
@@ -41,7 +41,7 @@ function buildContext(toolId: string, options: AISDKToolOptions): ToolContext {
41
41
  * import { streamText } from 'ai';
42
42
  *
43
43
  * const sdkTool = toAISDKTool(myTool, {
44
- * resourceId: { projectId: 'proj_1', userId: 'user_1' },
44
+ * resourceId: { userId: 'user_1' },
45
45
  * });
46
46
  * const result = await streamText({
47
47
  * model: openai('gpt-4o'),
package/src/types.ts CHANGED
@@ -42,7 +42,7 @@ export interface ToolDefinition<TInput = any, TOutput = any> {
42
42
  * Transform tool output before sending to the model.
43
43
  * Useful for large outputs — keep full result in application, send summary to model.
44
44
  */
45
- toModelOutput?: (output: TOutput) => string;
45
+ toModelOutput?: (output: TOutput) => string | Array<{ type: string;[key: string]: unknown }>;
46
46
  }
47
47
 
48
48
  /**
@@ -62,7 +62,7 @@ export interface Tool<TInput = any, TOutput = any> {
62
62
  /** Approval requirement. */
63
63
  requireApproval?: boolean | ((input: TInput) => boolean);
64
64
  /** Output transformation for model context. */
65
- toModelOutput?: (output: TOutput) => string;
65
+ toModelOutput?: (output: TOutput) => string | Array<{ type: string;[key: string]: unknown }>;
66
66
  }
67
67
 
68
68
  /**