digital-workers 2.1.3 → 2.3.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.
Files changed (183) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +2 -0
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +33 -21
  5. package/dist/actions.js.map +1 -1
  6. package/dist/agent-comms.d.ts.map +1 -1
  7. package/dist/agent-comms.js +36 -25
  8. package/dist/agent-comms.js.map +1 -1
  9. package/dist/approve.d.ts +40 -8
  10. package/dist/approve.d.ts.map +1 -1
  11. package/dist/approve.js +86 -20
  12. package/dist/approve.js.map +1 -1
  13. package/dist/ask.d.ts +38 -7
  14. package/dist/ask.d.ts.map +1 -1
  15. package/dist/ask.js +85 -25
  16. package/dist/ask.js.map +1 -1
  17. package/dist/browse.d.ts +223 -0
  18. package/dist/browse.d.ts.map +1 -0
  19. package/dist/browse.js +392 -0
  20. package/dist/browse.js.map +1 -0
  21. package/dist/capability-tiers.js +3 -3
  22. package/dist/capability-tiers.js.map +1 -1
  23. package/dist/cascade-context.d.ts +28 -28
  24. package/dist/client.d.ts +162 -0
  25. package/dist/client.d.ts.map +1 -0
  26. package/dist/client.js +64 -0
  27. package/dist/client.js.map +1 -0
  28. package/dist/decide.d.ts +42 -6
  29. package/dist/decide.d.ts.map +1 -1
  30. package/dist/decide.js +54 -11
  31. package/dist/decide.js.map +1 -1
  32. package/dist/do.d.ts +36 -7
  33. package/dist/do.d.ts.map +1 -1
  34. package/dist/do.js +82 -39
  35. package/dist/do.js.map +1 -1
  36. package/dist/error-escalation.d.ts.map +1 -1
  37. package/dist/error-escalation.js +38 -38
  38. package/dist/error-escalation.js.map +1 -1
  39. package/dist/generate.d.ts +48 -7
  40. package/dist/generate.d.ts.map +1 -1
  41. package/dist/generate.js +49 -8
  42. package/dist/generate.js.map +1 -1
  43. package/dist/goals.d.ts +10 -9
  44. package/dist/goals.d.ts.map +1 -1
  45. package/dist/goals.js +30 -24
  46. package/dist/goals.js.map +1 -1
  47. package/dist/image.d.ts +189 -0
  48. package/dist/image.d.ts.map +1 -0
  49. package/dist/image.js +528 -0
  50. package/dist/image.js.map +1 -0
  51. package/dist/index.d.ts +49 -2
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +58 -2
  54. package/dist/index.js.map +1 -1
  55. package/dist/is.d.ts +45 -10
  56. package/dist/is.d.ts.map +1 -1
  57. package/dist/is.js +56 -21
  58. package/dist/is.js.map +1 -1
  59. package/dist/kpis.d.ts +24 -15
  60. package/dist/kpis.d.ts.map +1 -1
  61. package/dist/kpis.js +16 -14
  62. package/dist/kpis.js.map +1 -1
  63. package/dist/load-balancing.d.ts.map +1 -1
  64. package/dist/load-balancing.js +124 -38
  65. package/dist/load-balancing.js.map +1 -1
  66. package/dist/logger.d.ts +76 -0
  67. package/dist/logger.d.ts.map +1 -0
  68. package/dist/logger.js +39 -0
  69. package/dist/logger.js.map +1 -0
  70. package/dist/notify.d.ts +38 -9
  71. package/dist/notify.d.ts.map +1 -1
  72. package/dist/notify.js +72 -17
  73. package/dist/notify.js.map +1 -1
  74. package/dist/role.d.ts +5 -4
  75. package/dist/role.d.ts.map +1 -1
  76. package/dist/role.js +13 -10
  77. package/dist/role.js.map +1 -1
  78. package/dist/runtime.d.ts +310 -0
  79. package/dist/runtime.d.ts.map +1 -0
  80. package/dist/runtime.js +510 -0
  81. package/dist/runtime.js.map +1 -0
  82. package/dist/team.d.ts +11 -6
  83. package/dist/team.d.ts.map +1 -1
  84. package/dist/team.js +22 -15
  85. package/dist/team.js.map +1 -1
  86. package/dist/transports/email.d.ts +318 -0
  87. package/dist/transports/email.d.ts.map +1 -0
  88. package/dist/transports/email.js +779 -0
  89. package/dist/transports/email.js.map +1 -0
  90. package/dist/transports/slack.d.ts +515 -0
  91. package/dist/transports/slack.d.ts.map +1 -0
  92. package/dist/transports/slack.js +844 -0
  93. package/dist/transports/slack.js.map +1 -0
  94. package/dist/transports.d.ts.map +1 -1
  95. package/dist/transports.js +44 -25
  96. package/dist/transports.js.map +1 -1
  97. package/dist/types.d.ts +141 -19
  98. package/dist/types.d.ts.map +1 -1
  99. package/dist/types.js +5 -0
  100. package/dist/types.js.map +1 -1
  101. package/dist/utils/id.d.ts +19 -0
  102. package/dist/utils/id.d.ts.map +1 -0
  103. package/dist/utils/id.js +21 -0
  104. package/dist/utils/id.js.map +1 -0
  105. package/dist/video.d.ts +203 -0
  106. package/dist/video.d.ts.map +1 -0
  107. package/dist/video.js +528 -0
  108. package/dist/video.js.map +1 -0
  109. package/dist/worker.d.ts +343 -0
  110. package/dist/worker.d.ts.map +1 -0
  111. package/dist/worker.js +698 -0
  112. package/dist/worker.js.map +1 -0
  113. package/package.json +32 -14
  114. package/src/actions.ts +39 -30
  115. package/src/agent-comms.ts +54 -92
  116. package/src/approve.ts +91 -20
  117. package/src/ask.ts +99 -25
  118. package/src/browse.ts +627 -0
  119. package/src/capability-tiers.ts +5 -5
  120. package/src/client.ts +221 -0
  121. package/src/decide.ts +81 -35
  122. package/src/do.ts +98 -52
  123. package/src/error-escalation.ts +55 -67
  124. package/src/generate.ts +52 -18
  125. package/src/goals.ts +36 -27
  126. package/src/image.ts +816 -0
  127. package/src/index.ts +187 -2
  128. package/src/is.ts +59 -25
  129. package/src/kpis.ts +41 -36
  130. package/src/load-balancing.ts +132 -46
  131. package/src/logger.ts +93 -0
  132. package/src/notify.ts +78 -17
  133. package/src/role.ts +30 -20
  134. package/src/runtime.ts +796 -0
  135. package/src/team.ts +24 -19
  136. package/src/transports/email.ts +1160 -0
  137. package/src/transports/slack.ts +1320 -0
  138. package/src/transports.ts +58 -43
  139. package/src/types.ts +174 -46
  140. package/src/utils/id.ts +21 -0
  141. package/src/video.ts +906 -0
  142. package/src/worker.ts +1007 -0
  143. package/test/approve.test.ts +305 -0
  144. package/test/ask.test.ts +274 -0
  145. package/test/browse.test.ts +361 -0
  146. package/test/decide.test.ts +252 -0
  147. package/test/do.test.ts +144 -0
  148. package/test/error-logging.test.ts +357 -0
  149. package/test/generate.test.ts +319 -0
  150. package/test/image.test.ts +398 -0
  151. package/test/is.test.ts +287 -0
  152. package/test/load-balancing-safety.test.ts +404 -0
  153. package/test/notify.test.ts +434 -0
  154. package/test/primitives.test.ts +320 -0
  155. package/test/runtime-integration.test.ts +892 -0
  156. package/test/transports/crypto.test.ts +230 -0
  157. package/test/transports/email.test.ts +866 -0
  158. package/test/transports/id-generation.test.ts +91 -0
  159. package/test/transports/slack.test.ts +760 -0
  160. package/test/type-safety.test.ts +834 -0
  161. package/test/types.test.ts +60 -2
  162. package/test/video.test.ts +530 -0
  163. package/test/worker.test.ts +1433 -0
  164. package/tsconfig.json +4 -1
  165. package/vitest.config.ts +42 -0
  166. package/wrangler.jsonc +36 -0
  167. package/.turbo/turbo-build.log +0 -4
  168. package/LICENSE +0 -21
  169. package/src/actions.js +0 -436
  170. package/src/approve.js +0 -234
  171. package/src/ask.js +0 -226
  172. package/src/decide.js +0 -244
  173. package/src/do.js +0 -227
  174. package/src/generate.js +0 -298
  175. package/src/goals.js +0 -205
  176. package/src/index.js +0 -68
  177. package/src/is.js +0 -317
  178. package/src/kpis.js +0 -270
  179. package/src/notify.js +0 -219
  180. package/src/role.js +0 -110
  181. package/src/team.js +0 -130
  182. package/src/transports.js +0 -357
  183. package/src/types.js +0 -71
