@loopstack/ai-module 0.18.0 → 0.19.0-rc.0
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 +20 -36
- package/dist/ai.module.d.ts +1 -0
- package/dist/ai.module.d.ts.map +1 -0
- package/dist/ai.module.js +1 -2
- package/dist/ai.module.js.map +1 -1
- package/dist/documents/ai-message-document.d.ts +2 -2
- package/dist/documents/ai-message-document.d.ts.map +1 -0
- package/dist/documents/ai-message-document.js +2 -3
- package/dist/documents/ai-message-document.js.map +1 -1
- package/dist/documents/index.d.ts +1 -0
- package/dist/documents/index.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/providers/anthropic.provider.d.ts +1 -0
- package/dist/providers/anthropic.provider.d.ts.map +1 -0
- package/dist/providers/openai.provider.d.ts +1 -0
- package/dist/providers/openai.provider.d.ts.map +1 -0
- package/dist/schemas/ai-generate-tool-base.schema.d.ts +1 -0
- package/dist/schemas/ai-generate-tool-base.schema.d.ts.map +1 -0
- package/dist/services/ai-messages-helper.service.d.ts +1 -0
- package/dist/services/ai-messages-helper.service.d.ts.map +1 -0
- package/dist/services/ai-provider-model-helper.service.d.ts +1 -0
- package/dist/services/ai-provider-model-helper.service.d.ts.map +1 -0
- package/dist/services/ai-provider-registry.service.d.ts +1 -0
- package/dist/services/ai-provider-registry.service.d.ts.map +1 -0
- package/dist/services/ai-tools-helper.service.d.ts +3 -2
- package/dist/services/ai-tools-helper.service.d.ts.map +1 -0
- package/dist/services/ai-tools-helper.service.js +8 -3
- package/dist/services/ai-tools-helper.service.js.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/tools/ai-generate-document.tool.d.ts +4 -5
- package/dist/tools/ai-generate-document.tool.d.ts.map +1 -0
- package/dist/tools/ai-generate-document.tool.js +5 -6
- package/dist/tools/ai-generate-document.tool.js.map +1 -1
- package/dist/tools/ai-generate-object.tool.d.ts +4 -5
- package/dist/tools/ai-generate-object.tool.d.ts.map +1 -0
- package/dist/tools/ai-generate-object.tool.js +8 -8
- package/dist/tools/ai-generate-object.tool.js.map +1 -1
- package/dist/tools/ai-generate-text.tool.d.ts +4 -5
- package/dist/tools/ai-generate-text.tool.d.ts.map +1 -0
- package/dist/tools/ai-generate-text.tool.js +2 -4
- package/dist/tools/ai-generate-text.tool.js.map +1 -1
- package/dist/tools/delegate-tool-call.tool.d.ts +4 -5
- package/dist/tools/delegate-tool-call.tool.d.ts.map +1 -0
- package/dist/tools/delegate-tool-call.tool.js +7 -6
- package/dist/tools/delegate-tool-call.tool.js.map +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/package.json +3 -4
- package/src/ai.module.ts +1 -2
- package/src/documents/ai-message-document.ts +3 -4
- package/src/services/ai-tools-helper.service.ts +11 -5
- package/src/tools/ai-generate-document.tool.ts +21 -10
- package/src/tools/ai-generate-object.tool.ts +23 -12
- package/src/tools/ai-generate-text.tool.ts +16 -9
- package/src/tools/delegate-tool-call.tool.ts +19 -7
package/README.md
CHANGED
|
@@ -19,35 +19,28 @@ This module is essential for workflows that need natural language processing, co
|
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
You can add this module using the `loopstack` cli or via `npm`.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
### a) Add Sources via `loopstack add`
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
|
|
28
|
-
cd my-project
|
|
27
|
+
loopstack add @loopstack/ai-module
|
|
29
28
|
```
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
cd my-project
|
|
35
|
-
docker compose up -d
|
|
36
|
-
```
|
|
30
|
+
This command copies the source files into your `src` directory.
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
- It is a great way to explore the code to learn new concepts or add own customizations
|
|
33
|
+
- It will set up the module for you, so you do not need to manually update your application
|
|
39
34
|
|
|
40
|
-
|
|
35
|
+
### b) Install via `npm install` (recommended)
|
|
41
36
|
|
|
42
37
|
```bash
|
|
43
38
|
npm install --save @loopstack/ai-module
|
|
44
39
|
```
|
|
45
40
|
|
|
46
|
-
|
|
41
|
+
Use npm install if you want to use and maintain the module as node dependency.
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
loopstack add @loopstack/ai-module
|
|
50
|
-
```
|
|
43
|
+
- Use this, if you do not need to make changes to the code or want to review the source code.
|
|
51
44
|
|
|
52
45
|
### Configure API Keys
|
|
53
46
|
|
|
@@ -63,22 +56,13 @@ ANTHROPIC_API_KEY=sk-ant-...
|
|
|
63
56
|
|
|
64
57
|
## Setup
|
|
65
58
|
|
|
66
|
-
### 1.
|
|
59
|
+
### 1. Manual setup (optional)
|
|
67
60
|
|
|
68
|
-
|
|
61
|
+
> This step is automatically done for you when using the `loopstack add` command.
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
import { LoopCoreModule } from '@loopstack/core';
|
|
74
|
-
import { DefaultWorkspace } from './default.workspace';
|
|
75
|
-
|
|
76
|
-
@Module({
|
|
77
|
-
imports: [LoopCoreModule, AiModule],
|
|
78
|
-
providers: [DefaultWorkspace],
|
|
79
|
-
})
|
|
80
|
-
export class DefaultModule {}
|
|
81
|
-
```
|
|
63
|
+
- Add `AiModule` to the imports of `default.module.ts` or any other custom module.
|
|
64
|
+
|
|
65
|
+
See here for more information about working with [Modules](https://loopstack.ai/docs/building-with-loopstack/creating-a-module) and [Workspaces](https://loopstack.ai/docs/building-with-loopstack/creating-workspaces)
|
|
82
66
|
|
|
83
67
|
### 2. Use in Your Workflow
|
|
84
68
|
|
|
@@ -93,7 +77,7 @@ import {
|
|
|
93
77
|
AiMessageDocument,
|
|
94
78
|
DelegateToolCall,
|
|
95
79
|
} from '@loopstack/ai-module';
|
|
96
|
-
import { BlockConfig,
|
|
80
|
+
import { BlockConfig, DefineHelper, InjectDocument, InjectTool } from '@loopstack/common';
|
|
97
81
|
import { WorkflowBase } from '@loopstack/core';
|
|
98
82
|
|
|
99
83
|
@Injectable()
|
|
@@ -102,13 +86,13 @@ import { WorkflowBase } from '@loopstack/core';
|
|
|
102
86
|
})
|
|
103
87
|
export class MyWorkflow extends WorkflowBase {
|
|
104
88
|
// Tools
|
|
105
|
-
@
|
|
106
|
-
@
|
|
107
|
-
@
|
|
108
|
-
@
|
|
89
|
+
@InjectTool() aiGenerateText: AiGenerateText;
|
|
90
|
+
@InjectTool() aiGenerateObject: AiGenerateObject;
|
|
91
|
+
@InjectTool() aiGenerateDocument: AiGenerateDocument;
|
|
92
|
+
@InjectTool() delegateToolCall: DelegateToolCall;
|
|
109
93
|
|
|
110
94
|
// Documents
|
|
111
|
-
@
|
|
95
|
+
@InjectDocument() aiMessageDocument: AiMessageDocument;
|
|
112
96
|
}
|
|
113
97
|
```
|
|
114
98
|
|
package/dist/ai.module.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.module.d.ts","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":"AAYA,qBAwBa,QAAQ;CAAG"}
|
package/dist/ai.module.js
CHANGED
|
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.AiModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const core_1 = require("@nestjs/core");
|
|
12
|
-
const core_2 = require("@loopstack/core");
|
|
13
12
|
const core_ui_module_1 = require("@loopstack/core-ui-module");
|
|
14
13
|
const documents_1 = require("./documents");
|
|
15
14
|
const anthropic_provider_1 = require("./providers/anthropic.provider");
|
|
@@ -24,7 +23,7 @@ let AiModule = class AiModule {
|
|
|
24
23
|
exports.AiModule = AiModule;
|
|
25
24
|
exports.AiModule = AiModule = __decorate([
|
|
26
25
|
(0, common_1.Module)({
|
|
27
|
-
imports: [
|
|
26
|
+
imports: [core_ui_module_1.CoreUiModule, core_1.DiscoveryModule],
|
|
28
27
|
providers: [
|
|
29
28
|
services_1.AiMessagesHelperService,
|
|
30
29
|
services_2.AiProviderModelHelperService,
|
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,uCAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"ai.module.js","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uCAA+C;AAC/C,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,6BAAY,EAAE,sBAAe,CAAC;QACxC,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-message-document.d.ts","sourceRoot":"","sources":["../../src/documents/ai-message-document.ts"],"names":[],"mappings":"AAWA,qBASa,iBAAiB;CAAG"}
|
|
@@ -10,19 +10,18 @@ exports.AiMessageDocument = void 0;
|
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const zod_1 = require("zod");
|
|
12
12
|
const common_2 = require("@loopstack/common");
|
|
13
|
-
const core_1 = require("@loopstack/core");
|
|
14
13
|
const AiMessageDocumentSchema = zod_1.z.object({
|
|
15
14
|
id: zod_1.z.string().optional(),
|
|
16
15
|
role: zod_1.z.union([zod_1.z.literal('system'), zod_1.z.literal('user'), zod_1.z.literal('assistant')]),
|
|
17
16
|
metadata: zod_1.z.any().optional(),
|
|
18
17
|
parts: zod_1.z.array(zod_1.z.any()),
|
|
19
18
|
});
|
|
20
|
-
let AiMessageDocument = class AiMessageDocument
|
|
19
|
+
let AiMessageDocument = class AiMessageDocument {
|
|
21
20
|
};
|
|
22
21
|
exports.AiMessageDocument = AiMessageDocument;
|
|
23
22
|
exports.AiMessageDocument = AiMessageDocument = __decorate([
|
|
24
23
|
(0, common_1.Injectable)(),
|
|
25
|
-
(0, common_2.
|
|
24
|
+
(0, common_2.Document)({
|
|
26
25
|
config: {
|
|
27
26
|
type: 'document',
|
|
28
27
|
description: 'Ai Message Document.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-message-document.js","sourceRoot":"","sources":["../../src/documents/ai-message-document.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,6BAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"ai-message-document.js","sourceRoot":"","sources":["../../src/documents/ai-message-document.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,6BAAwB;AACxB,8CAA4D;AAE5D,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,iBAAiB;CAAG,CAAA;AAApB,8CAAiB;4BAAjB,iBAAiB;IAT7B,IAAA,mBAAU,GAAE;IACZ,IAAA,iBAAQ,EAAC;QACR,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,CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/documents/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC"}
|
|
@@ -4,3 +4,4 @@ export declare class AnthropicProviderService implements AiProviderInterface {
|
|
|
4
4
|
createClient(options: AiProviderOptions): import("@ai-sdk/anthropic").AnthropicProvider;
|
|
5
5
|
getModel(client: ReturnType<typeof createAnthropic>, model: string): import("@ai-sdk/provider").LanguageModelV3;
|
|
6
6
|
}
|
|
7
|
+
//# sourceMappingURL=anthropic.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.provider.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAc,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEvF,qBAGa,wBAAyB,YAAW,mBAAmB;IAClE,YAAY,CAAC,OAAO,EAAE,iBAAiB;IAOvC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM;CAGnE"}
|
|
@@ -4,3 +4,4 @@ export declare class OpenAiProviderService implements AiProviderInterface {
|
|
|
4
4
|
createClient(options: AiProviderOptions): import("@ai-sdk/openai").OpenAIProvider;
|
|
5
5
|
getModel(client: ReturnType<typeof createOpenAI>, model: string): import("@ai-sdk/provider").LanguageModelV3;
|
|
6
6
|
}
|
|
7
|
+
//# sourceMappingURL=openai.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.provider.d.ts","sourceRoot":"","sources":["../../src/providers/openai.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAc,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEvF,qBAGa,qBAAsB,YAAW,mBAAmB;IAC/D,YAAY,CAAC,OAAO,EAAE,iBAAiB;IAOvC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,EAAE,KAAK,EAAE,MAAM;CAGhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-tool-base.schema.d.ts","sourceRoot":"","sources":["../../src/schemas/ai-generate-tool-base.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;iBAmBnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-messages-helper.service.d.ts","sourceRoot":"","sources":["../../src/services/ai-messages-helper.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,qBACa,uBAAuB;IAClC,OAAO,CAAC,cAAc;IAUtB,WAAW,CACT,SAAS,EAAE,cAAc,EAAE,EAC3B,IAAI,EAAE;QAAE,QAAQ,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;QAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAAE,GACtG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE;CAQ1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-provider-model-helper.service.d.ts","sourceRoot":"","sources":["../../src/services/ai-provider-model-helper.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,qBACa,4BAA4B;IAC3B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;gBAAlB,kBAAkB,EAAE,yBAAyB;IAE1E,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,WAAW;IAYnB,gBAAgB,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,aAAa;CAUhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-provider-registry.service.d.ts","sourceRoot":"","sources":["../../src/services/ai-provider-registry.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,EAIL,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAE3B,qBACa,yBAA0B,YAAW,YAAY;IAK1D,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAL5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8C;IACrE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0C;gBAGjD,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,SAAS;IAGvC,YAAY;IAIZ,OAAO,CAAC,aAAa;IAoBrB,OAAO,CAAC,gBAAgB;IAOxB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,aAAa;IAkB5E,qBAAqB,IAAI,MAAM,EAAE;CAGlC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WorkflowInterface } from '@loopstack/common';
|
|
2
2
|
export declare class AiToolsHelperService {
|
|
3
|
-
getTools(tools: string[], parent:
|
|
3
|
+
getTools(tools: string[], parent: WorkflowInterface): Record<string, any> | undefined;
|
|
4
4
|
}
|
|
5
|
+
//# sourceMappingURL=ai-tools-helper.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-tools-helper.service.d.ts","sourceRoot":"","sources":["../../src/services/ai-tools-helper.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,iBAAiB,EAAoD,MAAM,mBAAmB,CAAC;AAGvH,qBACa,oBAAoB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS;CA2BtF"}
|
|
@@ -8,18 +8,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AiToolsHelperService = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
|
+
const common_2 = require("@loopstack/common");
|
|
11
12
|
let AiToolsHelperService = class AiToolsHelperService {
|
|
12
13
|
getTools(tools, parent) {
|
|
13
14
|
const toolDefinitions = {};
|
|
14
15
|
for (const toolName of tools) {
|
|
15
|
-
const tool =
|
|
16
|
+
const tool = (0, common_2.getBlockTool)(parent, toolName);
|
|
16
17
|
if (!tool) {
|
|
17
18
|
throw new Error(`Tool with name ${toolName} not available in Workflow context.`);
|
|
18
19
|
}
|
|
19
|
-
const inputSchema = tool
|
|
20
|
+
const inputSchema = (0, common_2.getBlockArgsSchema)(tool);
|
|
21
|
+
const config = (0, common_2.getBlockConfig)(tool);
|
|
22
|
+
if (!config) {
|
|
23
|
+
throw new Error(`Block ${tool.constructor.name} is missing @BlockConfig decorator`);
|
|
24
|
+
}
|
|
20
25
|
if (inputSchema) {
|
|
21
26
|
toolDefinitions[toolName] = {
|
|
22
|
-
description:
|
|
27
|
+
description: config.description,
|
|
23
28
|
inputSchema,
|
|
24
29
|
};
|
|
25
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-tools-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-tools-helper.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;
|
|
1
|
+
{"version":3,"file":"ai-tools-helper.service.js","sourceRoot":"","sources":["../../src/services/ai-tools-helper.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,8CAAuH;AAIhH,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,QAAQ,CAAC,KAAe,EAAE,MAAyB;QAEjD,MAAM,eAAe,GAAwB,EAAE,CAAC;QAEhD,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,IAAA,qBAAY,EAAgB,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC3D,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,qCAAqC,CAAC,CAAC;YACnF,CAAC;YAED,MAAM,WAAW,GAAG,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAC;YAE7C,MAAM,MAAM,GAAG,IAAA,uBAAc,EAAe,IAAI,CAAC,CAAC;YAClD,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,oCAAoC,CAAC,CAAC;YACtF,CAAC;YAED,IAAI,WAAW,EAAE,CAAC;gBAChB,eAAe,CAAC,QAAQ,CAAC,GAAG;oBAC1B,WAAW,EAAE,MAAM,CAAC,WAAW;oBAC/B,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;AA5BY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CA4BhC"}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ToolResult } from '@loopstack/common';
|
|
2
|
-
import { ToolBase, WorkflowBase } from '@loopstack/core';
|
|
3
|
-
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
1
|
+
import { ToolInterface, ToolResult, WorkflowExecution, WorkflowInterface } from '@loopstack/common';
|
|
4
2
|
import { AiGenerateObjectArgsType } from './ai-generate-object.tool';
|
|
5
|
-
export declare class AiGenerateDocument
|
|
3
|
+
export declare class AiGenerateDocument implements ToolInterface<AiGenerateObjectArgsType> {
|
|
6
4
|
private aiGenerateObject;
|
|
7
5
|
private createDocument;
|
|
8
6
|
private getRequiredTool;
|
|
9
|
-
execute(args: AiGenerateObjectArgsType, ctx: WorkflowExecution
|
|
7
|
+
execute(args: AiGenerateObjectArgsType, ctx: WorkflowExecution<any>, parent: WorkflowInterface): Promise<ToolResult>;
|
|
10
8
|
}
|
|
9
|
+
//# sourceMappingURL=ai-generate-document.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-document.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-generate-document.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,aAAa,EACb,UAAU,EAEV,iBAAiB,EACjB,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAoB,wBAAwB,EAA0B,MAAM,2BAA2B,CAAC;AAE/G,qBAOa,kBAAmB,YAAW,aAAa,CAAC,wBAAwB,CAAC;IAClE,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,cAAc,CAAkB;IAEtD,OAAO,CAAC,eAAe;IAQjB,OAAO,CACX,IAAI,EAAE,wBAAwB,EAC9B,GAAG,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAC3B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,UAAU,CAAC;CAcvB"}
|
|
@@ -12,14 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AiGenerateDocument = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const common_2 = require("@loopstack/common");
|
|
15
|
-
const core_1 = require("@loopstack/core");
|
|
16
15
|
const core_ui_module_1 = require("@loopstack/core-ui-module");
|
|
17
16
|
const ai_generate_object_tool_1 = require("./ai-generate-object.tool");
|
|
18
|
-
let AiGenerateDocument = class AiGenerateDocument
|
|
17
|
+
let AiGenerateDocument = class AiGenerateDocument {
|
|
19
18
|
aiGenerateObject;
|
|
20
19
|
createDocument;
|
|
21
20
|
getRequiredTool(name) {
|
|
22
|
-
const tool =
|
|
21
|
+
const tool = (0, common_2.getBlockTool)(this, name);
|
|
23
22
|
if (tool === undefined) {
|
|
24
23
|
throw new Error(`Tool "${name}" is not available`);
|
|
25
24
|
}
|
|
@@ -38,16 +37,16 @@ let AiGenerateDocument = class AiGenerateDocument extends core_1.ToolBase {
|
|
|
38
37
|
};
|
|
39
38
|
exports.AiGenerateDocument = AiGenerateDocument;
|
|
40
39
|
__decorate([
|
|
41
|
-
(0, common_2.
|
|
40
|
+
(0, common_2.InjectTool)(),
|
|
42
41
|
__metadata("design:type", ai_generate_object_tool_1.AiGenerateObject)
|
|
43
42
|
], AiGenerateDocument.prototype, "aiGenerateObject", void 0);
|
|
44
43
|
__decorate([
|
|
45
|
-
(0, common_2.
|
|
44
|
+
(0, common_2.InjectTool)(),
|
|
46
45
|
__metadata("design:type", core_ui_module_1.CreateDocument)
|
|
47
46
|
], AiGenerateDocument.prototype, "createDocument", void 0);
|
|
48
47
|
exports.AiGenerateDocument = AiGenerateDocument = __decorate([
|
|
49
48
|
(0, common_1.Injectable)(),
|
|
50
|
-
(0, common_2.
|
|
49
|
+
(0, common_2.Tool)({
|
|
51
50
|
config: {
|
|
52
51
|
description: 'Generates a structured object using a LLM and creates it as document',
|
|
53
52
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-document.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-document.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"ai-generate-document.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-document.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,8CAS2B;AAC3B,8DAA2D;AAC3D,uEAA+G;AASxG,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACP,gBAAgB,CAAoB;IACpC,cAAc,CAAkB;IAE9C,eAAe,CAAC,IAAY;QAClC,MAAM,IAAI,GAAG,IAAA,qBAAY,EAAgB,IAAI,EAAE,IAAI,CAAC,CAAC;QACrD,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,GAA2B,EAC3B,MAAyB;QAEzB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QACzF,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,IAAe;aAChC;SACF,EACD,GAAG,EACH,MAAM,CACP,CAAC;IACJ,CAAC;CACF,CAAA;AA9BY,gDAAkB;AACP;IAArB,IAAA,mBAAU,GAAE;8BAA4B,0CAAgB;4DAAC;AACpC;IAArB,IAAA,mBAAU,GAAE;8BAA0B,+BAAc;0DAAC;6BAF3C,kBAAkB;IAP9B,IAAA,mBAAU,GAAE;IACZ,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EAAE,sEAAsE;SACpF;KACF,CAAC;IACD,IAAA,sBAAa,EAAC,gDAAsB,CAAC;GACzB,kBAAkB,CA8B9B"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { ToolResult } from '@loopstack/common';
|
|
3
|
-
import { ToolBase, WorkflowBase } from '@loopstack/core';
|
|
4
|
-
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
2
|
+
import { ToolInterface, ToolResult, WorkflowExecution, WorkflowInterface } from '@loopstack/common';
|
|
5
3
|
import { AiMessagesHelperService } from '../services';
|
|
6
4
|
import { AiProviderModelHelperService } from '../services';
|
|
7
5
|
export declare const AiGenerateObjectSchema: z.ZodObject<{
|
|
@@ -28,10 +26,11 @@ export declare const AiGenerateObjectSchema: z.ZodObject<{
|
|
|
28
26
|
}, z.core.$strip>;
|
|
29
27
|
}, z.core.$strict>;
|
|
30
28
|
export type AiGenerateObjectArgsType = z.infer<typeof AiGenerateObjectSchema>;
|
|
31
|
-
export declare class AiGenerateObject
|
|
29
|
+
export declare class AiGenerateObject implements ToolInterface<AiGenerateObjectArgsType> {
|
|
32
30
|
private readonly aiMessagesHelperService;
|
|
33
31
|
private readonly aiProviderModelHelperService;
|
|
34
32
|
constructor(aiMessagesHelperService: AiMessagesHelperService, aiProviderModelHelperService: AiProviderModelHelperService);
|
|
35
|
-
execute(args: AiGenerateObjectArgsType, ctx: WorkflowExecution
|
|
33
|
+
execute(args: AiGenerateObjectArgsType, ctx: WorkflowExecution<any>, parent: WorkflowInterface): Promise<ToolResult>;
|
|
36
34
|
private handleGenerateObject;
|
|
37
35
|
}
|
|
36
|
+
//# sourceMappingURL=ai-generate-object.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-object.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-generate-object.tool.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGL,aAAa,EACb,UAAU,EAEV,iBAAiB,EACjB,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAE3D,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;kBAKxB,CAAC;AAEZ,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE9E,qBAOa,gBAAiB,YAAW,aAAa,CAAC,wBAAwB,CAAC;IAE5E,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,4BAA4B;gBAD5B,uBAAuB,EAAE,uBAAuB,EAChD,4BAA4B,EAAE,4BAA4B;IAGvE,OAAO,CACX,IAAI,EAAE,wBAAwB,EAC9B,GAAG,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAC3B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,UAAU,CAAC;YA4CR,oBAAoB;CAsBnC"}
|
|
@@ -10,10 +10,10 @@ 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 common_1 = require("@nestjs/common");
|
|
13
14
|
const ai_1 = require("ai");
|
|
14
15
|
const zod_1 = require("zod");
|
|
15
|
-
const
|
|
16
|
-
const core_1 = require("@loopstack/core");
|
|
16
|
+
const common_2 = require("@loopstack/common");
|
|
17
17
|
const ai_generate_tool_base_schema_1 = require("../schemas/ai-generate-tool-base.schema");
|
|
18
18
|
const services_1 = require("../services");
|
|
19
19
|
const services_2 = require("../services");
|
|
@@ -23,11 +23,10 @@ exports.AiGenerateObjectSchema = ai_generate_tool_base_schema_1.AiGenerateToolBa
|
|
|
23
23
|
document: zod_1.z.string(),
|
|
24
24
|
}),
|
|
25
25
|
}).strict();
|
|
26
|
-
let AiGenerateObject = class AiGenerateObject
|
|
26
|
+
let AiGenerateObject = class AiGenerateObject {
|
|
27
27
|
aiMessagesHelperService;
|
|
28
28
|
aiProviderModelHelperService;
|
|
29
29
|
constructor(aiMessagesHelperService, aiProviderModelHelperService) {
|
|
30
|
-
super();
|
|
31
30
|
this.aiMessagesHelperService = aiMessagesHelperService;
|
|
32
31
|
this.aiProviderModelHelperService = aiProviderModelHelperService;
|
|
33
32
|
}
|
|
@@ -49,11 +48,11 @@ let AiGenerateObject = class AiGenerateObject extends core_1.ToolBase {
|
|
|
49
48
|
});
|
|
50
49
|
options.messages = await (0, ai_1.convertToModelMessages)(messages);
|
|
51
50
|
}
|
|
52
|
-
const document =
|
|
51
|
+
const document = (0, common_2.getBlockDocument)(parent, args.response.document);
|
|
53
52
|
if (!document) {
|
|
54
53
|
throw new Error(`Document with name "${args.response.document}" not found in tool execution context.`);
|
|
55
54
|
}
|
|
56
|
-
const responseSchema = document
|
|
55
|
+
const responseSchema = (0, common_2.getBlockArgsSchema)(document);
|
|
57
56
|
if (!responseSchema) {
|
|
58
57
|
throw new Error(`AI object generation source document must have a schema.`);
|
|
59
58
|
}
|
|
@@ -83,12 +82,13 @@ let AiGenerateObject = class AiGenerateObject extends core_1.ToolBase {
|
|
|
83
82
|
};
|
|
84
83
|
exports.AiGenerateObject = AiGenerateObject;
|
|
85
84
|
exports.AiGenerateObject = AiGenerateObject = __decorate([
|
|
86
|
-
(0, common_1.
|
|
85
|
+
(0, common_1.Injectable)(),
|
|
86
|
+
(0, common_2.Tool)({
|
|
87
87
|
config: {
|
|
88
88
|
description: 'Generates a structured object using a LLM',
|
|
89
89
|
},
|
|
90
90
|
}),
|
|
91
|
-
(0,
|
|
91
|
+
(0, common_2.WithArguments)(exports.AiGenerateObjectSchema),
|
|
92
92
|
__metadata("design:paramtypes", [services_1.AiMessagesHelperService,
|
|
93
93
|
services_2.AiProviderModelHelperService])
|
|
94
94
|
], AiGenerateObject);
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
1
|
+
{"version":3,"file":"ai-generate-object.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-object.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAA4C;AAC5C,2BAQY;AACZ,6BAAwB;AACxB,8CAU2B;AAC3B,0FAAmF;AACnF,0CAAsD;AACtD,0CAA2D;AAE9C,QAAA,sBAAsB,GAAG,uDAAwB,CAAC,MAAM,CAAC;IACpE,QAAQ,EAAE,OAAC,CAAC,MAAM,CAAC;QACjB,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACzB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;KACrB,CAAC;CACH,CAAC,CAAC,MAAM,EAAE,CAAC;AAWL,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAER;IACA;IAFnB,YACmB,uBAAgD,EAChD,4BAA0D;QAD1D,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,iCAA4B,GAA5B,4BAA4B,CAA8B;IAC1E,CAAC;IAEJ,KAAK,CAAC,OAAO,CACX,IAA8B,EAC9B,GAA2B,EAC3B,MAAyB;QAEzB,MAAM,KAAK,GAAG,IAAI,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3E,MAAM,OAAO,GAGT;YACF,QAAQ,EAAE,EAAE;SACb,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACpB,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,IAAI,CAAC,MAAM;aACL,CAAC,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AAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACjF,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;AA5EY,4CAAgB;2BAAhB,gBAAgB;IAP5B,IAAA,mBAAU,GAAE;IACZ,IAAA,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EAAE,2CAA2C;SACzD;KACF,CAAC;IACD,IAAA,sBAAa,EAAC,8BAAsB,CAAC;qCAGQ,kCAAuB;QAClB,uCAA4B;GAHlE,gBAAgB,CA4E5B"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { ToolResult } from '@loopstack/common';
|
|
3
|
-
import { ToolBase, WorkflowBase } from '@loopstack/core';
|
|
4
|
-
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
2
|
+
import { ToolInterface, ToolResult, WorkflowExecution, WorkflowInterface } from '@loopstack/common';
|
|
5
3
|
import { AiMessagesHelperService } from '../services';
|
|
6
4
|
import { AiProviderModelHelperService } from '../services';
|
|
7
5
|
import { AiToolsHelperService } from '../services';
|
|
@@ -26,12 +24,13 @@ export declare const AiGenerateTextSchema: z.ZodObject<{
|
|
|
26
24
|
tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
25
|
}, z.core.$strict>;
|
|
28
26
|
type AiGenerateTextArgsType = z.infer<typeof AiGenerateTextSchema>;
|
|
29
|
-
export declare class AiGenerateText
|
|
27
|
+
export declare class AiGenerateText implements ToolInterface<AiGenerateTextArgsType> {
|
|
30
28
|
private readonly aiMessagesHelperService;
|
|
31
29
|
private readonly aiToolsHelperService;
|
|
32
30
|
private readonly aiProviderModelHelperService;
|
|
33
31
|
constructor(aiMessagesHelperService: AiMessagesHelperService, aiToolsHelperService: AiToolsHelperService, aiProviderModelHelperService: AiProviderModelHelperService);
|
|
34
|
-
execute(args: AiGenerateTextArgsType, ctx: WorkflowExecution
|
|
32
|
+
execute(args: AiGenerateTextArgsType, ctx: WorkflowExecution<any>, parent: WorkflowInterface): Promise<ToolResult>;
|
|
35
33
|
private handleGenerateText;
|
|
36
34
|
}
|
|
37
35
|
export {};
|
|
36
|
+
//# sourceMappingURL=ai-generate-text.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-generate-text.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,aAAa,EACb,UAAU,EAEV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;kBAEtB,CAAC;AAEZ,KAAK,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEnE,qBAOa,cAAe,YAAW,aAAa,CAAC,sBAAsB,CAAC;IAExE,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IACxC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC,OAAO,CAAC,QAAQ,CAAC,4BAA4B;gBAF5B,uBAAuB,EAAE,uBAAuB,EAChD,oBAAoB,EAAE,oBAAoB,EAC1C,4BAA4B,EAAE,4BAA4B;IAGvE,OAAO,CACX,IAAI,EAAE,sBAAsB,EAC5B,GAAG,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAC3B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,UAAU,CAAC;YAoCR,kBAAkB;CAgDjC"}
|
|
@@ -14,7 +14,6 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const ai_1 = require("ai");
|
|
15
15
|
const zod_1 = require("zod");
|
|
16
16
|
const common_2 = require("@loopstack/common");
|
|
17
|
-
const core_1 = require("@loopstack/core");
|
|
18
17
|
const ai_generate_tool_base_schema_1 = require("../schemas/ai-generate-tool-base.schema");
|
|
19
18
|
const services_1 = require("../services");
|
|
20
19
|
const services_2 = require("../services");
|
|
@@ -22,12 +21,11 @@ const services_3 = require("../services");
|
|
|
22
21
|
exports.AiGenerateTextSchema = ai_generate_tool_base_schema_1.AiGenerateToolBaseSchema.extend({
|
|
23
22
|
tools: zod_1.z.array(zod_1.z.string()).optional(),
|
|
24
23
|
}).strict();
|
|
25
|
-
let AiGenerateText = class AiGenerateText
|
|
24
|
+
let AiGenerateText = class AiGenerateText {
|
|
26
25
|
aiMessagesHelperService;
|
|
27
26
|
aiToolsHelperService;
|
|
28
27
|
aiProviderModelHelperService;
|
|
29
28
|
constructor(aiMessagesHelperService, aiToolsHelperService, aiProviderModelHelperService) {
|
|
30
|
-
super();
|
|
31
29
|
this.aiMessagesHelperService = aiMessagesHelperService;
|
|
32
30
|
this.aiToolsHelperService = aiToolsHelperService;
|
|
33
31
|
this.aiProviderModelHelperService = aiProviderModelHelperService;
|
|
@@ -101,7 +99,7 @@ let AiGenerateText = class AiGenerateText extends core_1.ToolBase {
|
|
|
101
99
|
exports.AiGenerateText = AiGenerateText;
|
|
102
100
|
exports.AiGenerateText = AiGenerateText = __decorate([
|
|
103
101
|
(0, common_1.Injectable)(),
|
|
104
|
-
(0, common_2.
|
|
102
|
+
(0, common_2.Tool)({
|
|
105
103
|
config: {
|
|
106
104
|
description: 'Generates text using a LLM',
|
|
107
105
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-generate-text.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAA4C;AAC5C,2BAAkH;AAClH,6BAAwB;AACxB,
|
|
1
|
+
{"version":3,"file":"ai-generate-text.tool.js","sourceRoot":"","sources":["../../src/tools/ai-generate-text.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAA4C;AAC5C,2BAAkH;AAClH,6BAAwB;AACxB,8CAO2B;AAC3B,0FAAmF;AACnF,0CAAsD;AACtD,0CAA2D;AAC3D,0CAAmD;AAEtC,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;AAWL,IAAM,cAAc,GAApB,MAAM,cAAc;IAEN;IACA;IACA;IAHnB,YACmB,uBAAgD,EAChD,oBAA0C,EAC1C,4BAA0D;QAF1D,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,iCAA4B,GAA5B,4BAA4B,CAA8B;IAC1E,CAAC;IAEJ,KAAK,CAAC,OAAO,CACX,IAA4B,EAC5B,GAA2B,EAC3B,MAAyB;QAEzB,MAAM,KAAK,GAAG,IAAI,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE3E,MAAM,OAAO,GAIT;YACF,QAAQ,EAAE,EAAE;SACb,CAAC;QAEF,OAAO,CAAC,KAAK,GAAG,IAAI,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
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { ToolResult } from '@loopstack/common';
|
|
3
|
-
import { ToolBase, WorkflowBase } from '@loopstack/core';
|
|
4
|
-
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
2
|
+
import { ToolInterface, ToolResult, WorkflowExecution, WorkflowInterface } from '@loopstack/common';
|
|
5
3
|
declare const DelegateToolCallsToolSchema: z.ZodObject<{
|
|
6
4
|
message: z.ZodObject<{
|
|
7
5
|
id: z.ZodString;
|
|
@@ -13,7 +11,8 @@ declare const DelegateToolCallsToolSchema: z.ZodObject<{
|
|
|
13
11
|
}, z.core.$strip>;
|
|
14
12
|
}, z.core.$strip>;
|
|
15
13
|
type DelegateToolCallsToolArgs = z.infer<typeof DelegateToolCallsToolSchema>;
|
|
16
|
-
export declare class DelegateToolCall
|
|
17
|
-
execute(args: DelegateToolCallsToolArgs, ctx: WorkflowExecution
|
|
14
|
+
export declare class DelegateToolCall implements ToolInterface<DelegateToolCallsToolArgs> {
|
|
15
|
+
execute(args: DelegateToolCallsToolArgs, ctx: WorkflowExecution<any>, parent: WorkflowInterface): Promise<ToolResult>;
|
|
18
16
|
}
|
|
19
17
|
export {};
|
|
18
|
+
//# sourceMappingURL=delegate-tool-call.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegate-tool-call.tool.d.ts","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,aAAa,EACb,UAAU,EAEV,iBAAiB,EACjB,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAE3B,QAAA,MAAM,2BAA2B;;;;;;;;;iBAW/B,CAAC;AAEH,KAAK,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAE7E,qBAOa,gBAAiB,YAAW,aAAa,CAAC,yBAAyB,CAAC;IACzE,OAAO,CACX,IAAI,EAAE,yBAAyB,EAC/B,GAAG,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAC3B,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,UAAU,CAAC;CA2CvB"}
|
|
@@ -7,9 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.DelegateToolCall = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
10
11
|
const zod_1 = require("zod");
|
|
11
|
-
const
|
|
12
|
-
const core_1 = require("@loopstack/core");
|
|
12
|
+
const common_2 = require("@loopstack/common");
|
|
13
13
|
const DelegateToolCallsToolSchema = zod_1.z.object({
|
|
14
14
|
message: zod_1.z.object({
|
|
15
15
|
id: zod_1.z.string(),
|
|
@@ -20,7 +20,7 @@ const DelegateToolCallsToolSchema = zod_1.z.object({
|
|
|
20
20
|
})),
|
|
21
21
|
}),
|
|
22
22
|
});
|
|
23
|
-
let DelegateToolCall = class DelegateToolCall
|
|
23
|
+
let DelegateToolCall = class DelegateToolCall {
|
|
24
24
|
async execute(args, ctx, parent) {
|
|
25
25
|
const parts = args.message.parts;
|
|
26
26
|
const resultParts = [];
|
|
@@ -32,7 +32,7 @@ let DelegateToolCall = class DelegateToolCall extends core_1.ToolBase {
|
|
|
32
32
|
throw new Error(`No toolCallId provided`);
|
|
33
33
|
}
|
|
34
34
|
const toolName = part.type.replace(/^tool-/, '');
|
|
35
|
-
const tool =
|
|
35
|
+
const tool = (0, common_2.getBlockTool)(parent, toolName);
|
|
36
36
|
if (!tool) {
|
|
37
37
|
throw new Error(`Tool ${toolName} not found.`);
|
|
38
38
|
}
|
|
@@ -60,11 +60,12 @@ let DelegateToolCall = class DelegateToolCall extends core_1.ToolBase {
|
|
|
60
60
|
};
|
|
61
61
|
exports.DelegateToolCall = DelegateToolCall;
|
|
62
62
|
exports.DelegateToolCall = DelegateToolCall = __decorate([
|
|
63
|
-
(0, common_1.
|
|
63
|
+
(0, common_1.Injectable)(),
|
|
64
|
+
(0, common_2.Tool)({
|
|
64
65
|
config: {
|
|
65
66
|
description: 'Delegate a tool call.',
|
|
66
67
|
},
|
|
67
68
|
}),
|
|
68
|
-
(0,
|
|
69
|
+
(0, common_2.WithArguments)(DelegateToolCallsToolSchema)
|
|
69
70
|
], DelegateToolCall);
|
|
70
71
|
//# sourceMappingURL=delegate-tool-call.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-tool-call.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"delegate-tool-call.tool.js","sourceRoot":"","sources":["../../src/tools/delegate-tool-call.tool.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAE5C,6BAAwB;AACxB,8CAQ2B;AAE3B,MAAM,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QAChB,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;QACd,KAAK,EAAE,OAAC,CAAC,KAAK,CACZ,OAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,KAAK,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;YACzB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;SAClC,CAAC,CACH;KACF,CAAC;CACH,CAAC,CAAC;AAWI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,KAAK,CAAC,OAAO,CACX,IAA+B,EAC/B,GAA2B,EAC3B,MAAyB;QAEzB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QACjC,MAAM,WAAW,GAAiB,EAAE,CAAC;QAErC,K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,aAAI,EAAC;QACJ,MAAM,EAAE;YACN,WAAW,EAAE,uBAAuB;SACrC;KACF,CAAC;IACD,IAAA,sBAAa,EAAC,2BAA2B,CAAC;GAC9B,gBAAgB,CAgD5B"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"openai",
|
|
11
11
|
"tool"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.
|
|
13
|
+
"version": "0.19.0-rc.0",
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"author": {
|
|
16
16
|
"name": "Jakob Klippel",
|
|
@@ -34,9 +34,8 @@
|
|
|
34
34
|
"@ai-sdk/anthropic": "^3.0.23",
|
|
35
35
|
"@ai-sdk/openai": "^3.0.19",
|
|
36
36
|
"@ai-sdk/provider-utils": "^4.0.9",
|
|
37
|
-
"@loopstack/common": "^0.
|
|
38
|
-
"@loopstack/core": "^0.
|
|
39
|
-
"@loopstack/core-ui-module": "^0.18.0",
|
|
37
|
+
"@loopstack/common": "^0.19.0-rc.0",
|
|
38
|
+
"@loopstack/core-ui-module": "^0.19.0-rc.0",
|
|
40
39
|
"@nestjs/common": "^11.1.12",
|
|
41
40
|
"@nestjs/config": "^4.0.2",
|
|
42
41
|
"@nestjs/core": "^11.1.12",
|
package/src/ai.module.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Module } from '@nestjs/common';
|
|
2
2
|
import { DiscoveryModule } from '@nestjs/core';
|
|
3
|
-
import { LoopCoreModule } from '@loopstack/core';
|
|
4
3
|
import { CoreUiModule } from '@loopstack/core-ui-module';
|
|
5
4
|
import { AiMessageDocument } from './documents';
|
|
6
5
|
import { AnthropicProviderService } from './providers/anthropic.provider';
|
|
@@ -12,7 +11,7 @@ import { AiProviderRegistryService } from './services/ai-provider-registry.servi
|
|
|
12
11
|
import { AiGenerateDocument, AiGenerateObject, AiGenerateText, DelegateToolCall } from './tools';
|
|
13
12
|
|
|
14
13
|
@Module({
|
|
15
|
-
imports: [
|
|
14
|
+
imports: [CoreUiModule, DiscoveryModule],
|
|
16
15
|
providers: [
|
|
17
16
|
// services
|
|
18
17
|
AiMessagesHelperService,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import { DocumentBase } from '@loopstack/core';
|
|
3
|
+
import { Document, WithArguments } from '@loopstack/common';
|
|
5
4
|
|
|
6
5
|
const AiMessageDocumentSchema = z.object({
|
|
7
6
|
id: z.string().optional(),
|
|
@@ -11,7 +10,7 @@ const AiMessageDocumentSchema = z.object({
|
|
|
11
10
|
});
|
|
12
11
|
|
|
13
12
|
@Injectable()
|
|
14
|
-
@
|
|
13
|
+
@Document({
|
|
15
14
|
config: {
|
|
16
15
|
type: 'document',
|
|
17
16
|
description: 'Ai Message Document.',
|
|
@@ -19,4 +18,4 @@ const AiMessageDocumentSchema = z.object({
|
|
|
19
18
|
configFile: __dirname + '/ai-message-document.yaml',
|
|
20
19
|
})
|
|
21
20
|
@WithArguments(AiMessageDocumentSchema)
|
|
22
|
-
export class AiMessageDocument
|
|
21
|
+
export class AiMessageDocument {}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { ToolInterface, WorkflowInterface, getBlockArgsSchema, getBlockConfig, getBlockTool } from '@loopstack/common';
|
|
3
|
+
import { WorkflowType } from '@loopstack/contracts/dist/types';
|
|
3
4
|
|
|
4
5
|
@Injectable()
|
|
5
6
|
export class AiToolsHelperService {
|
|
6
|
-
getTools(tools: string[], parent:
|
|
7
|
+
getTools(tools: string[], parent: WorkflowInterface): Record<string, any> | undefined {
|
|
7
8
|
// using any instead of ToolSet bc ai sdk types have some nesting issue
|
|
8
9
|
const toolDefinitions: Record<string, any> = {};
|
|
9
10
|
|
|
10
11
|
for (const toolName of tools) {
|
|
11
|
-
const tool = parent
|
|
12
|
+
const tool = getBlockTool<ToolInterface>(parent, toolName);
|
|
12
13
|
if (!tool) {
|
|
13
14
|
throw new Error(`Tool with name ${toolName} not available in Workflow context.`);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
const inputSchema = tool
|
|
17
|
+
const inputSchema = getBlockArgsSchema(tool);
|
|
18
|
+
|
|
19
|
+
const config = getBlockConfig<WorkflowType>(tool);
|
|
20
|
+
if (!config) {
|
|
21
|
+
throw new Error(`Block ${tool.constructor.name} is missing @BlockConfig decorator`);
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
if (inputSchema) {
|
|
19
25
|
toolDefinitions[toolName] = {
|
|
20
|
-
description:
|
|
26
|
+
description: config.description,
|
|
21
27
|
inputSchema,
|
|
22
28
|
} as unknown; // using unknown bc ai sdk types have some nesting issue
|
|
23
29
|
}
|
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
InjectTool,
|
|
4
|
+
Tool,
|
|
5
|
+
ToolInterface,
|
|
6
|
+
ToolResult,
|
|
7
|
+
WithArguments,
|
|
8
|
+
WorkflowExecution,
|
|
9
|
+
WorkflowInterface,
|
|
10
|
+
getBlockTool,
|
|
11
|
+
} from '@loopstack/common';
|
|
4
12
|
import { CreateDocument } from '@loopstack/core-ui-module';
|
|
5
|
-
import { WorkflowExecution } from '@loopstack/core/dist/workflow-processor/interfaces/workflow-execution.interface';
|
|
6
13
|
import { AiGenerateObject, AiGenerateObjectArgsType, AiGenerateObjectSchema } from './ai-generate-object.tool';
|
|
7
14
|
|
|
8
15
|
@Injectable()
|
|
9
|
-
@
|
|
16
|
+
@Tool({
|
|
10
17
|
config: {
|
|
11
18
|
description: 'Generates a structured object using a LLM and creates it as document',
|
|
12
19
|
},
|
|
13
20
|
})
|
|
14
21
|
@WithArguments(AiGenerateObjectSchema)
|
|
15
|
-
export class AiGenerateDocument
|
|
16
|
-
@
|
|
17
|
-
@
|
|
22
|
+
export class AiGenerateDocument implements ToolInterface<AiGenerateObjectArgsType> {
|
|
23
|
+
@InjectTool() private aiGenerateObject!: AiGenerateObject;
|
|
24
|
+
@InjectTool() private createDocument!: CreateDocument;
|
|
18
25
|
|
|
19
|
-
private getRequiredTool(name: string):
|
|
20
|
-
const tool = this
|
|
26
|
+
private getRequiredTool(name: string): ToolInterface {
|
|
27
|
+
const tool = getBlockTool<ToolInterface>(this, name);
|
|
21
28
|
if (tool === undefined) {
|
|
22
29
|
throw new Error(`Tool "${name}" is not available`);
|
|
23
30
|
}
|
|
24
31
|
return tool;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
async execute(
|
|
34
|
+
async execute(
|
|
35
|
+
args: AiGenerateObjectArgsType,
|
|
36
|
+
ctx: WorkflowExecution<any>,
|
|
37
|
+
parent: WorkflowInterface,
|
|
38
|
+
): Promise<ToolResult> {
|
|
28
39
|
const result = await this.getRequiredTool('aiGenerateObject').execute(args, ctx, parent);
|
|
29
40
|
return this.getRequiredTool('createDocument').execute(
|
|
30
41
|
{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ModelMessage } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
2
3
|
import {
|
|
3
4
|
GenerateTextResult,
|
|
4
5
|
LanguageModel,
|
|
@@ -9,10 +10,17 @@ import {
|
|
|
9
10
|
generateText,
|
|
10
11
|
} from 'ai';
|
|
11
12
|
import { z } from 'zod';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import {
|
|
14
|
+
DocumentInterface,
|
|
15
|
+
Tool,
|
|
16
|
+
ToolInterface,
|
|
17
|
+
ToolResult,
|
|
18
|
+
WithArguments,
|
|
19
|
+
WorkflowExecution,
|
|
20
|
+
WorkflowInterface,
|
|
21
|
+
getBlockArgsSchema,
|
|
22
|
+
getBlockDocument,
|
|
23
|
+
} from '@loopstack/common';
|
|
16
24
|
import { AiGenerateToolBaseSchema } from '../schemas/ai-generate-tool-base.schema';
|
|
17
25
|
import { AiMessagesHelperService } from '../services';
|
|
18
26
|
import { AiProviderModelHelperService } from '../services';
|
|
@@ -26,21 +34,24 @@ export const AiGenerateObjectSchema = AiGenerateToolBaseSchema.extend({
|
|
|
26
34
|
|
|
27
35
|
export type AiGenerateObjectArgsType = z.infer<typeof AiGenerateObjectSchema>;
|
|
28
36
|
|
|
29
|
-
@
|
|
37
|
+
@Injectable()
|
|
38
|
+
@Tool({
|
|
30
39
|
config: {
|
|
31
40
|
description: 'Generates a structured object using a LLM',
|
|
32
41
|
},
|
|
33
42
|
})
|
|
34
43
|
@WithArguments(AiGenerateObjectSchema)
|
|
35
|
-
export class AiGenerateObject
|
|
44
|
+
export class AiGenerateObject implements ToolInterface<AiGenerateObjectArgsType> {
|
|
36
45
|
constructor(
|
|
37
46
|
private readonly aiMessagesHelperService: AiMessagesHelperService,
|
|
38
47
|
private readonly aiProviderModelHelperService: AiProviderModelHelperService,
|
|
39
|
-
) {
|
|
40
|
-
super();
|
|
41
|
-
}
|
|
48
|
+
) {}
|
|
42
49
|
|
|
43
|
-
async execute(
|
|
50
|
+
async execute(
|
|
51
|
+
args: AiGenerateObjectArgsType,
|
|
52
|
+
ctx: WorkflowExecution<any>,
|
|
53
|
+
parent: WorkflowInterface,
|
|
54
|
+
): Promise<ToolResult> {
|
|
44
55
|
const model = this.aiProviderModelHelperService.getProviderModel(args.llm);
|
|
45
56
|
|
|
46
57
|
const options: {
|
|
@@ -64,11 +75,11 @@ export class AiGenerateObject extends ToolBase<AiGenerateObjectArgsType> {
|
|
|
64
75
|
options.messages = await convertToModelMessages(messages);
|
|
65
76
|
}
|
|
66
77
|
|
|
67
|
-
const document
|
|
78
|
+
const document = getBlockDocument<DocumentInterface>(parent, args.response.document);
|
|
68
79
|
if (!document) {
|
|
69
80
|
throw new Error(`Document with name "${args.response.document}" not found in tool execution context.`);
|
|
70
81
|
}
|
|
71
|
-
const responseSchema = document
|
|
82
|
+
const responseSchema = getBlockArgsSchema(document);
|
|
72
83
|
if (!responseSchema) {
|
|
73
84
|
throw new Error(`AI object generation source document must have a schema.`);
|
|
74
85
|
}
|
|
@@ -2,9 +2,14 @@ import { ModelMessage } from '@ai-sdk/provider-utils';
|
|
|
2
2
|
import { Injectable } from '@nestjs/common';
|
|
3
3
|
import { LanguageModel, ToolSet, UIMessage, convertToModelMessages, createUIMessageStream, streamText } from 'ai';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import {
|
|
6
|
+
Tool,
|
|
7
|
+
ToolInterface,
|
|
8
|
+
ToolResult,
|
|
9
|
+
WithArguments,
|
|
10
|
+
WorkflowExecution,
|
|
11
|
+
WorkflowInterface,
|
|
12
|
+
} from '@loopstack/common';
|
|
8
13
|
import { AiGenerateToolBaseSchema } from '../schemas/ai-generate-tool-base.schema';
|
|
9
14
|
import { AiMessagesHelperService } from '../services';
|
|
10
15
|
import { AiProviderModelHelperService } from '../services';
|
|
@@ -17,22 +22,24 @@ export const AiGenerateTextSchema = AiGenerateToolBaseSchema.extend({
|
|
|
17
22
|
type AiGenerateTextArgsType = z.infer<typeof AiGenerateTextSchema>;
|
|
18
23
|
|
|
19
24
|
@Injectable()
|
|
20
|
-
@
|
|
25
|
+
@Tool({
|
|
21
26
|
config: {
|
|
22
27
|
description: 'Generates text using a LLM',
|
|
23
28
|
},
|
|
24
29
|
})
|
|
25
30
|
@WithArguments(AiGenerateTextSchema)
|
|
26
|
-
export class AiGenerateText
|
|
31
|
+
export class AiGenerateText implements ToolInterface<AiGenerateTextArgsType> {
|
|
27
32
|
constructor(
|
|
28
33
|
private readonly aiMessagesHelperService: AiMessagesHelperService,
|
|
29
34
|
private readonly aiToolsHelperService: AiToolsHelperService,
|
|
30
35
|
private readonly aiProviderModelHelperService: AiProviderModelHelperService,
|
|
31
|
-
) {
|
|
32
|
-
super();
|
|
33
|
-
}
|
|
36
|
+
) {}
|
|
34
37
|
|
|
35
|
-
async execute(
|
|
38
|
+
async execute(
|
|
39
|
+
args: AiGenerateTextArgsType,
|
|
40
|
+
ctx: WorkflowExecution<any>,
|
|
41
|
+
parent: WorkflowInterface,
|
|
42
|
+
): Promise<ToolResult> {
|
|
36
43
|
const model = this.aiProviderModelHelperService.getProviderModel(args.llm);
|
|
37
44
|
|
|
38
45
|
const options: {
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
1
2
|
import { ToolUIPart, UIMessage } from 'ai';
|
|
2
3
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
Tool,
|
|
6
|
+
ToolInterface,
|
|
7
|
+
ToolResult,
|
|
8
|
+
WithArguments,
|
|
9
|
+
WorkflowExecution,
|
|
10
|
+
WorkflowInterface,
|
|
11
|
+
getBlockTool,
|
|
12
|
+
} from '@loopstack/common';
|
|
6
13
|
|
|
7
14
|
const DelegateToolCallsToolSchema = z.object({
|
|
8
15
|
message: z.object({
|
|
@@ -19,14 +26,19 @@ const DelegateToolCallsToolSchema = z.object({
|
|
|
19
26
|
|
|
20
27
|
type DelegateToolCallsToolArgs = z.infer<typeof DelegateToolCallsToolSchema>;
|
|
21
28
|
|
|
22
|
-
@
|
|
29
|
+
@Injectable()
|
|
30
|
+
@Tool({
|
|
23
31
|
config: {
|
|
24
32
|
description: 'Delegate a tool call.',
|
|
25
33
|
},
|
|
26
34
|
})
|
|
27
35
|
@WithArguments(DelegateToolCallsToolSchema)
|
|
28
|
-
export class DelegateToolCall
|
|
29
|
-
async execute(
|
|
36
|
+
export class DelegateToolCall implements ToolInterface<DelegateToolCallsToolArgs> {
|
|
37
|
+
async execute(
|
|
38
|
+
args: DelegateToolCallsToolArgs,
|
|
39
|
+
ctx: WorkflowExecution<any>,
|
|
40
|
+
parent: WorkflowInterface,
|
|
41
|
+
): Promise<ToolResult> {
|
|
30
42
|
const parts = args.message.parts;
|
|
31
43
|
const resultParts: ToolUIPart[] = [];
|
|
32
44
|
|
|
@@ -41,7 +53,7 @@ export class DelegateToolCall extends ToolBase<DelegateToolCallsToolArgs> {
|
|
|
41
53
|
|
|
42
54
|
const toolName = part.type.replace(/^tool-/, '');
|
|
43
55
|
|
|
44
|
-
const tool = parent
|
|
56
|
+
const tool = getBlockTool<ToolInterface>(parent, toolName);
|
|
45
57
|
if (!tool) {
|
|
46
58
|
throw new Error(`Tool ${toolName} not found.`);
|
|
47
59
|
}
|