summaryrefslogtreecommitdiff
path: root/packages/core/src/test-utils/tools.ts
diff options
context:
space:
mode:
authorjoshualitt <[email protected]>2025-08-06 10:50:02 -0700
committerGitHub <[email protected]>2025-08-06 17:50:02 +0000
commit6133bea388a2de69c71a6be6f1450707f2ce4dfb (patch)
tree367de1d618069ea80e47d7e86c4fb8f82ad032a7 /packages/core/src/test-utils/tools.ts
parent882a97aff998b2f19731e9966d135f1db5a59914 (diff)
feat(core): Introduce `DeclarativeTool` and `ToolInvocation`. (#5613)
Diffstat (limited to 'packages/core/src/test-utils/tools.ts')
-rw-r--r--packages/core/src/test-utils/tools.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/packages/core/src/test-utils/tools.ts b/packages/core/src/test-utils/tools.ts
new file mode 100644
index 00000000..b168db9c
--- /dev/null
+++ b/packages/core/src/test-utils/tools.ts
@@ -0,0 +1,63 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { vi } from 'vitest';
+import {
+ BaseTool,
+ Icon,
+ ToolCallConfirmationDetails,
+ ToolResult,
+} from '../tools/tools.js';
+import { Schema, Type } from '@google/genai';
+
+/**
+ * A highly configurable mock tool for testing purposes.
+ */
+export class MockTool extends BaseTool<{ [key: string]: unknown }, ToolResult> {
+ executeFn = vi.fn();
+ shouldConfirm = false;
+
+ constructor(
+ name = 'mock-tool',
+ displayName?: string,
+ description = 'A mock tool for testing.',
+ params: Schema = {
+ type: Type.OBJECT,
+ properties: { param: { type: Type.STRING } },
+ },
+ ) {
+ super(name, displayName ?? name, description, Icon.Hammer, params);
+ }
+
+ async execute(
+ params: { [key: string]: unknown },
+ _abortSignal: AbortSignal,
+ ): Promise<ToolResult> {
+ const result = this.executeFn(params);
+ return (
+ result ?? {
+ llmContent: `Tool ${this.name} executed successfully.`,
+ returnDisplay: `Tool ${this.name} executed successfully.`,
+ }
+ );
+ }
+
+ async shouldConfirmExecute(
+ _params: { [key: string]: unknown },
+ _abortSignal: AbortSignal,
+ ): Promise<ToolCallConfirmationDetails | false> {
+ if (this.shouldConfirm) {
+ return {
+ type: 'exec' as const,
+ title: `Confirm ${this.displayName}`,
+ command: this.name,
+ rootCommand: this.name,
+ onConfirm: async () => {},
+ };
+ }
+ return false;
+ }
+}