package/src/do.js DELETED
@@ -1,227 +0,0 @@
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
- };
package/src/generate.js DELETED
@@ -1,298 +0,0 @@
1
- /**
2
- * Content generation functionality for digital workers
3
- */
4
- import { generateObject, generateText } from 'ai-functions';
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 async function generate(prompt, options = {}) {
54
- const { type = 'text', schema, instructions, model = 'sonnet', } = options;
55
- const startTime = Date.now();
56
- switch (type) {
57
- case 'text': {
58
- const systemPrompt = instructions
59
- ? `You are an expert content generator. ${instructions}`
60
- : 'You are an expert content generator.';
61
- const result = await generateText({
62
- model,
63
- prompt,
64
- system: systemPrompt,
65
- });
66
- return {
67
- content: result.text,
68
- type: 'text',
69
- metadata: {
70
- model,
71
- tokens: result.usage?.totalTokens,
72
- duration: Date.now() - startTime,
73
- },
74
- };
75
- }
76
- case 'structured': {
77
- if (!schema) {
78
- throw new Error('Schema is required for structured content generation');
79
- }
80
- const systemPrompt = instructions
81
- ? `You are an expert at generating structured data. ${instructions}`
82
- : 'You are an expert at generating structured data.';
83
- const result = await generateObject({
84
- model,
85
- schema,
86
- prompt,
87
- system: systemPrompt,
88
- });
89
- return {
90
- content: result.object,
91
- type: 'structured',
92
- metadata: {
93
- model,
94
- tokens: result.usage?.totalTokens,
95
- duration: Date.now() - startTime,
96
- },
97
- };
98
- }
99
- case 'code': {
100
- const systemPrompt = instructions
101
- ? `You are an expert programmer. Generate clean, well-documented code. ${instructions}`
102
- : 'You are an expert programmer. Generate clean, well-documented code.';
103
- const result = await generateObject({
104
- model,
105
- schema: {
106
- code: 'The generated code',
107
- language: 'Programming language used',
108
- explanation: 'Brief explanation of the code',
109
- },
110
- prompt,
111
- system: systemPrompt,
112
- });
113
- const codeResult = result.object;
114
- return {
115
- content: codeResult.code,
116
- type: 'code',
117
- metadata: {
118
- model,
119
- tokens: result.usage?.totalTokens,
120
- duration: Date.now() - startTime,
121
- language: codeResult.language,
122
- explanation: codeResult.explanation,
123
- },
124
- };
125
- }
126
- case 'image': {
127
- // Image generation would integrate with image generation APIs
128
- // For now, return a placeholder
129
- throw new Error('Image generation not yet implemented');
130
- }
131
- case 'video': {
132
- // Video generation would integrate with video generation APIs
133
- throw new Error('Video generation not yet implemented');
134
- }
135
- case 'audio': {
136
- // Audio generation would integrate with audio generation APIs
137
- throw new Error('Audio generation not yet implemented');
138
- }
139
- default:
140
- throw new Error(`Unknown content type: ${type}`);
141
- }
142
- }
143
- /**
144
- * Generate multiple variations of content
145
- *
146
- * @param prompt - What to generate
147
- * @param count - Number of variations to generate
148
- * @param options - Generation options
149
- * @returns Promise resolving to array of generated content
150
- *
151
- * @example
152
- * ```ts
153
- * const variations = await generate.variations(
154
- * 'Write a catchy headline for a coffee shop',
155
- * 5,
156
- * { type: 'text' }
157
- * )
158
- *
159
- * variations.forEach((v, i) => {
160
- * console.log(`${i + 1}. ${v.content}`)
161
- * })
162
- * ```
163
- */
164
- generate.variations = async (prompt, count, options = {}) => {
165
- return Promise.all(Array.from({ length: count }, () => generate(prompt, options)));
166
- };
167
- /**
168
- * Generate content with a specific tone
169
- *
170
- * @param prompt - What to generate
171
- * @param tone - The desired tone
172
- * @param options - Generation options
173
- * @returns Promise resolving to generated content
174
- *
175
- * @example
176
- * ```ts
177
- * const professional = await generate.withTone(
178
- * 'Write an email declining a meeting',
179
- * 'professional',
180
- * { type: 'text' }
181
- * )
182
- *
183
- * const friendly = await generate.withTone(
184
- * 'Write an email declining a meeting',
185
- * 'friendly',
186
- * { type: 'text' }
187
- * )
188
- * ```
189
- */
190
- generate.withTone = async (prompt, tone, options = {}) => {
191
- const toneInstructions = {
192
- professional: 'Use a professional, business-appropriate tone.',
193
- casual: 'Use a casual, conversational tone.',
194
- friendly: 'Use a warm, friendly tone.',
195
- formal: 'Use a formal, ceremonious tone.',
196
- humorous: 'Use a light, humorous tone.',
197
- empathetic: 'Use an empathetic, understanding tone.',
198
- };
199
- return generate(prompt, {
200
- ...options,
201
- instructions: `${toneInstructions[tone]} ${options.instructions || ''}`,
202
- });
203
- };
204
- /**
205
- * Generate content for a specific audience
206
- *
207
- * @param prompt - What to generate
208
- * @param audience - Target audience
209
- * @param options - Generation options
210
- * @returns Promise resolving to generated content
211
- *
212
- * @example
213
- * ```ts
214
- * const technical = await generate.forAudience(
215
- * 'Explain how OAuth works',
216
- * 'software engineers',
217
- * { type: 'text' }
218
- * )
219
- *
220
- * const nonTechnical = await generate.forAudience(
221
- * 'Explain how OAuth works',
222
- * 'non-technical business users',
223
- * { type: 'text' }
224
- * )
225
- * ```
226
- */
227
- generate.forAudience = async (prompt, audience, options = {}) => {
228
- return generate(prompt, {
229
- ...options,
230
- instructions: `Write for ${audience}. ${options.instructions || ''}`,
231
- });
232
- };
233
- /**
234
- * Generate content with specific length
235
- *
236
- * @param prompt - What to generate
237
- * @param length - Desired length
238
- * @param options - Generation options
239
- * @returns Promise resolving to generated content
240
- *
241
- * @example
242
- * ```ts
243
- * const short = await generate.withLength(
244
- * 'Describe our company',
245
- * 'short',
246
- * { type: 'text' }
247
- * )
248
- *
249
- * const detailed = await generate.withLength(
250
- * 'Describe our company',
251
- * 'detailed',
252
- * { type: 'text' }
253
- * )
254
- * ```
255
- */
256
- generate.withLength = async (prompt, length, options = {}) => {
257
- const lengthInstructions = {
258
- brief: 'Keep it very brief - 1-2 sentences maximum.',
259
- short: 'Keep it short - around 50-100 words.',
260
- medium: 'Use a medium length - around 150-300 words.',
261
- long: 'Write a longer piece - around 400-600 words.',
262
- detailed: 'Write a detailed, comprehensive piece - 800+ words.',
263
- };
264
- return generate(prompt, {
265
- ...options,
266
- instructions: `${lengthInstructions[length]} ${options.instructions || ''}`,
267
- });
268
- };
269
- /**
270
- * Generate content by iteratively refining it
271
- *
272
- * @param prompt - What to generate
273
- * @param refinements - Refinement prompts to apply
274
- * @param options - Generation options
275
- * @returns Promise resolving to refined content
276
- *
277
- * @example
278
- * ```ts
279
- * const refined = await generate.refine(
280
- * 'Write a product tagline',
281
- * [
282
- * 'Make it more memorable',
283
- * 'Add a sense of urgency',
284
- * 'Emphasize the value proposition',
285
- * ],
286
- * { type: 'text' }
287
- * )
288
- * ```
289
- */
290
- generate.refine = async (prompt, refinements, options = {}) => {
291
- // Generate initial content
292
- let result = await generate(prompt, options);
293
- // Apply refinements iteratively
294
- for (const refinement of refinements) {
295
- result = await generate(`Refine the following content: ${result.content}\n\nRefinement: ${refinement}`, options);
296
- }
297
- return result;
298
- };