@luanpoppe/ai 1.0.1 → 1.0.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luanpoppe/ai",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [],
@@ -11,12 +11,12 @@
11
11
  "@langchain/google-genai": "^2.1.3",
12
12
  "@langchain/openai": "^1.2.0",
13
13
  "langchain": "^1.2.3",
14
- "typescript": "^5.9.3",
15
14
  "zod": "^4.2.1"
16
15
  },
17
16
  "devDependencies": {
18
17
  "@types/node": "^25.0.3",
19
- "tsx": "^4.21.0"
18
+ "tsx": "^4.21.0",
19
+ "typescript": "^5.9.3"
20
20
  },
21
21
  "scripts": {
22
22
  "build": "tsc"
package/src/index.ts CHANGED
@@ -11,13 +11,14 @@ import {
11
11
  } from "langchain";
12
12
  import { ClientTool, ServerTool } from "@langchain/core/tools";
13
13
  import { LangchainMessages } from "./langchain/messages";
14
+ import { LangchainTools } from "./langchain/tools";
14
15
 
15
16
  type LangchainConstructor = {
16
17
  googleGeminiToken?: string;
17
18
  openAIApiKey?: string;
18
19
  };
19
20
 
20
- export type CallParams = {
21
+ export type LangchainCallParams = {
21
22
  aiModel: AIModelNames;
22
23
  messages: MessageInput[];
23
24
  systemPrompt?: string;
@@ -26,23 +27,24 @@ export type CallParams = {
26
27
  tools?: (ServerTool | ClientTool)[];
27
28
  };
28
29
 
29
- export type CallReturn = Promise<{
30
+ export type LangchainCallReturn = Promise<{
30
31
  text: string;
31
32
  messages: BaseMessage[];
32
33
  }>;
33
34
 
34
- export type CallStructuredOutputParams<T extends z.ZodSchema> = CallParams & {
35
- outputSchema: T;
36
- };
35
+ export type LangchainCallStructuredOutputParams<T extends z.ZodSchema> =
36
+ LangchainCallParams & {
37
+ outputSchema: T;
38
+ };
37
39
 
38
- export type CallStructuredOutputReturn<T> = Promise<{
40
+ export type LangchainCallStructuredOutputReturn<T> = Promise<{
39
41
  response: z.infer<T>;
40
42
  }>;
41
43
 
42
44
  export class Langchain {
43
45
  constructor(private tokens: LangchainConstructor) {}
44
46
 
45
- async call(params: CallParams): CallReturn {
47
+ async call(params: LangchainCallParams): LangchainCallReturn {
46
48
  const { messages } = params;
47
49
 
48
50
  const agent = createAgent({
@@ -52,14 +54,14 @@ export class Langchain {
52
54
  const response = await agent.invoke({ messages });
53
55
 
54
56
  return {
55
- text: response.messages[0]?.text ?? "Empty response from the model",
57
+ text: response.messages.at(-1)?.text ?? "Empty response from the model",
56
58
  messages: response.messages,
57
59
  };
58
60
  }
59
61
 
60
62
  async callStructuredOutput<T extends z.ZodSchema>(
61
- params: CallStructuredOutputParams<T>
62
- ): CallStructuredOutputReturn<typeof params.outputSchema> {
63
+ params: LangchainCallStructuredOutputParams<T>
64
+ ): LangchainCallStructuredOutputReturn<typeof params.outputSchema> {
63
65
  const { outputSchema, messages } = params;
64
66
 
65
67
  const agent = createAgent({
@@ -94,7 +96,9 @@ export class Langchain {
94
96
  throw new Error("Model not supported");
95
97
  }
96
98
 
97
- private standardAgent(params: CallParams): Parameters<typeof createAgent>[0] {
99
+ private standardAgent(
100
+ params: LangchainCallParams
101
+ ): Parameters<typeof createAgent>[0] {
98
102
  const { aiModel, systemPrompt, maxRetries = 3, middleware, tools } = params;
99
103
 
100
104
  const model = this.getModel(aiModel);
@@ -122,4 +126,4 @@ export class Langchain {
122
126
  }
123
127
  }
124
128
 
125
- export { LangchainModels, LangchainMessages };
129
+ export { LangchainModels, LangchainMessages, LangchainTools };
package/tsconfig.json CHANGED
@@ -9,7 +9,7 @@
9
9
  // See also https://aka.ms/tsconfig/module
10
10
  "module": "nodenext",
11
11
  "target": "esnext",
12
- "types": ["@types/node"],
12
+ "types": ["node"],
13
13
  // For nodejs:
14
14
  // "lib": ["esnext"],
15
15
  // "types": ["node"],