@loopstack/ai-module 0.16.0 → 0.16.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/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
package/README.md CHANGED
@@ -1,2 +1,261 @@
1
- # Loopstack AI Module
1
+ # @loopstack/ai-module
2
2
 
3
+ > A module for the [Loopstack AI](https://loopstack.ai) automation framework.
4
+
5
+ This module provides tools for integrating Large Language Models (LLMs) into your workflows, with support for OpenAI and Anthropic providers.
6
+
7
+ ## Overview
8
+
9
+ The AI Module enables workflows to leverage LLM capabilities for text generation, structured object generation, and agentic tool calling patterns. It abstracts provider-specific implementations behind a unified interface.
10
+
11
+ By using this module, you'll be able to:
12
+
13
+ - Generate text responses using OpenAI or Anthropic models
14
+ - Generate structured objects that conform to document schemas
15
+ - Build agentic workflows with LLM tool calling
16
+ - Create AI-powered conversational interfaces
17
+
18
+ This module is essential for workflows that need natural language processing, content generation, or AI-driven decision making.
19
+
20
+ ## Installation
21
+
22
+ ### Prerequisites
23
+
24
+ Create a new Loopstack project if you haven't already:
25
+
26
+ ```bash
27
+ npx create-loopstack-app my-project
28
+ cd my-project
29
+ ```
30
+
31
+ Start Environment
32
+
33
+ ```bash
34
+ cd my-project
35
+ docker compose up -d
36
+ ```
37
+
38
+ ### Install the Module
39
+
40
+ #### As Node Dependency via Npm:
41
+
42
+ ```bash
43
+ npm install --save @loopstack/ai-module
44
+ ```
45
+
46
+ #### OR: Copy Sources via Loopstack CLI
47
+
48
+ ```bash
49
+ loopstack add @loopstack/ai-module
50
+ ```
51
+
52
+ ### Configure API Keys
53
+
54
+ Set your provider API keys as environment variables:
55
+
56
+ ```bash
57
+ # OpenAI
58
+ OPENAI_API_KEY=sk-...
59
+
60
+ # Anthropic
61
+ ANTHROPIC_API_KEY=sk-ant-...
62
+ ```
63
+
64
+ ## Setup
65
+
66
+ ### 1. Import the Module
67
+
68
+ Add `AiModule` to your `default.module.ts` (included in the skeleton app) or to your own module:
69
+
70
+ ```typescript
71
+ import { Module } from '@nestjs/common';
72
+ import { LoopCoreModule } from '@loopstack/core';
73
+ import { AiModule } from '@loopstack/ai-module';
74
+ import { DefaultWorkspace } from './default.workspace';
75
+
76
+ @Module({
77
+ imports: [LoopCoreModule, AiModule],
78
+ providers: [DefaultWorkspace],
79
+ })
80
+ export class DefaultModule {}
81
+ ```
82
+
83
+ ### 2. Use in Your Workflow
84
+
85
+ Inject the tools and documents in your workflow class:
86
+
87
+ ```typescript
88
+ import { Injectable } from '@nestjs/common';
89
+ import { BlockConfig, Document, Tool, Helper } from '@loopstack/common';
90
+ import { WorkflowBase } from '@loopstack/core';
91
+ import {
92
+ AiGenerateText,
93
+ AiGenerateObject,
94
+ AiGenerateDocument,
95
+ DelegateToolCall,
96
+ AiMessageDocument,
97
+ } from '@loopstack/ai-module';
98
+
99
+ @Injectable()
100
+ @BlockConfig({
101
+ configFile: __dirname + '/my.workflow.yaml',
102
+ })
103
+ export class MyWorkflow extends WorkflowBase {
104
+ // Tools
105
+ @Tool() aiGenerateText: AiGenerateText;
106
+ @Tool() aiGenerateObject: AiGenerateObject;
107
+ @Tool() aiGenerateDocument: AiGenerateDocument;
108
+ @Tool() delegateToolCall: DelegateToolCall;
109
+
110
+ // Documents
111
+ @Document() aiMessageDocument: AiMessageDocument;
112
+ }
113
+ ```
114
+
115
+ ## Tool Reference
116
+
117
+ ### AiGenerateText
118
+
119
+ Generates text using an LLM with optional tool calling support.
120
+
121
+ #### Arguments
122
+
123
+ | Argument | Type | Required | Description |
124
+ |----------|------|----------|-------------|
125
+ | `llm.provider` | string | No | Provider name (`openai` or `anthropic`) |
126
+ | `llm.model` | string | No | Model identifier (e.g., `gpt-4o`, `claude-3-sonnet`) |
127
+ | `llm.envApiKey` | string | No | Environment variable name for API key |
128
+ | `prompt` | string | No | Simple text prompt |
129
+ | `messages` | array | No | Array of message objects with `role` and `content` |
130
+ | `messagesSearchTag` | string | No | Tag to search for messages in workflow documents |
131
+ | `tools` | string[] | No | Array of tool names to make available to the LLM |
132
+
133
+ #### Example
134
+
135
+ ```yaml
136
+ - tool: aiGenerateText
137
+ args:
138
+ llm:
139
+ provider: openai
140
+ model: gpt-4o
141
+ messagesSearchTag: message
142
+ tools:
143
+ - getWeather
144
+ assign:
145
+ llmResponse: ${ result.data }
146
+ ```
147
+
148
+ ### AiGenerateObject
149
+
150
+ Generates a structured object using an LLM that conforms to a document schema.
151
+
152
+ #### Arguments
153
+
154
+ | Argument | Type | Required | Description |
155
+ |----------|------|----------|-------------|
156
+ | `llm.provider` | string | No | Provider name |
157
+ | `llm.model` | string | No | Model identifier |
158
+ | `prompt` | string | No | Simple text prompt |
159
+ | `messages` | array | No | Array of message objects |
160
+ | `messagesSearchTag` | string | No | Tag to search for messages |
161
+ | `response.document` | string | Yes | Document name whose schema defines the output structure |
162
+ | `response.id` | string | No | Custom ID for the generated object |
163
+
164
+ #### Example
165
+
166
+ ```yaml
167
+ - tool: aiGenerateObject
168
+ args:
169
+ llm:
170
+ provider: anthropic
171
+ model: claude-3-sonnet
172
+ prompt: "Extract the key information from this text: {{ inputText }}"
173
+ response:
174
+ document: infoDocument
175
+ assign:
176
+ entities: ${ result.data }
177
+ ```
178
+
179
+ ### AiGenerateDocument
180
+
181
+ Combines `AiGenerateObject` and `CreateDocument` into a single operation. Generates a structured object and immediately creates it as a document.
182
+
183
+ #### Arguments
184
+
185
+ Same as `AiGenerateObject`. The generated object is automatically created as a document using the specified document type.
186
+
187
+ #### Example
188
+
189
+ ```yaml
190
+ - tool: aiGenerateDocument
191
+ args:
192
+ llm:
193
+ provider: openai
194
+ model: gpt-4o
195
+ messagesSearchTag: message
196
+ response:
197
+ document: summaryDocument
198
+ ```
199
+
200
+ ### DelegateToolCall
201
+
202
+ Executes tool calls requested by the LLM and returns the results in the expected format.
203
+
204
+ #### Arguments
205
+
206
+ | Argument | Type | Required | Description |
207
+ |----------|------|----------|-------------|
208
+ | `message` | object | Yes | The LLM response message containing tool call parts |
209
+ | `message.id` | string | Yes | Message identifier |
210
+ | `message.parts` | array | Yes | Array of tool call parts with `type`, `input`, and `toolCallId` |
211
+
212
+ #### Example
213
+
214
+ ```yaml
215
+ - tool: delegateToolCall
216
+ args:
217
+ message: ${ llmResponse }
218
+ assign:
219
+ toolCallResult: ${ result.data }
220
+ ```
221
+
222
+ ## Document Types
223
+
224
+ ### AiMessageDocument
225
+
226
+ Represents an AI conversation message with support for multi-part content (text, tool calls, tool results).
227
+
228
+ **Schema:**
229
+ ```typescript
230
+ {
231
+ id?: string; // Message identifier
232
+ role: 'system' | 'user' | 'assistant'; // Message role
233
+ metadata?: any; // Optional metadata
234
+ parts: any[]; // Message content parts
235
+ }
236
+ ```
237
+
238
+ **Example:**
239
+ ```yaml
240
+ - tool: createDocument
241
+ args:
242
+ document: aiMessageDocument
243
+ update:
244
+ content:
245
+ role: user
246
+ parts:
247
+ - type: text
248
+ text: How is the weather in Berlin?
249
+ ```
250
+
251
+ ## About
252
+
253
+ Author: [Jakob Klippel](https://www.linkedin.com/in/jakob-klippel/)
254
+
255
+ License: Apache-2.0
256
+
257
+ ### Additional Resources
258
+
259
+ - [Loopstack Documentation](https://loopstack.ai/docs)
260
+ - [Getting Started with Loopstack](https://loopstack.ai/docs/getting-started)
261
+ - For more examples how to use this module look for `@loopstack/ai-module` in the [Loopstack Registry](https://loopstack.ai/registry)
package/dist/ai.module.js CHANGED
@@ -26,16 +26,20 @@ exports.AiModule = AiModule = __decorate([
26
26
  (0, common_1.Module)({
27
27
  imports: [core_1.LoopCoreModule, core_ui_module_1.CoreUiModule, core_2.DiscoveryModule],
28
28
  providers: [
29
+ // services
29
30
  services_1.AiMessagesHelperService,
30
31
  services_2.AiProviderModelHelperService,
31
32
  services_3.AiToolsHelperService,
32
33
  ai_provider_registry_service_1.AiProviderRegistryService,
34
+ // ai providers
33
35
  openai_provider_1.OpenAiProviderService,
34
36
  anthropic_provider_1.AnthropicProviderService,
37
+ // tools
35
38
  tools_1.AiGenerateDocument,
36
39
  tools_1.AiGenerateObject,
37
40
  tools_1.AiGenerateText,
38
41
  tools_1.DelegateToolCall,
42
+ // documents
39
43
  documents_1.AiMessageDocument,
40
44
  ],
41
45
  exports: [
@@ -1 +1 @@
1
- {"version":3,"file":"ai.module.js","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,0CAAiD;AACjD,0FAAoF;AACpF,iEAAoE;AACpE,uEAA0E;AAC1E,uCAA+C;AAC/C,yCAAqD;AACrD,yCAA0D;AAC1D,yCAAkD;AAClD,mCAKiB;AACjB,2CAAgD;AAChD,8DAAyD;AAgClD,IAAM,QAAQ,GAAd,MAAM,QAAQ;CAAG,CAAA;AAAX,4BAAQ;mBAAR,QAAQ;IA9BpB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAc,EAAE,6BAAY,EAAE,sBAAe,CAAC;QACxD,SAAS,EAAE;YAET,kCAAuB;YACvB,uCAA4B;YAC5B,+BAAoB;YACpB,wDAAyB;YAGzB,uCAAqB;YACrB,6CAAwB;YAGxB,0BAAkB;YAClB,wBAAgB;YAChB,sBAAc;YACd,wBAAgB;YAGhB,6BAAiB;SAClB;QACD,OAAO,EAAE;YACP,0BAAkB;YAClB,wBAAgB;YAChB,sBAAc;YACd,wBAAgB;YAChB,6BAAiB;SAClB;KACF,CAAC;GACW,QAAQ,CAAG"}
1
+ {"version":3,"file":"ai.module.js","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,0CAAiD;AACjD,0FAAoF;AACpF,iEAAoE;AACpE,uEAA0E;AAC1E,uCAA+C;AAC/C,yCAAqD;AACrD,yCAA0D;AAC1D,yCAAkD;AAClD,mCAKiB;AACjB,2CAAgD;AAChD,8DAAyD;AAgClD,IAAM,QAAQ,GAAd,MAAM,QAAQ;CAAG,CAAA;AAAX,4BAAQ;mBAAR,QAAQ;IA9BpB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAc,EAAE,6BAAY,EAAE,sBAAe,CAAC;QACxD,SAAS,EAAE;YACT,WAAW;YACX,kCAAuB;YACvB,uCAA4B;YAC5B,+BAAoB;YACpB,wDAAyB;YAEzB,eAAe;YACf,uCAAqB;YACrB,6CAAwB;YAExB,QAAQ;YACR,0BAAkB;YAClB,wBAAgB;YAChB,sBAAc;YACd,wBAAgB;YAEhB,YAAY;YACZ,6BAAiB;SAClB;QACD,OAAO,EAAE;YACP,0BAAkB;YAClB,wBAAgB;YAChB,sBAAc;YACd,wBAAgB;YAChB,6BAAiB;SAClB;KACF,CAAC;GACW,QAAQ,CAAG"}
@@ -6,52 +6,52 @@ export declare const AiGenerateToolBaseSchema: z.ZodObject<{
6
6
  envApiKey: z.ZodOptional<z.ZodString>;
7
7
  cacheResponse: z.ZodOptional<z.ZodBoolean>;
8
8
  }, "strip", z.ZodTypeAny, {
9
- model?: string | undefined;
10
- provider?: string | undefined;
11
- envApiKey?: string | undefined;
12
- cacheResponse?: boolean | undefined;
9
+ model?: string;
10
+ provider?: string;
11
+ envApiKey?: string;
12
+ cacheResponse?: boolean;
13
13
  }, {
14
- model?: string | undefined;
15
- provider?: string | undefined;
16
- envApiKey?: string | undefined;
17
- cacheResponse?: boolean | undefined;
14
+ model?: string;
15
+ provider?: string;
16
+ envApiKey?: string;
17
+ cacheResponse?: boolean;
18
18
  }>>;
19
19
  messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
20
20
  role: z.ZodEnum<["system", "assistant", "user", "tool"]>;
21
21
  content: z.ZodAny;
22
22
  }, "strip", z.ZodTypeAny, {
23
- role: "system" | "assistant" | "user" | "tool";
23
+ role?: "system" | "assistant" | "user" | "tool";
24
24
  content?: any;
25
25
  }, {
26
- role: "system" | "assistant" | "user" | "tool";
26
+ role?: "system" | "assistant" | "user" | "tool";
27
27
  content?: any;
28
28
  }>, "many">>;
29
29
  prompt: z.ZodOptional<z.ZodString>;
30
30
  messagesSearchTag: z.ZodOptional<z.ZodString>;
31
31
  }, "strip", z.ZodTypeAny, {
32
32
  llm?: {
33
- model?: string | undefined;
34
- provider?: string | undefined;
35
- envApiKey?: string | undefined;
36
- cacheResponse?: boolean | undefined;
37
- } | undefined;
33
+ model?: string;
34
+ provider?: string;
35
+ envApiKey?: string;
36
+ cacheResponse?: boolean;
37
+ };
38
38
  messages?: {
39
- role: "system" | "assistant" | "user" | "tool";
39
+ role?: "system" | "assistant" | "user" | "tool";
40
40
  content?: any;
41
- }[] | undefined;
42
- prompt?: string | undefined;
43
- messagesSearchTag?: string | undefined;
41
+ }[];
42
+ prompt?: string;
43
+ messagesSearchTag?: string;
44
44
  }, {
45
45
  llm?: {
46
- model?: string | undefined;
47
- provider?: string | undefined;
48
- envApiKey?: string | undefined;
49
- cacheResponse?: boolean | undefined;
50
- } | undefined;
46
+ model?: string;
47
+ provider?: string;
48
+ envApiKey?: string;
49
+ cacheResponse?: boolean;
50
+ };
51
51
  messages?: {
52
- role: "system" | "assistant" | "user" | "tool";
52
+ role?: "system" | "assistant" | "user" | "tool";
53
53
  content?: any;
54
- }[] | undefined;
55
- prompt?: string | undefined;
56
- messagesSearchTag?: string | undefined;
54
+ }[];
55
+ prompt?: string;
56
+ messagesSearchTag?: string;
57
57
  }>;
@@ -10,6 +10,7 @@ exports.AiToolsHelperService = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
11
  let AiToolsHelperService = class AiToolsHelperService {
12
12
  getTools(tools, parent) {
13
+ // using any instead of ToolSet bc ai sdk types have some nesting issue
13
14
  const toolDefinitions = {};
14
15
  for (const toolName of tools) {
15
16
  const tool = parent.getTool(toolName);
@@ -21,7 +22,7 @@ let AiToolsHelperService = class AiToolsHelperService {
21
22
  toolDefinitions[toolName] = {
22
23
  description: tool.config.description,
23
24
  inputSchema,
24
- };
25
+ }; // using any bc ai sdk types have some nesting issue
25
26
  }
26
27
  }
27
28
  return Object.keys(toolDefinitions).length ? toolDefinitions : undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ai-tools-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-tools-helper.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAIrC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,QAAQ,CACN,KAAe,EACf,MAAoB;QAGpB,MAAM,eAAe,GAAwB,EAAE,CAAC;QAEhD,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACtC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CACb,kBAAkB,QAAQ,qCAAqC,CAChE,CAAC;YACJ,CAAC;YAED,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC;YAEpC,IAAI,WAAW,EAAE,CAAC;gBAChB,eAAe,CAAC,QAAQ,CAAC,GAAG;oBAC1B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;oBACpC,WAAW;iBACL,CAAC;YACX,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;CACF,CAAA;AA5BY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CA4BhC"}
1
+ {"version":3,"file":"ai-tools-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-tools-helper.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAIrC,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,QAAQ,CACN,KAAe,EACf,MAAoB;QAEpB,uEAAuE;QACvE,MAAM,eAAe,GAAwB,EAAE,CAAC;QAEhD,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACtC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CACb,kBAAkB,QAAQ,qCAAqC,CAChE,CAAC;YACJ,CAAC;YAED,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC;YAEpC,IAAI,WAAW,EAAE,CAAC;gBAChB,eAAe,CAAC,QAAQ,CAAC,GAAG;oBAC1B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;oBACpC,WAAW;iBACL,CAAC,CAAC,oDAAoD;YAChE,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;CACF,CAAA;AA5BY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CA4BhC"}
@@ -11,24 +11,24 @@ export declare const AiGenerateObjectSchema: z.ZodObject<{
11
11
  envApiKey: z.ZodOptional<z.ZodString>;
12
12
  cacheResponse: z.ZodOptional<z.ZodBoolean>;
13
13
  }, "strip", z.ZodTypeAny, {
14
- model?: string | undefined;
15
- provider?: string | undefined;
16
- envApiKey?: string | undefined;
17
- cacheResponse?: boolean | undefined;
14
+ model?: string;
15
+ provider?: string;
16
+ envApiKey?: string;
17
+ cacheResponse?: boolean;
18
18
  }, {
19
- model?: string | undefined;
20
- provider?: string | undefined;
21
- envApiKey?: string | undefined;
22
- cacheResponse?: boolean | undefined;
19
+ model?: string;
20
+ provider?: string;
21
+ envApiKey?: string;
22
+ cacheResponse?: boolean;
23
23
  }>>;
24
24
  messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
25
25
  role: z.ZodEnum<["system", "assistant", "user", "tool"]>;
26
26
  content: z.ZodAny;
27
27
  }, "strip", z.ZodTypeAny, {
28
- role: "system" | "assistant" | "user" | "tool";
28
+ role?: "system" | "assistant" | "user" | "tool";
29
29
  content?: any;
30
30
  }, {
31
- role: "system" | "assistant" | "user" | "tool";
31
+ role?: "system" | "assistant" | "user" | "tool";
32
32
  content?: any;
33
33
  }>, "many">>;
34
34
  prompt: z.ZodOptional<z.ZodString>;
@@ -38,46 +38,46 @@ export declare const AiGenerateObjectSchema: z.ZodObject<{
38
38
  id: z.ZodOptional<z.ZodString>;
39
39
  document: z.ZodString;
40
40
  }, "strip", z.ZodTypeAny, {
41
- document: string;
42
- id?: string | undefined;
41
+ id?: string;
42
+ document?: string;
43
43
  }, {
44
- document: string;
45
- id?: string | undefined;
44
+ id?: string;
45
+ document?: string;
46
46
  }>;
47
47
  }, "strict", z.ZodTypeAny, {
48
- response: {
49
- document: string;
50
- id?: string | undefined;
51
- };
52
48
  llm?: {
53
- model?: string | undefined;
54
- provider?: string | undefined;
55
- envApiKey?: string | undefined;
56
- cacheResponse?: boolean | undefined;
57
- } | undefined;
49
+ model?: string;
50
+ provider?: string;
51
+ envApiKey?: string;
52
+ cacheResponse?: boolean;
53
+ };
58
54
  messages?: {
59
- role: "system" | "assistant" | "user" | "tool";
55
+ role?: "system" | "assistant" | "user" | "tool";
60
56
  content?: any;
61
- }[] | undefined;
62
- prompt?: string | undefined;
63
- messagesSearchTag?: string | undefined;
64
- }, {
65
- response: {
66
- document: string;
67
- id?: string | undefined;
57
+ }[];
58
+ prompt?: string;
59
+ messagesSearchTag?: string;
60
+ response?: {
61
+ id?: string;
62
+ document?: string;
68
63
  };
64
+ }, {
69
65
  llm?: {
70
- model?: string | undefined;
71
- provider?: string | undefined;
72
- envApiKey?: string | undefined;
73
- cacheResponse?: boolean | undefined;
74
- } | undefined;
66
+ model?: string;
67
+ provider?: string;
68
+ envApiKey?: string;
69
+ cacheResponse?: boolean;
70
+ };
75
71
  messages?: {
76
- role: "system" | "assistant" | "user" | "tool";
72
+ role?: "system" | "assistant" | "user" | "tool";
77
73
  content?: any;
78
- }[] | undefined;
79
- prompt?: string | undefined;
80
- messagesSearchTag?: string | undefined;
74
+ }[];
75
+ prompt?: string;
76
+ messagesSearchTag?: string;
77
+ response?: {
78
+ id?: string;
79
+ document?: string;
80
+ };
81
81
  }>;
