actient 1.0.3 → 1.1.1

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/LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright © 2026 <copyright holders>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright © 2026 <copyright holders>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,165 +1,289 @@
1
- # Actient
2
-
3
- Connect and run your functions with your favorite AI easier.
4
-
5
- ### In this page
6
-
7
- - [Get Started](#get-started)
8
- - [How it's work](#how-its-work)
9
- - [References](#references)
10
- - [Supported SDK](#our-supported-sdk)
11
- - [AI Agent](#ai-agent)
12
- - [registerAction()](#registeraction)
13
- - [execute()](#execute)
14
- - [Best Practices](#best-practices)
15
- - [Unknown action](#unknown-action)
16
- - [Specific rules](#specific-rules)
17
- - [Typescript Support](#typescript-support)
18
-
19
- ## Get started
20
-
21
- Install package:
22
-
23
- ```bash
24
- npm install actient zod openai
25
- ```
26
-
27
- ## How it's work?
28
-
29
- ```js
30
- import { AIAgent } from "actient";
31
- import { OpenAIIntentParser } from "actient/providers/openai";
32
- import { z } from "zod";
33
-
34
- // define ai agent
35
- const agent = new AIAgent({
36
- ai: new OpenAIIntentParser({
37
- apiKey: "your_api_key",
38
- model: "ai-model",
39
- }),
40
- });
41
-
42
- // register your function as action
43
- agent.registerAction("increase_stock", {
44
- description: "Add product stock",
45
- schema: z.object({
46
- name: z.string(),
47
- amount: z.number().positive(),
48
- }),
49
- handler: async ({ name, amount }) => {
50
- // you can create simple or complex logic here
51
- return prisma.product.updateMany({
52
- where: { name: { contains: name, mode: "insensitive" } },
53
- data: { stock: { increment: amount } },
54
- });
55
- },
56
- });
57
-
58
- // it will execute action to update your product stock
59
- agent.execute("Can you add 5 units of stock to my product named monitor?");
60
- ```
61
-
62
- ## References
63
-
64
- This section documents the main function provided by `actient`, including the core agent, intent parser, and available AI providers.
65
-
66
- ### Our supported SDK:
67
-
68
- You need to install the SDK before using this library. Use the intent parser importing from `actient/providers/*` to setup your AI.
69
-
70
- | Provider | SDK | Intent Parser |
71
- | -------- | --------------- | -------------------------------------------------------------- |
72
- | Open AI | `openai` | `OpenAIIntentParser`, imported from `actient/providers/openai` |
73
- | Groq | `groq-sdk` | `GroqIntentParser`, imported from `actient/providers/groq` |
74
- | Gemini | `@google/genai` | `GeminiIntentParser`, imported from `actient/providers/gemini` |
75
-
76
- ### AI Agent
77
-
78
- You can define and select your ai agent using `AIAgent` instance.
79
-
80
- ```js
81
- const agent = new AIAgent({
82
- ai: new OpenAIIntentParser({
83
- apiKey: "your_api_key", // api key from ai provider
84
- model: "ai-model",
85
- }),
86
- });
87
- ```
88
-
89
- #### Options
90
-
91
- | Name | Desciption |
92
- | ---- | ---------------------------------------------------------------------------------------- |
93
- | ai | Define your selected ai intent parser. See our supported intent parser to get the detail |
94
-
95
- ### registerAction()
96
-
97
- Registers actions that can be executed by the agent.
98
-
99
- ```js
100
- agent.registerAction("action_identifier", {
101
- description: "Action description",
102
- rules: ["specific rule"],
103
- schema: z.object({
104
- params: z.string(),
105
- }),
106
- handler: async ({ params }) => {
107
- // you can create simple or complex logic here
108
- return `Success to execute: ${params}`;
109
- },
110
- });
111
- ```
112
-
113
- #### Options
114
-
115
- | Name | Type | Required | Desciption |
116
- | ------------ | --------------- | -------- | -------------------------------------------------------------------- |
117
- | \_identifier | string | ✅ | Unique action identifier (used by AI to recognize the functions) |
118
- | description | string | ✅ | Brief explanation of the action function (used in the system prompt) |
119
- | rules | array of string | | Specific rules for the action |
120
- | schema | ZodSchema | | Zod schema for action parameter validation |
121
- | handler | function | ✅ | Async function that will be executed by AI |
122
-
123
- ### execute()
124
-
125
- Runs agent based on user input.
126
-
127
- ```js
128
- const result = await agent.execute("User prompt");
129
- ```
130
-
131
- ## Best Practices
132
-
133
- This section outlines recommended best practices to help you build reliable, maintainable, and predictable AI-driven actions using this library.
134
-
135
- ### Unknown Action
136
-
137
- The AI ​​will only execute the appropriate action. If no appropriate action is found, it will treat it as `UNKNOWN`. You can handle this by defining a register with the identifier as `UNKNOWN`.
138
-
139
- ```js
140
- agent.registerAction("UNKNOWN", {
141
- description: "Default handler for unknown intents",
142
- rules: ["Handle unknown intents gracefully and inform the user."],
143
- schema: z.object({
144
- message: z.string(),
145
- }),
146
- handler: async ({ message }) => {
147
- return { message };
148
- },
149
- });
150
- ```
151
-
152
- ### Specific rules
153
-
154
- Add specific rules to ensure the AI ​​works properly and prevent the AI ​​from deviating from its task.
155
-
156
- ```js
157
- agent.registerAction("action", {
158
- rules: ["rule 1", "rule 2"],
159
- // ...
160
- });
161
- ```
162
-
163
- ## Typescript Support
164
-
165
- This library is completely written and maintained using typescript.
1
+ # Actient
2
+
3
+ Connect and run your functions with your favorite AI easier.
4
+
5
+ ### In this page
6
+
7
+ - [Get Started](#get-started)
8
+ - [How it's work](#how-its-work)
9
+ - [References](#references)
10
+ - [Supported SDK](#our-supported-sdk)
11
+ - [AI Agent](#ai-agent)
12
+ - [registerAction()](#registeraction)
13
+ - [execute()](#execute)
14
+ - [Sessions](#session)
15
+ - [Memory Store](#memory-store)
16
+ - [Redis](#redis-store)
17
+ - [Custom Store](#custom-store)
18
+ - [Best Practices](#best-practices)
19
+ - [Unknown action](#unknown-action)
20
+ - [Specific rules](#specific-rules)
21
+ - [Typescript Support](#typescript-support)
22
+
23
+ ## Get started
24
+
25
+ Install package:
26
+
27
+ ```bash
28
+ npm install actient zod openai
29
+ ```
30
+
31
+ ## How it's work?
32
+
33
+ ```js
34
+ import { AIAgent } from "actient";
35
+ import { OpenAIIntentParser } from "actient/providers/openai";
36
+ import { z } from "zod";
37
+
38
+ // define ai agent
39
+ const agent = new AIAgent({
40
+ ai: new OpenAIIntentParser({
41
+ apiKey: "your_api_key",
42
+ model: "ai-model",
43
+ }),
44
+ });
45
+
46
+ // register your function as action
47
+ agent.registerAction("increase_stock", {
48
+ description: "Add product stock",
49
+ schema: z.object({
50
+ name: z.string(),
51
+ amount: z.number().positive(),
52
+ }),
53
+ handler: async ({ name, amount }) => {
54
+ // you can create simple or complex logic here
55
+ return prisma.product.updateMany({
56
+ where: { name: { contains: name, mode: "insensitive" } },
57
+ data: { stock: { increment: amount } },
58
+ });
59
+ },
60
+ });
61
+
62
+ // it will execute action to update your product stock
63
+ agent.execute("Can you add 5 units of stock to my product named monitor?");
64
+ ```
65
+
66
+ ## References
67
+
68
+ This section documents the main function provided by `actient`, including the core agent, intent parser, and available AI providers.
69
+
70
+ ### Our supported SDK:
71
+
72
+ You need to install the SDK before using this library. Use the intent parser importing from `actient/providers/*` to setup your AI.
73
+
74
+ | Provider | SDK | Intent Parser |
75
+ | -------- | --------------- | -------------------------------------------------------------- |
76
+ | Open AI | `openai` | `OpenAIIntentParser`, imported from `actient/providers/openai` |
77
+ | Groq | `groq-sdk` | `GroqIntentParser`, imported from `actient/providers/groq` |
78
+ | Gemini | `@google/genai` | `GeminiIntentParser`, imported from `actient/providers/gemini` |
79
+
80
+ ### AI Agent
81
+
82
+ You can define and select your ai agent using `AIAgent` instance.
83
+
84
+ ```js
85
+ const agent = new AIAgent({
86
+ ai: new OpenAIIntentParser({
87
+ apiKey: "your_api_key", // api key from ai provider
88
+ model: "ai-model",
89
+ }),
90
+ });
91
+ ```
92
+
93
+ #### Options
94
+
95
+ | Name | Desciption |
96
+ | ---- | ---------------------------------------------------------------------------------------- |
97
+ | ai | Define your selected ai intent parser. See our supported intent parser to get the detail |
98
+
99
+ ### registerAction()
100
+
101
+ Registers actions that can be executed by the agent.
102
+
103
+ ```js
104
+ agent.registerAction("action_identifier", {
105
+ description: "Action description",
106
+ rules: ["specific rule"],
107
+ schema: z.object({
108
+ params: z.string(),
109
+ }),
110
+ handler: async ({ params }) => {
111
+ // you can create simple or complex logic here
112
+ return `Success to execute: ${params}`;
113
+ },
114
+ });
115
+ ```
116
+
117
+ #### Options
118
+
119
+ | Name | Type | Required | Desciption |
120
+ | ------------ | --------------- | -------- | -------------------------------------------------------------------- |
121
+ | \_identifier | string | ✅ | Unique action identifier (used by AI to recognize the functions) |
122
+ | description | string | ✅ | Brief explanation of the action function (used in the system prompt) |
123
+ | rules | array of string | ❌ | Specific rules for the action |
124
+ | schema | ZodSchema | ✅ | Zod schema for action parameter validation |
125
+ | handler | function | ✅ | Async function that will be executed by AI |
126
+
127
+ ### execute()
128
+
129
+ Runs agent based on user input.
130
+
131
+ ```js
132
+ const result = await agent.execute("User prompt");
133
+ ```
134
+
135
+ ## Session
136
+
137
+ You can make your AI to memorize the context of conversation to better experience.
138
+
139
+ ```js
140
+ import { MemorySessionStore } from "actient";
141
+
142
+ const agent = new AIAgent({
143
+ ai: new GeminiIntentParser(),
144
+ session: {
145
+ enabled: true, // default false
146
+ store: new MemorySessionStore(),
147
+ maxLength: 10, // length cache of messages
148
+ },
149
+ });
150
+
151
+ // Important: Session IDs are created and managed by you. You can create multiple or single sessions for each user.
152
+ const result = await agent.execute("User prompt", { sessionId: "session_id" });
153
+ ```
154
+
155
+ ### Memory Store
156
+
157
+ This is a simple way to store your conversations but it's not recomended for complex case.
158
+
159
+ ```js
160
+ import { MemorySessionStore } from "actient";
161
+
162
+ const agent = new AIAgent({
163
+ ai: new GeminiIntentParser(),
164
+ session: {
165
+ enabled: true, // default false
166
+ store: new MemorySessionStore(),
167
+ maxLength: 10, // length cache of messages
168
+ },
169
+ });
170
+ ```
171
+
172
+ ### Redis Store
173
+
174
+ This is the better way to implement session store.
175
+
176
+ ```js
177
+ import { RedisSessionStore } from "actient";
178
+
179
+ const redis = new Redis(); // from ioredis
180
+
181
+ const agent = new AIAgent({
182
+ ai: new GeminiIntentParser(),
183
+ session: {
184
+ enabled: true, // default false
185
+ store: new RedisSessionStore(redis, 3600),
186
+ maxLength: 10, // length cache of messages
187
+ },
188
+ });
189
+ ```
190
+
191
+ ### Custom Store
192
+
193
+ You can create session store by your own. You can integrate with your favorite database.
194
+
195
+ For example using `prisma`:
196
+
197
+ ```prisma
198
+ model AgentSession {
199
+ id String @id @default(cuid())
200
+ sessionId String @unique
201
+ data Json
202
+ createdAt DateTime @default(now())
203
+ updatedAt DateTime @updatedAt
204
+
205
+ @@index([sessionId])
206
+ }
207
+ ```
208
+
209
+ And your session store will look like this:
210
+
211
+ ```ts
212
+ import type { SessionStore, AgentSession } from "actient";
213
+ import { AIAgent } from "actient";
214
+ import { prisma } from "@/lib/prisma";
215
+
216
+ class MyCustomStore implements SessionStore<AgentSession> {
217
+ async get(sessionId: string) {
218
+ // get session data from postgre using prisma
219
+ const session = await prisma.agentSession.findUnique({
220
+ where: { sessionId },
221
+ });
222
+
223
+ if (!session) return null;
224
+
225
+ return session.data as AgentSession;
226
+ }
227
+
228
+ async set(sessionId: string, data: AgentSession) {
229
+ // post session data to database
230
+ await prisma.agentSession.upsert({
231
+ where: { sessionId },
232
+ update: { data },
233
+ create: { sessionId, data },
234
+ });
235
+ }
236
+
237
+ async clear(sessionId: string) {
238
+ // clear session from db
239
+ await prisma.agentSession.deleteMany({
240
+ where: { sessionId },
241
+ });
242
+ }
243
+ }
244
+
245
+ const agent = new AIAgent({
246
+ ai: new GeminiIntentParser(),
247
+ session: {
248
+ enabled: true, // default false
249
+ store: new MyCustomStore(),
250
+ maxLength: 10, // length cache of messages
251
+ },
252
+ });
253
+ ```
254
+
255
+ ## Best Practices
256
+
257
+ This section outlines recommended best practices to help you build reliable, maintainable, and predictable AI-driven actions using this library.
258
+
259
+ ### Unknown Action
260
+
261
+ The AI ​​will only execute the appropriate action. If no appropriate action is found, it will treat it as `UNKNOWN`. You can handle this by defining a register with the identifier as `UNKNOWN`.
262
+
263
+ ```js
264
+ agent.registerAction("UNKNOWN", {
265
+ description: "Default handler for unknown intents",
266
+ rules: ["Handle unknown intents gracefully and inform the user."],
267
+ schema: z.object({
268
+ message: z.string(),
269
+ }),
270
+ handler: async ({ message }) => {
271
+ return { message };
272
+ },
273
+ });
274
+ ```
275
+
276
+ ### Specific rules
277
+
278
+ Add specific rules to ensure the AI ​​works properly and prevent the AI ​​from deviating from its task.
279
+
280
+ ```js
281
+ agent.registerAction("action", {
282
+ rules: ["rule 1", "rule 2"],
283
+ // ...
284
+ });
285
+ ```
286
+
287
+ ## Typescript Support
288
+
289
+ This library is completely written and maintained using typescript.
@@ -1,3 +1,5 @@
1
+ import { createRequire } from 'module';
2
+
1
3
  // src/utils/prompt.ts
2
4
  var generateSystemPrompt = (actions) => {
3
5
  return `
@@ -37,36 +39,21 @@ If no action matches, return:
37
39
  }
38
40
  `.trim();
39
41
  };
40
-
41
- // src/utils/loader.ts
42
- async function loadGemini() {
43
- try {
44
- return await import('@google/genai');
45
- } catch {
46
- throw new Error(
47
- "Gemini support requires `@google/genai`. Install it with:\nnpm install @google/genai"
48
- );
49
- }
50
- }
51
- async function loadOpenAI() {
52
- try {
53
- return await import('openai');
54
- } catch {
55
- throw new Error(
56
- "OpenAI support requires `openai`. Install it with:\nnpm install openai"
57
- );
58
- }
59
- }
60
- async function loadGroq() {
42
+ var require2 = createRequire(import.meta.url);
43
+ function loadPackage(packageName) {
61
44
  try {
62
- return await import('groq-sdk');
63
- } catch {
64
- throw new Error(
65
- "Groq support requires `groq-sdk`. Install it with:\nnpm install groq-sdk"
66
- );
45
+ return require2(packageName);
46
+ } catch (err) {
47
+ if (err?.code === "MODULE_NOT_FOUND") {
48
+ throw new Error(
49
+ `This feature requires "${packageName}". Install it with:
50
+ npm install ${packageName}`
51
+ );
52
+ }
53
+ throw err;
67
54
  }
68
55
  }
69
56
 
70
- export { generateSystemPrompt, loadGemini, loadGroq, loadOpenAI };
71
- //# sourceMappingURL=chunk-UNGR3PLJ.js.map
72
- //# sourceMappingURL=chunk-UNGR3PLJ.js.map
57
+ export { generateSystemPrompt, loadPackage };
58
+ //# sourceMappingURL=chunk-RECTO6FA.js.map
59
+ //# sourceMappingURL=chunk-RECTO6FA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/prompt.ts","../src/utils/loader.ts"],"names":["require"],"mappings":";;;AAEO,IAAM,oBAAA,GAAuB,CAAC,OAAA,KAAuC;AAC1E,EAAA,OAAO;AAAA;;AAAA;;AAAA;AAAA,EAMP,OAAA,CACC,GAAA;AAAA,IACC,CAAC,CAAA,KAAM,CAAA,EAAA,EAAK,EAAE,IAAI,CAAA,EAAA,EAAK,EAAE,WAAW;AAAA;AAAA,EAEtC,OAAO,OAAA,CAAQ,CAAA,CAAE,UAAU,CAAA,CAC1B,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,IAAI,CAAA,KAAM,CAAA,MAAA,EAAS,GAAG,CAAA,EAAA,EAAK,IAAI,EAAE,CAAA,CAC5C,IAAA,CAAK,IAAI,CAAC;AAAA,kBAAA,EAET,CAAA,CAAE,KAAA,EAAO,MAAA,GAAS,CAAA,CAAE,MAAM,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,MAAA,EAAS,CAAC,CAAA,CAAE,CAAA,CAAE,IAAA,CAAK,IAAI,IAAI,YAClE;AAAA,EAAA;AAAA,GAEA,CACC,IAAA,CAAK,IAAI,CAAC;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAuBX,IAAA,EAAK;AACP;AC5CA,IAAMA,QAAAA,GAAU,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAEtC,SAAS,YAAe,WAAA,EAAwB;AACrD,EAAA,IAAI;AACF,IAAA,OAAOA,SAAQ,WAAW,CAAA;AAAA,EAC5B,SAAS,GAAA,EAAU;AACjB,IAAA,IAAI,GAAA,EAAK,SAAS,kBAAA,EAAoB;AACpC,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,0BAA0B,WAAW,CAAA;AAAA,YAAA,EACpB,WAAW,CAAA;AAAA,OAC9B;AAAA,IACF;AACA,IAAA,MAAM,GAAA;AAAA,EACR;AACF","file":"chunk-RECTO6FA.js","sourcesContent":["import type { AvailableAction } from \"../intent/intent-parser\";\n\nexport const generateSystemPrompt = (actions: AvailableAction[]): string => {\n return `\nYou are an intent parser.\n\nYour task is to translate user input into a structured JSON intent.\n\nAvailable actions:\n${actions\n .map(\n (a) => `- ${a.name}: ${a.description}\n Parameters:\n${Object.entries(a.parameters)\n .map(([key, type]) => ` - ${key}: ${type}`)\n .join(\"\\n\")}\n Specific rules: ${\n a.rules?.length ? a.rules.map((r) => ` - ${r}`).join(\"\\n\") : \" - None\"\n }\n `,\n )\n .join(\"\\n\")}\n\n \nRules:\n- Respond ONLY with valid JSON\n- Do NOT include markdown\n- Do NOT explain anything\n- Do NOT invent actions\n- Only use actions listed above\n- Parameter names MUST exactly match the schema\n- Do NOT rename parameters\n- Do NOT invent parameters\n- JSON format:\n{\n \"action\": \"action_name\",\n \"params\": { ... }\n}\n\nIf no action matches, return:\n{\n \"action\": \"UNKNOWN\",\n \"params\": {}\n}\n`.trim();\n};\n\nexport const generatePlanPrompt = (actions: AvailableAction[]): string => {\n return `\n You are an execution planner.\n\nYour task is to convert user request into ordered execution steps.\n\nAvailable actions:\n${actions\n .map(\n (a) => `- ${a.name}: ${a.description}\n Parameters:\n${Object.entries(a.parameters)\n .map(([key, type]) => ` - ${key}: ${type}`)\n .join(\"\\n\")}\n Specific rules: ${\n a.rules?.length ? a.rules.map((r) => ` - ${r}`).join(\"\\n\") : \" - None\"\n }\n `,\n )\n .join(\"\\n\")}\n\nRules:\n- Return ONLY valid JSON\n- Do NOT explain anything\n- Do NOT include markdown\n- Do NOT invent actions\n- Only use listed actions\n- Steps must be ordered logically\n- If a step depends on previous result, use \"$stepId.property\"\n- Only reference step IDs defined earlier\n- Do NOT assume hidden context\n\nFormat:\n{\n \"steps\": [\n {\n \"id\": \"optional_string\",\n \"action\": \"action_name\",\n \"params\": {}\n }\n ]\n}\n `;\n};\n","import { createRequire } from \"module\";\nconst require = createRequire(import.meta.url);\n\nexport function loadPackage<T>(packageName: string): T {\n try {\n return require(packageName);\n } catch (err: any) {\n if (err?.code === \"MODULE_NOT_FOUND\") {\n throw new Error(\n `This feature requires \"${packageName}\". Install it with:\\n` +\n `npm install ${packageName}`,\n );\n }\n throw err;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,23 @@
1
- import { I as Intent, a as IntentParser } from './intent-parser-tPkUA2YT.js';
1
+ import { I as IntentParser, S as SessionStore, A as AgentSession, a as Intent } from './intent-parser-guF1BU1U.js';
2
+ export { b as AIMessage } from './intent-parser-guF1BU1U.js';
2
3
  import { ZodSchema } from 'zod';
3
4
 
4
5
  interface AIProvider {
5
6
  parseIntent(prompt: string, availableActions: any[]): Promise<Intent>;
6
7
  }
8
+ type Session = {
9
+ enabled: Boolean;
10
+ store?: SessionStore<AgentSession>;
11
+ maxLength?: number;
12
+ };
7
13
  declare class AIAgent {
8
14
  private registry;
9
15
  private intentParser;
16
+ private session;
17
+ private sessionStore;
10
18
  constructor(options: {
11
19
  ai: IntentParser;
20
+ session: Session;
12
21
  });
13
22
  registerAction<TParams, TResult>(name: string, config: {
14
23
  description: string;
@@ -16,7 +25,25 @@ declare class AIAgent {
16
25
  schema: ZodSchema<TParams>;
17
26
  handler: (params: TParams) => Promise<TResult>;
18
27
  }): void;
19
- execute(prompt: string): Promise<any>;
28
+ execute(prompt: string, options?: {
29
+ sessionId?: string;
30
+ }): Promise<any>;
20
31
  }
21
32
 
22
- export { AIAgent, type AIProvider };
33
+ declare class MemorySessionStore implements SessionStore<AgentSession> {
34
+ private store;
35
+ get(sessionId: string): Promise<AgentSession | null>;
36
+ set(sessionId: string, data: AgentSession): Promise<void>;
37
+ clear(sessionId: string): Promise<void>;
38
+ }
39
+
40
+ declare class RedisSessionStore implements SessionStore<AgentSession> {
41
+ private client;
42
+ private ttl?;
43
+ constructor(client: any, ttl?: number | undefined);
44
+ get(sessionId: string): Promise<AgentSession | null>;
45
+ set(sessionId: string, data: AgentSession): Promise<void>;
46
+ clear(sessionId: string): Promise<void>;
47
+ }
48
+
49
+ export { AIAgent, type AIProvider, AgentSession, MemorySessionStore, RedisSessionStore, SessionStore };
package/dist/index.js CHANGED
@@ -57,16 +57,32 @@ var ActionRegistry = class {
57
57
  var AIAgent = class {
58
58
  registry;
59
59
  intentParser;
60
+ session;
61
+ sessionStore = null;
60
62
  constructor(options) {
61
63
  this.registry = new ActionRegistry();
62
64
  this.intentParser = options.ai;
65
+ this.session = options.session;
66
+ if (this.session.enabled) {
67
+ if (!this.session.store) {
68
+ throw new Error(
69
+ "Session store must be provided when session is enabled"
70
+ );
71
+ }
72
+ this.sessionStore = this.session.store;
73
+ }
63
74
  }
64
75
  registerAction(name, config) {
65
76
  this.registry.register(name, config);
66
77
  }
67
- async execute(prompt) {
78
+ async execute(prompt, options) {
68
79
  const availableActions = this.registry.list();
69
- const intent = await this.intentParser.parse(prompt, availableActions);
80
+ if (!this.sessionStore) throw new Error("Session is not defined");
81
+ const intent = await this.intentParser.parse(prompt, availableActions, {
82
+ sessionId: options?.sessionId || "",
83
+ sessionStore: this.sessionStore,
84
+ maxLength: this.session?.maxLength || 0
85
+ });
70
86
  if (!intent?.action) {
71
87
  throw new Error("Invalid intent: missing action");
72
88
  }
@@ -81,6 +97,43 @@ var AIAgent = class {
81
97
  }
82
98
  };
83
99
 
84
- export { AIAgent };
100
+ // src/sessions/memory.ts
101
+ var MemorySessionStore = class {
102
+ store = /* @__PURE__ */ new Map();
103
+ async get(sessionId) {
104
+ return this.store.get(sessionId) ?? null;
105
+ }
106
+ async set(sessionId, data) {
107
+ this.store.set(sessionId, data);
108
+ }
109
+ async clear(sessionId) {
110
+ this.store.delete(sessionId);
111
+ }
112
+ };
113
+
114
+ // src/sessions/redis.ts
115
+ var RedisSessionStore = class {
116
+ constructor(client, ttl) {
117
+ this.client = client;
118
+ this.ttl = ttl;
119
+ }
120
+ async get(sessionId) {
121
+ const data = await this.client.get(sessionId);
122
+ return data ? JSON.parse(data) : null;
123
+ }
124
+ async set(sessionId, data) {
125
+ const value = JSON.stringify(data);
126
+ if (this.ttl) {
127
+ await this.client.set(sessionId, value, "EX", this.ttl);
128
+ } else {
129
+ await this.client.set(sessionId, value);
130
+ }
131
+ }
132
+ async clear(sessionId) {
133
+ await this.client.del(sessionId);
134
+ }
135
+ };
136
+
137
+ export { AIAgent, MemorySessionStore, RedisSessionStore };
85
138
  //# sourceMappingURL=index.js.map
86
139
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/registry/action-registry.ts","../src/agent.ts"],"names":[],"mappings":";;;AAcO,IAAM,iBAAN,MAAqB;AAAA,EAClB,OAAA,uBAAc,GAAA,EAA8B;AAAA,EAEpD,QAAA,CACE,MACA,MAAA,EACA;AACA,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA,EAAG;AAC1B,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,QAAA,EAAW,IAAI,CAAA,oBAAA,CAAsB,CAAA;AAAA,IACvD;AAEA,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,IAAA,EAAM,MAAM,CAAA;AAAA,EAC/B;AAAA,EAEA,IAAI,IAAA,EAAgC;AAClC,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA;AAEpC,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,QAAA,EAAW,IAAI,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACtD;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAEA,IAAA,GAKG;AACD,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,OAAA,EAAS,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,IAAA,EAAM,MAAM,CAAA,MAAO;AAAA,MACjE,IAAA;AAAA,MACA,KAAA,EAAO,MAAA,CAAO,KAAA,IAAS,EAAC;AAAA,MACxB,aAAa,MAAA,CAAO,WAAA;AAAA,MACpB,UAAA,EAAY,IAAA,CAAK,iBAAA,CAAkB,MAAA,CAAO,MAAM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AA;;;AC5EO,IAAM,UAAN,MAAc;AAAA,EACX,QAAA;AAAA,EACA,YAAA;AAAA,EAER,YAAY,OAAA,EAA+B;AACzC,IAAA,IAAA,CAAK,QAAA,GAAW,IAAI,cAAA,EAAe;AACnC,IAAA,IAAA,CAAK,eAAe,OAAA,CAAQ,EAAA;AAAA,EAC9B;AAAA,EAEA,cAAA,CACE,MACA,MAAA,EAMA;AACA,IAAA,IAAA,CAAK,QAAA,CAAS,QAAA,CAAS,IAAA,EAAM,MAAM,CAAA;AAAA,EACrC;AAAA,EAEA,MAAM,QAAQ,MAAA,EAA8B;AAC1C,IAAA,MAAM,gBAAA,GAAmB,IAAA,CAAK,QAAA,CAAS,IAAA,EAAK;AAC5C,IAAA,MAAM,SAAS,MAAM,IAAA,CAAK,YAAA,CAAa,KAAA,CAAM,QAAQ,gBAAgB,CAAA;AAErE,IAAA,IAAI,CAAC,QAAQ,MAAA,EAAQ;AACnB,MAAA,MAAM,IAAI,MAAM,gCAAgC,CAAA;AAAA,IAClD;AAEA,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAAO,MAAM,CAAA;AAE9C,IAAA,IAAI,MAAA,CAAO,MAAA,KAAW,SAAA,IAAa,CAAC,MAAA,EAAQ;AAC1C,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAEA,IAAA,MAAM,eAAA,GAAkB,MAAA,CAAO,MAAA,CAAO,KAAA,CAAM,OAAO,MAAM,CAAA;AACzD,IAAA,OAAO,MAAA,CAAO,QAAQ,eAAe,CAAA;AAAA,EACvC;AACF","file":"index.js","sourcesContent":["import type { ZodSchema } from \"zod\";\r\nimport { z } from \"zod\";\r\n\r\nexport type ActionHandler<TParams = any, TResult = any> = (\r\n params: TParams\r\n) => Promise<TResult>;\r\n\r\nexport interface ActionDefinition<TParams = any, TResult = any> {\r\n description: string;\r\n rules?: string[];\r\n schema: ZodSchema<TParams>;\r\n handler: ActionHandler<TParams, TResult>;\r\n}\r\n\r\nexport class ActionRegistry {\r\n private actions = new Map<string, ActionDefinition>();\r\n\r\n register<TParams, TResult>(\r\n name: string,\r\n action: ActionDefinition<TParams, TResult>\r\n ) {\r\n if (this.actions.has(name)) {\r\n throw new Error(`Action \"${name}\" already registered`);\r\n }\r\n\r\n this.actions.set(name, action);\r\n }\r\n\r\n get(name: string): ActionDefinition {\r\n const action = this.actions.get(name);\r\n\r\n if (!action) {\r\n throw new Error(`Action \"${name}\" is not registered`);\r\n }\r\n\r\n return action;\r\n }\r\n\r\n list(): Array<{\r\n name: string;\r\n rules: string[];\r\n description: string;\r\n parameters: Record<string, string>;\r\n }> {\r\n return Array.from(this.actions.entries()).map(([name, action]) => ({\r\n name,\r\n rules: action.rules || [],\r\n description: action.description,\r\n parameters: this.zodToSimpleSchema(action.schema),\r\n }));\r\n }\r\n\r\n has(name: string): boolean {\r\n return this.actions.has(name);\r\n }\r\n\r\n private zodToSimpleSchema(schema: ZodSchema<any>) {\r\n if (!(schema instanceof z.ZodObject)) {\r\n return {};\r\n }\r\n\r\n const shape = schema.shape;\r\n const result: Record<string, string> = {};\r\n\r\n for (const key in shape) {\r\n const field = shape[key];\r\n\r\n result[key] = this.mapZodType(field);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n private mapZodType(field: any): string {\r\n // unwrap optional / nullable\r\n if (field instanceof z.ZodOptional || field instanceof z.ZodNullable) {\r\n return this.mapZodType(field.unwrap());\r\n }\r\n\r\n if (field instanceof z.ZodString) return \"string\";\r\n if (field instanceof z.ZodNumber) return \"number\";\r\n if (field instanceof z.ZodBoolean) return \"boolean\";\r\n if (field instanceof z.ZodArray) return \"array\";\r\n if (field instanceof z.ZodEnum) return \"enum\";\r\n if (field instanceof z.ZodObject) return \"object\";\r\n\r\n return \"unknown\";\r\n }\r\n}\r\n","import {\r\n ActionRegistry,\r\n // ActionDefinition,\r\n} from \"./registry/action-registry\";\r\nimport type { IntentParser } from \"./intent/intent-parser\";\r\nimport type { ZodSchema } from \"zod\";\r\nimport type { Intent } from \"./types/intent\";\r\n\r\nexport interface AIProvider {\r\n parseIntent(prompt: string, availableActions: any[]): Promise<Intent>;\r\n}\r\n\r\nexport class AIAgent {\r\n private registry: ActionRegistry;\r\n private intentParser: IntentParser;\r\n\r\n constructor(options: { ai: IntentParser }) {\r\n this.registry = new ActionRegistry();\r\n this.intentParser = options.ai;\r\n }\r\n\r\n registerAction<TParams, TResult>(\r\n name: string,\r\n config: {\r\n description: string;\r\n rules?: string[];\r\n schema: ZodSchema<TParams>;\r\n handler: (params: TParams) => Promise<TResult>;\r\n }\r\n ) {\r\n this.registry.register(name, config);\r\n }\r\n\r\n async execute(prompt: string): Promise<any> {\r\n const availableActions = this.registry.list();\r\n const intent = await this.intentParser.parse(prompt, availableActions);\r\n\r\n if (!intent?.action) {\r\n throw new Error(\"Invalid intent: missing action\");\r\n }\r\n\r\n const action = this.registry.get(intent.action);\r\n\r\n if (intent.action === \"UNKNOWN\" && !action) {\r\n throw new Error(\r\n \"Unable to determine user intent, please define a default action.\"\r\n );\r\n }\r\n\r\n const validatedParams = action.schema.parse(intent.params);\r\n return action.handler(validatedParams);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../src/registry/action-registry.ts","../src/agent.ts","../src/sessions/memory.ts","../src/sessions/redis.ts"],"names":[],"mappings":";;;AAcO,IAAM,iBAAN,MAAqB;AAAA,EAClB,OAAA,uBAAc,GAAA,EAA8B;AAAA,EAEpD,QAAA,CACE,MACA,MAAA,EACA;AACA,IAAA,IAAI,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA,EAAG;AAC1B,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,QAAA,EAAW,IAAI,CAAA,oBAAA,CAAsB,CAAA;AAAA,IACvD;AAEA,IAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,IAAA,EAAM,MAAM,CAAA;AAAA,EAC/B;AAAA,EAEA,IAAI,IAAA,EAAgC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,IAAA,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,SAAA,EAAW,IAAI,CAAA;AAAA,EAChC;AAAA,EAEA,MAAM,MAAM,SAAA,EAAkC;AAC5C,IAAA,IAAA,CAAK,KAAA,CAAM,OAAO,SAAS,CAAA;AAAA,EAC7B;AACF;;;ACdO,IAAM,oBAAN,MAA8D;AAAA,EACnE,WAAA,CACU,QACA,GAAA,EACR;AAFQ,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EACP;AAAA,EAEH,MAAM,IAAI,SAAA,EAAiD;AACzD,IAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,MAAA,CAAO,IAAI,SAAS,CAAA;AAC5C,IAAA,OAAO,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA,GAAI,IAAA;AAAA,EACnC;AAAA,EAEA,MAAM,GAAA,CAAI,SAAA,EAAmB,IAAA,EAAmC;AAC9D,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA;AAEjC,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,KAAK,MAAA,CAAO,GAAA,CAAI,WAAW,KAAA,EAAO,IAAA,EAAM,KAAK,GAAG,CAAA;AAAA,IACxD,CAAA,MAAO;AACL,MAAA,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,SAAA,EAAW,KAAK,CAAA;AAAA,IACxC;AAAA,EACF;AAAA,EAEA,MAAM,MAAM,SAAA,EAAkC;AAC5C,IAAA,MAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,SAAS,CAAA;AAAA,EACjC;AACF","file":"index.js","sourcesContent":["import type { ZodSchema } from \"zod\";\nimport { z } from \"zod\";\n\nexport type ActionHandler<TParams = any, TResult = any> = (\n params: TParams,\n) => Promise<TResult>;\n\nexport interface ActionDefinition<TParams = any, TResult = any> {\n description: string;\n rules?: string[];\n schema: ZodSchema<TParams>;\n handler: ActionHandler<TParams, TResult>;\n}\n\nexport class ActionRegistry {\n private actions = new Map<string, ActionDefinition>();\n\n register<TParams, TResult>(\n name: string,\n action: ActionDefinition<TParams, TResult>,\n ) {\n if (this.actions.has(name)) {\n throw new Error(`Action \"${name}\" already registered`);\n }\n\n this.actions.set(name, action);\n }\n\n get(name: string): ActionDefinition {\n const action = this.actions.get(name);\n\n if (!action) {\n throw new Error(`Action \"${name}\" is not registered`);\n }\n\n return action;\n }\n\n list(): Array<{\n name: string;\n rules: string[];\n description: string;\n parameters: Record<string, string>;\n }> {\n return Array.from(this.actions.entries()).map(([name, action]) => ({\n name,\n rules: action.rules || [],\n description: action.description,\n parameters: this.zodToSimpleSchema(action.schema),\n }));\n }\n\n has(name: string): boolean {\n return this.actions.has(name);\n }\n\n private zodToSimpleSchema(schema: ZodSchema<any>) {\n if (!(schema instanceof z.ZodObject)) {\n return {};\n }\n\n const shape = schema.shape;\n const result: Record<string, string> = {};\n\n for (const key in shape) {\n const field = shape[key];\n\n result[key] = this.mapZodType(field);\n }\n\n return result;\n }\n\n private mapZodType(field: any): string {\n // unwrap optional / nullable\n if (field instanceof z.ZodOptional || field instanceof z.ZodNullable) {\n return this.mapZodType(field.unwrap());\n }\n\n if (field instanceof z.ZodString) return \"string\";\n if (field instanceof z.ZodNumber) return \"number\";\n if (field instanceof z.ZodBoolean) return \"boolean\";\n if (field instanceof z.ZodArray) return \"array\";\n if (field instanceof z.ZodEnum) return \"enum\";\n if (field instanceof z.ZodObject) return \"object\";\n\n return \"unknown\";\n }\n}\n","import { ActionRegistry } from \"./registry/action-registry\";\nimport type { IntentParser } from \"./intent/intent-parser\";\nimport type { ZodSchema } from \"zod\";\nimport type { Intent } from \"./types/intent\";\nimport type { AgentSession, SessionStore } from \"./types/session\";\n\nexport interface AIProvider {\n parseIntent(prompt: string, availableActions: any[]): Promise<Intent>;\n}\n\ntype Session = {\n enabled: Boolean;\n store?: SessionStore<AgentSession>;\n maxLength?: number;\n};\n\nexport class AIAgent {\n private registry: ActionRegistry;\n private intentParser: IntentParser;\n private session: Session;\n private sessionStore: SessionStore<AgentSession> | null = null;\n\n constructor(options: { ai: IntentParser; session: Session }) {\n this.registry = new ActionRegistry();\n this.intentParser = options.ai;\n this.session = options.session;\n\n if (this.session.enabled) {\n if (!this.session.store) {\n throw new Error(\n \"Session store must be provided when session is enabled\",\n );\n }\n\n this.sessionStore = this.session.store;\n }\n }\n\n registerAction<TParams, TResult>(\n name: string,\n config: {\n description: string;\n rules?: string[];\n schema: ZodSchema<TParams>;\n handler: (params: TParams) => Promise<TResult>;\n },\n ) {\n this.registry.register(name, config);\n }\n\n async execute(\n prompt: string,\n options?: {\n sessionId?: string;\n },\n ): Promise<any> {\n const availableActions = this.registry.list();\n if (!this.sessionStore) throw new Error(\"Session is not defined\");\n\n const intent = await this.intentParser.parse(prompt, availableActions, {\n sessionId: options?.sessionId || \"\",\n sessionStore: this.sessionStore,\n maxLength: this.session?.maxLength || 0,\n });\n\n if (!intent?.action) {\n throw new Error(\"Invalid intent: missing action\");\n }\n\n const action = this.registry.get(intent.action);\n\n if (intent.action === \"UNKNOWN\" && !action) {\n throw new Error(\n \"Unable to determine user intent, please define a default action.\",\n );\n }\n\n const validatedParams = action.schema.parse(intent.params);\n return action.handler(validatedParams);\n }\n}\n","import type { SessionStore, AgentSession } from \"../types/session\";\n\nexport class MemorySessionStore implements SessionStore<AgentSession> {\n private store = new Map<string, AgentSession>();\n\n async get(sessionId: string): Promise<AgentSession | null> {\n return this.store.get(sessionId) ?? null;\n }\n\n async set(sessionId: string, data: AgentSession): Promise<void> {\n this.store.set(sessionId, data);\n }\n\n async clear(sessionId: string): Promise<void> {\n this.store.delete(sessionId);\n }\n}\n","import type { SessionStore, AgentSession } from \"../types/session\";\n\nexport class RedisSessionStore implements SessionStore<AgentSession> {\n constructor(\n private client: any,\n private ttl?: number, // optional TTL\n ) {}\n\n async get(sessionId: string): Promise<AgentSession | null> {\n const data = await this.client.get(sessionId);\n return data ? JSON.parse(data) : null;\n }\n\n async set(sessionId: string, data: AgentSession): Promise<void> {\n const value = JSON.stringify(data);\n\n if (this.ttl) {\n await this.client.set(sessionId, value, \"EX\", this.ttl);\n } else {\n await this.client.set(sessionId, value);\n }\n }\n\n async clear(sessionId: string): Promise<void> {\n await this.client.del(sessionId);\n }\n}\n"]}
@@ -0,0 +1,34 @@
1
+ interface Intent {
2
+ action: string;
3
+ params: Record<string, any>;
4
+ }
5
+
6
+ type AIMessage = {
7
+ role: "user" | "assistant" | "system";
8
+ content: string;
9
+ };
10
+ type AgentSession = {
11
+ messages: AIMessage[];
12
+ state?: Record<string, any>;
13
+ };
14
+ interface SessionStore<T = unknown> {
15
+ get(sessionId: string): Promise<T | null>;
16
+ set(sessionId: string, data: T): Promise<void>;
17
+ clear(sessionId: string): Promise<void>;
18
+ }
19
+
20
+ interface AvailableAction {
21
+ name: string;
22
+ rules?: string[];
23
+ description: string;
24
+ parameters: Record<string, string>;
25
+ }
26
+ interface IntentParser {
27
+ parse(prompt: string, actions: AvailableAction[], options?: {
28
+ sessionId: string;
29
+ sessionStore: SessionStore<AgentSession>;
30
+ maxLength?: number;
31
+ }): Promise<Intent>;
32
+ }
33
+
34
+ export type { AgentSession as A, IntentParser as I, SessionStore as S, Intent as a, AIMessage as b, AvailableAction as c };
@@ -1,4 +1,4 @@
1
- import { a as IntentParser, A as AvailableAction, I as Intent } from '../intent-parser-tPkUA2YT.js';
1
+ import { I as IntentParser, c as AvailableAction, S as SessionStore, A as AgentSession, a as Intent } from '../intent-parser-guF1BU1U.js';
2
2
 
3
3
  declare class GeminiIntentParser implements IntentParser {
4
4
  private client?;
@@ -9,7 +9,11 @@ declare class GeminiIntentParser implements IntentParser {
9
9
  model?: string;
10
10
  });
11
11
  private getClient;
12
- parse(prompt: string, actions: AvailableAction[]): Promise<Intent>;
12
+ parse(prompt: string | string[], actions: AvailableAction[], options?: {
13
+ sessionId: string;
14
+ sessionStore: SessionStore<AgentSession>;
15
+ maxLength?: number;
16
+ }): Promise<Intent>;
13
17
  private safeParseJSON;
14
18
  }
15
19
 
@@ -1,10 +1,34 @@
1
- import { loadGemini, generateSystemPrompt } from '../chunk-UNGR3PLJ.js';
1
+ import { loadPackage, generateSystemPrompt } from '../chunk-RECTO6FA.js';
2
+
3
+ // src/utils/content-formatter.ts
4
+ function formatContents(messages, model) {
5
+ switch (model) {
6
+ case "gemini":
7
+ return messages.map((msg) => ({
8
+ role: msg.role === "assistant" ? "model" : msg.role,
9
+ parts: [{ text: msg.content }]
10
+ }));
11
+ case "openai":
12
+ return messages.map((msg) => ({
13
+ role: msg.role,
14
+ content: msg.content
15
+ }));
16
+ case "groq":
17
+ return messages.map((msg) => ({
18
+ role: msg.role,
19
+ content: msg.content
20
+ }));
21
+ default:
22
+ return [];
23
+ }
24
+ }
2
25
 
3
26
  // src/providers/gemini.ts
4
27
  var GeminiIntentParser = class {
5
28
  client;
6
29
  apiKey;
7
30
  model;
31
+ // private readonly opts: GeminiModule.GoogleGenAIOptions | undefined;
8
32
  constructor(options) {
9
33
  this.apiKey = options.apiKey;
10
34
  this.model = options.model ?? "gemini-2.5-flash";
@@ -12,27 +36,55 @@ var GeminiIntentParser = class {
12
36
  // lazy loader
13
37
  async getClient() {
14
38
  if (this.client) return this.client;
15
- const { GoogleGenAI } = await loadGemini();
39
+ const { GoogleGenAI } = loadPackage("@google/genai");
16
40
  this.client = new GoogleGenAI({ apiKey: this.apiKey });
17
41
  return this.client;
18
42
  }
19
- async parse(prompt, actions) {
43
+ async parse(prompt, actions, options) {
20
44
  const client = await this.getClient();
21
45
  const systemPrompt = generateSystemPrompt(actions);
46
+ let history = [];
47
+ if (options?.sessionId && options.sessionStore) {
48
+ const session = await options.sessionStore.get(options.sessionId);
49
+ if (session) history = session.messages;
50
+ }
51
+ const newMessage = {
52
+ role: "user",
53
+ content: Array.isArray(prompt) ? prompt.join("\n") : prompt
54
+ };
55
+ const messages = [
56
+ { role: "system", content: systemPrompt },
57
+ ...history,
58
+ newMessage
59
+ ];
60
+ const contents = formatContents(messages, "gemini");
22
61
  const result = await client.models.generateContent({
23
62
  model: this.model,
24
- contents: [
25
- {
26
- role: "user",
27
- parts: [{ text: systemPrompt + "\n\nUser input:\n" + prompt }]
28
- }
29
- ]
63
+ contents
30
64
  });
31
- const content = result.text;
32
- if (!content) {
65
+ const responseText = result.text;
66
+ if (!responseText) {
33
67
  throw new Error("Gemini returned empty response");
34
68
  }
35
- return this.safeParseJSON(content);
69
+ if (options?.sessionId && options.sessionStore) {
70
+ let session = await options.sessionStore.get(options.sessionId) ?? {
71
+ messages: [],
72
+ state: {}
73
+ };
74
+ session.messages.push(newMessage);
75
+ session.messages.push({
76
+ role: "assistant",
77
+ content: responseText
78
+ });
79
+ if (options.maxLength && options.maxLength > 0) {
80
+ session = {
81
+ ...session,
82
+ messages: session.messages.slice(-options.maxLength)
83
+ };
84
+ }
85
+ await options.sessionStore.set(options.sessionId, session);
86
+ }
87
+ return this.safeParseJSON(responseText);
36
88
  }
37
89
  // json guard
38
90
  safeParseJSON(text) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/providers/gemini.ts"],"names":[],"mappings":";;;AAMO,IAAM,qBAAN,MAAiD;AAAA,EAC9C,MAAA;AAAA,EACS,MAAA;AAAA,EACA,KAAA;AAAA,EAEjB,YAAY,OAAA,EAA6C;AACvD,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,KAAA,GAAQ,QAAQ,KAAA,IAAS,kBAAA;AAAA,EAChC;AAAA;AAAA,EAGA,MAAc,SAAA,GAAkC;AAC9C,IAAA,IAAI,IAAA,CAAK,MAAA,EAAQ,OAAO,IAAA,CAAK,MAAA;AAE7B,IAAA,MAAM,EAAE,WAAA,EAAY,GAAI,MAAM,UAAA,EAAW;AACzC,IAAA,IAAA,CAAK,SAAS,IAAI,WAAA,CAAY,EAAE,MAAA,EAAQ,IAAA,CAAK,QAAQ,CAAA;AAErD,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EAEA,MAAM,KAAA,CAAM,MAAA,EAAgB,OAAA,EAA6C;AACvE,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,SAAA,EAAU;AACpC,IAAA,MAAM,YAAA,GAAe,qBAAqB,OAAO,CAAA;AAEjD,IAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,MAAA,CAAO,eAAA,CAAgB;AAAA,MACjD,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,QAAA,EAAU;AAAA,QACR;AAAA,UACE,IAAA,EAAM,MAAA;AAAA,UACN,OAAO,CAAC,EAAE,MAAM,YAAA,GAAe,mBAAA,GAAsB,QAAQ;AAAA;AAC/D;AACF,KACD,CAAA;AAED,IAAA,MAAM,UAAU,MAAA,CAAO,IAAA;AAEvB,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,MAAM,gCAAgC,CAAA;AAAA,IAClD;AAEA,IAAA,OAAO,IAAA,CAAK,cAAc,OAAO,CAAA;AAAA,EACnC;AAAA;AAAA,EAGQ,cAAc,IAAA,EAAsB;AAC1C,IAAA,IAAI;AACF,MAAA,MAAM,OAAA,GAAU,IAAA,CACb,OAAA,CAAQ,UAAA,EAAY,EAAE,EACtB,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA,CAClB,IAAA,EAAK;AAER,MAAA,OAAO,IAAA,CAAK,MAAM,OAAO,CAAA;AAAA,IAC3B,CAAA,CAAA,MAAQ;AACN,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA;AAAA,EAAqC,IAAI,CAAA,CAAE,CAAA;AAAA,IAC7D;AAAA,EACF;AACF","file":"gemini.js","sourcesContent":["import type { Intent } from \"../types/intent\";\r\nimport type { AvailableAction, IntentParser } from \"../intent/intent-parser\";\r\nimport { generateSystemPrompt } from \"../utils/prompt\";\r\nimport { loadGemini } from \"../utils/loader\";\r\nimport type { GoogleGenAI } from \"@google/genai\"; // just for type import\r\n\r\nexport class GeminiIntentParser implements IntentParser {\r\n private client?: GoogleGenAI;\r\n private readonly apiKey: string;\r\n private readonly model: string;\r\n\r\n constructor(options: { apiKey: string; model?: string }) {\r\n this.apiKey = options.apiKey;\r\n this.model = options.model ?? \"gemini-2.5-flash\";\r\n }\r\n\r\n // lazy loader\r\n private async getClient(): Promise<GoogleGenAI> {\r\n if (this.client) return this.client;\r\n\r\n const { GoogleGenAI } = await loadGemini();\r\n this.client = new GoogleGenAI({ apiKey: this.apiKey });\r\n\r\n return this.client;\r\n }\r\n\r\n async parse(prompt: string, actions: AvailableAction[]): Promise<Intent> {\r\n const client = await this.getClient();\r\n const systemPrompt = generateSystemPrompt(actions);\r\n\r\n const result = await client.models.generateContent({\r\n model: this.model,\r\n contents: [\r\n {\r\n role: \"user\",\r\n parts: [{ text: systemPrompt + \"\\n\\nUser input:\\n\" + prompt }],\r\n },\r\n ],\r\n });\r\n\r\n const content = result.text;\r\n\r\n if (!content) {\r\n throw new Error(\"Gemini returned empty response\");\r\n }\r\n\r\n return this.safeParseJSON(content);\r\n }\r\n\r\n // json guard\r\n private safeParseJSON(text: string): Intent {\r\n try {\r\n const cleaned = text\r\n .replace(/```json/g, \"\")\r\n .replace(/```/g, \"\")\r\n .trim();\r\n\r\n return JSON.parse(cleaned);\r\n } catch {\r\n throw new Error(`Invalid JSON returned by Gemini:\\n${text}`);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../src/utils/content-formatter.ts","../../src/providers/gemini.ts"],"names":[],"mappings":";;;AAEO,SAAS,cAAA,CACd,UACA,KAAA,EACA;AACA,EAAA,QAAQ,KAAA;AAAO,IACb,KAAK,QAAA;AACH,MAAA,OAAO,QAAA,CAAS,GAAA,CAAI,CAAC,GAAA,MAAS;AAAA,QAC5B,IAAA,EAAM,GAAA,CAAI,IAAA,KAAS,WAAA,GAAc,UAAU,GAAA,CAAI,IAAA;AAAA,QAC/C,OAAO,CAAC,EAAE,IA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,CAAA;AAED,MAAA,IAAI,OAAA,CAAQ,SAAA,IAAa,OAAA,CAAQ,SAAA,GAAY,CAAA,EAAG;AAC9C,QAAA,OAAA,GAAU;AAAA,UACR,GAAG,OAAA;AAAA,UACH,UAAU,OAAA,CAAQ,QAAA,CAAS,KAAA,CAAM,CAAC,QAAQ,SAAS;AAAA,SACrD;AAAA,MACF;AAEA,MAAA,MAAM,OAAA,CAAQ,YAAA,CAAa,GAAA,CAAI,OAAA,CAAQ,WAAW,OAAO,CAAA;AAAA,IAC3D;AAEA,IAAA,OAAO,IAAA,CAAK,cAAc,YAAY,CAAA;AAAA,EACxC;AAAA;AAAA,EAGQ,cAAc,IAAA,EAAsB;AAC1C,IAAA,IAAI;AACF,MAAA,MAAM,OAAA,GAAU,IAAA,CACb,OAAA,CAAQ,UAAA,EAAY,EAAE,EACtB,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA,CAClB,IAAA,EAAK;AAER,MAAA,OAAO,IAAA,CAAK,MAAM,OAAO,CAAA;AAAA,IAC3B,CAAA,CAAA,MAAQ;AACN,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA;AAAA,EAAqC,IAAI,CAAA,CAAE,CAAA;AAAA,IAC7D;AAAA,EACF;AACF","file":"gemini.js","sourcesContent":["import type { AIMessage } from \"../types/session\";\n\nexport function formatContents(\n messages: AIMessage[],\n model: \"gemini\" | \"openai\" | \"groq\",\n) {\n switch (model) {\n case \"gemini\":\n return messages.map((msg) => ({\n role: msg.role === \"assistant\" ? \"model\" : msg.role,\n parts: [{ text: msg.content }],\n }));\n\n case \"openai\":\n return messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n }));\n\n case \"groq\":\n return messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n }));\n\n default:\n return [];\n }\n}\n","import type { Intent } from \"../types/intent\";\nimport type { AgentSession, AIMessage, SessionStore } from \"../types/session\";\nimport type { AvailableAction, IntentParser } from \"../intent/intent-parser\";\nimport { generateSystemPrompt } from \"../utils/prompt\";\nimport { loadPackage } from \"../utils/loader\";\nimport type * as GeminiModule from \"@google/genai\"; // just for type import\nimport { formatContents } from \"../utils/content-formatter\";\n\nexport class GeminiIntentParser implements IntentParser {\n private client?: GeminiModule.GoogleGenAI;\n private readonly apiKey: string;\n private readonly model: string;\n // private readonly opts: GeminiModule.GoogleGenAIOptions | undefined;\n\n constructor(options: {\n apiKey: string;\n model?: string;\n // opts?: GeminiModule.GoogleGenAIOptions;\n }) {\n this.apiKey = options.apiKey;\n this.model = options.model ?? \"gemini-2.5-flash\";\n // this.opts = options.opts;\n }\n\n // lazy loader\n private async getClient(): Promise<GeminiModule.GoogleGenAI> {\n if (this.client) return this.client;\n\n const { GoogleGenAI } = loadPackage<typeof GeminiModule>(\"@google/genai\");\n this.client = new GoogleGenAI({ apiKey: this.apiKey });\n\n return this.client;\n }\n\n async parse(\n prompt: string | string[],\n actions: AvailableAction[],\n options?: {\n sessionId: string;\n sessionStore: SessionStore<AgentSession>;\n maxLength?: number;\n },\n ): Promise<Intent> {\n const client = await this.getClient();\n const systemPrompt = generateSystemPrompt(actions);\n\n let history: AIMessage[] = [];\n\n if (options?.sessionId && options.sessionStore) {\n const session = await options.sessionStore.get(options.sessionId);\n if (session) history = session.messages;\n }\n\n const newMessage: AIMessage = {\n role: \"user\",\n content: Array.isArray(prompt) ? prompt.join(\"\\n\") : prompt,\n };\n\n const messages: AIMessage[] = [\n { role: \"system\", content: systemPrompt },\n ...history,\n newMessage,\n ];\n\n const contents = formatContents(messages, \"gemini\");\n\n const result = await client.models.generateContent({\n model: this.model,\n contents,\n });\n\n const responseText = result.text;\n\n if (!responseText) {\n throw new Error(\"Gemini returned empty response\");\n }\n\n if (options?.sessionId && options.sessionStore) {\n let session = (await options.sessionStore.get(options.sessionId)) ?? {\n messages: [],\n state: {},\n };\n\n session.messages.push(newMessage);\n session.messages.push({\n role: \"assistant\",\n content: responseText,\n });\n\n if (options.maxLength && options.maxLength > 0) {\n session = {\n ...session,\n messages: session.messages.slice(-options.maxLength),\n };\n }\n\n await options.sessionStore.set(options.sessionId, session);\n }\n\n return this.safeParseJSON(responseText);\n }\n\n // json guard\n private safeParseJSON(text: string): Intent {\n try {\n const cleaned = text\n .replace(/```json/g, \"\")\n .replace(/```/g, \"\")\n .trim();\n\n return JSON.parse(cleaned);\n } catch {\n throw new Error(`Invalid JSON returned by Gemini:\\n${text}`);\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { a as IntentParser, A as AvailableAction, I as Intent } from '../intent-parser-tPkUA2YT.js';
1
+ import { I as IntentParser, c as AvailableAction, a as Intent } from '../intent-parser-guF1BU1U.js';
2
2
 
3
3
  declare class GroqIntentParser implements IntentParser {
4
4
  private client?;
@@ -1,4 +1,4 @@
1
- import { loadGroq, generateSystemPrompt } from '../chunk-UNGR3PLJ.js';
1
+ import { loadPackage, generateSystemPrompt } from '../chunk-RECTO6FA.js';
2
2
 
3
3
  // src/providers/groq.ts
4
4
  var GroqIntentParser = class {
@@ -11,7 +11,7 @@ var GroqIntentParser = class {
11
11
  }
12
12
  async getClient() {
13
13
  if (this.client) return this.client;
14
- const { default: Groq } = await loadGroq();
14
+ const { default: Groq } = loadPackage("groq-sdk");
15
15
  this.client = new Groq({ apiKey: this.apiKey });
16
16
  return this.client;
17
17
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/providers/groq.ts"],"names":[],"mappings":";;;AAMO,IAAM,mBAAN,MAA+C;AAAA,EAC5C,MAAA;AAAA,EACS,MAAA;AAAA,EACA,KAAA;AAAA,EAEjB,YAAY,OAAA,EAA6C;AACvD,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,KAAA,GAAQ,QAAQ,KAAA,IAAS,iBAAA;AAAA,EAChC;AAAA,EAEA,MAAc,SAAA,GAA2B;AACvC,IAAA,IAAI,IAAA,CAAK,MAAA,EAAQ,OAAO,IAAA,CAAK,MAAA;AAE7B,IAAA,MAAM,EAAE,OAAA,EAAS,IAAA,EAAK,GAAI,MAAM,QAAA,EAAS;AACzC,IAAA,IAAA,CAAK,SAAS,IAAI,IAAA,CAAK,EAAE,MAAA,EAAQ,IAAA,CAAK,QAAQ,CAAA;AAE9C,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EAEA,MAAM,KAAA,CAAM,MAAA,EAAgB,OAAA,EAA6C;AACvE,IAAA,MAAM,YAAA,GAAe,qBAAqB,OAAO,CAAA;AACjD,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,SAAA,EAAU;AAEpC,IAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,IAAA,CAAK,YAAY,MAAA,CAAO;AAAA,MACpD,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,WAAA,EAAa,CAAA;AAAA,MACb,QAAA,EAAU;AAAA,QACR,EAAE,IAAA,EAAM,QAAA,EAAU,OAAA,EAAS,YAAA,EAAa;AAAA,QACxC,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAA,EAAS,MAAA;AAAO;AAClC,KACD,CAAA;AAED,IAAA,MAAM,OAAA,GAAU,QAAA,CAAS,OAAA,CAAQ,CAAC,GAAG,OAAA,EAAS,OAAA;AAE9C,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,MAAM,8BAA8B,CAAA;AAAA,IAChD;AAEA,IAAA,OAAO,IAAA,CAAK,cAAc,OAAO,CAAA;AAAA,EACnC;AAAA,EAEQ,cAAc,IAAA,EAAsB;AAC1C,IAAA,IAAI;AACF,MAAA,OAAO,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,IACxB,CAAA,CAAA,MAAQ;AACN,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA;AAAA,EAAmC,IAAI,CAAA,CAAE,CAAA;AAAA,IAC3D;AAAA,EACF;AACF","file":"groq.js","sourcesContent":["import type { Intent } from \"../types/intent\";\r\nimport type { AvailableAction, IntentParser } from \"../intent/intent-parser\";\r\nimport { generateSystemPrompt } from \"../utils/prompt\";\r\nimport { loadGroq } from \"../utils/loader\";\r\nimport type Groq from \"groq-sdk\";\r\n\r\nexport class GroqIntentParser implements IntentParser {\r\n private client?: Groq;\r\n private readonly apiKey: string;\r\n private readonly model: string;\r\n\r\n constructor(options: { apiKey: string; model?: string }) {\r\n this.apiKey = options.apiKey;\r\n this.model = options.model ?? \"llama3-70b-8192\";\r\n }\r\n\r\n private async getClient(): Promise<Groq> {\r\n if (this.client) return this.client;\r\n\r\n const { default: Groq } = await loadGroq();\r\n this.client = new Groq({ apiKey: this.apiKey });\r\n\r\n return this.client;\r\n }\r\n\r\n async parse(prompt: string, actions: AvailableAction[]): Promise<Intent> {\r\n const systemPrompt = generateSystemPrompt(actions);\r\n const client = await this.getClient();\r\n\r\n const response = await client.chat.completions.create({\r\n model: this.model,\r\n temperature: 0,\r\n messages: [\r\n { role: \"system\", content: systemPrompt },\r\n { role: \"user\", content: prompt },\r\n ],\r\n });\r\n\r\n const content = response.choices[0]?.message?.content;\r\n\r\n if (!content) {\r\n throw new Error(\"Groq returned empty response\");\r\n }\r\n\r\n return this.safeParseJSON(content);\r\n }\r\n\r\n private safeParseJSON(text: string): Intent {\r\n try {\r\n return JSON.parse(text);\r\n } catch {\r\n throw new Error(`Invalid JSON returned by Groq:\\n${text}`);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../src/providers/groq.ts"],"names":[],"mappings":";;;AAMO,IAAM,mBAAN,MAA+C;AAAA,EAC5C,MAAA;AAAA,EACS,MAAA;AAAA,EACA,KAAA;AAAA,EAEjB,YAAY,OAAA,EAA6C;AACvD,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,KAAA,GAAQ,QAAQ,KAAA,IAAS,iBAAA;AAAA,EAChC;AAAA,EAEA,MAAc,SAAA,GAAsC;AAClD,IAAA,IAAI,IAAA,CAAK,MAAA,EAAQ,OAAO,IAAA,CAAK,MAAA;AA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Parser } from \"../intent/intent-parser\";\nimport { generateSystemPrompt } from \"../utils/prompt\";\nimport { loadPackage } from \"../utils/loader\";\nimport type * as GroqModule from \"groq-sdk\";\n\nexport class GroqIntentParser implements IntentParser {\n private client?: GroqModule.Groq;\n private readonly apiKey: string;\n private readonly model: string;\n\n constructor(options: { apiKey: string; model?: string }) {\n this.apiKey = options.apiKey;\n this.model = options.model ?? \"llama3-70b-8192\";\n }\n\n private async getClient(): Promise<GroqModule.Groq> {\n if (this.client) return this.client;\n\n const { default: Groq } = loadPackage<typeof GroqModule>(\"groq-sdk\");\n this.client = new Groq({ apiKey: this.apiKey });\n\n return this.client;\n }\n\n async parse(prompt: string, actions: AvailableAction[]): Promise<Intent> {\n const systemPrompt = generateSystemPrompt(actions);\n const client = await this.getClient();\n\n const response = await client.chat.completions.create({\n model: this.model,\n temperature: 0,\n messages: [\n { role: \"system\", content: systemPrompt },\n { role: \"user\", content: prompt },\n ],\n });\n\n const content = response.choices[0]?.message?.content;\n\n if (!content) {\n throw new Error(\"Groq returned empty response\");\n }\n\n return this.safeParseJSON(content);\n }\n\n private safeParseJSON(text: string): Intent {\n try {\n return JSON.parse(text);\n } catch {\n throw new Error(`Invalid JSON returned by Groq:\\n${text}`);\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { a as IntentParser, A as AvailableAction, I as Intent } from '../intent-parser-tPkUA2YT.js';
1
+ import { I as IntentParser, c as AvailableAction, a as Intent } from '../intent-parser-guF1BU1U.js';
2
2
 
3
3
  declare class OpenAIIntentParser implements IntentParser {
4
4
  private client?;
@@ -1,4 +1,4 @@
1
- import { loadOpenAI, generateSystemPrompt } from '../chunk-UNGR3PLJ.js';
1
+ import { loadPackage, generateSystemPrompt } from '../chunk-RECTO6FA.js';
2
2
 
3
3
  // src/providers/openai.ts
4
4
  var OpenAIIntentParser = class {
@@ -11,7 +11,7 @@ var OpenAIIntentParser = class {
11
11
  }
12
12
  async getClient() {
13
13
  if (this.client) return this.client;
14
- const { default: OpenAI } = await loadOpenAI();
14
+ const { default: OpenAI } = loadPackage("openai");
15
15
  this.client = new OpenAI({ apiKey: this.apiKey });
16
16
  return this.client;
17
17
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/providers/openai.ts"],"names":[],"mappings":";;;AAMO,IAAM,qBAAN,MAAiD;AAAA,EAC9C,MAAA;AAAA,EACS,MAAA;AAAA,EACA,KAAA;AAAA,EAEjB,YAAY,OAAA,EAA6C;AACvD,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,KAAA,GAAQ,QAAQ,KAAA,IAAS,aAAA;AAAA,EAChC;AAAA,EAEA,MAAc,SAAA,GAA6B;AACzC,IAAA,IAAI,IAAA,CAAK,MAAA,EAAQ,OAAO,IAAA,CAAK,MAAA;AAE7B,IAAA,MAAM,EAAE,OAAA,EAAS,MAAA,EAAO,GAAI,MAAM,UAAA,EAAW;AAC7C,IAAA,IAAA,CAAK,SAAS,IAAI,MAAA,CAAO,EAAE,MAAA,EAAQ,IAAA,CAAK,QAAQ,CAAA;AAEhD,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EAEA,MAAM,KAAA,CAAM,MAAA,EAAgB,OAAA,EAA6C;AACvE,IAAA,MAAM,YAAA,GAAe,qBAAqB,OAAO,CAAA;AACjD,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,SAAA,EAAU;AAEpC,IAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,IAAA,CAAK,YAAY,MAAA,CAAO;AAAA,MACpD,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,WAAA,EAAa,CAAA;AAAA,MACb,QAAA,EAAU;AAAA,QACR,EAAE,IAAA,EAAM,QAAA,EAAU,OAAA,EAAS,YAAA,EAAa;AAAA,QACxC,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAA,EAAS,MAAA;AAAO;AAClC,KACD,CAAA;AAED,IAAA,MAAM,OAAA,GAAU,QAAA,CAAS,OAAA,CAAQ,CAAC,GAAG,OAAA,EAAS,OAAA;AAE9C,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,MAAM,4BAA4B,CAAA;AAAA,IAC9C;AAEA,IAAA,OAAO,IAAA,CAAK,cAAc,OAAO,CAAA;AAAA,EACnC;AAAA,EAEQ,cAAc,IAAA,EAAsB;AAC1C,IAAA,IAAI;AACF,MAAA,OAAO,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,IACxB,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,6BAAA,EAAgC,IAAI,CAAA,CAAE,CAAA;AAAA,IACxD;AAAA,EACF;AACF","file":"openai.js","sourcesContent":["import type { Intent } from \"../types/intent\";\r\nimport type { AvailableAction, IntentParser } from \"../intent/intent-parser\";\r\nimport { loadOpenAI } from \"../utils/loader\";\r\nimport { generateSystemPrompt } from \"../utils/prompt\";\r\nimport type OpenAI from \"openai\";\r\n\r\nexport class OpenAIIntentParser implements IntentParser {\r\n private client?: OpenAI;\r\n private readonly apiKey;\r\n private readonly model: string;\r\n\r\n constructor(options: { apiKey: string; model?: string }) {\r\n this.apiKey = options.apiKey;\r\n this.model = options.model ?? \"gpt-4o-mini\";\r\n }\r\n\r\n private async getClient(): Promise<OpenAI> {\r\n if (this.client) return this.client;\r\n\r\n const { default: OpenAI } = await loadOpenAI();\r\n this.client = new OpenAI({ apiKey: this.apiKey });\r\n\r\n return this.client;\r\n }\r\n\r\n async parse(prompt: string, actions: AvailableAction[]): Promise<Intent> {\r\n const systemPrompt = generateSystemPrompt(actions);\r\n const client = await this.getClient();\r\n\r\n const response = await client.chat.completions.create({\r\n model: this.model,\r\n temperature: 0,\r\n messages: [\r\n { role: \"system\", content: systemPrompt },\r\n { role: \"user\", content: prompt },\r\n ],\r\n });\r\n\r\n const content = response.choices[0]?.message?.content;\r\n\r\n if (!content) {\r\n throw new Error(\"AI returned empty response\");\r\n }\r\n\r\n return this.safeParseJSON(content);\r\n }\r\n\r\n private safeParseJSON(text: string): Intent {\r\n try {\r\n return JSON.parse(text);\r\n } catch (err) {\r\n throw new Error(`Invalid JSON returned by AI: ${text}`);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../src/providers/openai.ts"],"names":[],"mappings":";;;AAMO,IAAM,qBAAN,MAAiD;AAAA,EAC9C,MAAA;AAAA,EACS,MAAA;AAAA,EACA,KAAA;AAAA,EAEjB,YAAY,OAAA,EAA6C;AACvD,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,KAAA,GAAQ,QAAQ,KAAA,IAAS,aAAA;AAAA,EAChC;AAAA,EAEA,MAAc,SAAA,GAA0C;AACtD,IAAA,IAAI,IAAA,CAAK,MAAA,EAAQ,OAAO,IAAA,CAAK,MAAA;AAE7B,IAAA,MAAM,EAAE,OAAA,EAAS,MAAA,EAAO,GAAI,YAAiC,QAAQ,CAAA;AACrE,IAAA,IAAA,CAAK,SAAS,IAAI,MAAA,CAAO,EAAE,MAAA,EAAQ,IAAA,CAAK,QAAQ,CAAA;AAEhD,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EAEA,MAAM,KAAA,CAAM,MAAA,EAAgB,OAAA,EAA6C;AACvE,IAAA,MAAM,YAAA,GAAe,qBAAqB,OAAO,CAAA;AACjD,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,SAAA,EAAU;AAEpC,IAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,IAAA,CAAK,YAAY,MAAA,CAAO;AAAA,MACpD,OAAO,IAAA,CAAK,KAAA;AAAA,MACZ,WAAA,EAAa,CAAA;AAAA,MACb,QAAA,EAAU;AAAA,QACR,EAAE,IAAA,EAAM,QAAA,EAAU,OAAA,EAAS,YAAA,EAAa;AAAA,QACxC,EAAE,IAAA,EAAM,MAAA,EAAQ,OAAA,EAAS,MAAA;AAAO;AAClC,KACD,CAAA;AAED,IAAA,MAAM,OAAA,GAAU,QAAA,CAAS,OAAA,CAAQ,CAAC,GAAG,OAAA,EAAS,OAAA;AAE9C,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,MAAM,4BAA4B,CAAA;AAAA,IAC9C;AAEA,IAAA,OAAO,IAAA,CAAK,cAAc,OAAO,CAAA;AAAA,EACnC;AAAA,EAEQ,cAAc,IAAA,EAAsB;AAC1C,IAAA,IAAI;AACF,MAAA,OAAO,IAAA,CAAK,MAAM,IAAI,CAAA;AAAA,IACxB,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,6BAAA,EAAgC,IAAI,CAAA,CAAE,CAAA;AAAA,IACxD;AAAA,EACF;AACF","file":"openai.js","sourcesContent":["import type { Intent } from \"../types/intent\";\nimport type { AvailableAction, IntentParser } from \"../intent/intent-parser\";\nimport { loadPackage } from \"../utils/loader\";\nimport { generateSystemPrompt } from \"../utils/prompt\";\nimport type * as OpenAIModule from \"openai\";\n\nexport class OpenAIIntentParser implements IntentParser {\n private client?: OpenAIModule.OpenAI;\n private readonly apiKey;\n private readonly model: string;\n\n constructor(options: { apiKey: string; model?: string }) {\n this.apiKey = options.apiKey;\n this.model = options.model ?? \"gpt-4o-mini\";\n }\n\n private async getClient(): Promise<OpenAIModule.OpenAI> {\n if (this.client) return this.client;\n\n const { default: OpenAI } = loadPackage<typeof OpenAIModule>(\"openai\");\n this.client = new OpenAI({ apiKey: this.apiKey });\n\n return this.client;\n }\n\n async parse(prompt: string, actions: AvailableAction[]): Promise<Intent> {\n const systemPrompt = generateSystemPrompt(actions);\n const client = await this.getClient();\n\n const response = await client.chat.completions.create({\n model: this.model,\n temperature: 0,\n messages: [\n { role: \"system\", content: systemPrompt },\n { role: \"user\", content: prompt },\n ],\n });\n\n const content = response.choices[0]?.message?.content;\n\n if (!content) {\n throw new Error(\"AI returned empty response\");\n }\n\n return this.safeParseJSON(content);\n }\n\n private safeParseJSON(text: string): Intent {\n try {\n return JSON.parse(text);\n } catch (err) {\n throw new Error(`Invalid JSON returned by AI: ${text}`);\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "actient",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "build": "tsup",
@@ -26,21 +26,22 @@
26
26
  ],
27
27
  "exports": {
28
28
  ".": {
29
+ "types": "./dist/index.d.ts",
29
30
  "import": "./dist/index.js",
30
- "types": "./dist/index.d.ts"
31
+ "default": "./dist/index.js"
31
32
  },
32
33
  "./providers/*": {
34
+ "types": "./dist/providers/*.d.ts",
33
35
  "import": "./dist/providers/*.js",
34
- "types": "./dist/providers/*.d.ts"
36
+ "default": "./dist/providers/*.js"
35
37
  }
36
38
  },
37
39
  "dependencies": {
38
40
  "zod": "^4.2.1"
39
41
  },
40
42
  "peerDependencies": {
41
- "openai": "^4.0.0 || ^6.0.0",
42
- "groq-sdk": "^0.37.0",
43
- "@google/genai": "^1.0.0"
43
+ "@google/genai": "^1.0.0",
44
+ "openai": "^4.0.0 || ^6.0.0"
44
45
  },
45
46
  "peerDependenciesMeta": {
46
47
  "openai": {
@@ -54,10 +55,11 @@
54
55
  }
55
56
  },
56
57
  "devDependencies": {
57
- "tsup": "^8.5.1",
58
- "typescript": "^5.9.3",
58
+ "@google/genai": "^1.0.0",
59
+ "@types/node": "^25.5.0",
60
+ "groq-sdk": "^1.1.2",
59
61
  "openai": "^4.0.0 || ^6.0.0",
60
- "groq-sdk": "^0.37.0",
61
- "@google/genai": "^1.0.0"
62
+ "tsup": "^8.5.1",
63
+ "typescript": "^5.9.3"
62
64
  }
63
65
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/prompt.ts","../src/ut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AAC/B,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,OAAO,UAAU,CAAA;AAAA,EAChC,CAAA,CAAA,MAAQ;AACN,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AACF","file":"chunk-UNGR3PLJ.js","sourcesContent":["import type { AvailableAction } from \"../intent/intent-parser\";\r\n\r\nexport const generateSystemPrompt = (actions: AvailableAction[]): string => {\r\n return `\r\nYou are an intent parser.\r\n\r\nYour task is to translate user input into a structured JSON intent.\r\n\r\nAvailable actions:\r\n${actions\r\n .map(\r\n (a) => `- ${a.name}: ${a.description}\r\n Parameters:\r\n${Object.entries(a.parameters)\r\n .map(([key, type]) => ` - ${key}: ${type}`)\r\n .join(\"\\n\")}\r\n Specific rules: ${\r\n a.rules?.length ? a.rules.map((r) => ` - ${r}`).join(\"\\n\") : \" - None\"\r\n }\r\n `\r\n )\r\n .join(\"\\n\")}\r\n\r\n \r\nRules:\r\n- Respond ONLY with valid JSON\r\n- Do NOT include markdown\r\n- Do NOT explain anything\r\n- Do NOT invent actions\r\n- Only use actions listed above\r\n- Parameter names MUST exactly match the schema\r\n- Do NOT rename parameters\r\n- Do NOT invent parameters\r\n- JSON format:\r\n{\r\n \"action\": \"action_name\",\r\n \"params\": { ... }\r\n}\r\n\r\nIf no action matches, return:\r\n{\r\n \"action\": \"UNKNOWN\",\r\n \"params\": {}\r\n}\r\n`.trim();\r\n};\r\n","export async function loadGemini() {\r\n try {\r\n return await import(\"@google/genai\");\r\n } catch {\r\n throw new Error(\r\n \"Gemini support requires `@google/genai`. Install it with:\\n\" +\r\n \"npm install @google/genai\"\r\n );\r\n }\r\n}\r\n\r\nexport async function loadOpenAI() {\r\n try {\r\n return await import(\"openai\");\r\n } catch {\r\n throw new Error(\r\n \"OpenAI support requires `openai`. Install it with:\\n\" +\r\n \"npm install openai\"\r\n );\r\n }\r\n}\r\n\r\nexport async function loadGroq() {\r\n try {\r\n return await import(\"groq-sdk\");\r\n } catch {\r\n throw new Error(\r\n \"Groq support requires `groq-sdk`. Install it with:\\n\" +\r\n \"npm install groq-sdk\"\r\n );\r\n }\r\n}\r\n"]}
@@ -1,16 +0,0 @@
1
- interface Intent {
2
- action: string;
3
- params: Record<string, any>;
4
- }
5
-
6
- interface AvailableAction {
7
- name: string;
8
- rules?: string[];
9
- description: string;
10
- parameters: Record<string, string>;
11
- }
12
- interface IntentParser {
13
- parse(prompt: string, actions: AvailableAction[]): Promise<Intent>;
14
- }
15
-
16
- export type { AvailableAction as A, Intent as I, IntentParser as a };