Skip to content

Commit 167117c

Browse files
straighten up types
1 parent 537fa8d commit 167117c

File tree

15 files changed

+74
-40
lines changed

15 files changed

+74
-40
lines changed

libs/providers/langchain-anthropic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@
9797
"README.md",
9898
"LICENSE"
9999
]
100-
}
100+
}

libs/providers/langchain-anthropic/src/tools/bash.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { z } from "zod/v4";
21
import Anthropic from "@anthropic-ai/sdk";
32
import { tool } from "@langchain/core/tools";
4-
import type { ToolRuntime } from "@langchain/core/tools";
3+
import type { DynamicStructuredTool, ToolRuntime } from "@langchain/core/tools";
54

65
import {
76
Bash20250124CommandSchema,
@@ -100,7 +99,7 @@ export function bash_20250124(options?: Bash20250124Options) {
10099
{
101100
name,
102101
description: "A tool for executing bash commands",
103-
schema: z.toJSONSchema(Bash20250124CommandSchema),
102+
schema: Bash20250124CommandSchema,
104103
}
105104
);
106105

@@ -112,5 +111,10 @@ export function bash_20250124(options?: Bash20250124Options) {
112111
} satisfies Anthropic.Beta.BetaToolBash20250124,
113112
};
114113

115-
return bashTool;
114+
return bashTool as DynamicStructuredTool<
115+
typeof Bash20250124CommandSchema,
116+
Bash20250124Command,
117+
unknown,
118+
string
119+
>;
116120
}

libs/providers/langchain-anthropic/src/tools/computer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515

1616
const TOOL_NAME = "computer";
1717

18-
type ComputerUseReturnType =
18+
export type ComputerUseReturnType =
1919
| string
2020
| Promise<string>
2121
| ToolMessage<any>
@@ -266,6 +266,6 @@ export function computer_20250124(options: Computer20250124Options) {
266266
typeof Computer20250124ActionSchema,
267267
Computer20250124Action,
268268
any,
269-
ToolMessage<any>
269+
ComputerUseReturnType
270270
>;
271271
}

