kernl 0.11.2 → 0.12.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.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +62 -0
  3. package/dist/agent/__tests__/run.test.js +2 -2
  4. package/dist/context.d.ts +2 -1
  5. package/dist/context.d.ts.map +1 -1
  6. package/dist/context.js +1 -0
  7. package/dist/kernl/kernl.d.ts +1 -1
  8. package/dist/kernl/kernl.d.ts.map +1 -1
  9. package/dist/lifecycle/__tests__/hooks.test.js +6 -6
  10. package/dist/storage/__tests__/in-memory.test.js +1 -1
  11. package/dist/thread/__tests__/fixtures/mock-model.js +3 -3
  12. package/dist/thread/__tests__/integration.test.js +14 -14
  13. package/dist/thread/__tests__/thread-persistence.test.js +6 -6
  14. package/dist/thread/__tests__/thread.test.js +22 -22
  15. package/dist/thread/thread.js +5 -5
  16. package/dist/thread/utils.js +5 -5
  17. package/dist/tool/__tests__/tool.test.js +4 -4
  18. package/dist/tool/tool.d.ts +1 -2
  19. package/dist/tool/tool.d.ts.map +1 -1
  20. package/dist/tool/tool.js +2 -2
  21. package/dist/tool/toolkit.d.ts +5 -3
  22. package/dist/tool/toolkit.d.ts.map +1 -1
  23. package/dist/tool/toolkit.js +3 -1
  24. package/dist/tool/types.d.ts +1 -2
  25. package/dist/tool/types.d.ts.map +1 -1
  26. package/package.json +5 -5
  27. package/src/agent/__tests__/run.test.ts +2 -2
  28. package/src/context.ts +2 -1
  29. package/src/kernl/kernl.ts +1 -1
  30. package/src/lifecycle/__tests__/hooks.test.ts +6 -6
  31. package/src/storage/__tests__/in-memory.test.ts +1 -1
  32. package/src/thread/__tests__/fixtures/mock-model.ts +3 -3
  33. package/src/thread/__tests__/integration.test.ts +18 -18
  34. package/src/thread/__tests__/thread-persistence.test.ts +6 -6
  35. package/src/thread/__tests__/thread.test.ts +22 -22
  36. package/src/thread/thread.ts +5 -5
  37. package/src/thread/utils.ts +5 -5
  38. package/src/tool/__tests__/tool.test.ts +4 -8
  39. package/src/tool/tool.ts +3 -3
  40. package/src/tool/toolkit.ts +5 -3
  41. package/src/tool/types.ts +0 -2
@@ -186,7 +186,7 @@ describe("FunctionTool", () => {
186
186
  describe("isEnabled", () => {
187
187
  it("should default to enabled", async () => {
188
188
  const ctx = mockContext();
189
- const enabled = await simpleStringTool.isEnabled(ctx, null as any);
189
+ const enabled = await simpleStringTool.isEnabled(ctx);
190
190
 
191
191
  expect(enabled).toBe(true);
192
192
  });
@@ -201,7 +201,7 @@ describe("FunctionTool", () => {
201
201
  });
202
202
 
203
203
  const ctx = mockContext();
204
- const enabled = await disabledTool.isEnabled(ctx, null as any);
204
+ const enabled = await disabledTool.isEnabled(ctx);
205
205
 
206
206
  expect(enabled).toBe(false);
207
207
  });
@@ -224,12 +224,8 @@ describe("FunctionTool", () => {
224
224
  const enabledCtx = mockContext<MyContext>({ enabled: true });
225
225
  const disabledCtx = mockContext<MyContext>({ enabled: false });
226
226
 
227
- expect(await conditionalTool.isEnabled(enabledCtx, null as any)).toBe(
228
- true,
229
- );
230
- expect(await conditionalTool.isEnabled(disabledCtx, null as any)).toBe(
231
- false,
232
- );
227
+ expect(await conditionalTool.isEnabled(enabledCtx)).toBe(true);
228
+ expect(await conditionalTool.isEnabled(disabledCtx)).toBe(false);
233
229
  });
234
230
  });
235
231
  });
package/src/tool/tool.ts CHANGED
@@ -62,7 +62,7 @@ export abstract class BaseTool<TContext = UnknownContext> {
62
62
  /**
63
63
  * Determines whether the tool should be exposed to the model for the current run.
64
64
  */
65
- abstract isEnabled(context: Context<TContext>, agent: BaseAgent<TContext>): Promise<boolean>;
65
+ abstract isEnabled(context: Context<TContext>): Promise<boolean>;
66
66
 
67
67
  /**
68
68
  * Serialize this tool for sending to the model
@@ -117,10 +117,10 @@ export class FunctionTool<
117
117
  // setup enabled function
118
118
  this.isEnabled =
119
119
  typeof config.isEnabled === "function"
120
- ? async (context, agent) => {
120
+ ? async (context) => {
121
121
  const predicate =
122
122
  config.isEnabled as ToolEnabledPredicate<TContext>;
123
- const result = await predicate({ context, agent });
123
+ const result = await predicate({ context });
124
124
  return Boolean(result);
125
125
  }
126
126
  : async () =>
@@ -30,15 +30,17 @@ export abstract class BaseToolkit<TContext = UnknownContext> {
30
30
  abstract readonly description: string;
31
31
 
32
32
  /**
33
- * The agent this toolkit is bound to (if any)
33
+ * The agent this toolkit is bound to (if any).
34
+ * Uses `any` to allow toolkits with different context types
35
+ * to be composed in the same agent.
34
36
  */
35
- protected agent?: BaseAgent<TContext>;
37
+ protected agent?: BaseAgent<any>;
36
38
 
37
39
  /**
38
40
  * Bind this toolkit to an agent.
39
41
  * Called by agent constructor.
40
42
  */
41
- bind(agent: BaseAgent<TContext>): void {
43
+ bind(agent: BaseAgent<any>): void {
42
44
  this.agent = agent;
43
45
  }
44
46
 
package/src/tool/types.ts CHANGED
@@ -227,12 +227,10 @@ export type ToolApprovalFunction<TParameters extends ToolInputParameters> = (
227
227
 
228
228
  export type ToolEnabledFunction<TContext = UnknownContext> = (
229
229
  context: Context<TContext>,
230
- agent: BaseAgent<TContext>,
231
230
  ) => Promise<boolean>;
232
231
 
233
232
  export type ToolEnabledPredicate<TContext = UnknownContext> = (args: {
234
233
  context: Context<TContext>;
235
- agent: BaseAgent<TContext>;
236
234
  }) => boolean | Promise<boolean>;
237
235
 
238
236
  type ToolEnabledOption<Context = UnknownContext> =