digital-workers 0.1.1 → 2.0.2
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +17 -0
- package/README.md +290 -106
- package/dist/actions.d.ts +95 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +437 -0
- package/dist/actions.js.map +1 -0
- package/dist/approve.d.ts +49 -0
- package/dist/approve.d.ts.map +1 -0
- package/dist/approve.js +235 -0
- package/dist/approve.js.map +1 -0
- package/dist/ask.d.ts +42 -0
- package/dist/ask.d.ts.map +1 -0
- package/dist/ask.js +227 -0
- package/dist/ask.js.map +1 -0
- package/dist/decide.d.ts +62 -0
- package/dist/decide.d.ts.map +1 -0
- package/dist/decide.js +245 -0
- package/dist/decide.js.map +1 -0
- package/dist/do.d.ts +63 -0
- package/dist/do.d.ts.map +1 -0
- package/dist/do.js +228 -0
- package/dist/do.js.map +1 -0
- package/dist/generate.d.ts +61 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +299 -0
- package/dist/generate.js.map +1 -0
- package/dist/goals.d.ts +89 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +206 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/is.d.ts +54 -0
- package/dist/is.d.ts.map +1 -0
- package/dist/is.js +318 -0
- package/dist/is.js.map +1 -0
- package/dist/kpis.d.ts +103 -0
- package/dist/kpis.d.ts.map +1 -0
- package/dist/kpis.js +271 -0
- package/dist/kpis.js.map +1 -0
- package/dist/notify.d.ts +47 -0
- package/dist/notify.d.ts.map +1 -0
- package/dist/notify.js +220 -0
- package/dist/notify.js.map +1 -0
- package/dist/role.d.ts +53 -0
- package/dist/role.d.ts.map +1 -0
- package/dist/role.js +111 -0
- package/dist/role.js.map +1 -0
- package/dist/team.d.ts +61 -0
- package/dist/team.d.ts.map +1 -0
- package/dist/team.js +131 -0
- package/dist/team.js.map +1 -0
- package/dist/transports.d.ts +164 -0
- package/dist/transports.d.ts.map +1 -0
- package/dist/transports.js +358 -0
- package/dist/transports.js.map +1 -0
- package/dist/types.d.ts +693 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +72 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -61
- package/src/actions.ts +615 -0
- package/src/approve.ts +317 -0
- package/src/ask.ts +304 -0
- package/src/decide.ts +295 -0
- package/src/do.ts +275 -0
- package/src/generate.ts +364 -0
- package/src/goals.ts +220 -0
- package/src/index.ts +118 -0
- package/src/is.ts +372 -0
- package/src/kpis.ts +348 -0
- package/src/notify.ts +303 -0
- package/src/role.ts +116 -0
- package/src/team.ts +142 -0
- package/src/transports.ts +504 -0
- package/src/types.ts +843 -0
- package/test/actions.test.ts +546 -0
- package/test/standalone.test.ts +299 -0
- package/test/types.test.ts +460 -0
- package/tsconfig.json +9 -0
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -1,153 +1,337 @@
|
|
|
1
1
|
# digital-workers
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
Abstract interface for organizing digital work, independent of whether AI or humans perform individual tasks.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## Overview
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
**Digital workers** provides the foundational abstraction for structuring and organizing work in the digital enterprise. It defines a unified interface that both AI agents and humans implement, enabling you to design workflows without coupling them to specific execution strategies.
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
### Why This Abstraction Matters
|
|
11
10
|
|
|
12
|
-
-
|
|
13
|
-
- Context and memory management for long-running tasks
|
|
14
|
-
- Plan creation and execution for achieving objectives
|
|
15
|
-
- Multi-channel communication capabilities (Slack, Teams, Email, Phone)
|
|
16
|
-
- Enhanced autonomy through continuous self-evaluation
|
|
11
|
+
When building AI-powered systems, you face a fundamental question: *who should do this task?* Sometimes it's an AI agent operating autonomously. Sometimes it requires human judgment. Often it's a mix of both.
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
`digital-workers` lets you define work in terms of **what** needs to happen, not **who** does it:
|
|
19
14
|
|
|
20
|
-
|
|
15
|
+
```typescript
|
|
16
|
+
// This workflow doesn't care if alice is an AI agent or a human
|
|
17
|
+
await worker$.approve('Deploy v2.0 to production', alice, { via: 'slack' })
|
|
18
|
+
```
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
- **OKR Alignment**: Ensures actions align with organizational objectives and key results
|
|
20
|
+
The same Worker interface works whether `alice` is:
|
|
21
|
+
- A human product manager who gets a Slack notification
|
|
22
|
+
- An AI agent that evaluates deployment criteria autonomously
|
|
23
|
+
- A supervised AI that escalates to humans for high-risk decisions
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
### Package Relationships
|
|
29
26
|
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
```
|
|
28
|
+
┌─────────────────────────────────────────────────────────┐
|
|
29
|
+
│ ai-workflows │
|
|
30
|
+
│ (orchestrates work execution) │
|
|
31
|
+
└────────────────────────┬────────────────────────────────┘
|
|
32
|
+
│
|
|
33
|
+
▼
|
|
34
|
+
┌─────────────────────────────────────────────────────────┐
|
|
35
|
+
│ digital-workers │
|
|
36
|
+
│ (abstract interface for work & workers) │
|
|
37
|
+
└────────────────────────┬────────────────────────────────┘
|
|
38
|
+
│
|
|
39
|
+
┌─────────────┴─────────────┐
|
|
40
|
+
▼ ▼
|
|
41
|
+
┌─────────────────────┐ ┌─────────────────────────────┐
|
|
42
|
+
│ autonomous-agents │ │ human-in-the-loop │
|
|
43
|
+
│ (AI implementation)│ │ (human implementation) │
|
|
44
|
+
└─────────────────────┘ └─────────────────────────────┘
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- **digital-workers**: Defines the abstract `Worker` interface, action types, and communication patterns
|
|
48
|
+
- **autonomous-agents**: Implements `Worker` for AI agents with autonomous decision-making
|
|
49
|
+
- **human-in-the-loop**: Implements `Worker` for humans with approval workflows and notifications
|
|
33
50
|
|
|
34
|
-
|
|
35
|
-
yarn add digital-workers
|
|
51
|
+
## Installation
|
|
36
52
|
|
|
37
|
-
|
|
53
|
+
```bash
|
|
38
54
|
pnpm add digital-workers
|
|
39
55
|
```
|
|
40
56
|
|
|
41
|
-
##
|
|
57
|
+
## Core Concepts
|
|
58
|
+
|
|
59
|
+
### The Worker Abstraction
|
|
42
60
|
|
|
43
|
-
|
|
61
|
+
A **Worker** is the unified interface for any entity that can perform work—whether AI or human. This abstraction enables you to:
|
|
62
|
+
|
|
63
|
+
1. **Design workflows once** - Define your business logic without hardcoding execution strategy
|
|
64
|
+
2. **Swap implementations** - Start with humans, transition to AI agents as they prove reliable
|
|
65
|
+
3. **Mix freely** - Teams can include both AI agents and humans working together
|
|
66
|
+
4. **Route dynamically** - Assign tasks based on availability, capability, or risk level
|
|
67
|
+
|
|
68
|
+
### Worker
|
|
69
|
+
|
|
70
|
+
A **Worker** is the common interface for both AI agents and humans:
|
|
44
71
|
|
|
45
72
|
```typescript
|
|
46
|
-
import { Worker } from 'digital-workers'
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
name: '
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
73
|
+
import type { Worker } from 'digital-workers'
|
|
74
|
+
|
|
75
|
+
const alice: Worker = {
|
|
76
|
+
id: 'user_alice',
|
|
77
|
+
name: 'Alice',
|
|
78
|
+
type: 'human',
|
|
79
|
+
status: 'available',
|
|
80
|
+
contacts: {
|
|
81
|
+
email: 'alice@company.com',
|
|
82
|
+
slack: { workspace: 'acme', user: 'U123' },
|
|
83
|
+
phone: '+1-555-1234',
|
|
56
84
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const codeReviewer: Worker = {
|
|
88
|
+
id: 'agent_reviewer',
|
|
89
|
+
name: 'Code Reviewer',
|
|
90
|
+
type: 'agent',
|
|
91
|
+
status: 'available',
|
|
92
|
+
contacts: {
|
|
93
|
+
api: { endpoint: 'https://api.internal/reviewer', auth: 'bearer' },
|
|
94
|
+
webhook: { url: 'https://hooks.internal/reviewer' },
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Contacts
|
|
100
|
+
|
|
101
|
+
Workers have **contacts** that define how they can be reached:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import type { Contacts } from 'digital-workers'
|
|
105
|
+
|
|
106
|
+
const contacts: Contacts = {
|
|
107
|
+
email: 'team@company.com', // Simple string
|
|
108
|
+
slack: { workspace: 'acme', channel: '#eng' }, // Config object
|
|
109
|
+
phone: { number: '+1-555-0000', voice: 'en-US' },
|
|
110
|
+
sms: '+1-555-0001',
|
|
111
|
+
teams: { tenant: 'company', channel: 'Engineering' },
|
|
112
|
+
discord: { server: 'dev-community', channel: 'support' },
|
|
113
|
+
telegram: { chat: '@company_support' },
|
|
114
|
+
web: { url: 'https://dashboard.company.com', pushEnabled: true },
|
|
115
|
+
api: { endpoint: 'https://api.company.com', auth: 'bearer' },
|
|
116
|
+
webhook: { url: 'https://hooks.company.com/events' },
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Team
|
|
121
|
+
|
|
122
|
+
**Teams** group workers with shared contacts:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { Team } from 'digital-workers'
|
|
126
|
+
|
|
127
|
+
const engineering = Team({
|
|
128
|
+
id: 'team_eng',
|
|
129
|
+
name: 'Engineering',
|
|
130
|
+
members: [alice, bob, codeReviewer],
|
|
131
|
+
contacts: {
|
|
132
|
+
slack: '#engineering',
|
|
133
|
+
email: 'eng@company.com',
|
|
72
134
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
135
|
+
lead: alice,
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Worker Actions
|
|
140
|
+
|
|
141
|
+
Worker actions are durable workflow actions with Actor/Object semantics that integrate with `ai-workflows`:
|
|
142
|
+
|
|
143
|
+
### Using with Workflows (Recommended)
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { Workflow } from 'ai-workflows'
|
|
147
|
+
import { registerWorkerActions, withWorkers } from 'digital-workers'
|
|
148
|
+
|
|
149
|
+
const workflow = Workflow($ => {
|
|
150
|
+
registerWorkerActions($)
|
|
151
|
+
const worker$ = withWorkers($)
|
|
152
|
+
|
|
153
|
+
$.on.Expense.submitted(async (expense) => {
|
|
154
|
+
// Notify finance team
|
|
155
|
+
await worker$.notify(finance, `New expense: ${expense.amount}`)
|
|
156
|
+
|
|
157
|
+
// Request approval from manager
|
|
158
|
+
const approval = await worker$.approve(
|
|
159
|
+
`Expense: $${expense.amount} for ${expense.description}`,
|
|
160
|
+
manager,
|
|
161
|
+
{ via: 'slack' }
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
if (approval.approved) {
|
|
165
|
+
await worker$.notify(expense.submitter, 'Your expense was approved!')
|
|
80
166
|
}
|
|
81
|
-
}
|
|
167
|
+
})
|
|
82
168
|
})
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Direct Workflow Integration
|
|
83
172
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
173
|
+
```typescript
|
|
174
|
+
// Using $.do for durable actions
|
|
175
|
+
await $.do('Worker.notify', {
|
|
176
|
+
actor: 'system',
|
|
177
|
+
object: alice,
|
|
178
|
+
action: 'notify',
|
|
179
|
+
message: 'Deployment complete',
|
|
180
|
+
via: 'slack',
|
|
89
181
|
})
|
|
90
182
|
|
|
91
|
-
//
|
|
92
|
-
await
|
|
93
|
-
|
|
94
|
-
|
|
183
|
+
// Using $.send for fire-and-forget
|
|
184
|
+
await $.send('Worker.notified', { ... })
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Action Types
|
|
188
|
+
|
|
189
|
+
#### notify - Send notifications
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
await worker$.notify(target, 'Message content', {
|
|
193
|
+
via: 'slack', // Channel to use
|
|
194
|
+
priority: 'urgent', // 'low' | 'normal' | 'high' | 'urgent'
|
|
95
195
|
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### ask - Request information
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
const result = await worker$.ask<Priority>(
|
|
202
|
+
target,
|
|
203
|
+
'What priority should this be?',
|
|
204
|
+
{
|
|
205
|
+
via: 'slack',
|
|
206
|
+
schema: { priority: 'low | normal | high' },
|
|
207
|
+
}
|
|
208
|
+
)
|
|
209
|
+
console.log(result.answer) // { priority: 'high' }
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
#### approve - Request approval
|
|
96
213
|
|
|
97
|
-
|
|
98
|
-
await
|
|
99
|
-
|
|
100
|
-
|
|
214
|
+
```typescript
|
|
215
|
+
const result = await worker$.approve(
|
|
216
|
+
'Deploy v2.0 to production',
|
|
217
|
+
manager,
|
|
218
|
+
{
|
|
219
|
+
via: 'slack',
|
|
220
|
+
context: { version: '2.0', environment: 'production' },
|
|
221
|
+
timeout: 3600000, // 1 hour
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
if (result.approved) {
|
|
226
|
+
console.log(`Approved by ${result.approvedBy?.name}`)
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### decide - AI-powered decisions
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
const result = await worker$.decide({
|
|
234
|
+
options: ['React', 'Vue', 'Svelte'],
|
|
235
|
+
context: 'Choosing a frontend framework for our new project',
|
|
236
|
+
criteria: ['DX', 'Performance', 'Ecosystem'],
|
|
101
237
|
})
|
|
238
|
+
|
|
239
|
+
console.log(result.choice) // 'React'
|
|
240
|
+
console.log(result.reasoning) // 'React offers the best ecosystem...'
|
|
241
|
+
console.log(result.confidence) // 0.85
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Standalone Functions
|
|
245
|
+
|
|
246
|
+
For use outside workflows:
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { notify, ask, approve, decide } from 'digital-workers'
|
|
250
|
+
|
|
251
|
+
// Simple notification
|
|
252
|
+
await notify(alice, 'Task completed', { via: 'slack' })
|
|
253
|
+
|
|
254
|
+
// Ask with variants
|
|
255
|
+
await ask(alice, 'What is the status?')
|
|
256
|
+
await ask.ai('What is our refund policy?', { policies: [...] })
|
|
257
|
+
await ask.yesNo(manager, 'Should we proceed?')
|
|
258
|
+
|
|
259
|
+
// Approval variants
|
|
260
|
+
await approve('Deploy to production', manager)
|
|
261
|
+
await approve.all('Major change', [cto, vpe, securityLead])
|
|
262
|
+
await approve.any('Urgent fix', oncallTeam)
|
|
263
|
+
|
|
264
|
+
// Decision making
|
|
265
|
+
await decide({ options: ['A', 'B', 'C'], criteria: ['cost', 'time'] })
|
|
266
|
+
await decide.yesNo('Should we proceed?', context)
|
|
267
|
+
await decide.prioritize(['Task 1', 'Task 2', 'Task 3'])
|
|
102
268
|
```
|
|
103
269
|
|
|
104
|
-
##
|
|
270
|
+
## Additional Utilities
|
|
105
271
|
|
|
106
|
-
###
|
|
272
|
+
### Role Definition
|
|
107
273
|
|
|
108
|
-
|
|
274
|
+
```typescript
|
|
275
|
+
import { Role } from 'digital-workers'
|
|
276
|
+
|
|
277
|
+
const engineer = Role({
|
|
278
|
+
name: 'Software Engineer',
|
|
279
|
+
description: 'Builds and maintains software',
|
|
280
|
+
responsibilities: ['Write code', 'Review PRs', 'Fix bugs'],
|
|
281
|
+
skills: ['TypeScript', 'React', 'Node.js'],
|
|
282
|
+
})
|
|
283
|
+
```
|
|
109
284
|
|
|
110
|
-
|
|
285
|
+
### Goals & KPIs
|
|
111
286
|
|
|
112
|
-
|
|
287
|
+
```typescript
|
|
288
|
+
import { Goals, kpis, okrs } from 'digital-workers'
|
|
113
289
|
|
|
114
|
-
|
|
290
|
+
const teamGoals = Goals({
|
|
291
|
+
shortTerm: ['Ship v2.0', 'Reduce tech debt'],
|
|
292
|
+
longTerm: ['100% test coverage'],
|
|
293
|
+
metrics: [
|
|
294
|
+
{ name: 'Velocity', current: 42, target: 50, unit: 'points' },
|
|
295
|
+
],
|
|
296
|
+
})
|
|
297
|
+
```
|
|
115
298
|
|
|
116
|
-
|
|
299
|
+
### Content Generation
|
|
117
300
|
|
|
118
|
-
|
|
301
|
+
```typescript
|
|
302
|
+
import { generate } from 'digital-workers'
|
|
119
303
|
|
|
120
|
-
|
|
304
|
+
const result = await generate('Write a product description', {
|
|
305
|
+
type: 'text',
|
|
306
|
+
instructions: 'Keep it under 100 words',
|
|
307
|
+
})
|
|
308
|
+
```
|
|
121
309
|
|
|
122
|
-
|
|
123
|
-
| -------------- | ----------------------- | ------------------------------------------------- |
|
|
124
|
-
| name | string | The name of the worker |
|
|
125
|
-
| description | string | Description of the worker's purpose |
|
|
126
|
-
| id | string (optional) | Unique identifier for the worker |
|
|
127
|
-
| initialContext | object (optional) | Initial context data for the worker |
|
|
128
|
-
| initialPlans | Plan[] (optional) | Initial plans for the worker to execute |
|
|
129
|
-
| communication | CommunicationConfig | Configuration for communication channels |
|
|
130
|
-
| eventLoop | EventLoopConfig | Configuration for the event loop and KPI tracking |
|
|
310
|
+
### Type Validation
|
|
131
311
|
|
|
132
|
-
|
|
312
|
+
```typescript
|
|
313
|
+
import { is } from 'digital-workers'
|
|
133
314
|
|
|
134
|
-
|
|
315
|
+
const result = await is('hello@example.com', 'email')
|
|
316
|
+
console.log(result.valid) // true
|
|
317
|
+
```
|
|
135
318
|
|
|
136
|
-
|
|
137
|
-
| --------------- | --------------------------------------------------- | ----------------------------------------------------- |
|
|
138
|
-
| id | string | Unique identifier for the worker |
|
|
139
|
-
| agent | AutonomousAgent | The underlying autonomous agent |
|
|
140
|
-
| context | object | Current context data for the worker |
|
|
141
|
-
| plans | Plan[] | Current plans for the worker |
|
|
142
|
-
| execute | (input: any) => Promise<any> | Executes an action using the underlying agent |
|
|
143
|
-
| updateContext | (newContext: any) => Promise<void> | Updates the worker's context |
|
|
144
|
-
| sendMessage | (channel: string, message: any) => Promise<void> | Sends a message via the specified communication channel |
|
|
319
|
+
## Type Reference
|
|
145
320
|
|
|
146
|
-
|
|
321
|
+
Key types exported:
|
|
147
322
|
|
|
148
|
-
-
|
|
149
|
-
-
|
|
323
|
+
- `Worker` - Worker interface
|
|
324
|
+
- `Team` - Team interface
|
|
325
|
+
- `WorkerRef` - Lightweight worker reference
|
|
326
|
+
- `Contacts` - Contact configuration
|
|
327
|
+
- `ContactChannel` - Channel names
|
|
328
|
+
- `WorkerAction` - Action types
|
|
329
|
+
- `NotifyResult`, `AskResult`, `ApprovalResult`, `DecideResult`, `DoResult`
|
|
330
|
+
- `WorkerContext` - Context extension for workflows
|
|
150
331
|
|
|
151
|
-
##
|
|
332
|
+
## Related Packages
|
|
152
333
|
|
|
153
|
-
|
|
334
|
+
- `autonomous-agents` - **Implements** `Worker` for AI agents with autonomous decision-making, goals, and metrics
|
|
335
|
+
- `human-in-the-loop` - **Implements** `Worker` for humans with approval workflows, notifications, and escalation
|
|
336
|
+
- `ai-workflows` - **Uses** `digital-workers` to orchestrate work execution with durable, event-driven workflows
|
|
337
|
+
- `services-as-software` - External service integration (crosses company boundaries, unlike workers)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker Actions - Workflow Integration
|
|
3
|
+
*
|
|
4
|
+
* Worker actions (notify, ask, approve, decide, do) are durable workflow actions
|
|
5
|
+
* that integrate with ai-workflows. They can be invoked via:
|
|
6
|
+
*
|
|
7
|
+
* 1. `$.do('Worker.notify', data)` - Durable action
|
|
8
|
+
* 2. `$.send('Worker.notify', data)` - Fire and forget
|
|
9
|
+
* 3. `$.notify(target, message)` - Convenience method (when using withWorkers)
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import type { WorkflowContext } from 'ai-workflows';
|
|
14
|
+
import type { ActionTarget, NotifyActionData, AskActionData, ApproveActionData, DecideActionData, DoActionData, NotifyResult, AskResult, ApprovalResult, DecideResult, DoResult, NotifyOptions, AskOptions, ApproveOptions, DecideOptions, WorkerContext } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Handle Worker.notify action
|
|
17
|
+
*/
|
|
18
|
+
export declare function handleNotify(data: NotifyActionData, $: WorkflowContext): Promise<NotifyResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Handle Worker.ask action
|
|
21
|
+
*/
|
|
22
|
+
export declare function handleAsk<T = string>(data: AskActionData, $: WorkflowContext): Promise<AskResult<T>>;
|
|
23
|
+
/**
|
|
24
|
+
* Handle Worker.approve action
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleApprove(data: ApproveActionData, $: WorkflowContext): Promise<ApprovalResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Handle Worker.decide action
|
|
29
|
+
*/
|
|
30
|
+
export declare function handleDecide<T = string>(data: DecideActionData, $: WorkflowContext): Promise<DecideResult<T>>;
|
|
31
|
+
/**
|
|
32
|
+
* Handle Worker.do action
|
|
33
|
+
*/
|
|
34
|
+
export declare function handleDo<T = unknown>(data: DoActionData, $: WorkflowContext): Promise<DoResult<T>>;
|
|
35
|
+
/**
|
|
36
|
+
* Register Worker action handlers with a workflow
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { Workflow } from 'ai-workflows'
|
|
41
|
+
* import { registerWorkerActions } from 'digital-workers'
|
|
42
|
+
*
|
|
43
|
+
* const workflow = Workflow($ => {
|
|
44
|
+
* registerWorkerActions($)
|
|
45
|
+
*
|
|
46
|
+
* $.on.Expense.submitted(async (expense, $) => {
|
|
47
|
+
* const approval = await $.do('Worker.approve', {
|
|
48
|
+
* actor: 'system',
|
|
49
|
+
* object: manager,
|
|
50
|
+
* request: `Expense: $${expense.amount}`,
|
|
51
|
+
* via: 'slack',
|
|
52
|
+
* })
|
|
53
|
+
* })
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function registerWorkerActions($: WorkflowContext): void;
|
|
58
|
+
/**
|
|
59
|
+
* Extend WorkflowContext with convenience methods for worker actions
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const workflow = Workflow($ => {
|
|
64
|
+
* const worker$ = withWorkers($)
|
|
65
|
+
*
|
|
66
|
+
* $.on.Expense.submitted(async (expense) => {
|
|
67
|
+
* await worker$.notify(finance, `New expense: ${expense.amount}`)
|
|
68
|
+
*
|
|
69
|
+
* const approval = await worker$.approve(
|
|
70
|
+
* `Expense: $${expense.amount}`,
|
|
71
|
+
* manager,
|
|
72
|
+
* { via: 'slack' }
|
|
73
|
+
* )
|
|
74
|
+
* })
|
|
75
|
+
* })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function withWorkers($: WorkflowContext): WorkflowContext & WorkerContext;
|
|
79
|
+
/**
|
|
80
|
+
* Send a notification (standalone, non-durable)
|
|
81
|
+
*/
|
|
82
|
+
export declare function notify(target: ActionTarget, message: string, options?: NotifyOptions): Promise<NotifyResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Ask a question (standalone, non-durable)
|
|
85
|
+
*/
|
|
86
|
+
export declare function ask<T = string>(target: ActionTarget, question: string, options?: AskOptions): Promise<AskResult<T>>;
|
|
87
|
+
/**
|
|
88
|
+
* Request approval (standalone, non-durable)
|
|
89
|
+
*/
|
|
90
|
+
export declare function approve(request: string, target: ActionTarget, options?: ApproveOptions): Promise<ApprovalResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Make a decision (standalone, non-durable)
|
|
93
|
+
*/
|
|
94
|
+
export declare function decide<T = string>(options: DecideOptions<T>): Promise<DecideResult<T>>;
|
|
95
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,EAIV,YAAY,EAGZ,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,YAAY,CAAA;AAMnB;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,gBAAgB,EACtB,CAAC,EAAE,eAAe,GACjB,OAAO,CAAC,YAAY,CAAC,CAkDvB;AAED;;GAEG;AACH,wBAAsB,SAAS,CAAC,CAAC,GAAG,MAAM,EACxC,IAAI,EAAE,aAAa,EACnB,CAAC,EAAE,eAAe,GACjB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CA4BvB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,EACvB,CAAC,EAAE,eAAe,GACjB,OAAO,CAAC,cAAc,CAAC,CAiCzB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,GAAG,MAAM,EAC3C,IAAI,EAAE,gBAAgB,EACtB,CAAC,EAAE,eAAe,GACjB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAU1B;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,CAAC,GAAG,OAAO,EACxC,IAAI,EAAE,YAAY,EAClB,CAAC,EAAE,eAAe,GACjB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAyDtB;AAMD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,eAAe,GAAG,IAAI,CAY9D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,eAAe,GAAG,eAAe,GAAG,aAAa,CAgE/E;AAMD;;GAEG;AACH,wBAAsB,MAAM,CAC1B,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CA2BvB;AAED;;GAEG;AACH,wBAAsB,GAAG,CAAC,CAAC,GAAG,MAAM,EAClC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAgBvB;AAED;;GAEG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,cAAc,CAAC,CAiBzB;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,CAAC,GAAG,MAAM,EACrC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GACxB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1B"}
|