@loopstack/ai-module 0.15.1 → 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 +4 -0
- package/README.md +260 -1
- package/dist/ai.module.js +4 -0
- package/dist/ai.module.js.map +1 -1
- package/dist/services/ai-provider-model-helper.service.d.ts +1 -1
- package/dist/services/ai-provider-model-helper.service.js +4 -4
- package/dist/services/ai-provider-model-helper.service.js.map +1 -1
- package/dist/services/ai-tools-helper.service.js +2 -1
- package/dist/services/ai-tools-helper.service.js.map +1 -1
- package/dist/tools/ai-generate-document.tool.d.ts +4 -4
- package/dist/tools/ai-generate-document.tool.js +9 -2
- package/dist/tools/ai-generate-document.tool.js.map +1 -1
- package/dist/tools/ai-generate-object.tool.js +4 -2
- package/dist/tools/ai-generate-object.tool.js.map +1 -1
- package/dist/tools/ai-generate-text.tool.js +8 -10
- package/dist/tools/ai-generate-text.tool.js.map +1 -1
- package/dist/tools/delegate-tool-call.tool.d.ts +46 -3
- package/dist/tools/delegate-tool-call.tool.js +11 -1
- package/dist/tools/delegate-tool-call.tool.js.map +1 -1
- package/package.json +4 -5
package/.prettierrc
ADDED
package/README.md
CHANGED
|
@@ -1,2 +1,261 @@
|
|
|
1
|
-
#
|
|
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: [
|
package/dist/ai.module.js.map
CHANGED
|
@@ -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;
|
|
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"}
|
|
@@ -27,7 +27,7 @@ let AiProviderModelHelperService = class AiProviderModelHelperService {
|
|
|
27
27
|
}
|
|
28
28
|
getModel(modelName) {
|
|
29
29
|
const model = modelName ?? process.env['DEFAULT_MODEL'];
|
|
30
|
-
if (!
|
|
30
|
+
if (!model) {
|
|
31
31
|
throw new Error(`No Model defined. Please provide DEFAULT_MODEL or set the model parameter in the completion service call.`);
|
|
32
32
|
}
|
|
33
33
|
return model;
|
|
@@ -40,9 +40,9 @@ let AiProviderModelHelperService = class AiProviderModelHelperService {
|
|
|
40
40
|
return provider;
|
|
41
41
|
}
|
|
42
42
|
getProviderModel(config) {
|
|
43
|
-
const modelName = this.getModel(config
|
|
44
|
-
const providerName = this.getProvider(config
|
|
45
|
-
const apiKey = this.getApiKey(config
|
|
43
|
+
const modelName = this.getModel(config?.model);
|
|
44
|
+
const providerName = this.getProvider(config?.provider);
|
|
45
|
+
const apiKey = this.getApiKey(config?.envApiKey, providerName);
|
|
46
46
|
return this.aiProviderRegistry.createModel(providerName, {
|
|
47
47
|
apiKey: apiKey,
|
|
48
48
|
model: modelName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-provider-model-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-provider-model-helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,iFAA2E;AAUpE,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACV;IAA7B,YAA6B,kBAA6C;QAA7C,uBAAkB,GAAlB,kBAAkB,CAA2B;IAAG,CAAC;IAEtE,SAAS,CACf,SAA6B,EAC7B,YAAoB;QAEpB,MAAM,UAAU,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,UAAU,CAAC;QAC3D,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAE5E,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,kDAAkD,SAAS,IAAI,UAAU,sBAAsB,CAChG,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,QAAQ,CAAC,SAA6B;QAC5C,MAAM,KAAK,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAExD,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"ai-provider-model-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-provider-model-helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,iFAA2E;AAUpE,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACV;IAA7B,YAA6B,kBAA6C;QAA7C,uBAAkB,GAAlB,kBAAkB,CAA2B;IAAG,CAAC;IAEtE,SAAS,CACf,SAA6B,EAC7B,YAAoB;QAEpB,MAAM,UAAU,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,UAAU,CAAC;QAC3D,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAE5E,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,kDAAkD,SAAS,IAAI,UAAU,sBAAsB,CAChG,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,QAAQ,CAAC,SAA6B;QAC5C,MAAM,KAAK,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAExD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CACb,2GAA2G,CAC5G,CAAC;QACJ,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,WAAW,CAAC,IAAwB;QAC1C,MAAM,QAAQ,GAAG,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAEzD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CAAC,MAA8B;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAC/C,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;QAE/D,OAAO,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,YAAY,EAAE;YACvD,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArDY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,mBAAU,GAAE;qCAEsC,wDAAyB;GAD/D,4BAA4B,CAqDxC"}
|
|
@@ -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;
|
|
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"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ToolResult } from '@loopstack/common';
|
|
2
2
|
import { Block, ToolBase } from '@loopstack/core';
|
|
3
|
-
import {
|
|
3
|
+
import { AiGenerateObjectArgsType } from './ai-generate-object.tool';
|
|
4
4
|
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
5
|
-
import { CreateDocument } from '@loopstack/core-ui-module';
|
|
6
5
|
export declare class AiGenerateDocument extends ToolBase<AiGenerateObjectArgsType> {
|
|
7
|
-
aiGenerateObject
|
|
8
|
-
createDocument
|
|
6
|
+
private aiGenerateObject;
|
|
7
|
+
private createDocument;
|
|
8
|
+
private getRequiredTool;
|
|
9
9
|
execute(args: AiGenerateObjectArgsType, ctx: WorkflowExecution, parent: Block): Promise<ToolResult>;
|
|
10
10
|
}
|
|
@@ -18,9 +18,16 @@ const core_ui_module_1 = require("@loopstack/core-ui-module");
|
|
|
18
18
|
let AiGenerateDocument = class AiGenerateDocument extends core_1.ToolBase {
|
|
19
19
|
aiGenerateObject;
|
|
20
20
|
createDocument;
|
|
21
|
+
getRequiredTool(name) {
|
|
22
|
+
const tool = this.getTool(name);
|
|
23
|
+
if (tool === undefined) {
|
|
24
|
+
throw new Error(`Tool "${name}" is not available`);
|
|
25
|
+
}
|
|
26
|
+
return tool;
|
|
27
|
+
}
|
|
21
28
|
async execute(args, ctx, parent) {
|
|
22
|
-
const result = await this.
|
|
23
|
-
return this.
|
|
29
|
+
const result = await this.getRequiredTool('aiGenerateObject').execute(args, ctx, parent);
|
|
30
|
+
return this.getRequiredTool('createDocument').execute({
|
|
24
31
|
id: args.response.id,
|
|
25
32
|
document: args.response.document,
|
|
26
33
|
update: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-document.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-document.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"ai-generate-document.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-document.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAoD;AACpD,8CAK2B;AAC3B,0CAAkD;AAClD,uEAImC;AAEnC,8DAA2D;AAUpD,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,eAAkC;IACxD,gBAAgB,CAAoB;IACpC,cAAc,CAAkB;IAExC,eAAe,CAAC,IAAY;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,oBAAoB,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAA8B,EAC9B,GAAsB,EACtB,MAAa;QAEb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,OAAO,CACnE,IAAI,EACJ,GAAG,EACH,MAAM,CACP,CAAC;QACF,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,OAAO,CACnD;YACE,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAChC,MAAM,EAAE;gBACN,OAAO,EAAE,MAAM,CAAC,IAAI;aACrB;SACF,EACD,GAAG,EACH,MAAM,CACP,CAAC;IACJ,CAAC;CACF,CAAA;AAlCY,gDAAkB;AACb;IAAf,IAAA,aAAI,GAAE;8BAA4B,0CAAgB;4DAAC;AACpC;IAAf,IAAA,aAAI,GAAE;8BAA0B,+BAAc;0DAAC;6BAFrC,kBAAkB;IAR9B,IAAA,mBAAU,GAAE;IACZ,IAAA,oBAAW,EAAC;QACX,MAAM,EAAE;YACN,WAAW,EACT,sEAAsE;SACzE;KACF,CAAC;IACD,IAAA,sBAAa,EAAC,gDAAsB,CAAC;GACzB,kBAAkB,CAkC9B"}
|
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AiGenerateObject = exports.AiGenerateObjectSchema = void 0;
|
|
13
13
|
const zod_1 = require("zod");
|
|
14
14
|
const common_1 = require("@loopstack/common");
|
|
15
|
-
const lodash_1 = require("lodash");
|
|
16
15
|
const ai_1 = require("ai");
|
|
17
16
|
const core_1 = require("@loopstack/core");
|
|
18
17
|
const services_1 = require("../services");
|
|
@@ -39,7 +38,10 @@ let AiGenerateObject = class AiGenerateObject extends core_1.ToolBase {
|
|
|
39
38
|
options.prompt = args.prompt;
|
|
40
39
|
}
|
|
41
40
|
else {
|
|
42
|
-
const messages = this.aiMessagesHelperService.getMessages(ctx.state.getMetadata('documents'),
|
|
41
|
+
const messages = this.aiMessagesHelperService.getMessages(ctx.state.getMetadata('documents'), {
|
|
42
|
+
messages: args.messages,
|
|
43
|
+
messagesSearchTag: args.messagesSearchTag,
|
|
44
|
+
});
|
|
43
45
|
options.messages = (0, ai_1.convertToModelMessages)(messages);
|
|
44
46
|
}
|
|
45
47
|
const document = parent.getDocument(args.response.document);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-object.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-object.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAwB;AACxB,8CAA2E;AAC3E,
|
|
1
|
+
{"version":3,"file":"ai-generate-object.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-object.tool.ts"],"names":[],"mappings":";;;;;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exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AiGenerateText = exports.AiGenerateTextSchema = void 0;
|
|
13
13
|
const zod_1 = require("zod");
|
|
14
14
|
const common_1 = require("@loopstack/common");
|
|
15
|
-
const lodash_1 = require("lodash");
|
|
16
15
|
const core_1 = require("@loopstack/core");
|
|
17
16
|
const services_1 = require("../services");
|
|
18
17
|
const services_2 = require("../services");
|
|
@@ -42,7 +41,10 @@ let AiGenerateText = class AiGenerateText extends core_1.ToolBase {
|
|
|
42
41
|
options.prompt = args.prompt;
|
|
43
42
|
}
|
|
44
43
|
else {
|
|
45
|
-
const messages = this.aiMessagesHelperService.getMessages(ctx.state.getMetadata('documents'),
|
|
44
|
+
const messages = this.aiMessagesHelperService.getMessages(ctx.state.getMetadata('documents'), {
|
|
45
|
+
messages: args.messages,
|
|
46
|
+
messagesSearchTag: args.messagesSearchTag,
|
|
47
|
+
});
|
|
46
48
|
options.messages = (0, ai_1.convertToModelMessages)(messages, {
|
|
47
49
|
tools: options.tools,
|
|
48
50
|
});
|
|
@@ -66,15 +68,11 @@ let AiGenerateText = class AiGenerateText extends core_1.ToolBase {
|
|
|
66
68
|
sendReasoning: true,
|
|
67
69
|
}));
|
|
68
70
|
},
|
|
69
|
-
onFinish:
|
|
70
|
-
|
|
71
|
-
resolve(data.responseMessage);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
reject(error);
|
|
75
|
-
}
|
|
71
|
+
onFinish: (data) => {
|
|
72
|
+
resolve(data.responseMessage);
|
|
76
73
|
},
|
|
77
74
|
});
|
|
75
|
+
// Consume the stream to trigger execution
|
|
78
76
|
(async () => {
|
|
79
77
|
try {
|
|
80
78
|
const reader = stream.getReader();
|
|
@@ -85,7 +83,7 @@ let AiGenerateText = class AiGenerateText extends core_1.ToolBase {
|
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
catch (error) {
|
|
88
|
-
reject(error);
|
|
86
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
89
87
|
}
|
|
90
88
|
})();
|
|
91
89
|
});
|
|
@@ -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,
|
|
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;AAEZ,0FAAmF;AAGtE,QAAA,oBAAoB,GAAG,uDAAwB,CAAC,MAAM,CAAC;IAClE,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC,MAAM,EAAE,CAAC;AAUL,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,eAAgC;IAE/C;IACA;IACA;IAHnB,YACmB,uBAAgD,EAChD,oBAA0C,EAC1C,4BAA0D;QAE3E,KAAK,EAAE,CAAC;QAJS,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,iCAA4B,GAA5B,4BAA4B,CAA8B;IAG7E,CAAC;IAED,KAAK,CAAC,OAAO,CACX,IAA4B,EAC5B,GAAsB,EACtB,MAAoB;QAEpB,MAAM,KAAK,GAAG,IAAI,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3E,MAAM,OAAO,GAIT,EAAE,CAAC;QAEP,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK;YACxB,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;YACxD,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AC,CAAC;gBAEH,0CAA0C;gBAC1C,CAAC,KAAK,IAAI,EAAE;oBACV,IAAI,CAAC;wBACH,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;wBAClC,OAAO,IAAI,EAAE,CAAC;4BACZ,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;4BACrC,IAAI,IAAI;gCAAE,MAAM;wBAClB,CAAC;oBACH,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,MAAM,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBACpE,CAAC;gBACH,CAAC,CAAC,EAAE,CAAC;YACP,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YACxD,OAAO,CAAC,KAAK,CAAC,wBAAwB,iBAAiB,KAAK,EAAE,KAAK,CAAC,CAAC;YACrE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAA;AA5FY,wCAAc;yBAAd,cAAc;IAN1B,IAAA,oBAAW,EAAC;QACX,MAAM,EAAE;YACN,WAAW,EAAE,4BAA4B;SAC1C;KACF,CAAC;IACD,IAAA,sBAAa,EAAC,4BAAoB,CAAC;qCAGU,kCAAuB;QAC1B,+BAAoB;QACZ,uCAA4B;GAJlE,cAAc,CA4F1B"}
|
|
@@ -3,11 +3,54 @@ import { z } from 'zod';
|
|
|
3
3
|
import { ToolBase, WorkflowBase } from '@loopstack/core';
|
|
4
4
|
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
5
5
|
declare const DelegateToolCallsToolSchema: z.ZodObject<{
|
|
6
|
-
message: z.
|
|
6
|
+
message: z.ZodObject<{
|
|
7
|
+
id: z.ZodString;
|
|
8
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
9
|
+
type: z.ZodString;
|
|
10
|
+
input: z.ZodAny;
|
|
11
|
+
toolCallId: z.ZodString;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
type?: string;
|
|
14
|
+
input?: any;
|
|
15
|
+
toolCallId?: string;
|
|
16
|
+
}, {
|
|
17
|
+
type?: string;
|
|
18
|
+
input?: any;
|
|
19
|
+
toolCallId?: string;
|
|
20
|
+
}>, "many">;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
id?: string;
|
|
23
|
+
parts?: {
|
|
24
|
+
type?: string;
|
|
25
|
+
input?: any;
|
|
26
|
+
toolCallId?: string;
|
|
27
|
+
}[];
|
|
28
|
+
}, {
|
|
29
|
+
id?: string;
|
|
30
|
+
parts?: {
|
|
31
|
+
type?: string;
|
|
32
|
+
input?: any;
|
|
33
|
+
toolCallId?: string;
|
|
34
|
+
}[];
|
|
35
|
+
}>;
|
|
7
36
|
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
message?:
|
|
37
|
+
message?: {
|
|
38
|
+
id?: string;
|
|
39
|
+
parts?: {
|
|
40
|
+
type?: string;
|
|
41
|
+
input?: any;
|
|
42
|
+
toolCallId?: string;
|
|
43
|
+
}[];
|
|
44
|
+
};
|
|
9
45
|
}, {
|
|
10
|
-
message?:
|
|
46
|
+
message?: {
|
|
47
|
+
id?: string;
|
|
48
|
+
parts?: {
|
|
49
|
+
type?: string;
|
|
50
|
+
input?: any;
|
|
51
|
+
toolCallId?: string;
|
|
52
|
+
}[];
|
|
53
|
+
};
|
|
11
54
|
}>;
|
|
12
55
|
type DelegateToolCallsToolArgs = z.infer<typeof DelegateToolCallsToolSchema>;
|
|
13
56
|
export declare class DelegateToolCall extends ToolBase<DelegateToolCallsToolArgs> {
|
|
@@ -11,7 +11,14 @@ const common_1 = require("@loopstack/common");
|
|
|
11
11
|
const zod_1 = require("zod");
|
|
12
12
|
const core_1 = require("@loopstack/core");
|
|
13
13
|
const DelegateToolCallsToolSchema = zod_1.z.object({
|
|
14
|
-
message: zod_1.z.
|
|
14
|
+
message: zod_1.z.object({
|
|
15
|
+
id: zod_1.z.string(),
|
|
16
|
+
parts: zod_1.z.array(zod_1.z.object({
|
|
17
|
+
type: zod_1.z.string(),
|
|
18
|
+
input: zod_1.z.any(),
|
|
19
|
+
toolCallId: zod_1.z.string(),
|
|
20
|
+
})),
|
|
21
|
+
}),
|
|
15
22
|
});
|
|
16
23
|
let DelegateToolCall = class DelegateToolCall extends core_1.ToolBase {
|
|
17
24
|
async execute(args, ctx, parent) {
|
|
@@ -23,6 +30,9 @@ let DelegateToolCall = class DelegateToolCall extends core_1.ToolBase {
|
|
|
23
30
|
}
|
|
24
31
|
const toolName = part.type.replace(/^tool-/, '');
|
|
25
32
|
const tool = parent.getTool(toolName);
|
|
33
|
+
if (!tool) {
|
|
34
|
+
throw new Error(`Tool ${toolName} not found.`);
|
|
35
|
+
}
|
|
26
36
|
const result = await tool.execute(part.input, ctx, parent);
|
|
27
37
|
resultParts.push({
|
|
28
38
|
type: part.type,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-tool-call.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA2E;AAC3E,6BAAwB;AACxB,0CAAyD;AAIzD,MAAM,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"delegate-tool-call.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA2E;AAC3E,6BAAwB;AACxB,0CAAyD;AAIzD,MAAM,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,MAAM,C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,IAAI;iBACnB;gBACD,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,KAAK,EAAE,kBAAkB;aACL,CAAC,CAAC;QAC1B,CAAC;QAED,MAAM,aAAa,GAAG;YACpB,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;YACnB,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,WAAW;SACC,CAAC;QAEtB,OAAO;YACL,IAAI,EAAE,aAAa;SACpB,CAAC;IACJ,CAAC;CACF,CAAA;AA5CY,4CAAgB;2BAAhB,gBAAgB;IAN5B,IAAA,oBAAW,EAAC;QACX,MAAM,EAAE;YACN,WAAW,EAAE,uBAAuB;SACrC;KACF,CAAC;IACD,IAAA,sBAAa,EAAC,2BAA2B,CAAC;GAC9B,gBAAgB,CA4C5B"}
|
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.
|
|
5
|
+
"version": "0.16.1",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Jakob Klippel",
|
|
8
8
|
"url": "https://www.linkedin.com/in/jakob-klippel/"
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"build": "nest build",
|
|
23
23
|
"watch": "nest build --watch",
|
|
24
24
|
"compile": "tsc --noEmit",
|
|
25
|
-
"prepare": "npm run build",
|
|
26
25
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
27
26
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
28
27
|
"test": "jest",
|
|
@@ -42,9 +41,9 @@
|
|
|
42
41
|
"@ai-sdk/anthropic": "^2.0.1",
|
|
43
42
|
"@ai-sdk/openai": "^2.0.4",
|
|
44
43
|
"@ai-sdk/provider-utils": "^3.0.8",
|
|
45
|
-
"@loopstack/common": "^0.
|
|
46
|
-
"@loopstack/core": "^0.
|
|
47
|
-
"@loopstack/core-ui-module": "^0.
|
|
44
|
+
"@loopstack/common": "^0.16.0",
|
|
45
|
+
"@loopstack/core": "^0.16.0",
|
|
46
|
+
"@loopstack/core-ui-module": "^0.16.0",
|
|
48
47
|
"ai": "^5.0.6",
|
|
49
48
|
"lodash": "^4.17.21",
|
|
50
49
|
"zod": "^3.24.1"
|