@loopstack/hitl 0.1.1 → 0.2.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 +110 -0
- package/dist/hitl.module.d.ts.map +1 -1
- package/dist/hitl.module.js +4 -2
- package/dist/hitl.module.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/ask-clarification.tool.d.ts +20 -0
- package/dist/tools/ask-clarification.tool.d.ts.map +1 -0
- package/dist/tools/ask-clarification.tool.js +75 -0
- package/dist/tools/ask-clarification.tool.js.map +1 -0
- package/dist/tools/ask-for-approval.tool.d.ts +13 -0
- package/dist/tools/ask-for-approval.tool.d.ts.map +1 -0
- package/dist/tools/ask-for-approval.tool.js +60 -0
- package/dist/tools/ask-for-approval.tool.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/workflows/ask-user/ask-user.workflow.d.ts.map +1 -1
- package/dist/workflows/ask-user/ask-user.workflow.js +2 -1
- package/dist/workflows/ask-user/ask-user.workflow.js.map +1 -1
- package/package.json +5 -8
- package/src/documents/ask-user-confirm-document.ts +0 -20
- package/src/documents/ask-user-confirm-document.yaml +0 -6
- package/src/documents/ask-user-document.ts +0 -20
- package/src/documents/ask-user-document.yaml +0 -6
- package/src/documents/ask-user-options-document.ts +0 -24
- package/src/documents/ask-user-options-document.yaml +0 -6
- package/src/documents/confirm-user-document.ts +0 -18
- package/src/documents/confirm-user-document.yaml +0 -16
- package/src/documents/index.ts +0 -12
- package/src/hitl.module.ts +0 -11
- package/src/index.ts +0 -3
- package/src/workflows/ask-user/ask-user.ui.yaml +0 -6
- package/src/workflows/ask-user/ask-user.workflow.ts +0 -83
- package/src/workflows/confirm-user/confirm-user.ui.yaml +0 -5
- package/src/workflows/confirm-user/confirm-user.workflow.ts +0 -29
- package/src/workflows/index.ts +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @loopstack/hitl
|
|
2
|
+
|
|
3
|
+
> A module for the [Loopstack AI](https://loopstack.ai) automation framework.
|
|
4
|
+
|
|
5
|
+
Human-in-the-loop (HITL) building blocks for Loopstack workflows. Pause a running workflow, ask the user a question, and resume once they answer.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Most non-trivial workflows need a human decision at some point — "is this the right file?", "do you want to proceed?", "pick one of these options". This module provides two ready-to-use workflows that handle the wait-for-user pattern, along with the document types that render the prompts in the UI.
|
|
10
|
+
|
|
11
|
+
By using this module you'll get:
|
|
12
|
+
|
|
13
|
+
- **`AskUserWorkflow`** — asks a free-text question, a yes/no confirmation, or a multiple-choice question (mode is a runtime arg)
|
|
14
|
+
- **`ConfirmUserWorkflow`** — shows markdown content and waits for a confirm / deny response
|
|
15
|
+
- **4 document types** that render the prompts: `AskUserDocument`, `AskUserConfirmDocument`, `AskUserOptionsDocument`, `ConfirmUserDocument`
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install @loopstack/hitl
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Register the module:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { HitlModule } from '@loopstack/hitl';
|
|
27
|
+
|
|
28
|
+
@Module({
|
|
29
|
+
imports: [HitlModule /* ... */],
|
|
30
|
+
})
|
|
31
|
+
export class AppModule {}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How It Works
|
|
35
|
+
|
|
36
|
+
### Asking a text question as a sub-workflow
|
|
37
|
+
|
|
38
|
+
Use `@InjectWorkflow()` to launch `AskUserWorkflow` from a parent workflow. The call resolves with the user's answer once they respond in the UI:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { BaseWorkflow, InjectWorkflow, Transition, Workflow } from '@loopstack/common';
|
|
42
|
+
import { AskUserWorkflow } from '@loopstack/hitl';
|
|
43
|
+
|
|
44
|
+
@Workflow({ uiConfig: __dirname + '/my.ui.yaml' })
|
|
45
|
+
export class MyWorkflow extends BaseWorkflow {
|
|
46
|
+
@InjectWorkflow() askUser: AskUserWorkflow;
|
|
47
|
+
|
|
48
|
+
@Transition({ from: 'ready', to: 'done' })
|
|
49
|
+
async collectName() {
|
|
50
|
+
const { answer } = await this.askUser.run({ question: 'What is your name?' }, { alias: 'askName' });
|
|
51
|
+
// use `answer`
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Multiple-choice and confirmation modes
|
|
57
|
+
|
|
58
|
+
`AskUserWorkflow` takes an optional `mode`:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
await this.askUser.run({
|
|
62
|
+
question: 'Which environment?',
|
|
63
|
+
mode: 'options',
|
|
64
|
+
options: ['staging', 'production'],
|
|
65
|
+
allowCustomAnswer: false,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await this.askUser.run({
|
|
69
|
+
question: 'Proceed with deletion?',
|
|
70
|
+
mode: 'confirm',
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Showing long-form content for confirmation
|
|
75
|
+
|
|
76
|
+
`ConfirmUserWorkflow` is for "review and confirm" flows where you want to render markdown (e.g. a summary) and get a confirm / deny response:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { ConfirmUserWorkflow } from '@loopstack/hitl';
|
|
80
|
+
|
|
81
|
+
const { confirmed } = await this.confirmUser.run({
|
|
82
|
+
markdown: '## About to commit\n\n- 3 files changed',
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Documents
|
|
87
|
+
|
|
88
|
+
Each workflow saves one of the document types on the workflow repository — the Studio UI picks up those documents and renders the corresponding input widget. You generally don't need to interact with the document classes directly, but they're exported if you want to query or post-process answers.
|
|
89
|
+
|
|
90
|
+
## Public API
|
|
91
|
+
|
|
92
|
+
- **Module:** `HitlModule`
|
|
93
|
+
- **Workflows:** `AskUserWorkflow`, `ConfirmUserWorkflow`
|
|
94
|
+
- **Documents:** `AskUserDocument`, `AskUserConfirmDocument`, `AskUserOptionsDocument`, `ConfirmUserDocument`
|
|
95
|
+
|
|
96
|
+
## Dependencies
|
|
97
|
+
|
|
98
|
+
- `@loopstack/common` — `BaseWorkflow`, decorators
|
|
99
|
+
- `@loopstack/core` — `LoopCoreModule`
|
|
100
|
+
|
|
101
|
+
## About
|
|
102
|
+
|
|
103
|
+
Author: [Jakob Klippel](https://www.linkedin.com/in/jakob-klippel/)
|
|
104
|
+
|
|
105
|
+
License: MIT
|
|
106
|
+
|
|
107
|
+
### Additional Resources
|
|
108
|
+
|
|
109
|
+
- [Loopstack Documentation](https://loopstack.ai/docs)
|
|
110
|
+
- Find more Loopstack modules in the [Loopstack Registry](https://loopstack.ai/registry)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hitl.module.d.ts","sourceRoot":"","sources":["../src/hitl.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hitl.module.d.ts","sourceRoot":"","sources":["../src/hitl.module.ts"],"names":[],"mappings":"AAOA,qBAKa,UAAU;CAAG"}
|
package/dist/hitl.module.js
CHANGED
|
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.HitlModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const core_1 = require("@loopstack/core");
|
|
12
|
+
const ask_clarification_tool_1 = require("./tools/ask-clarification.tool");
|
|
13
|
+
const ask_for_approval_tool_1 = require("./tools/ask-for-approval.tool");
|
|
12
14
|
const ask_user_workflow_1 = require("./workflows/ask-user/ask-user.workflow");
|
|
13
15
|
const confirm_user_workflow_1 = require("./workflows/confirm-user/confirm-user.workflow");
|
|
14
16
|
let HitlModule = class HitlModule {
|
|
@@ -17,8 +19,8 @@ exports.HitlModule = HitlModule;
|
|
|
17
19
|
exports.HitlModule = HitlModule = __decorate([
|
|
18
20
|
(0, common_1.Module)({
|
|
19
21
|
imports: [core_1.LoopCoreModule],
|
|
20
|
-
providers: [ask_user_workflow_1.AskUserWorkflow, confirm_user_workflow_1.ConfirmUserWorkflow],
|
|
21
|
-
exports: [ask_user_workflow_1.AskUserWorkflow, confirm_user_workflow_1.ConfirmUserWorkflow],
|
|
22
|
+
providers: [ask_user_workflow_1.AskUserWorkflow, confirm_user_workflow_1.ConfirmUserWorkflow, ask_clarification_tool_1.AskClarificationTool, ask_for_approval_tool_1.AskForApprovalTool],
|
|
23
|
+
exports: [ask_user_workflow_1.AskUserWorkflow, confirm_user_workflow_1.ConfirmUserWorkflow, ask_clarification_tool_1.AskClarificationTool, ask_for_approval_tool_1.AskForApprovalTool],
|
|
22
24
|
})
|
|
23
25
|
], HitlModule);
|
|
24
26
|
//# sourceMappingURL=hitl.module.js.map
|
package/dist/hitl.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hitl.module.js","sourceRoot":"","sources":["../src/hitl.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,0CAAiD;AACjD,8EAAyE;AACzE,0FAAqF;AAO9E,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,gCAAU;qBAAV,UAAU;IALtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAc,CAAC;QACzB,SAAS,EAAE,CAAC,mCAAe,EAAE,2CAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"hitl.module.js","sourceRoot":"","sources":["../src/hitl.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,0CAAiD;AACjD,2EAAsE;AACtE,yEAAmE;AACnE,8EAAyE;AACzE,0FAAqF;AAO9E,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,gCAAU;qBAAV,UAAU;IALtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAc,CAAC;QACzB,SAAS,EAAE,CAAC,mCAAe,EAAE,2CAAmB,EAAE,6CAAoB,EAAE,0CAAkB,CAAC;QAC3F,OAAO,EAAE,CAAC,mCAAe,EAAE,2CAAmB,EAAE,6CAAoB,EAAE,0CAAkB,CAAC;KAC1F,CAAC;GACW,UAAU,CAAG"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
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;AAC5B,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./documents"), exports);
|
|
18
|
+
__exportStar(require("./tools"), exports);
|
|
18
19
|
__exportStar(require("./workflows"), exports);
|
|
19
20
|
__exportStar(require("./hitl.module"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8CAA4B;AAC5B,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB;AACxB,8CAA4B;AAC5B,gDAA8B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BaseTool, ToolCallOptions, ToolResult } from '@loopstack/common';
|
|
3
|
+
declare const AskClarificationInputSchema: z.ZodObject<{
|
|
4
|
+
question: z.ZodString;
|
|
5
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
6
|
+
options: "options";
|
|
7
|
+
text: "text";
|
|
8
|
+
confirm: "confirm";
|
|
9
|
+
}>>;
|
|
10
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
allowCustomAnswer: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
type AskClarificationInput = z.infer<typeof AskClarificationInputSchema>;
|
|
14
|
+
export declare class AskClarificationTool extends BaseTool {
|
|
15
|
+
private askUser;
|
|
16
|
+
call(args: AskClarificationInput, options?: ToolCallOptions): Promise<ToolResult>;
|
|
17
|
+
complete(result: Record<string, unknown>): Promise<ToolResult>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=ask-clarification.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-clarification.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ask-clarification.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAsC,eAAe,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG9G,QAAA,MAAM,2BAA2B;;;;;;;;;kBAyBtB,CAAC;AAEZ,KAAK,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEzE,qBASa,oBAAqB,SAAQ,QAAQ;IAC9B,OAAO,CAAC,OAAO,CAAkB;IAE7C,IAAI,CAAC,IAAI,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAyBjF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;CAWrE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AskClarificationTool = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const common_1 = require("@loopstack/common");
|
|
15
|
+
const ask_user_workflow_1 = require("../workflows/ask-user/ask-user.workflow");
|
|
16
|
+
const AskClarificationInputSchema = zod_1.z
|
|
17
|
+
.object({
|
|
18
|
+
question: zod_1.z
|
|
19
|
+
.string()
|
|
20
|
+
.describe('The clarification question to ask the user. Be specific about what information you need and why.'),
|
|
21
|
+
mode: zod_1.z
|
|
22
|
+
.enum(['text', 'options', 'confirm'])
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('How the question is presented. "text" (default) shows a free-text input. ' +
|
|
25
|
+
'"options" shows a list of choices for the user to pick from. ' +
|
|
26
|
+
'"confirm" shows Yes / No buttons.'),
|
|
27
|
+
options: zod_1.z
|
|
28
|
+
.array(zod_1.z.string())
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('The list of choices when mode is "options". Required when mode is "options".'),
|
|
31
|
+
allowCustomAnswer: zod_1.z
|
|
32
|
+
.boolean()
|
|
33
|
+
.optional()
|
|
34
|
+
.describe('When mode is "options", set to true to show an additional free-text input ' +
|
|
35
|
+
'so the user can provide a custom answer not in the list.'),
|
|
36
|
+
})
|
|
37
|
+
.strict();
|
|
38
|
+
let AskClarificationTool = class AskClarificationTool extends common_1.BaseTool {
|
|
39
|
+
askUser;
|
|
40
|
+
async call(args, options) {
|
|
41
|
+
const result = await this.askUser.run({
|
|
42
|
+
question: args.question,
|
|
43
|
+
mode: args.mode,
|
|
44
|
+
options: args.options,
|
|
45
|
+
allowCustomAnswer: args.allowCustomAnswer,
|
|
46
|
+
}, { alias: 'askUser', callback: options?.callback });
|
|
47
|
+
const workflowId = result.workflowId;
|
|
48
|
+
await this.repository.save(common_1.LinkDocument, { status: 'pending', label: 'Waiting for user answer...', workflowId, embed: true, expanded: true }, { id: `ask_clarification_link_${workflowId}` });
|
|
49
|
+
return {
|
|
50
|
+
data: { workflowId },
|
|
51
|
+
pending: { workflowId },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async complete(result) {
|
|
55
|
+
const data = result;
|
|
56
|
+
await this.repository.save(common_1.LinkDocument, { status: 'success', label: 'User answered', workflowId: data.workflowId, embed: true, expanded: false }, { id: `ask_clarification_link_${data.workflowId}` });
|
|
57
|
+
return { data: data.data?.answer ?? result };
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.AskClarificationTool = AskClarificationTool;
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, common_1.InjectWorkflow)(),
|
|
63
|
+
__metadata("design:type", ask_user_workflow_1.AskUserWorkflow)
|
|
64
|
+
], AskClarificationTool.prototype, "askUser", void 0);
|
|
65
|
+
exports.AskClarificationTool = AskClarificationTool = __decorate([
|
|
66
|
+
(0, common_1.Tool)({
|
|
67
|
+
uiConfig: {
|
|
68
|
+
description: 'Ask the user a clarification question and wait for their answer. ' +
|
|
69
|
+
'Use this when you need more information from the user before you can proceed. ' +
|
|
70
|
+
'IMPORTANT: This must be the only tool call in your response.',
|
|
71
|
+
},
|
|
72
|
+
schema: AskClarificationInputSchema,
|
|
73
|
+
})
|
|
74
|
+
], AskClarificationTool);
|
|
75
|
+
//# sourceMappingURL=ask-clarification.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-clarification.tool.js","sourceRoot":"","sources":["../../src/tools/ask-clarification.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAwB;AACxB,8CAA8G;AAC9G,+EAA0E;AAE1E,MAAM,2BAA2B,GAAG,OAAC;KAClC,MAAM,CAAC;IACN,QAAQ,EAAE,OAAC;SACR,MAAM,EAAE;SACR,QAAQ,CAAC,kGAAkG,CAAC;IAC/G,IAAI,EAAE,OAAC;SACJ,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;SACpC,QAAQ,EAAE;SACV,QAAQ,CACP,2EAA2E;QACzE,+DAA+D;QAC/D,mCAAmC,CACtC;IACH,OAAO,EAAE,OAAC;SACP,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CAAC,8EAA8E,CAAC;IAC3F,iBAAiB,EAAE,OAAC;SACjB,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,QAAQ,CACP,4EAA4E;QAC1E,0DAA0D,CAC7D;CACJ,CAAC;KACD,MAAM,EAAE,CAAC;AAaL,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,iBAAQ;IACtB,OAAO,CAAkB;IAEnD,KAAK,CAAC,IAAI,CAAC,IAA2B,EAAE,OAAyB;QAC/D,MAAM,MAAM,GAAG,M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,IAAA,aAAI,EAAC;QACJ,QAAQ,EAAE;YACR,WAAW,EACT,mEAAmE;gBACnE,gFAAgF;gBAChF,8DAA8D;SACjE;QACD,MAAM,EAAE,2BAA2B;KACpC,CAAC;GACW,oBAAoB,CAuChC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { BaseTool, ToolCallOptions, ToolResult } from '@loopstack/common';
|
|
3
|
+
declare const AskForApprovalInputSchema: z.ZodObject<{
|
|
4
|
+
concept: z.ZodString;
|
|
5
|
+
}, z.core.$strict>;
|
|
6
|
+
type AskForApprovalInput = z.infer<typeof AskForApprovalInputSchema>;
|
|
7
|
+
export declare class AskForApprovalTool extends BaseTool {
|
|
8
|
+
private confirmUser;
|
|
9
|
+
call(args: AskForApprovalInput, options?: ToolCallOptions): Promise<ToolResult>;
|
|
10
|
+
complete(result: Record<string, unknown>): Promise<ToolResult>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=ask-for-approval.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-for-approval.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ask-for-approval.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAsC,eAAe,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG9G,QAAA,MAAM,yBAAyB;;kBAIpB,CAAC;AAEZ,KAAK,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAErE,qBASa,kBAAmB,SAAQ,QAAQ;IAC5B,OAAO,CAAC,WAAW,CAAsB;IAErD,IAAI,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAoB/E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;CAkBrE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AskForApprovalTool = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const common_1 = require("@loopstack/common");
|
|
15
|
+
const confirm_user_workflow_1 = require("../workflows/confirm-user/confirm-user.workflow");
|
|
16
|
+
const AskForApprovalInputSchema = zod_1.z
|
|
17
|
+
.object({
|
|
18
|
+
concept: zod_1.z.string().describe('The final concept as a markdown string to present for user approval.'),
|
|
19
|
+
})
|
|
20
|
+
.strict();
|
|
21
|
+
let AskForApprovalTool = class AskForApprovalTool extends common_1.BaseTool {
|
|
22
|
+
confirmUser;
|
|
23
|
+
async call(args, options) {
|
|
24
|
+
const result = await this.confirmUser.run({ markdown: args.concept }, { alias: 'confirmUser', callback: options?.callback });
|
|
25
|
+
const workflowId = result.workflowId;
|
|
26
|
+
await this.repository.save(common_1.LinkDocument, { status: 'pending', label: 'Waiting for approval...', workflowId, embed: true, expanded: true }, { id: `ask_for_approval_link_${workflowId}` });
|
|
27
|
+
return {
|
|
28
|
+
data: { workflowId },
|
|
29
|
+
pending: { workflowId },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async complete(result) {
|
|
33
|
+
const data = result;
|
|
34
|
+
const approved = data.data?.confirmed ?? false;
|
|
35
|
+
await this.repository.save(common_1.LinkDocument, {
|
|
36
|
+
status: approved ? 'success' : 'failure',
|
|
37
|
+
label: approved ? 'Concept approved' : 'Concept denied',
|
|
38
|
+
workflowId: data.workflowId,
|
|
39
|
+
embed: true,
|
|
40
|
+
expanded: false,
|
|
41
|
+
}, { id: `ask_for_approval_link_${data.workflowId}` });
|
|
42
|
+
return { data: approved ? { concept: data.data?.markdown } : { denied: true } };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.AskForApprovalTool = AskForApprovalTool;
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, common_1.InjectWorkflow)(),
|
|
48
|
+
__metadata("design:type", confirm_user_workflow_1.ConfirmUserWorkflow)
|
|
49
|
+
], AskForApprovalTool.prototype, "confirmUser", void 0);
|
|
50
|
+
exports.AskForApprovalTool = AskForApprovalTool = __decorate([
|
|
51
|
+
(0, common_1.Tool)({
|
|
52
|
+
uiConfig: {
|
|
53
|
+
description: 'Present the final concept to the user for approval. The concept is shown as formatted markdown ' +
|
|
54
|
+
'with a confirm button. Call this when the user indicates the concept is complete. ' +
|
|
55
|
+
'IMPORTANT: This must be the only tool call in your response.',
|
|
56
|
+
},
|
|
57
|
+
schema: AskForApprovalInputSchema,
|
|
58
|
+
})
|
|
59
|
+
], AskForApprovalTool);
|
|
60
|
+
//# sourceMappingURL=ask-for-approval.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-for-approval.tool.js","sourceRoot":"","sources":["../../src/tools/ask-for-approval.tool.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAwB;AACxB,8CAA8G;AAC9G,2FAAsF;AAEtF,MAAM,yBAAyB,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,UAAU,EAAE,IAAI,CAAC,UAAW;YAC5B,KAAK,EAAE,IAAI;YACX,QAAQ,EAAE,KAAK;SAChB,EACD,EAAE,EAAE,EAAE,yBAAyB,IAAI,CAAC,UAAU,EAAE,EAAE,CACnD,CAAC;QAEF,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;IAClF,CAAC;CACF,CAAA;AAzCY,gDAAkB;AACH;IAAzB,IAAA,uBAAc,GAAE;8BAAsB,2CAAmB;uDAAC;6BADhD,kBAAkB;IAT9B,IAAA,aAAI,EAAC;QACJ,QAAQ,EAAE;YACR,WAAW,EACT,iGAAiG;gBACjG,oFAAoF;gBACpF,8DAA8D;SACjE;QACD,MAAM,EAAE,yBAAyB;KAClC,CAAC;GACW,kBAAkB,CAyC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AskForApprovalTool = exports.AskClarificationTool = void 0;
|
|
4
|
+
var ask_clarification_tool_1 = require("./ask-clarification.tool");
|
|
5
|
+
Object.defineProperty(exports, "AskClarificationTool", { enumerable: true, get: function () { return ask_clarification_tool_1.AskClarificationTool; } });
|
|
6
|
+
var ask_for_approval_tool_1 = require("./ask-for-approval.tool");
|
|
7
|
+
Object.defineProperty(exports, "AskForApprovalTool", { enumerable: true, get: function () { return ask_for_approval_tool_1.AskForApprovalTool; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/ask-user/ask-user.workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA+C,MAAM,mBAAmB,CAAC;AAS9F,qBASa,eAAgB,SAAQ,YAAY;IAE/C,KAAK;IAIC,mBAAmB;IAenB,mBAAmB;IAMnB,gBAAgB;IAMhB,YAAY,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAuB5E,OAAO,CAAC,aAAa;
|
|
1
|
+
{"version":3,"file":"ask-user.workflow.d.ts","sourceRoot":"","sources":["../../../src/workflows/ask-user/ask-user.workflow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA+C,MAAM,mBAAmB,CAAC;AAS9F,qBASa,eAAgB,SAAQ,YAAY;IAE/C,KAAK;IAIC,mBAAmB;IAenB,mBAAmB;IAMnB,gBAAgB;IAMhB,YAAY,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAuB5E,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,aAAa;CAGtB"}
|
|
@@ -46,7 +46,8 @@ let AskUserWorkflow = class AskUserWorkflow extends common_1.BaseWorkflow {
|
|
|
46
46
|
return { answer: payload.answer };
|
|
47
47
|
}
|
|
48
48
|
isOptionsMode() {
|
|
49
|
-
|
|
49
|
+
const args = this.ctx.args;
|
|
50
|
+
return (args?.mode === 'options' || (args?.mode === undefined && Array.isArray(args?.options) && args.options.length > 0));
|
|
50
51
|
}
|
|
51
52
|
isConfirmMode() {
|
|
52
53
|
return this.ctx.args?.mode === 'confirm';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user.workflow.js","sourceRoot":"","sources":["../../../src/workflows/ask-user/ask-user.workflow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6BAAwB;AACxB,8CAA8F;AAC9F,yFAAmF;AACnF,yEAAoE;AACpE,yFAAmF;AAEnF,MAAM,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IACnC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAWI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,qBAAY;IAE/C,KAAK,KAAI,CAAC;IAIJ,AAAN,KAAK,CAAC,mBAAmB;QACvB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAIzD,CAAC;QACF,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CACxB,kDAAsB,EACtB,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,iBAAiB,EAAE,EACvD,EAAE,EAAE,EAAE,UAAU,EAAE,CACnB,CAAC;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,mBAAmB;QACvB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAA4B,CAAC;QAC3D,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,kDAAsB,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACvF,CAAC;IAGK,AAAN,KAAK,CAAC,gBAAgB;QACpB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAA4B,CAAC;QAC3D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",
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
20
|
"exports": {
|
|
21
|
-
".": "./dist/index.js"
|
|
22
|
-
"./src/*": "./src/*"
|
|
21
|
+
".": "./dist/index.js"
|
|
23
22
|
},
|
|
24
23
|
"scripts": {
|
|
25
24
|
"build": "nest build",
|
|
@@ -30,14 +29,13 @@
|
|
|
30
29
|
"watch": "nest build --watch"
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
|
-
"@loopstack/common": "^0.
|
|
34
|
-
"@loopstack/core": "^0.
|
|
32
|
+
"@loopstack/common": "^0.28.0",
|
|
33
|
+
"@loopstack/core": "^0.28.0",
|
|
35
34
|
"@nestjs/common": "^11.1.19",
|
|
36
35
|
"zod": "^4.3.6"
|
|
37
36
|
},
|
|
38
37
|
"files": [
|
|
39
|
-
"dist"
|
|
40
|
-
"src"
|
|
38
|
+
"dist"
|
|
41
39
|
],
|
|
42
40
|
"jest": {
|
|
43
41
|
"moduleFileExtensions": [
|
|
@@ -65,7 +63,6 @@
|
|
|
65
63
|
}
|
|
66
64
|
],
|
|
67
65
|
"installModes": [
|
|
68
|
-
"add",
|
|
69
66
|
"install"
|
|
70
67
|
]
|
|
71
68
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Document } from '@loopstack/common';
|
|
3
|
-
|
|
4
|
-
export const AskUserConfirmDocumentSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
question: z.string(),
|
|
7
|
-
answer: z.string().optional(),
|
|
8
|
-
})
|
|
9
|
-
.strict();
|
|
10
|
-
|
|
11
|
-
export type AskUserConfirmDocumentType = z.infer<typeof AskUserConfirmDocumentSchema>;
|
|
12
|
-
|
|
13
|
-
@Document({
|
|
14
|
-
uiConfig: __dirname + '/ask-user-confirm-document.yaml',
|
|
15
|
-
schema: AskUserConfirmDocumentSchema,
|
|
16
|
-
})
|
|
17
|
-
export class AskUserConfirmDocument {
|
|
18
|
-
question: string;
|
|
19
|
-
answer?: string;
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Document } from '@loopstack/common';
|
|
3
|
-
|
|
4
|
-
export const AskUserDocumentSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
question: z.string(),
|
|
7
|
-
answer: z.string().optional(),
|
|
8
|
-
})
|
|
9
|
-
.strict();
|
|
10
|
-
|
|
11
|
-
export type AskUserDocumentType = z.infer<typeof AskUserDocumentSchema>;
|
|
12
|
-
|
|
13
|
-
@Document({
|
|
14
|
-
uiConfig: __dirname + '/ask-user-document.yaml',
|
|
15
|
-
schema: AskUserDocumentSchema,
|
|
16
|
-
})
|
|
17
|
-
export class AskUserDocument {
|
|
18
|
-
question: string;
|
|
19
|
-
answer?: string;
|
|
20
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Document } from '@loopstack/common';
|
|
3
|
-
|
|
4
|
-
export const AskUserOptionsDocumentSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
question: z.string(),
|
|
7
|
-
options: z.array(z.string()),
|
|
8
|
-
allowCustomAnswer: z.boolean().optional(),
|
|
9
|
-
answer: z.string().optional(),
|
|
10
|
-
})
|
|
11
|
-
.strict();
|
|
12
|
-
|
|
13
|
-
export type AskUserOptionsDocumentType = z.infer<typeof AskUserOptionsDocumentSchema>;
|
|
14
|
-
|
|
15
|
-
@Document({
|
|
16
|
-
uiConfig: __dirname + '/ask-user-options-document.yaml',
|
|
17
|
-
schema: AskUserOptionsDocumentSchema,
|
|
18
|
-
})
|
|
19
|
-
export class AskUserOptionsDocument {
|
|
20
|
-
question: string;
|
|
21
|
-
options: string[];
|
|
22
|
-
allowCustomAnswer?: boolean;
|
|
23
|
-
answer?: string;
|
|
24
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { Document } from '@loopstack/common';
|
|
3
|
-
|
|
4
|
-
export const ConfirmUserDocumentSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
markdown: z.string(),
|
|
7
|
-
})
|
|
8
|
-
.strict();
|
|
9
|
-
|
|
10
|
-
export type ConfirmUserDocumentType = z.infer<typeof ConfirmUserDocumentSchema>;
|
|
11
|
-
|
|
12
|
-
@Document({
|
|
13
|
-
uiConfig: __dirname + '/confirm-user-document.yaml',
|
|
14
|
-
schema: ConfirmUserDocumentSchema,
|
|
15
|
-
})
|
|
16
|
-
export class ConfirmUserDocument {
|
|
17
|
-
markdown: string;
|
|
18
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
type: document
|
|
2
|
-
ui:
|
|
3
|
-
widgets:
|
|
4
|
-
- widget: form
|
|
5
|
-
options:
|
|
6
|
-
properties:
|
|
7
|
-
markdown:
|
|
8
|
-
widget: markdown-view
|
|
9
|
-
actions:
|
|
10
|
-
- type: button
|
|
11
|
-
transition: userDenied
|
|
12
|
-
label: 'Deny'
|
|
13
|
-
variant: outline
|
|
14
|
-
- type: button
|
|
15
|
-
transition: userConfirmed
|
|
16
|
-
label: 'Confirm'
|
package/src/documents/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { AskUserDocument, AskUserDocumentSchema, AskUserDocumentType } from './ask-user-document';
|
|
2
|
-
export {
|
|
3
|
-
AskUserConfirmDocument,
|
|
4
|
-
AskUserConfirmDocumentSchema,
|
|
5
|
-
AskUserConfirmDocumentType,
|
|
6
|
-
} from './ask-user-confirm-document';
|
|
7
|
-
export {
|
|
8
|
-
AskUserOptionsDocument,
|
|
9
|
-
AskUserOptionsDocumentSchema,
|
|
10
|
-
AskUserOptionsDocumentType,
|
|
11
|
-
} from './ask-user-options-document';
|
|
12
|
-
export { ConfirmUserDocument, ConfirmUserDocumentSchema, ConfirmUserDocumentType } from './confirm-user-document';
|
package/src/hitl.module.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
2
|
-
import { LoopCoreModule } from '@loopstack/core';
|
|
3
|
-
import { AskUserWorkflow } from './workflows/ask-user/ask-user.workflow';
|
|
4
|
-
import { ConfirmUserWorkflow } from './workflows/confirm-user/confirm-user.workflow';
|
|
5
|
-
|
|
6
|
-
@Module({
|
|
7
|
-
imports: [LoopCoreModule],
|
|
8
|
-
providers: [AskUserWorkflow, ConfirmUserWorkflow],
|
|
9
|
-
exports: [AskUserWorkflow, ConfirmUserWorkflow],
|
|
10
|
-
})
|
|
11
|
-
export class HitlModule {}
|
package/src/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
title: 'Ask User'
|
|
2
|
-
|
|
3
|
-
description: |
|
|
4
|
-
Generic sub-workflow that presents a question to the user and waits for their answer.
|
|
5
|
-
Used by async tool calls (e.g. askClarification) to interrupt an agent loop for user input.
|
|
6
|
-
Supports three modes: text (default), options (pick from a list), and confirm (yes/no).
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { BaseWorkflow, Final, Guard, Initial, Transition, Workflow } from '@loopstack/common';
|
|
3
|
-
import { AskUserConfirmDocument } from '../../documents/ask-user-confirm-document';
|
|
4
|
-
import { AskUserDocument } from '../../documents/ask-user-document';
|
|
5
|
-
import { AskUserOptionsDocument } from '../../documents/ask-user-options-document';
|
|
6
|
-
|
|
7
|
-
const AskUserAnswerSchema = z.object({
|
|
8
|
-
answer: z.string(),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
@Workflow({
|
|
12
|
-
uiConfig: __dirname + '/ask-user.ui.yaml',
|
|
13
|
-
schema: z.object({
|
|
14
|
-
question: z.string(),
|
|
15
|
-
mode: z.enum(['text', 'options', 'confirm']).optional(),
|
|
16
|
-
options: z.array(z.string()).optional(),
|
|
17
|
-
allowCustomAnswer: z.boolean().optional(),
|
|
18
|
-
}),
|
|
19
|
-
})
|
|
20
|
-
export class AskUserWorkflow extends BaseWorkflow {
|
|
21
|
-
@Initial({ to: 'show_question' })
|
|
22
|
-
start() {}
|
|
23
|
-
|
|
24
|
-
@Transition({ from: 'show_question', to: 'waiting_for_user', priority: 10 })
|
|
25
|
-
@Guard('isOptionsMode')
|
|
26
|
-
async showQuestionOptions() {
|
|
27
|
-
const { question, options, allowCustomAnswer } = this.ctx.args as {
|
|
28
|
-
question: string;
|
|
29
|
-
options?: string[];
|
|
30
|
-
allowCustomAnswer?: boolean;
|
|
31
|
-
};
|
|
32
|
-
await this.repository.save(
|
|
33
|
-
AskUserOptionsDocument,
|
|
34
|
-
{ question, options: options ?? [], allowCustomAnswer },
|
|
35
|
-
{ id: 'question' },
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@Transition({ from: 'show_question', to: 'waiting_for_user', priority: 10 })
|
|
40
|
-
@Guard('isConfirmMode')
|
|
41
|
-
async showQuestionConfirm() {
|
|
42
|
-
const { question } = this.ctx.args as { question: string };
|
|
43
|
-
await this.repository.save(AskUserConfirmDocument, { question }, { id: 'question' });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@Transition({ from: 'show_question', to: 'waiting_for_user' })
|
|
47
|
-
async showQuestionText() {
|
|
48
|
-
const { question } = this.ctx.args as { question: string };
|
|
49
|
-
await this.repository.save(AskUserDocument, { question }, { id: 'question' });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@Final({ from: 'waiting_for_user', wait: true, schema: AskUserAnswerSchema })
|
|
53
|
-
async userAnswered(payload: { answer: string }): Promise<{ answer: string }> {
|
|
54
|
-
const { question, mode, options, allowCustomAnswer } = this.ctx.args as {
|
|
55
|
-
question: string;
|
|
56
|
-
mode?: string;
|
|
57
|
-
options?: string[];
|
|
58
|
-
allowCustomAnswer?: boolean;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
if (mode === 'options') {
|
|
62
|
-
await this.repository.save(
|
|
63
|
-
AskUserOptionsDocument,
|
|
64
|
-
{ question, options: options ?? [], allowCustomAnswer, answer: payload.answer },
|
|
65
|
-
{ id: 'question' },
|
|
66
|
-
);
|
|
67
|
-
} else if (mode === 'confirm') {
|
|
68
|
-
await this.repository.save(AskUserConfirmDocument, { question, answer: payload.answer }, { id: 'question' });
|
|
69
|
-
} else {
|
|
70
|
-
await this.repository.save(AskUserDocument, { question, answer: payload.answer }, { id: 'question' });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return { answer: payload.answer };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private isOptionsMode(): boolean {
|
|
77
|
-
return (this.ctx.args as { mode?: string })?.mode === 'options';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private isConfirmMode(): boolean {
|
|
81
|
-
return (this.ctx.args as { mode?: string })?.mode === 'confirm';
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { BaseWorkflow, Final, Initial, Workflow } from '@loopstack/common';
|
|
3
|
-
import { ConfirmUserDocument } from '../../documents/confirm-user-document';
|
|
4
|
-
|
|
5
|
-
@Workflow({
|
|
6
|
-
uiConfig: __dirname + '/confirm-user.ui.yaml',
|
|
7
|
-
schema: z.object({
|
|
8
|
-
markdown: z.string(),
|
|
9
|
-
}),
|
|
10
|
-
})
|
|
11
|
-
export class ConfirmUserWorkflow extends BaseWorkflow {
|
|
12
|
-
markdown?: string;
|
|
13
|
-
|
|
14
|
-
@Initial({ to: 'waiting_for_confirmation' })
|
|
15
|
-
async showContent(args: { markdown: string }) {
|
|
16
|
-
this.markdown = args.markdown;
|
|
17
|
-
await this.repository.save(ConfirmUserDocument, { markdown: args.markdown }, { id: 'content' });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@Final({ from: 'waiting_for_confirmation', wait: true })
|
|
21
|
-
async userConfirmed(): Promise<{ confirmed: boolean; markdown: string }> {
|
|
22
|
-
return Promise.resolve({ confirmed: true, markdown: this.markdown! });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@Final({ from: 'waiting_for_confirmation', wait: true })
|
|
26
|
-
async userDenied(): Promise<{ confirmed: boolean; markdown: string }> {
|
|
27
|
-
return Promise.resolve({ confirmed: false, markdown: this.markdown! });
|
|
28
|
-
}
|
|
29
|
-
}
|
package/src/workflows/index.ts
DELETED