82
82
  export type AiGenerateObjectArgsType = z.infer<typeof AiGenerateObjectSchema>;
83
83
  export declare class AiGenerateObject extends ToolBase<AiGenerateObjectArgsType> {
@@ -12,24 +12,24 @@ export declare const AiGenerateTextSchema: z.ZodObject<{
12
12
  envApiKey: z.ZodOptional<z.ZodString>;
13
13
  cacheResponse: z.ZodOptional<z.ZodBoolean>;
14
14
  }, "strip", z.ZodTypeAny, {
15
- model?: string | undefined;
16
- provider?: string | undefined;
17
- envApiKey?: string | undefined;
18
- cacheResponse?: boolean | undefined;
15
+ model?: string;
16
+ provider?: string;
17
+ envApiKey?: string;
18
+ cacheResponse?: boolean;
19
19
  }, {
20
- model?: string | undefined;
21
- provider?: string | undefined;
22
- envApiKey?: string | undefined;
23
- cacheResponse?: boolean | undefined;
20
+ model?: string;
21
+ provider?: string;
22
+ envApiKey?: string;
23
+ cacheResponse?: boolean;
24
24
  }>>;
25
25
  messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
26
26
  role: z.ZodEnum<["system", "assistant", "user", "tool"]>;
27
27
  content: z.ZodAny;
28
28
  }, "strip", z.ZodTypeAny, {
29
- role: "system" | "assistant" | "user" | "tool";
29
+ role?: "system" | "assistant" | "user" | "tool";
30
30
  content?: any;
31
31
  }, {
32
- role: "system" | "assistant" | "user" | "tool";
32
+ role?: "system" | "assistant" | "user" | "tool";
33
33
  content?: any;
34
34
  }>, "many">>;
