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/dist/decide.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision-making functionality for digital workers
|
|
3
|
+
*/
|
|
4
|
+
import { generateObject } from 'ai-functions';
|
|
5
|
+
/**
|
|
6
|
+
* Make a decision from a set of options
|
|
7
|
+
*
|
|
8
|
+
* Uses AI to evaluate options and make a reasoned decision,
|
|
9
|
+
* or can route to human decision-makers for critical choices.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Decision options with configuration
|
|
12
|
+
* @returns Promise resolving to decision result
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const decision = await decide({
|
|
17
|
+
* options: ['Option A', 'Option B', 'Option C'],
|
|
18
|
+
* context: 'We need to choose a technology stack for our new project',
|
|
19
|
+
* criteria: [
|
|
20
|
+
* 'Developer experience',
|
|
21
|
+
* 'Performance',
|
|
22
|
+
* 'Community support',
|
|
23
|
+
* 'Long-term viability',
|
|
24
|
+
* ],
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* console.log(`Decision: ${decision.choice}`)
|
|
28
|
+
* console.log(`Reasoning: ${decision.reasoning}`)
|
|
29
|
+
* console.log(`Confidence: ${decision.confidence}`)
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* // Complex decision with structured options
|
|
35
|
+
* const decision = await decide({
|
|
36
|
+
* options: [
|
|
37
|
+
* { id: 'migrate', label: 'Migrate to new platform' },
|
|
38
|
+
* { id: 'refactor', label: 'Refactor existing system' },
|
|
39
|
+
* { id: 'rebuild', label: 'Rebuild from scratch' },
|
|
40
|
+
* ],
|
|
41
|
+
* context: {
|
|
42
|
+
* budget: '$500k',
|
|
43
|
+
* timeline: '6 months',
|
|
44
|
+
* teamSize: 5,
|
|
45
|
+
* currentSystem: 'Legacy monolith',
|
|
46
|
+
* },
|
|
47
|
+
* criteria: ['Cost', 'Time to market', 'Risk', 'Scalability'],
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export async function decide(options) {
|
|
52
|
+
const { options: choices, context, criteria = [], includeReasoning = true, } = options;
|
|
53
|
+
// Format context for the prompt
|
|
54
|
+
const contextStr = typeof context === 'string'
|
|
55
|
+
? context
|
|
56
|
+
: context
|
|
57
|
+
? JSON.stringify(context, null, 2)
|
|
58
|
+
: 'No additional context provided';
|
|
59
|
+
// Format choices for the prompt
|
|
60
|
+
const choicesStr = choices
|
|
61
|
+
.map((choice, i) => {
|
|
62
|
+
if (typeof choice === 'object' && choice !== null) {
|
|
63
|
+
return `${i + 1}. ${JSON.stringify(choice)}`;
|
|
64
|
+
}
|
|
65
|
+
return `${i + 1}. ${choice}`;
|
|
66
|
+
})
|
|
67
|
+
.join('\n');
|
|
68
|
+
const result = await generateObject({
|
|
69
|
+
model: 'sonnet',
|
|
70
|
+
schema: {
|
|
71
|
+
choice: 'The chosen option (must be one of the provided options)',
|
|
72
|
+
reasoning: includeReasoning
|
|
73
|
+
? 'Detailed reasoning explaining why this choice is best'
|
|
74
|
+
: 'Brief explanation of the choice',
|
|
75
|
+
confidence: 'Confidence level in this decision as a decimal (number)',
|
|
76
|
+
alternatives: [
|
|
77
|
+
{
|
|
78
|
+
option: 'An alternative option that was considered',
|
|
79
|
+
score: 'Score for this alternative from 0-100 (number)',
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
criteriaScores: criteria.length > 0
|
|
83
|
+
? 'Scores for each criterion as object mapping criterion name to score (0-100)'
|
|
84
|
+
: undefined,
|
|
85
|
+
},
|
|
86
|
+
system: `You are a decision-making expert. Analyze the options carefully and make the best choice based on the context and criteria provided.
|
|
87
|
+
|
|
88
|
+
${criteria.length > 0 ? `Evaluation Criteria:\n${criteria.map((c, i) => `${i + 1}. ${c}`).join('\n')}` : ''}`,
|
|
89
|
+
prompt: `Make a decision based on the following:
|
|
90
|
+
|
|
91
|
+
Context:
|
|
92
|
+
${contextStr}
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
${choicesStr}
|
|
96
|
+
|
|
97
|
+
${criteria.length > 0 ? `\nEvaluate each option against these criteria:\n${criteria.join(', ')}` : ''}
|
|
98
|
+
|
|
99
|
+
Provide your decision with clear reasoning.`,
|
|
100
|
+
});
|
|
101
|
+
const response = result.object;
|
|
102
|
+
return {
|
|
103
|
+
choice: response.choice,
|
|
104
|
+
reasoning: response.reasoning,
|
|
105
|
+
confidence: Math.min(1, Math.max(0, response.confidence)),
|
|
106
|
+
alternatives: response.alternatives,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Make a binary (yes/no) decision
|
|
111
|
+
*
|
|
112
|
+
* @param question - The yes/no question
|
|
113
|
+
* @param context - Context for the decision
|
|
114
|
+
* @returns Promise resolving to decision
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const decision = await decide.yesNo(
|
|
119
|
+
* 'Should we proceed with the deployment?',
|
|
120
|
+
* {
|
|
121
|
+
* tests: 'All passing',
|
|
122
|
+
* codeReview: 'Approved',
|
|
123
|
+
* loadTests: 'Within acceptable range',
|
|
124
|
+
* }
|
|
125
|
+
* )
|
|
126
|
+
*
|
|
127
|
+
* if (decision.choice === 'yes') {
|
|
128
|
+
* // Proceed with deployment
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
decide.yesNo = async (question, context) => {
|
|
133
|
+
return decide({
|
|
134
|
+
options: ['yes', 'no'],
|
|
135
|
+
context: typeof context === 'string'
|
|
136
|
+
? `${question}\n\n${context}`
|
|
137
|
+
: `${question}\n\n${context ? JSON.stringify(context, null, 2) : ''}`,
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Make a prioritization decision
|
|
142
|
+
*
|
|
143
|
+
* Ranks options by priority instead of choosing one.
|
|
144
|
+
*
|
|
145
|
+
* @param items - Items to prioritize
|
|
146
|
+
* @param context - Context for prioritization
|
|
147
|
+
* @param criteria - Criteria for prioritization
|
|
148
|
+
* @returns Promise resolving to prioritized list
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const prioritized = await decide.prioritize(
|
|
153
|
+
* ['Feature A', 'Bug fix B', 'Tech debt C', 'Feature D'],
|
|
154
|
+
* 'Sprint planning for next 2 weeks',
|
|
155
|
+
* ['User impact', 'Urgency', 'Effort required']
|
|
156
|
+
* )
|
|
157
|
+
*
|
|
158
|
+
* console.log('Priority order:', prioritized.map(p => p.choice))
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
decide.prioritize = async (items, context, criteria = []) => {
|
|
162
|
+
const contextStr = typeof context === 'string'
|
|
163
|
+
? context
|
|
164
|
+
: context
|
|
165
|
+
? JSON.stringify(context, null, 2)
|
|
166
|
+
: 'No additional context provided';
|
|
167
|
+
const itemsStr = items
|
|
168
|
+
.map((item, i) => `${i + 1}. ${typeof item === 'object' ? JSON.stringify(item) : item}`)
|
|
169
|
+
.join('\n');
|
|
170
|
+
const result = await generateObject({
|
|
171
|
+
model: 'sonnet',
|
|
172
|
+
schema: {
|
|
173
|
+
prioritized: [
|
|
174
|
+
{
|
|
175
|
+
item: 'The item',
|
|
176
|
+
rank: 'Priority rank (1 = highest) (number)',
|
|
177
|
+
reasoning: 'Why this priority',
|
|
178
|
+
confidence: 'Confidence in this ranking (number)',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
system: `You are a prioritization expert. Rank items by priority based on the context and criteria.
|
|
183
|
+
|
|
184
|
+
${criteria.length > 0 ? `Prioritization Criteria:\n${criteria.map((c, i) => `${i + 1}. ${c}`).join('\n')}` : ''}`,
|
|
185
|
+
prompt: `Prioritize the following items:
|
|
186
|
+
|
|
187
|
+
Context:
|
|
188
|
+
${contextStr}
|
|
189
|
+
|
|
190
|
+
Items:
|
|
191
|
+
${itemsStr}
|
|
192
|
+
|
|
193
|
+
${criteria.length > 0 ? `\nConsider these criteria when prioritizing:\n${criteria.join(', ')}` : ''}
|
|
194
|
+
|
|
195
|
+
Rank all items from highest to lowest priority.`,
|
|
196
|
+
});
|
|
197
|
+
const response = result.object;
|
|
198
|
+
return response.prioritized.map((p) => ({
|
|
199
|
+
choice: p.item,
|
|
200
|
+
rank: p.rank,
|
|
201
|
+
reasoning: p.reasoning,
|
|
202
|
+
confidence: Math.min(1, Math.max(0, p.confidence)),
|
|
203
|
+
}));
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Make a decision with approval required
|
|
207
|
+
*
|
|
208
|
+
* Makes a recommendation but requires human approval before finalizing.
|
|
209
|
+
*
|
|
210
|
+
* @param options - Decision options
|
|
211
|
+
* @param approver - Who should approve the decision
|
|
212
|
+
* @returns Promise resolving to approved decision
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const decision = await decide.withApproval(
|
|
217
|
+
* {
|
|
218
|
+
* options: ['Rollback', 'Fix forward', 'Wait'],
|
|
219
|
+
* context: 'Production incident - 500 errors on checkout',
|
|
220
|
+
* criteria: ['User impact', 'Recovery time', 'Risk'],
|
|
221
|
+
* },
|
|
222
|
+
* 'oncall-engineer@company.com'
|
|
223
|
+
* )
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
decide.withApproval = async (options, approver) => {
|
|
227
|
+
// First, make the decision
|
|
228
|
+
const decision = await decide(options);
|
|
229
|
+
// Then request approval
|
|
230
|
+
const { approve } = await import('./approve.js');
|
|
231
|
+
const approval = await approve(`Approve decision: ${decision.choice}`, { id: approver }, {
|
|
232
|
+
via: 'slack',
|
|
233
|
+
context: {
|
|
234
|
+
decision,
|
|
235
|
+
options: options.options,
|
|
236
|
+
context: options.context,
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
...decision,
|
|
241
|
+
approved: approval.approved,
|
|
242
|
+
approvedBy: approval.approvedBy?.id ?? approval.approvedBy?.name,
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
//# sourceMappingURL=decide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decide.js","sourceRoot":"","sources":["../src/decide.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAyB;IAEzB,MAAM,EACJ,OAAO,EAAE,OAAO,EAChB,OAAO,EACP,QAAQ,GAAG,EAAE,EACb,gBAAgB,GAAG,IAAI,GACxB,GAAG,OAAO,CAAA;IAEX,gCAAgC;IAChC,MAAM,UAAU,GAAG,OAAO,OAAO,KAAK,QAAQ;QAC5C,CAAC,CAAC,OAAO;QACT,CAAC,C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I;QACZ,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;KACnD,CAAC,CAAC,CAAA;AACL,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,YAAY,GAAG,KAAK,EACzB,OAAyB,EACzB,QAAgB,EACmD,EAAE;IACrE,2BAA2B;IAC3B,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAA;IAEtC,wBAAwB;IACxB,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAA;IAChD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAC5B,qBAAqB,QAAQ,CAAC,MAAM,EAAE,EACtC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAChB;QACE,GAAG,EAAE,OAAO;QACZ,OAAO,EAAE;YACP,QAAQ;YACR,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB;KACF,CACF,CAAA;IAED,OAAO;QACL,GAAG,QAAQ;QACX,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,QAAQ,CAAC,UAAU,EAAE,IAAI;KACjE,CAAA;AACH,CAAC,CAAA"}
|
package/dist/do.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task execution functionality for digital workers
|
|
3
|
+
*/
|
|
4
|
+
import type { TaskResult, DoOptions } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Execute a task
|
|
7
|
+
*
|
|
8
|
+
* Routes tasks to appropriate workers (AI or human) based on complexity
|
|
9
|
+
* and requirements. Handles retries, timeouts, and background execution.
|
|
10
|
+
*
|
|
11
|
+
* @param task - Description of the task to execute
|
|
12
|
+
* @param options - Execution options (retries, timeout, background, etc.)
|
|
13
|
+
* @returns Promise resolving to task result
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Execute a simple task
|
|
18
|
+
* const result = await do('Generate monthly sales report', {
|
|
19
|
+
* timeout: 60000, // 1 minute
|
|
20
|
+
* context: {
|
|
21
|
+
* month: 'January',
|
|
22
|
+
* year: 2024,
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* if (result.success) {
|
|
27
|
+
* console.log('Report:', result.result)
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // Execute with retries
|
|
34
|
+
* const result = await do('Sync data to backup server', {
|
|
35
|
+
* maxRetries: 3,
|
|
36
|
+
* timeout: 30000,
|
|
37
|
+
* context: {
|
|
38
|
+
* source: 'primary-db',
|
|
39
|
+
* destination: 'backup-db',
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // Execute in background
|
|
47
|
+
* const result = await do('Process large dataset', {
|
|
48
|
+
* background: true,
|
|
49
|
+
* context: {
|
|
50
|
+
* dataset: 'customer_transactions.csv',
|
|
51
|
+
* outputFormat: 'parquet',
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function doTask<T = unknown>(task: string, options?: DoOptions): Promise<TaskResult<T>>;
|
|
57
|
+
export declare namespace doTask {
|
|
58
|
+
var parallel: <T = unknown>(tasks: string[], options?: DoOptions) => Promise<Array<TaskResult<T>>>;
|
|
59
|
+
var sequence: <T = unknown>(tasks: string[], options?: DoOptions) => Promise<Array<TaskResult<T>>>;
|
|
60
|
+
var withDependencies: <T = unknown>(task: string, dependencies: string[], options?: DoOptions) => Promise<TaskResult<T>>;
|
|
61
|
+
}
|
|
62
|
+
export { doTask as do };
|
|
63
|
+
//# sourceMappingURL=do.d.ts.map
|
package/dist/do.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do.d.ts","sourceRoot":"","sources":["../src/do.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAsB,MAAM,CAAC,CAAC,GAAG,OAAO,EACtC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,SAAc,GACtB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAiGxB;yBApGqB,MAAM;mBA8HH,CAAC,mBACjB,MAAM,EAAE,YACN,SAAS,KACjB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;mBAsBP,CAAC,mBACjB,MAAM,EAAE,YACN,SAAS,KACjB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;2BAiCC,CAAC,kBAC1B,MAAM,gBACE,MAAM,EAAE,YACb,SAAS,KACjB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;;AAxFzB,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,CAAA"}
|
package/dist/do.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task execution functionality for digital workers
|
|
3
|
+
*/
|
|
4
|
+
import { define } from 'ai-functions';
|
|
5
|
+
/**
|
|
6
|
+
* Execute a task
|
|
7
|
+
*
|
|
8
|
+
* Routes tasks to appropriate workers (AI or human) based on complexity
|
|
9
|
+
* and requirements. Handles retries, timeouts, and background execution.
|
|
10
|
+
*
|
|
11
|
+
* @param task - Description of the task to execute
|
|
12
|
+
* @param options - Execution options (retries, timeout, background, etc.)
|
|
13
|
+
* @returns Promise resolving to task result
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Execute a simple task
|
|
18
|
+
* const result = await do('Generate monthly sales report', {
|
|
19
|
+
* timeout: 60000, // 1 minute
|
|
20
|
+
* context: {
|
|
21
|
+
* month: 'January',
|
|
22
|
+
* year: 2024,
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* if (result.success) {
|
|
27
|
+
* console.log('Report:', result.result)
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // Execute with retries
|
|
34
|
+
* const result = await do('Sync data to backup server', {
|
|
35
|
+
* maxRetries: 3,
|
|
36
|
+
* timeout: 30000,
|
|
37
|
+
* context: {
|
|
38
|
+
* source: 'primary-db',
|
|
39
|
+
* destination: 'backup-db',
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* // Execute in background
|
|
47
|
+
* const result = await do('Process large dataset', {
|
|
48
|
+
* background: true,
|
|
49
|
+
* context: {
|
|
50
|
+
* dataset: 'customer_transactions.csv',
|
|
51
|
+
* outputFormat: 'parquet',
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export async function doTask(task, options = {}) {
|
|
57
|
+
const { maxRetries = 0, timeout, background = false, context, } = options;
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
const steps = [];
|
|
60
|
+
// Use agentic function for complex tasks
|
|
61
|
+
const taskFn = define.agentic({
|
|
62
|
+
name: 'executeTask',
|
|
63
|
+
description: 'Execute a task using available tools and capabilities',
|
|
64
|
+
args: {
|
|
65
|
+
task: 'Description of the task to execute',
|
|
66
|
+
contextInfo: 'Additional context and parameters for the task',
|
|
67
|
+
},
|
|
68
|
+
returnType: {
|
|
69
|
+
result: 'The result of executing the task',
|
|
70
|
+
steps: ['List of steps taken to complete the task'],
|
|
71
|
+
},
|
|
72
|
+
instructions: `Execute the following task:
|
|
73
|
+
|
|
74
|
+
${task}
|
|
75
|
+
|
|
76
|
+
${context ? `Context: ${JSON.stringify(context, null, 2)}` : ''}
|
|
77
|
+
|
|
78
|
+
Work step-by-step to complete the task. Use available tools as needed.
|
|
79
|
+
Document each step you take for transparency.`,
|
|
80
|
+
maxIterations: 10,
|
|
81
|
+
tools: [], // Tools would be provided by the execution environment
|
|
82
|
+
});
|
|
83
|
+
let retries = 0;
|
|
84
|
+
let lastError;
|
|
85
|
+
while (retries <= maxRetries) {
|
|
86
|
+
try {
|
|
87
|
+
const response = await Promise.race([
|
|
88
|
+
taskFn.call({ task, contextInfo: context ? JSON.stringify(context) : '' }),
|
|
89
|
+
timeout
|
|
90
|
+
? new Promise((_, reject) => setTimeout(() => reject(new Error('Task timeout')), timeout))
|
|
91
|
+
: new Promise(() => { }), // Never resolves if no timeout
|
|
92
|
+
]);
|
|
93
|
+
const typedResponse = response;
|
|
94
|
+
// Track steps if provided
|
|
95
|
+
if (typedResponse.steps) {
|
|
96
|
+
steps.push(...typedResponse.steps.map((step) => ({
|
|
97
|
+
...step,
|
|
98
|
+
timestamp: new Date(),
|
|
99
|
+
})));
|
|
100
|
+
}
|
|
101
|
+
const duration = Date.now() - startTime;
|
|
102
|
+
return {
|
|
103
|
+
result: typedResponse.result,
|
|
104
|
+
success: true,
|
|
105
|
+
duration,
|
|
106
|
+
steps,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
lastError = error;
|
|
111
|
+
retries++;
|
|
112
|
+
if (retries <= maxRetries) {
|
|
113
|
+
steps.push({
|
|
114
|
+
action: `Retry attempt ${retries}`,
|
|
115
|
+
result: { error: lastError.message },
|
|
116
|
+
timestamp: new Date(),
|
|
117
|
+
});
|
|
118
|
+
// Exponential backoff
|
|
119
|
+
await new Promise((resolve) => setTimeout(resolve, Math.pow(2, retries) * 1000));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const duration = Date.now() - startTime;
|
|
124
|
+
return {
|
|
125
|
+
result: undefined,
|
|
126
|
+
success: false,
|
|
127
|
+
error: lastError?.message || 'Task failed',
|
|
128
|
+
duration,
|
|
129
|
+
steps,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// Export as 'do' with proper typing
|
|
133
|
+
export { doTask as do };
|
|
134
|
+
/**
|
|
135
|
+
* Execute multiple tasks in parallel
|
|
136
|
+
*
|
|
137
|
+
* @param tasks - Array of tasks to execute
|
|
138
|
+
* @param options - Execution options
|
|
139
|
+
* @returns Promise resolving to array of task results
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* const results = await do.parallel([
|
|
144
|
+
* 'Generate sales report',
|
|
145
|
+
* 'Generate marketing report',
|
|
146
|
+
* 'Generate finance report',
|
|
147
|
+
* ], {
|
|
148
|
+
* timeout: 60000,
|
|
149
|
+
* })
|
|
150
|
+
*
|
|
151
|
+
* const successful = results.filter(r => r.success)
|
|
152
|
+
* console.log(`Completed ${successful.length} of ${results.length} tasks`)
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
doTask.parallel = async (tasks, options = {}) => {
|
|
156
|
+
return Promise.all(tasks.map((task) => doTask(task, options)));
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Execute tasks in sequence
|
|
160
|
+
*
|
|
161
|
+
* @param tasks - Array of tasks to execute sequentially
|
|
162
|
+
* @param options - Execution options
|
|
163
|
+
* @returns Promise resolving to array of task results
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* const results = await do.sequence([
|
|
168
|
+
* 'Backup database',
|
|
169
|
+
* 'Run migrations',
|
|
170
|
+
* 'Restart application',
|
|
171
|
+
* ], {
|
|
172
|
+
* maxRetries: 1,
|
|
173
|
+
* })
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
doTask.sequence = async (tasks, options = {}) => {
|
|
177
|
+
const results = [];
|
|
178
|
+
for (const task of tasks) {
|
|
179
|
+
const result = await doTask(task, options);
|
|
180
|
+
results.push(result);
|
|
181
|
+
// Stop if a task fails (unless we're continuing on error)
|
|
182
|
+
if (!result.success && !options.context?.continueOnError) {
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return results;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Execute a task with specific dependencies
|
|
190
|
+
*
|
|
191
|
+
* @param task - The task to execute
|
|
192
|
+
* @param dependencies - Tasks that must complete first
|
|
193
|
+
* @param options - Execution options
|
|
194
|
+
* @returns Promise resolving to task result
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```ts
|
|
198
|
+
* const result = await do.withDependencies(
|
|
199
|
+
* 'Deploy application',
|
|
200
|
+
* ['Run tests', 'Build artifacts', 'Get approval'],
|
|
201
|
+
* { maxRetries: 1 }
|
|
202
|
+
* )
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
doTask.withDependencies = async (task, dependencies, options = {}) => {
|
|
206
|
+
// Execute dependencies in sequence
|
|
207
|
+
const depResults = await doTask.sequence(dependencies, options);
|
|
208
|
+
// Check if all dependencies succeeded
|
|
209
|
+
const allSuccessful = depResults.every((r) => r.success);
|
|
210
|
+
if (!allSuccessful) {
|
|
211
|
+
const failed = depResults.filter((r) => !r.success);
|
|
212
|
+
return {
|
|
213
|
+
result: undefined,
|
|
214
|
+
success: false,
|
|
215
|
+
error: `Dependencies failed: ${failed.map((r) => r.error).join(', ')}`,
|
|
216
|
+
duration: 0,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
// Execute main task with dependency results as context
|
|
220
|
+
return doTask(task, {
|
|
221
|
+
...options,
|
|
222
|
+
context: {
|
|
223
|
+
...options.context,
|
|
224
|
+
dependencies: depResults.map((r) => r.result),
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=do.js.map
|
package/dist/do.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do.js","sourceRoot":"","sources":["../src/do.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAGrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,IAAY,EACZ,UAAqB,EAAE;IAEvB,MAAM,EACJ,UAAU,GAAG,CAAC,EACd,OAAO,EACP,UAAU,GAAG,KAAK,EAClB,OAAO,GACR,GAAG,OAAO,CAAA;IAEX,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAC5B,MAAM,KAAK,GAA2B,EAAE,CAAA;IAExC,yCAAyC;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;QAC5B,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,uDAAuD;QACpE,IAAI,EAAE;YACJ,IAAI,EAAE,oCAAoC;YAC1C,WAAW,EAAE,gDAAgD;SAC9D;QACD,UAAU,EAAE;YACV,MAAM,EAAE,kCAAkC;YAC1C,KAAK,EAAE,CAAC,0CAA0C,CAAC;SACpD;QACD,YAAY,EAAE;;EAEhB,IAAI;;EAEJ,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;;;8CAGjB;QAC1C,aAAa,EAAE,EAAE;QACjB,KAAK,EAAE,EAAE,EAAE,uDAAuD;KACnE,CAAC,CAAA;IAEF,IAAI,O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
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content generation functionality for digital workers
|
|
3
|
+
*/
|
|
4
|
+
import type { GenerateResult, GenerateOptions } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Generate content
|
|
7
|
+
*
|
|
8
|
+
* Uses AI to generate various types of content including text,
|
|
9
|
+
* code, structured data, images, video, and audio.
|
|
10
|
+
*
|
|
11
|
+
* @param prompt - What to generate
|
|
12
|
+
* @param options - Generation options
|
|
13
|
+
* @returns Promise resolving to generated content
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Generate text content
|
|
18
|
+
* const result = await generate('Write a product description for wireless earbuds', {
|
|
19
|
+
* type: 'text',
|
|
20
|
+
* instructions: 'Focus on sound quality and battery life. Keep it under 100 words.',
|
|
21
|
+
* })
|
|
22
|
+
* console.log(result.content)
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Generate structured data
|
|
28
|
+
* const result = await generate('Create a user profile', {
|
|
29
|
+
* type: 'structured',
|
|
30
|
+
* schema: {
|
|
31
|
+
* name: 'User full name',
|
|
32
|
+
* email: 'Email address',
|
|
33
|
+
* role: 'admin | user | guest',
|
|
34
|
+
* preferences: {
|
|
35
|
+
* theme: 'light | dark',
|
|
36
|
+
* notifications: 'Whether to receive notifications (boolean)',
|
|
37
|
+
* },
|
|
38
|
+
* },
|
|
39
|
+
* })
|
|
40
|
+
* console.log(result.content) // { name: '...', email: '...', ... }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* // Generate code
|
|
46
|
+
* const result = await generate('Create a React component for a todo list', {
|
|
47
|
+
* type: 'code',
|
|
48
|
+
* instructions: 'Use TypeScript and hooks. Include prop types.',
|
|
49
|
+
* })
|
|
50
|
+
* console.log(result.content) // TypeScript React component code
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function generate<T = string>(prompt: string, options?: GenerateOptions): Promise<GenerateResult<T>>;
|
|
54
|
+
export declare namespace generate {
|
|
55
|
+
var variations: <T = string>(prompt: string, count: number, options?: GenerateOptions) => Promise<Array<GenerateResult<T>>>;
|
|
56
|
+
var withTone: <T = string>(prompt: string, tone: "professional" | "casual" | "friendly" | "formal" | "humorous" | "empathetic", options?: GenerateOptions) => Promise<GenerateResult<T>>;
|
|
57
|
+
var forAudience: <T = string>(prompt: string, audience: string, options?: GenerateOptions) => Promise<GenerateResult<T>>;
|
|
58
|
+
var withLength: <T = string>(prompt: string, length: "brief" | "short" | "medium" | "long" | "detailed", options?: GenerateOptions) => Promise<GenerateResult<T>>;
|
|
59
|
+
var refine: <T = string>(prompt: string, refinements: string[], options?: GenerateOptions) => Promise<GenerateResult<T>>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAsB,QAAQ,CAAC,CAAC,GAAG,MAAM,EACvC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAkH5B;yBArHqB,QAAQ;qBA4ID,CAAC,mBACpB,MAAM,SACP,MAAM,YACJ,eAAe,KACvB,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;mBA6BT,CAAC,mBAClB,MAAM,QACR,cAAc,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,YAC1E,eAAe,KACvB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;sBAuCC,CAAC,mBACrB,MAAM,YACJ,MAAM,YACP,eAAe,KACvB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;qBA8BA,CAAC,mBACpB,MAAM,UACN,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,YACjD,eAAe,KACvB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;iBAoCJ,CAAC,mBAChB,MAAM,eACD,MAAM,EAAE,YACZ,eAAe,KACvB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC"}
|