libs/providers/langchain-anthropic/src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
computer_20250124,
1919
type Computer20251124Options,
2020
type Computer20250124Options,
21+
type ComputerUseReturnType,
2122
} from "./computer.js";
2223
import {
2324
codeExecution_20250825,
@@ -45,6 +46,7 @@ export type {
4546
Bash20250124Options,
4647
Computer20251124Options,
4748
Computer20250124Options,
49+
ComputerUseReturnType,
4850
CodeExecution20250825Options,
4951
TextEditor20250728Options,
5052
ToolSearchOptions,

libs/providers/langchain-anthropic/src/tools/memory.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { z } from "zod/v4";
21
import Anthropic from "@anthropic-ai/sdk";
32
import { tool } from "@langchain/core/tools";
43
import type { DynamicStructuredTool, ToolRuntime } from "@langchain/core/tools";
54

65
import {
76
Memory20250818CommandSchema,
87
type MemoryTool20250818Options,
8+
type Memory20250818Command,
99
} from "./types.js";
1010

1111
/**
@@ -51,7 +51,7 @@ export function memory_20250818(
5151
) => string | Promise<string>,
5252
{
5353
name: "memory",
54-
schema: z.toJSONSchema(Memory20250818CommandSchema),
54+
schema: Memory20250818CommandSchema,
5555
}
5656
);
5757

@@ -63,5 +63,10 @@ export function memory_20250818(
6363
} satisfies Anthropic.Beta.BetaMemoryTool20250818,
6464
};
6565

66-
return memoryTool;
66+
return memoryTool as DynamicStructuredTool<
67+
typeof Memory20250818CommandSchema,
68+
Memory20250818Command,
69+
unknown,
70+
string | Promise<string>
71+
>;
6772
}

libs/providers/langchain-anthropic/src/tools/textEditor.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { z } from "zod/v4";
21
import Anthropic from "@anthropic-ai/sdk";
32
import { tool } from "@langchain/core/tools";
43
import type { DynamicStructuredTool, ToolRuntime } from "@langchain/core/tools";
@@ -77,9 +76,7 @@ export interface TextEditor20250728Options {
7776
*
7877
* @see https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/text-editor-tool
7978
*/
80-
export function textEditor_20250728(
81-
options?: TextEditor20250728Options
82-
): DynamicStructuredTool {
79+
export function textEditor_20250728(options?: TextEditor20250728Options) {
8380
const name = "str_replace_based_edit_tool";
8481
const textEditorTool = tool(
8582
options?.execute as (
@@ -89,7 +86,7 @@ export function textEditor_20250728(
8986
{
9087
name,
9188
description: "A tool for editing text files",
92-
schema: z.toJSONSchema(TextEditor20250728CommandSchema),
89+
schema: TextEditor20250728CommandSchema,
9390
}
9491
);
9592

@@ -104,5 +101,10 @@ export function textEditor_20250728(
104101
} satisfies Anthropic.Beta.Messages.BetaToolTextEditor20250728,
105102
};
106103

107-
return textEditorTool;
104+
return textEditorTool as DynamicStructuredTool<
105+
typeof TextEditor20250728CommandSchema,
106+
TextEditor20250728Command,
107+
unknown,
108+
string | Promise<string>
109+
>;
108110
}

libs/providers/langchain-openai/src/tools/applyPatch.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod/v4";
22
import { OpenAI as OpenAIClient } from "openai";
3-
import { tool } from "@langchain/core/tools";
3+
import { tool, type DynamicStructuredTool } from "@langchain/core/tools";
44

55
/**
66
* Re-export operation types from OpenAI SDK for convenience.
@@ -170,7 +170,7 @@ export function applyPatch(options: ApplyPatchOptions) {
170170
name: TOOL_NAME,
171171
description:
172172
"Apply structured diffs to create, update, or delete files in the codebase.",
173-
schema: z.toJSONSchema(ApplyPatchOperationSchema),
173+
schema: ApplyPatchOperationSchema,
174174
});
175175

176176
patchTool.extras = {
@@ -180,5 +180,10 @@ export function applyPatch(options: ApplyPatchOptions) {
180180
} satisfies ApplyPatchTool,
181181
};
182182

183-
return patchTool;
183+
return patchTool as DynamicStructuredTool<
184+
typeof ApplyPatchOperationSchema,
185+
ApplyPatchOperation,
186+
unknown,
187+
string
188+
>;
184189
}

libs/providers/langchain-openai/src/tools/codeInterpreter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { OpenAI as OpenAIClient } from "openai";
2+
import type { ServerTool } from "@langchain/core/tools";
23

34
/**
45
* Memory limit options for the Code Interpreter container.
@@ -141,9 +142,7 @@ function convertContainer(
141142
* - Files in model input are automatically uploaded to the container
142143
* - Generated files are returned as `container_file_citation` annotations
143144
*/
144-
export function codeInterpreter(
145-
options?: CodeInterpreterOptions
146-
): CodeInterpreterTool {
145+
export function codeInterpreter(options?: CodeInterpreterOptions): ServerTool {
147146
return {
148147
type: "code_interpreter",
149148
container: convertContainer(options?.container),

libs/providers/langchain-openai/src/tools/computerUse.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import { z } from "zod/v4";
23
import { OpenAI as OpenAIClient } from "openai";
34
import { tool, type DynamicStructuredTool } from "@langchain/core/tools";
@@ -155,6 +156,12 @@ export interface ComputerUseInput {
155156
action: ComputerUseAction;
156157
}
157158

159+
export type ComputerUseReturnType =
160+
| string
161+
| Promise<string>
162+
| ToolMessage<any>
163+
| Promise<ToolMessage<any>>;
164+
158165
/**
159166
* Options for the Computer Use tool.
160167
*/
@@ -186,9 +193,8 @@ export interface ComputerUseOptions {
186193
*/
187194
execute: (
188195
action: ComputerUseAction,
189-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
190196
runtime: ToolRuntime<any, any>
191-
) => string | Promise<string> | ToolMessage | Promise<ToolMessage>;
197+
) => ComputerUseReturnType;
192198
}
193199

194200
/**
@@ -381,7 +387,6 @@ export function computerUse(options: ComputerUseOptions) {
381387
typeof ComputerUseActionSchema,
382388
ComputerUseInput,
383389
unknown,
384-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
385-
ToolMessage<any>
390+
ComputerUseReturnType
386391
>;
387392
}

libs/providers/langchain-openai/src/tools/fileSearch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { OpenAI as OpenAIClient } from "openai";
2+
import type { ServerTool } from "@langchain/core/tools";
23

34
/**
45
* Comparison operators for file attribute filtering.
@@ -250,7 +251,7 @@ function convertRankingOptions(
250251
* - Use `include: ["file_search_call.results"]` in the API call to get search results
251252
* - Supported file types include PDF, DOCX, TXT, MD, and many code file formats
252253
*/
253-
export function fileSearch(options: FileSearchOptions): FileSearchTool {
254+
export function fileSearch(options: FileSearchOptions): ServerTool {
254255
return {
255256
type: "file_search",
256257
vector_store_ids: options.vectorStoreIds,

0 commit comments

Comments
 (0)