35
35
  prompt: z.ZodOptional<z.ZodString>;
@@ -38,32 +38,32 @@ export declare const AiGenerateTextSchema: z.ZodObject<{
38
38
  tools: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
39
39
  }, "strict", z.ZodTypeAny, {
40
40
  llm?: {
41
- model?: string | undefined;
42
- provider?: string | undefined;
43
- envApiKey?: string | undefined;
44
- cacheResponse?: boolean | undefined;
45
- } | undefined;
41
+ model?: string;
42
+ provider?: string;
43
+ envApiKey?: string;
44
+ cacheResponse?: boolean;
45
+ };
46
46
  messages?: {
47
- role: "system" | "assistant" | "user" | "tool";
47
+ role?: "system" | "assistant" | "user" | "tool";
48
48
  content?: any;
49
- }[] | undefined;
50
- prompt?: string | undefined;
51
- messagesSearchTag?: string | undefined;
52
- tools?: string[] | undefined;
49
+ }[];
50
+ prompt?: string;
51
+ messagesSearchTag?: string;
52
+ tools?: string[];
53
53
  }, {
54
54
  llm?: {
55
- model?: string | undefined;
56
- provider?: string | undefined;
57
- envApiKey?: string | undefined;
58
- cacheResponse?: boolean | undefined;
59
- } | undefined;
55
+ model?: string;
56
+ provider?: string;
57
+ envApiKey?: string;
58
+ cacheResponse?: boolean;
59
+ };
60
60
  messages?: {
61
- role: "system" | "assistant" | "user" | "tool";
61
+ role?: "system" | "assistant" | "user" | "tool";
62
62
  content?: any;
63
- }[] | undefined;
64
- prompt?: string | undefined;
65
- messagesSearchTag?: string | undefined;
66
- tools?: string[] | undefined;
63
+ }[];
64
+ prompt?: string;
65
+ messagesSearchTag?: string;
66
+ tools?: string[];
67
67
  }>;
