@loopstack/ai-module 0.16.4 → 0.18.0-rc.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/README.md +33 -31
- package/dist/ai.module.js +8 -14
- package/dist/ai.module.js.map +1 -1
- package/dist/documents/ai-message-document.js +6 -10
- package/dist/documents/ai-message-document.js.map +1 -1
- package/dist/providers/anthropic.provider.d.ts +2 -1
- package/dist/providers/anthropic.provider.js.map +1 -1
- package/dist/providers/openai.provider.d.ts +2 -1
- package/dist/providers/openai.provider.js.map +1 -1
- package/dist/schemas/ai-generate-tool-base.schema.d.ts +9 -46
- package/dist/services/ai-messages-helper.service.d.ts +3 -3
- package/dist/services/ai-messages-helper.service.js.map +1 -1
- package/dist/services/ai-provider-model-helper.service.d.ts +2 -1
- package/dist/services/ai-provider-model-helper.service.js.map +1 -1
- package/dist/services/ai-provider-registry.service.d.ts +2 -1
- package/dist/services/ai-provider-registry.service.js +1 -1
- package/dist/services/ai-provider-registry.service.js.map +1 -1
- package/dist/services/ai-tools-helper.service.js.map +1 -1
- package/dist/tools/ai-generate-document.tool.d.ts +3 -3
- package/dist/tools/ai-generate-document.tool.js +1 -1
- package/dist/tools/ai-generate-document.tool.js.map +1 -1
- package/dist/tools/ai-generate-object.tool.d.ts +11 -63
- package/dist/tools/ai-generate-object.tool.js +16 -8
- package/dist/tools/ai-generate-object.tool.js.map +1 -1
- package/dist/tools/ai-generate-text.tool.d.ts +11 -51
- package/dist/tools/ai-generate-text.tool.js +17 -12
- package/dist/tools/ai-generate-text.tool.js.map +1 -1
- package/dist/tools/delegate-tool-call.tool.d.ts +4 -44
- package/dist/tools/delegate-tool-call.tool.js +1 -1
- package/dist/tools/delegate-tool-call.tool.js.map +1 -1
- package/package.json +35 -66
- package/src/ai.module.ts +38 -0
- package/src/documents/ai-message-document.ts +22 -0
- package/src/documents/ai-message-document.yaml +5 -0
- package/src/documents/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/providers/anthropic.provider.ts +18 -0
- package/src/providers/openai.provider.ts +18 -0
- package/src/schemas/ai-generate-tool-base.schema.ts +22 -0
- package/src/services/ai-messages-helper.service.ts +28 -0
- package/src/services/ai-provider-model-helper.service.ts +61 -0
- package/src/services/ai-provider-registry.service.ts +73 -0
- package/src/services/ai-tools-helper.service.ts +28 -0
- package/src/services/index.ts +4 -0
- package/src/tools/ai-generate-document.tool.ts +41 -0
- package/src/tools/ai-generate-object.tool.ts +109 -0
- package/src/tools/ai-generate-text.tool.ts +119 -0
- package/src/tools/delegate-tool-call.tool.ts +72 -0
- package/src/tools/index.ts +4 -0
- package/.prettierrc +0 -4
- package/LICENSE +0 -19
- package/tsconfig.build.json +0 -4
package/README.md
CHANGED
|
@@ -69,8 +69,8 @@ Add `AiModule` to your `default.module.ts` (included in the skeleton app) or to
|
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
71
|
import { Module } from '@nestjs/common';
|
|
72
|
-
import { LoopCoreModule } from '@loopstack/core';
|
|
73
72
|
import { AiModule } from '@loopstack/ai-module';
|
|
73
|
+
import { LoopCoreModule } from '@loopstack/core';
|
|
74
74
|
import { DefaultWorkspace } from './default.workspace';
|
|
75
75
|
|
|
76
76
|
@Module({
|
|
@@ -86,15 +86,15 @@ Inject the tools and documents in your workflow class:
|
|
|
86
86
|
|
|
87
87
|
```typescript
|
|
88
88
|
import { Injectable } from '@nestjs/common';
|
|
89
|
-
import { BlockConfig, Document, Tool, Helper } from '@loopstack/common';
|
|
90
|
-
import { WorkflowBase } from '@loopstack/core';
|
|
91
89
|
import {
|
|
92
|
-
AiGenerateText,
|
|
93
|
-
AiGenerateObject,
|
|
94
90
|
AiGenerateDocument,
|
|
95
|
-
|
|
91
|
+
AiGenerateObject,
|
|
92
|
+
AiGenerateText,
|
|
96
93
|
AiMessageDocument,
|
|
94
|
+
DelegateToolCall,
|
|
97
95
|
} from '@loopstack/ai-module';
|
|
96
|
+
import { BlockConfig, Document, Helper, Tool } from '@loopstack/common';
|
|
97
|
+
import { WorkflowBase } from '@loopstack/core';
|
|
98
98
|
|
|
99
99
|
@Injectable()
|
|
100
100
|
@BlockConfig({
|
|
@@ -120,15 +120,15 @@ Generates text using an LLM with optional tool calling support.
|
|
|
120
120
|
|
|
121
121
|
#### Arguments
|
|
122
122
|
|
|
123
|
-
| Argument
|
|
124
|
-
|
|
125
|
-
| `llm.provider`
|
|
126
|
-
| `llm.model`
|
|
127
|
-
| `llm.envApiKey`
|
|
128
|
-
| `prompt`
|
|
129
|
-
| `messages`
|
|
130
|
-
| `messagesSearchTag` | string
|
|
131
|
-
| `tools`
|
|
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
132
|
|
|
133
133
|
#### Example
|
|
134
134
|
|
|
@@ -151,15 +151,15 @@ Generates a structured object using an LLM that conforms to a document schema.
|
|
|
151
151
|
|
|
152
152
|
#### Arguments
|
|
153
153
|
|
|
154
|
-
| Argument
|
|
155
|
-
|
|
156
|
-
| `llm.provider`
|
|
157
|
-
| `llm.model`
|
|
158
|
-
| `prompt`
|
|
159
|
-
| `messages`
|
|
160
|
-
| `messagesSearchTag` | string | No
|
|
161
|
-
| `response.document` | string | Yes
|
|
162
|
-
| `response.id`
|
|
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
163
|
|
|
164
164
|
#### Example
|
|
165
165
|
|
|
@@ -169,7 +169,7 @@ Generates a structured object using an LLM that conforms to a document schema.
|
|
|
169
169
|
llm:
|
|
170
170
|
provider: anthropic
|
|
171
171
|
model: claude-3-sonnet
|
|
172
|
-
prompt:
|
|
172
|
+
prompt: 'Extract the key information from this text: {{ inputText }}'
|
|
173
173
|
response:
|
|
174
174
|
document: infoDocument
|
|
175
175
|
assign:
|
|
@@ -203,11 +203,11 @@ Executes tool calls requested by the LLM and returns the results in the expected
|
|
|
203
203
|
|
|
204
204
|
#### Arguments
|
|
205
205
|
|
|
206
|
-
| Argument
|
|
207
|
-
|
|
208
|
-
| `message`
|
|
209
|
-
| `message.id`
|
|
210
|
-
| `message.parts` | array
|
|
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
211
|
|
|
212
212
|
#### Example
|
|
213
213
|
|
|
@@ -226,6 +226,7 @@ Executes tool calls requested by the LLM and returns the results in the expected
|
|
|
226
226
|
Represents an AI conversation message with support for multi-part content (text, tool calls, tool results).
|
|
227
227
|
|
|
228
228
|
**Schema:**
|
|
229
|
+
|
|
229
230
|
```typescript
|
|
230
231
|
{
|
|
231
232
|
id?: string; // Message identifier
|
|
@@ -236,6 +237,7 @@ Represents an AI conversation message with support for multi-part content (text,
|
|
|
236
237
|
```
|
|
237
238
|
|
|
238
239
|
**Example:**
|
|
240
|
+
|
|
239
241
|
```yaml
|
|
240
242
|
- tool: createDocument
|
|
241
243
|
args:
|
|
@@ -258,4 +260,4 @@ License: Apache-2.0
|
|
|
258
260
|
|
|
259
261
|
- [Loopstack Documentation](https://loopstack.ai/docs)
|
|
260
262
|
- [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)
|
|
263
|
+
- 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
|
@@ -8,23 +8,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AiModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
|
-
const core_1 = require("@
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const core_1 = require("@nestjs/core");
|
|
12
|
+
const core_2 = require("@loopstack/core");
|
|
13
|
+
const core_ui_module_1 = require("@loopstack/core-ui-module");
|
|
14
|
+
const documents_1 = require("./documents");
|
|
14
15
|
const anthropic_provider_1 = require("./providers/anthropic.provider");
|
|
15
|
-
const
|
|
16
|
+
const openai_provider_1 = require("./providers/openai.provider");
|
|
16
17
|
const services_1 = require("./services");
|
|
17
18
|
const services_2 = require("./services");
|
|
18
19
|
const services_3 = require("./services");
|
|
20
|
+
const ai_provider_registry_service_1 = require("./services/ai-provider-registry.service");
|
|
19
21
|
const tools_1 = require("./tools");
|
|
20
|
-
const documents_1 = require("./documents");
|
|
21
|
-
const core_ui_module_1 = require("@loopstack/core-ui-module");
|
|
22
22
|
let AiModule = class AiModule {
|
|
23
23
|
};
|
|
24
24
|
exports.AiModule = AiModule;
|
|
25
25
|
exports.AiModule = AiModule = __decorate([
|
|
26
26
|
(0, common_1.Module)({
|
|
27
|
-
imports: [
|
|
27
|
+
imports: [core_2.LoopCoreModule, core_ui_module_1.CoreUiModule, core_1.DiscoveryModule],
|
|
28
28
|
providers: [
|
|
29
29
|
services_1.AiMessagesHelperService,
|
|
30
30
|
services_2.AiProviderModelHelperService,
|
|
@@ -38,13 +38,7 @@ exports.AiModule = AiModule = __decorate([
|
|
|
38
38
|
tools_1.DelegateToolCall,
|
|
39
39
|
documents_1.AiMessageDocument,
|
|
40
40
|
],
|
|
41
|
-
exports: [
|
|
42
|
-
tools_1.AiGenerateDocument,
|
|
43
|
-
tools_1.AiGenerateObject,
|
|
44
|
-
tools_1.AiGenerateText,
|
|
45
|
-
tools_1.DelegateToolCall,
|
|
46
|
-
documents_1.AiMessageDocument,
|
|
47
|
-
],
|
|
41
|
+
exports: [tools_1.AiGenerateDocument, tools_1.AiGenerateObject, tools_1.AiGenerateText, tools_1.DelegateToolCall, documents_1.AiMessageDocument],
|
|
48
42
|
})
|
|
49
43
|
], AiModule);
|
|
50
44
|
//# sourceMappingURL=ai.module.js.map
|
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,
|
|
1
|
+
{"version":3,"file":"ai.module.js","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uCAA+C;AAC/C,0CAAiD;AACjD,8DAAyD;AACzD,2CAAgD;AAChD,uEAA0E;AAC1E,iEAAoE;AACpE,yCAAqD;AACrD,yCAA0D;AAC1D,yCAAkD;AAClD,0FAAoF;AACpF,mCAAiG;AA0B1F,IAAM,QAAQ,GAAd,MAAM,QAAQ;CAAG,CAAA;AAAX,4BAAQ;mBAAR,QAAQ;IAxBpB,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,CAAC,0BAAkB,EAAE,wBAAgB,EAAE,sBAAc,EAAE,wBAAgB,EAAE,6BAAiB,CAAC;KACrG,CAAC;GACW,QAAQ,CAAG"}
|
|
@@ -7,17 +7,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AiMessageDocument = void 0;
|
|
10
|
-
const common_1 = require("@
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
11
|
const zod_1 = require("zod");
|
|
12
|
-
const common_2 = require("@
|
|
12
|
+
const common_2 = require("@loopstack/common");
|
|
13
13
|
const core_1 = require("@loopstack/core");
|
|
14
14
|
const AiMessageDocumentSchema = zod_1.z.object({
|
|
15
15
|
id: zod_1.z.string().optional(),
|
|
16
|
-
role: zod_1.z.union([
|
|
17
|
-
zod_1.z.literal('system'),
|
|
18
|
-
zod_1.z.literal('user'),
|
|
19
|
-
zod_1.z.literal('assistant'),
|
|
20
|
-
]),
|
|
16
|
+
role: zod_1.z.union([zod_1.z.literal('system'), zod_1.z.literal('user'), zod_1.z.literal('assistant')]),
|
|
21
17
|
metadata: zod_1.z.any().optional(),
|
|
22
18
|
parts: zod_1.z.array(zod_1.z.any()),
|
|
23
19
|
});
|
|
@@ -25,14 +21,14 @@ let AiMessageDocument = class AiMessageDocument extends core_1.DocumentBase {
|
|
|
25
21
|
};
|
|
26
22
|
exports.AiMessageDocument = AiMessageDocument;
|
|
27
23
|
exports.AiMessageDocument = AiMessageDocument = __decorate([
|
|
28
|
-
(0,
|
|
29
|
-
(0,
|
|
24
|
+
(0, common_1.Injectable)(),
|
|
25
|
+
(0, common_2.BlockConfig)({
|
|
30
26
|
config: {
|
|
31
27
|
type: 'document',
|
|
32
28
|
description: 'Ai Message Document.',
|
|
33
29
|
},
|
|
34
30
|
configFile: __dirname + '/ai-message-document.yaml',
|
|
35
31
|
}),
|
|
36
|
-
(0,
|
|
32
|
+
(0, common_2.WithArguments)(AiMessageDocumentSchema)
|
|
37
33
|
], AiMessageDocument);
|
|
38
34
|
//# sourceMappingURL=ai-message-document.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-message-document.js","sourceRoot":"","sources":["../../src/documents/ai-message-document.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"ai-message-document.js","sourceRoot":"","sources":["../../src/documents/ai-message-document.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,6BAAwB;AACxB,8CAA+D;AAC/D,0CAA+C;AAE/C,MAAM,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IACvC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzB,IAAI,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC/E,QAAQ,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAC5B,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;CACxB,CAAC,CAAC;AAWI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,mBAAY;CAAG,CAAA;AAAzC,8CAAiB;4BAAjB,iBAAiB;IAT7B,IAAA,mBAAU,GAAE;IACZ,IAAA,oBAAW,EAAC;QACX,MAAM,EAAE;YACN,IAAI,EAAE,UAAU;YAChB,WAAW,EAAE,sBAAsB;SACpC;QACD,UAAU,EAAE,SAAS,GAAG,2BAA2B;KACpD,CAAC;IACD,IAAA,sBAAa,EAAC,uBAAuB,CAAC;GAC1B,iBAAiB,CAAwB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
1
2
|
import { AiProviderInterface, AiProviderOptions } from '@loopstack/common';
|
|
2
3
|
export declare class AnthropicProviderService implements AiProviderInterface {
|
|
3
4
|
createClient(options: AiProviderOptions): import("@ai-sdk/anthropic").AnthropicProvider;
|
|
4
|
-
getModel(client:
|
|
5
|
+
getModel(client: ReturnType<typeof createAnthropic>, model: string): import("@ai-sdk/provider").LanguageModelV3;
|
|
5
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.provider.js","sourceRoot":"","sources":["../../src/providers/anthropic.provider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iDAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"anthropic.provider.js","sourceRoot":"","sources":["../../src/providers/anthropic.provider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iDAAoD;AACpD,8CAAuF;AAKhF,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACnC,YAAY,CAAC,OAA0B;QACrC,OAAO,IAAA,2BAAe,EAAC;YACrB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,MAA0C,EAAE,KAAa;QAChE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF,CAAA;AAXY,4DAAwB;mCAAxB,wBAAwB;IAHpC,IAAA,mBAAU,EAAC;QACV,IAAI,EAAE,WAAW;KAClB,CAAC;GACW,wBAAwB,CAWpC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createOpenAI } from '@ai-sdk/openai';
|
|
1
2
|
import { AiProviderInterface, AiProviderOptions } from '@loopstack/common';
|
|
2
3
|
export declare class OpenAiProviderService implements AiProviderInterface {
|
|
3
4
|
createClient(options: AiProviderOptions): import("@ai-sdk/openai").OpenAIProvider;
|
|
4
|
-
getModel(client:
|
|
5
|
+
getModel(client: ReturnType<typeof createOpenAI>, model: string): import("@ai-sdk/provider").LanguageModelV3;
|
|
5
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.provider.js","sourceRoot":"","sources":["../../src/providers/openai.provider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"openai.provider.js","sourceRoot":"","sources":["../../src/providers/openai.provider.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8C;AAC9C,8CAAuF;AAKhF,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAChC,YAAY,CAAC,OAA0B;QACrC,OAAO,IAAA,qBAAY,EAAC;YAClB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,MAAuC,EAAE,KAAa;QAC7D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF,CAAA;AAXY,sDAAqB;gCAArB,qBAAqB;IAHjC,IAAA,mBAAU,EAAC;QACV,IAAI,EAAE,QAAQ;KACf,CAAC;GACW,qBAAqB,CAWjC"}
|
|
@@ -5,53 +5,16 @@ export declare const AiGenerateToolBaseSchema: z.ZodObject<{
|
|
|
5
5
|
provider: z.ZodOptional<z.ZodString>;
|
|
6
6
|
envApiKey: z.ZodOptional<z.ZodString>;
|
|
7
7
|
cacheResponse: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
-
},
|
|
9
|
-
model?: string | undefined;
|
|
10
|
-
provider?: string | undefined;
|
|
11
|
-
envApiKey?: string | undefined;
|
|
12
|
-
cacheResponse?: boolean | undefined;
|
|
13
|
-
}, {
|
|
14
|
-
model?: string | undefined;
|
|
15
|
-
provider?: string | undefined;
|
|
16
|
-
envApiKey?: string | undefined;
|
|
17
|
-
cacheResponse?: boolean | undefined;
|
|
18
|
-
}>>;
|
|
8
|
+
}, z.core.$strip>>;
|
|
19
9
|
messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
20
|
-
role: z.ZodEnum<
|
|
10
|
+
role: z.ZodEnum<{
|
|
11
|
+
system: "system";
|
|
12
|
+
user: "user";
|
|
13
|
+
assistant: "assistant";
|
|
14
|
+
tool: "tool";
|
|
15
|
+
}>;
|
|
21
16
|
content: z.ZodAny;
|
|
22
|
-
},
|
|
23
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
24
|
-
content?: any;
|
|
25
|
-
}, {
|
|
26
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
27
|
-
content?: any;
|
|
28
|
-
}>, "many">>;
|
|
17
|
+
}, z.core.$strip>>>;
|
|
29
18
|
prompt: z.ZodOptional<z.ZodString>;
|
|
30
19
|
messagesSearchTag: z.ZodOptional<z.ZodString>;
|
|
31
|
-
},
|
|
32
|
-
llm?: {
|
|
33
|
-
model?: string | undefined;
|
|
34
|
-
provider?: string | undefined;
|
|
35
|
-
envApiKey?: string | undefined;
|
|
36
|
-
cacheResponse?: boolean | undefined;
|
|
37
|
-
} | undefined;
|
|
38
|
-
messages?: {
|
|
39
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
40
|
-
content?: any;
|
|
41
|
-
}[] | undefined;
|
|
42
|
-
prompt?: string | undefined;
|
|
43
|
-
messagesSearchTag?: string | undefined;
|
|
44
|
-
}, {
|
|
45
|
-
llm?: {
|
|
46
|
-
model?: string | undefined;
|
|
47
|
-
provider?: string | undefined;
|
|
48
|
-
envApiKey?: string | undefined;
|
|
49
|
-
cacheResponse?: boolean | undefined;
|
|
50
|
-
} | undefined;
|
|
51
|
-
messages?: {
|
|
52
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
53
|
-
content?: any;
|
|
54
|
-
}[] | undefined;
|
|
55
|
-
prompt?: string | undefined;
|
|
56
|
-
messagesSearchTag?: string | undefined;
|
|
57
|
-
}>;
|
|
20
|
+
}, z.core.$strip>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UIDataTypes, UIMessage, UITools } from 'ai';
|
|
2
2
|
import { DocumentEntity } from '@loopstack/common';
|
|
3
3
|
export declare class AiMessagesHelperService {
|
|
4
4
|
private searchMessages;
|
|
5
5
|
getMessages(documents: DocumentEntity[], args: {
|
|
6
|
-
messages?:
|
|
6
|
+
messages?: Omit<UIMessage<unknown, UIDataTypes, UITools>, 'id'>[];
|
|
7
7
|
messagesSearchTag?: string;
|
|
8
|
-
}):
|
|
8
|
+
}): Omit<UIMessage<unknown, UIDataTypes, UITools>, 'id'>[];
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-messages-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-messages-helper.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAKrC,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAC1B,cAAc,CACpB,SAA2B,EAC3B,GAAW;QAEX,OAAO,SAAS;aACb,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;aAClD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;aAC7D,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"ai-messages-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-messages-helper.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAKrC,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAC1B,cAAc,CACpB,SAA2B,EAC3B,GAAW;QAEX,OAAO,SAAS;aACb,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;aAClD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;aAC7D,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAA+D,CAAC,CAAC;IACjG,CAAC;IAED,WAAW,CACT,SAA2B,EAC3B,IAAuG;QAEvG,IAAI,QAAQ,GAAuE,IAAI,CAAC,QAAQ,CAAC;QACjG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;YACtB,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,iBAAiB,IAAI,SAAS,CAAC,CAAC;QACjF,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AAtBY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;GACA,uBAAuB,CAsBnC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LanguageModel } from 'ai';
|
|
1
2
|
import { AiProviderRegistryService } from './ai-provider-registry.service';
|
|
2
3
|
export interface AiProviderModelConfig {
|
|
3
4
|
model?: string;
|
|
@@ -11,5 +12,5 @@ export declare class AiProviderModelHelperService {
|
|
|
11
12
|
private getApiKey;
|
|
12
13
|
private getModel;
|
|
13
14
|
private getProvider;
|
|
14
|
-
getProviderModel(config?: AiProviderModelConfig):
|
|
15
|
+
getProviderModel(config?: AiProviderModelConfig): LanguageModel;
|
|
15
16
|
}
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"ai-provider-model-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-provider-model-helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAE5C,iFAA2E;AAUpE,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IACV;IAA7B,YAA6B,kBAA6C;QAA7C,uBAAkB,GAAlB,kBAAkB,CAA2B;IAAG,CAAC;IAEtE,SAAS,CAAC,SAA6B,EAAE,YAAoB;QACnE,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,CAAC,kDAAkD,SAAS,IAAI,UAAU,sBAAsB,CAAC,CAAC;QACnH,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;AAhDY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,mBAAU,GAAE;qCAEsC,wDAAyB;GAD/D,4BAA4B,CAgDxC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { DiscoveryService, Reflector } from '@nestjs/core';
|
|
3
|
+
import { LanguageModel } from 'ai';
|
|
3
4
|
import { AiProviderOptions } from '@loopstack/common';
|
|
4
5
|
export declare class AiProviderRegistryService implements OnModuleInit {
|
|
5
6
|
private readonly discoveryService;
|
|
@@ -10,6 +11,6 @@ export declare class AiProviderRegistryService implements OnModuleInit {
|
|
|
10
11
|
onModuleInit(): void;
|
|
11
12
|
private loadProviders;
|
|
12
13
|
private registerProvider;
|
|
13
|
-
createModel(providerName: string, options: AiProviderOptions):
|
|
14
|
+
createModel(providerName: string, options: AiProviderOptions): LanguageModel;
|
|
14
15
|
getAvailableProviders(): string[];
|
|
15
16
|
}
|
|
@@ -32,7 +32,7 @@ let AiProviderRegistryService = AiProviderRegistryService_1 = class AiProviderRe
|
|
|
32
32
|
.filter((wrapper) => wrapper.isDependencyTreeStatic())
|
|
33
33
|
.filter((wrapper) => wrapper.instance)
|
|
34
34
|
.forEach((wrapper) => {
|
|
35
|
-
const
|
|
35
|
+
const instance = wrapper.instance;
|
|
36
36
|
const metadata = this.reflector.get(common_2.AI_PROVIDER_DECORATOR, instance.constructor);
|
|
37
37
|
if (metadata) {
|
|
38
38
|
this.registerProvider(metadata.name, instance);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-provider-registry.service.js","sourceRoot":"","sources":["../../src/services/ai-provider-registry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkE;AAClE,uCAA2D;
|
|
1
|
+
{"version":3,"file":"ai-provider-registry.service.js","sourceRoot":"","sources":["../../src/services/ai-provider-registry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkE;AAClE,uCAA2D;AAE3D,8CAK2B;AAGpB,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IAKjB;IACA;IALF,MAAM,GAAG,IAAI,eAAM,CAAC,2BAAyB,CAAC,IAAI,CAAC,CAAC;IACpD,SAAS,GAAG,IAAI,GAAG,EAA+B,CAAC;IAEpE,YACmB,gBAAkC,EAClC,SAAoB;QADpB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,cAAS,GAAT,SAAS,CAAW;IACpC,CAAC;IAEJ,YAAY;QACV,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;QAEvD,SAAS;aACN,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,sBAAsB,EAAE,CAAC;aACrD,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC;aACrC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACnB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAA+B,CAAC;YACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CACjC,8BAAqB,EAC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;IAED,qBAAqB;QACnB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AA7DY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAM0B,uBAAgB;QACvB,gBAAS;GAN5B,yBAAyB,CA6DrC"}
|
|
@@ -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,
|
|
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,CAAC,KAAe,EAAE,MAAoB;QAE5C,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,CAAC,kBAAkB,QAAQ,qCAAqC,CAAC,CAAC;YACnF,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;iBACD,CAAC;YACf,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;AAvBY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAuBhC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ToolResult } from '@loopstack/common';
|
|
2
|
-
import {
|
|
3
|
-
import { AiGenerateObjectArgsType } from './ai-generate-object.tool';
|
|
2
|
+
import { ToolBase, WorkflowBase } from '@loopstack/core';
|
|
4
3
|
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
4
|
+
import { AiGenerateObjectArgsType } from './ai-generate-object.tool';
|
|
5
5
|
export declare class AiGenerateDocument extends ToolBase<AiGenerateObjectArgsType> {
|
|
6
6
|
private aiGenerateObject;
|
|
7
7
|
private createDocument;
|
|
8
8
|
private getRequiredTool;
|
|
9
|
-
execute(args: AiGenerateObjectArgsType, ctx: WorkflowExecution, parent:
|
|
9
|
+
execute(args: AiGenerateObjectArgsType, ctx: WorkflowExecution, parent: WorkflowBase): Promise<ToolResult>;
|
|
10
10
|
}
|
|
@@ -13,8 +13,8 @@ exports.AiGenerateDocument = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const common_2 = require("@loopstack/common");
|
|
15
15
|
const core_1 = require("@loopstack/core");
|
|
16
|
-
const ai_generate_object_tool_1 = require("./ai-generate-object.tool");
|
|
17
16
|
const core_ui_module_1 = require("@loopstack/core-ui-module");
|
|
17
|
+
const ai_generate_object_tool_1 = require("./ai-generate-object.tool");
|
|
18
18
|
let AiGenerateDocument = class AiGenerateDocument extends core_1.ToolBase {
|
|
19
19
|
aiGenerateObject;
|
|
20
20
|
createDocument;
|
|
@@ -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","source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DAAsB,CAAC;GACzB,kBAAkB,CA0B9B"}
|
|
@@ -1,84 +1,32 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ToolResult } from '@loopstack/common';
|
|
3
3
|
import { ToolBase, WorkflowBase } from '@loopstack/core';
|
|
4
|
+
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
4
5
|
import { AiMessagesHelperService } from '../services';
|
|
5
6
|
import { AiProviderModelHelperService } from '../services';
|
|
6
|
-
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
7
7
|
export declare const AiGenerateObjectSchema: z.ZodObject<{
|
|
8
8
|
llm: z.ZodOptional<z.ZodObject<{
|
|
9
9
|
model: z.ZodOptional<z.ZodString>;
|
|
10
10
|
provider: z.ZodOptional<z.ZodString>;
|
|
11
11
|
envApiKey: z.ZodOptional<z.ZodString>;
|
|
12
12
|
cacheResponse: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
-
},
|
|
14
|
-
model?: string | undefined;
|
|
15
|
-
provider?: string | undefined;
|
|
16
|
-
envApiKey?: string | undefined;
|
|
17
|
-
cacheResponse?: boolean | undefined;
|
|
18
|
-
}, {
|
|
19
|
-
model?: string | undefined;
|
|
20
|
-
provider?: string | undefined;
|
|
21
|
-
envApiKey?: string | undefined;
|
|
22
|
-
cacheResponse?: boolean | undefined;
|
|
23
|
-
}>>;
|
|
13
|
+
}, z.core.$strip>>;
|
|
24
14
|
messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
25
|
-
role: z.ZodEnum<
|
|
15
|
+
role: z.ZodEnum<{
|
|
16
|
+
system: "system";
|
|
17
|
+
user: "user";
|
|
18
|
+
assistant: "assistant";
|
|
19
|
+
tool: "tool";
|
|
20
|
+
}>;
|
|
26
21
|
content: z.ZodAny;
|
|
27
|
-
},
|
|
28
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
29
|
-
content?: any;
|
|
30
|
-
}, {
|
|
31
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
32
|
-
content?: any;
|
|
33
|
-
}>, "many">>;
|
|
22
|
+
}, z.core.$strip>>>;
|
|
34
23
|
prompt: z.ZodOptional<z.ZodString>;
|
|
35
24
|
messagesSearchTag: z.ZodOptional<z.ZodString>;
|
|
36
|
-
} & {
|
|
37
25
|
response: z.ZodObject<{
|
|
38
26
|
id: z.ZodOptional<z.ZodString>;
|
|
39
27
|
document: z.ZodString;
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
id?: string | undefined;
|
|
43
|
-
}, {
|
|
44
|
-
document: string;
|
|
45
|
-
id?: string | undefined;
|
|
46
|
-
}>;
|
|
47
|
-
}, "strict", z.ZodTypeAny, {
|
|
48
|
-
response: {
|
|
49
|
-
document: string;
|
|
50
|
-
id?: string | undefined;
|
|
51
|
-
};
|
|
52
|
-
llm?: {
|
|
53
|
-
model?: string | undefined;
|
|
54
|
-
provider?: string | undefined;
|
|
55
|
-
envApiKey?: string | undefined;
|
|
56
|
-
cacheResponse?: boolean | undefined;
|
|
57
|
-
} | undefined;
|
|
58
|
-
messages?: {
|
|
59
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
60
|
-
content?: any;
|
|
61
|
-
}[] | undefined;
|
|
62
|
-
prompt?: string | undefined;
|
|
63
|
-
messagesSearchTag?: string | undefined;
|
|
64
|
-
}, {
|
|
65
|
-
response: {
|
|
66
|
-
document: string;
|
|
67
|
-
id?: string | undefined;
|
|
68
|
-
};
|
|
69
|
-
llm?: {
|
|
70
|
-
model?: string | undefined;
|
|
71
|
-
provider?: string | undefined;
|
|
72
|
-
envApiKey?: string | undefined;
|
|
73
|
-
cacheResponse?: boolean | undefined;
|
|
74
|
-
} | undefined;
|
|
75
|
-
messages?: {
|
|
76
|
-
role: "system" | "assistant" | "user" | "tool";
|
|
77
|
-
content?: any;
|
|
78
|
-
}[] | undefined;
|
|
79
|
-
prompt?: string | undefined;
|
|
80
|
-
messagesSearchTag?: string | undefined;
|
|
81
|
-
}>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
}, z.core.$strict>;
|
|
82
30
|
export type AiGenerateObjectArgsType = z.infer<typeof AiGenerateObjectSchema>;
|
|
83
31
|
export declare class AiGenerateObject extends ToolBase<AiGenerateObjectArgsType> {
|
|
84
32
|
private readonly aiMessagesHelperService;
|
|
@@ -10,13 +10,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.AiGenerateObject = exports.AiGenerateObjectSchema = void 0;
|
|
13
|
+
const ai_1 = require("ai");
|
|
13
14
|
const zod_1 = require("zod");
|
|
14
15
|
const common_1 = require("@loopstack/common");
|
|
15
|
-
const ai_1 = require("ai");
|
|
16
16
|
const core_1 = require("@loopstack/core");
|
|
17
|
+
const ai_generate_tool_base_schema_1 = require("../schemas/ai-generate-tool-base.schema");
|
|
17
18
|
const services_1 = require("../services");
|
|
18
19
|
const services_2 = require("../services");
|
|
19
|
-
const ai_generate_tool_base_schema_1 = require("../schemas/ai-generate-tool-base.schema");
|
|
20
20
|
exports.AiGenerateObjectSchema = ai_generate_tool_base_schema_1.AiGenerateToolBaseSchema.extend({
|
|
21
21
|
response: zod_1.z.object({
|
|
22
22
|
id: zod_1.z.string().optional(),
|
|
@@ -33,16 +33,21 @@ let AiGenerateObject = class AiGenerateObject extends core_1.ToolBase {
|
|
|
33
33
|
}
|
|
34
34
|
async execute(args, ctx, parent) {
|
|
35
35
|
const model = this.aiProviderModelHelperService.getProviderModel(args.llm);
|
|
36
|
-
const options = {
|
|
36
|
+
const options = {
|
|
37
|
+
messages: [],
|
|
38
|
+
};
|
|
37
39
|
if (args.prompt) {
|
|
38
|
-
options.
|
|
40
|
+
options.messages.push({
|
|
41
|
+
role: 'user',
|
|
42
|
+
content: args.prompt,
|
|
43
|
+
});
|
|
39
44
|
}
|
|
40
45
|
else {
|
|
41
46
|
const messages = this.aiMessagesHelperService.getMessages(ctx.state.getMetadata('documents'), {
|
|
42
47
|
messages: args.messages,
|
|
43
48
|
messagesSearchTag: args.messagesSearchTag,
|
|
44
49
|
});
|
|
45
|
-
options.messages = (0, ai_1.convertToModelMessages)(messages);
|
|
50
|
+
options.messages = await (0, ai_1.convertToModelMessages)(messages);
|
|
46
51
|
}
|
|
47
52
|
const document = parent.getDocument(args.response.document);
|
|
48
53
|
if (!document) {
|
|
@@ -54,16 +59,19 @@ let AiGenerateObject = class AiGenerateObject extends core_1.ToolBase {
|
|
|
54
59
|
}
|
|
55
60
|
options.schema = responseSchema;
|
|
56
61
|
const response = await this.handleGenerateObject(model, options);
|
|
62
|
+
console.log(response);
|
|
57
63
|
return {
|
|
58
|
-
data: response.
|
|
64
|
+
data: response.output,
|
|
59
65
|
};
|
|
60
66
|
}
|
|
61
67
|
async handleGenerateObject(model, options) {
|
|
62
68
|
const startTime = performance.now();
|
|
63
69
|
try {
|
|
64
|
-
|
|
70
|
+
console.log(options.schema);
|
|
71
|
+
return (0, ai_1.generateText)({
|
|
65
72
|
model,
|
|
66
|
-
|
|
73
|
+
messages: options.messages,
|
|
74
|
+
...(options.schema ? { output: ai_1.Output.object({ schema: options.schema }) } : {}),
|
|
67
75
|
});
|
|
68
76
|
}
|
|
69
77
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-object.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-object.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ai-generate-object.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-object.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2BAQY;AACZ,6BAAwB;AACxB,8CAA2E;AAC3E,0CAAyD;AAGzD,0FAAmF;AACnF,0CAAsD;AACtD,0CAA2D;AAE9C,QAAA,sBAAsB,GAAG,uDAAwB,CAAC,MAAM,CAAC;IACpE,QAAQ,EAAE,O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