68
68
  type AiGenerateTextArgsType = z.infer<typeof AiGenerateTextSchema>;
69
69
  export declare class AiGenerateText extends ToolBase<AiGenerateTextArgsType> {
@@ -72,6 +72,7 @@ let AiGenerateText = class AiGenerateText extends core_1.ToolBase {
72
72
  resolve(data.responseMessage);
73
73
  },
74
74
  });
75
+ // Consume the stream to trigger execution
75
76
  (async () => {
76
77
  try {
77
78
  const reader = stream.getReader();
@@ -1 +1 @@
1
- {"version":3,"file":"ai-generate-text.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAwB;AACxB,8CAA2E;AAC3E,0CAAyD;AACzD,0CAAsD;AACtD,0CAA2D;AAC3D,0CAAmD;AACnD,2BAKY;AAE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Aa,EAAC,4BAAoB,CAAC;qCAGU,kCAAuB;QAC1B,+BAAoB;QACZ,uCAA4B;GAJlE,cAAc,CA4F1B"}
@@ -10,45 +10,45 @@ declare const DelegateToolCallsToolSchema: z.ZodObject<{
10
10
  input: z.ZodAny;
11
11
  toolCallId: z.ZodString;
12
12
  }, "strip", z.ZodTypeAny, {
13
- type: string;
14
- toolCallId: string;
13
+ type?: string;
15
14
  input?: any;
15
+ toolCallId?: string;
16
16
  }, {
17
- type: string;
18
- toolCallId: string;
17
+ type?: string;
19
18
  input?: any;
19
+ toolCallId?: string;
20
20
  }>, "many">;
21
21
  }, "strip", z.ZodTypeAny, {
22
- id: string;
23
- parts: {
24
- type: string;
25
- toolCallId: string;
22
+ id?: string;
23
+ parts?: {
24
+ type?: string;
26
25
  input?: any;
26
+ toolCallId?: string;
27
27
  }[];
28
28
  }, {
29
- id: string;
30
- parts: {
31
- type: string;
32
- toolCallId: string;
29
+ id?: string;
30
+ parts?: {
31
+ type?: string;
33
32
  input?: any;
33
+ toolCallId?: string;
34
34
  }[];
35
35
  }>;
36
36
  }, "strip", z.ZodTypeAny, {
37
- message: {
38
- id: string;
39
- parts: {
40
- type: string;
41
- toolCallId: string;
37
+ message?: {
38
+ id?: string;
39
+ parts?: {
40
+ type?: string;
42
41
  input?: any;
42
+ toolCallId?: string;
43
43
  }[];
44
44
  };
45
45
  }, {
46
- message: {
47
- id: string;
48
- parts: {
49
- type: string;
50
- toolCallId: string;
46
+ message?: {
47
+ id?: string;
48
+ parts?: {
49
+ type?: string;
51
50
  input?: any;
51
+ toolCallId?: string;
52
52
  }[];
53
53
  };
54
54
  }>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@loopstack/ai-module",
3
3
  "displayName": "Loopstack Ai Module",
4
4
  "description": "A collection of useful tools for performing AI actions using model provider APIs such as OpenAI and Anthropic",
5
- "version": "0.16.0",
5
+ "version": "0.16.1",
6
6
  "author": {
7
7
  "name": "Jakob Klippel",
8
8
  "url": "https://www.linkedin.com/in/jakob-klippel/"