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.
Files changed (83) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +17 -0
  3. package/README.md +290 -106
  4. package/dist/actions.d.ts +95 -0
  5. package/dist/actions.d.ts.map +1 -0
  6. package/dist/actions.js +437 -0
  7. package/dist/actions.js.map +1 -0
  8. package/dist/approve.d.ts +49 -0
  9. package/dist/approve.d.ts.map +1 -0
  10. package/dist/approve.js +235 -0
  11. package/dist/approve.js.map +1 -0
  12. package/dist/ask.d.ts +42 -0
  13. package/dist/ask.d.ts.map +1 -0
  14. package/dist/ask.js +227 -0
  15. package/dist/ask.js.map +1 -0
  16. package/dist/decide.d.ts +62 -0
  17. package/dist/decide.d.ts.map +1 -0
  18. package/dist/decide.js +245 -0
  19. package/dist/decide.js.map +1 -0
  20. package/dist/do.d.ts +63 -0
  21. package/dist/do.d.ts.map +1 -0
  22. package/dist/do.js +228 -0
  23. package/dist/do.js.map +1 -0
  24. package/dist/generate.d.ts +61 -0
  25. package/dist/generate.d.ts.map +1 -0
  26. package/dist/generate.js +299 -0
  27. package/dist/generate.js.map +1 -0
  28. package/dist/goals.d.ts +89 -0
  29. package/dist/goals.d.ts.map +1 -0
  30. package/dist/goals.js +206 -0
  31. package/dist/goals.js.map +1 -0
  32. package/dist/index.d.ts +68 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +69 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/is.d.ts +54 -0
  37. package/dist/is.d.ts.map +1 -0
  38. package/dist/is.js +318 -0
  39. package/dist/is.js.map +1 -0
  40. package/dist/kpis.d.ts +103 -0
  41. package/dist/kpis.d.ts.map +1 -0
  42. package/dist/kpis.js +271 -0
  43. package/dist/kpis.js.map +1 -0
  44. package/dist/notify.d.ts +47 -0
  45. package/dist/notify.d.ts.map +1 -0
  46. package/dist/notify.js +220 -0
  47. package/dist/notify.js.map +1 -0
  48. package/dist/role.d.ts +53 -0
  49. package/dist/role.d.ts.map +1 -0
  50. package/dist/role.js +111 -0
  51. package/dist/role.js.map +1 -0
  52. package/dist/team.d.ts +61 -0
  53. package/dist/team.d.ts.map +1 -0
  54. package/dist/team.js +131 -0
  55. package/dist/team.js.map +1 -0
  56. package/dist/transports.d.ts +164 -0
  57. package/dist/transports.d.ts.map +1 -0
  58. package/dist/transports.js +358 -0
  59. package/dist/transports.js.map +1 -0
  60. package/dist/types.d.ts +693 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/dist/types.js +72 -0
  63. package/dist/types.js.map +1 -0
  64. package/package.json +27 -61
  65. package/src/actions.ts +615 -0
  66. package/src/approve.ts +317 -0
  67. package/src/ask.ts +304 -0
  68. package/src/decide.ts +295 -0
  69. package/src/do.ts +275 -0
  70. package/src/generate.ts +364 -0
  71. package/src/goals.ts +220 -0
  72. package/src/index.ts +118 -0
  73. package/src/is.ts +372 -0
  74. package/src/kpis.ts +348 -0
  75. package/src/notify.ts +303 -0
  76. package/src/role.ts +116 -0
  77. package/src/team.ts +142 -0
  78. package/src/transports.ts +504 -0
  79. package/src/types.ts +843 -0
  80. package/test/actions.test.ts +546 -0
  81. package/test/standalone.test.ts +299 -0
  82. package/test/types.test.ts +460 -0
  83. package/tsconfig.json +9 -0
@@ -0,0 +1,299 @@
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
+ };
299
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAI3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,MAAc,EACd,UAA2B,EAAE;IAE7B,MAAM,EACJ,IAAI,GAAG,MAAM,EACb,MAAM,EACN,YAAY,EACZ,KAAK,G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E,sCAAsC;QAC7C,MAAM,EAAE,6CAA6C;QACrD,IAAI,EAAE,8CAA8C;QACpD,QAAQ,EAAE,qDAAqD;KAChE,CAAA;IAED,OAAO,QAAQ,CAAI,MAAM,EAAE;QACzB,GAAG,OAAO;QACV,YAAY,EAAE,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,YAAY,IAAI,EAAE,EAAE;KAC5E,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,QAAQ,CAAC,MAAM,GAAG,KAAK,EACrB,MAAc,EACd,WAAqB,EACrB,UAA2B,EAAE,EACD,EAAE;IAC9B,2BAA2B;IAC3B,IAAI,MAAM,GAAG,MAAM,QAAQ,CAAI,MAAM,EAAE,OAAO,CAAC,CAAA;IAE/C,gCAAgC;IAChC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,GAAG,MAAM,QAAQ,CACrB,iCAAiC,MAAM,CAAC,OAAO,mBAAmB,UAAU,EAAE,EAC9E,OAAO,CACR,CAAA;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Goals definition for digital workers
3
+ */
4
+ import type { WorkerGoals, KPI } from './types.js';
5
+ /**
6
+ * Define worker goals
7
+ *
8
+ * Goals provide direction and metrics for workers and teams.
9
+ * Supports short-term, long-term, and strategic objectives with KPIs.
10
+ *
11
+ * @param definition - Goals definition
12
+ * @returns The defined goals
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const engineeringGoals = Goals({
17
+ * shortTerm: [
18
+ * 'Complete Q1 roadmap features',
19
+ * 'Reduce bug backlog by 30%',
20
+ * 'Improve test coverage to 80%',
21
+ * ],
22
+ * longTerm: [
23
+ * 'Migrate to microservices architecture',
24
+ * 'Achieve 99.9% uptime',
25
+ * 'Build scalable platform for 1M users',
26
+ * ],
27
+ * strategic: [
28
+ * 'Become industry leader in performance',
29
+ * 'Enable product innovation through technology',
30
+ * ],
31
+ * metrics: [
32
+ * {
33
+ * name: 'Deployment Frequency',
34
+ * description: 'Number of deployments per week',
35
+ * current: 5,
36
+ * target: 10,
37
+ * unit: 'deploys/week',
38
+ * trend: 'up',
39
+ * period: 'weekly',
40
+ * },
41
+ * {
42
+ * name: 'Mean Time to Recovery',
43
+ * description: 'Average time to recover from incidents',
44
+ * current: 45,
45
+ * target: 30,
46
+ * unit: 'minutes',
47
+ * trend: 'down',
48
+ * period: 'monthly',
49
+ * },
50
+ * ],
51
+ * })
52
+ * ```
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const supportGoals = Goals({
57
+ * shortTerm: [
58
+ * 'Achieve 95% customer satisfaction',
59
+ * 'Reduce average response time to < 5 min',
60
+ * ],
61
+ * longTerm: [
62
+ * 'Build comprehensive knowledge base',
63
+ * 'Implement AI-first support workflow',
64
+ * ],
65
+ * metrics: [
66
+ * {
67
+ * name: 'Customer Satisfaction',
68
+ * description: 'CSAT score from surveys',
69
+ * current: 92,
70
+ * target: 95,
71
+ * unit: '%',
72
+ * trend: 'up',
73
+ * period: 'monthly',
74
+ * },
75
+ * ],
76
+ * })
77
+ * ```
78
+ */
79
+ export declare function Goals(definition: WorkerGoals): WorkerGoals;
80
+ export declare namespace Goals {
81
+ var addShortTerm: (goals: WorkerGoals, goal: string) => WorkerGoals;
82
+ var addLongTerm: (goals: WorkerGoals, goal: string) => WorkerGoals;
83
+ var addStrategic: (goals: WorkerGoals, goal: string) => WorkerGoals;
84
+ var addMetric: (goals: WorkerGoals, kpi: KPI) => WorkerGoals;
85
+ var updateMetric: (goals: WorkerGoals, name: string, updates: Partial<Omit<KPI, "name">>) => WorkerGoals;
86
+ var progress: (kpi: Pick<KPI, "current" | "target">) => number;
87
+ var onTrack: (kpi: Pick<KPI, "current" | "target">, threshold?: number) => boolean;
88
+ }
89
+ //# sourceMappingURL=goals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"goals.d.ts","sourceRoot":"","sources":["../src/goals.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,wBAAgB,KAAK,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW,CAE1D;yBAFe,KAAK;8BAgBQ,WAAW,QAAQ,MAAM,KAAG,WAAW;6BAiBxC,WAAW,QAAQ,MAAM,KAAG,WAAW;8BAiBtC,WAAW,QAAQ,MAAM,KAAG,WAAW;2BAyB1C,WAAW,OAAO,GAAG,KAAG,WAAW;8BAsBpD,WAAW,QACZ,MAAM,WACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,KAClC,WAAW;wBAmBS,IAAI,CAAC,GAAG,EAAE,SAAS,GAAG,QAAQ,CAAC,KAAG,MAAM;uBAkBzC,IAAI,CAAC,GAAG,EAAE,SAAS,GAAG,QAAQ,CAAC,yBAAoB,OAAO"}
package/dist/goals.js ADDED
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Goals definition for digital workers
3
+ */
4
+ /**
5
+ * Define worker goals
6
+ *
7
+ * Goals provide direction and metrics for workers and teams.
8
+ * Supports short-term, long-term, and strategic objectives with KPIs.
9
+ *
10
+ * @param definition - Goals definition
11
+ * @returns The defined goals
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const engineeringGoals = Goals({
16
+ * shortTerm: [
17
+ * 'Complete Q1 roadmap features',
18
+ * 'Reduce bug backlog by 30%',
19
+ * 'Improve test coverage to 80%',
20
+ * ],
21
+ * longTerm: [
22
+ * 'Migrate to microservices architecture',
23
+ * 'Achieve 99.9% uptime',
24
+ * 'Build scalable platform for 1M users',
25
+ * ],
26
+ * strategic: [
27
+ * 'Become industry leader in performance',
28
+ * 'Enable product innovation through technology',
29
+ * ],
30
+ * metrics: [
31
+ * {
32
+ * name: 'Deployment Frequency',
33
+ * description: 'Number of deployments per week',
34
+ * current: 5,
35
+ * target: 10,
36
+ * unit: 'deploys/week',
37
+ * trend: 'up',
38
+ * period: 'weekly',
39
+ * },
40
+ * {
41
+ * name: 'Mean Time to Recovery',
42
+ * description: 'Average time to recover from incidents',
43
+ * current: 45,
44
+ * target: 30,
45
+ * unit: 'minutes',
46
+ * trend: 'down',
47
+ * period: 'monthly',
48
+ * },
49
+ * ],
50
+ * })
51
+ * ```
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const supportGoals = Goals({
56
+ * shortTerm: [
57
+ * 'Achieve 95% customer satisfaction',
58
+ * 'Reduce average response time to < 5 min',
59
+ * ],
60
+ * longTerm: [
61
+ * 'Build comprehensive knowledge base',
62
+ * 'Implement AI-first support workflow',
63
+ * ],
64
+ * metrics: [
65
+ * {
66
+ * name: 'Customer Satisfaction',
67
+ * description: 'CSAT score from surveys',
68
+ * current: 92,
69
+ * target: 95,
70
+ * unit: '%',
71
+ * trend: 'up',
72
+ * period: 'monthly',
73
+ * },
74
+ * ],
75
+ * })
76
+ * ```
77
+ */
78
+ export function Goals(definition) {
79
+ return definition;
80
+ }
81
+ /**
82
+ * Add a short-term goal
83
+ *
84
+ * @param goals - The goals object
85
+ * @param goal - Goal to add
86
+ * @returns Updated goals
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const updated = Goals.addShortTerm(engineeringGoals, 'Complete security audit')
91
+ * ```
92
+ */
93
+ Goals.addShortTerm = (goals, goal) => ({
94
+ ...goals,
95
+ shortTerm: [...goals.shortTerm, goal],
96
+ });
97
+ /**
98
+ * Add a long-term goal
99
+ *
100
+ * @param goals - The goals object
101
+ * @param goal - Goal to add
102
+ * @returns Updated goals
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const updated = Goals.addLongTerm(engineeringGoals, 'Build ML platform')
107
+ * ```
108
+ */
109
+ Goals.addLongTerm = (goals, goal) => ({
110
+ ...goals,
111
+ longTerm: [...goals.longTerm, goal],
112
+ });
113
+ /**
114
+ * Add a strategic goal
115
+ *
116
+ * @param goals - The goals object
117
+ * @param goal - Goal to add
118
+ * @returns Updated goals
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * const updated = Goals.addStrategic(engineeringGoals, 'Become carbon neutral')
123
+ * ```
124
+ */
125
+ Goals.addStrategic = (goals, goal) => ({
126
+ ...goals,
127
+ strategic: [...(goals.strategic || []), goal],
128
+ });
129
+ /**
130
+ * Add a KPI metric
131
+ *
132
+ * @param goals - The goals object
133
+ * @param kpi - KPI to add
134
+ * @returns Updated goals
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const updated = Goals.addMetric(engineeringGoals, {
139
+ * name: 'Code Quality',
140
+ * description: 'Code quality score from SonarQube',
141
+ * current: 85,
142
+ * target: 90,
143
+ * unit: 'score',
144
+ * trend: 'up',
145
+ * period: 'weekly',
146
+ * })
147
+ * ```
148
+ */
149
+ Goals.addMetric = (goals, kpi) => ({
150
+ ...goals,
151
+ metrics: [...(goals.metrics || []), kpi],
152
+ });
153
+ /**
154
+ * Update a KPI metric
155
+ *
156
+ * @param goals - The goals object
157
+ * @param name - Name of KPI to update
158
+ * @param updates - Fields to update
159
+ * @returns Updated goals
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const updated = Goals.updateMetric(engineeringGoals, 'Deployment Frequency', {
164
+ * current: 8,
165
+ * trend: 'up',
166
+ * })
167
+ * ```
168
+ */
169
+ Goals.updateMetric = (goals, name, updates) => ({
170
+ ...goals,
171
+ metrics: goals.metrics?.map((kpi) => kpi.name === name ? { ...kpi, ...updates } : kpi),
172
+ });
173
+ /**
174
+ * Get progress for a KPI (0-1)
175
+ *
176
+ * @param kpi - The KPI
177
+ * @returns Progress value between 0 and 1
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * const kpi = { current: 75, target: 100 }
182
+ * const progress = Goals.progress(kpi) // 0.75
183
+ * ```
184
+ */
185
+ Goals.progress = (kpi) => {
186
+ if (kpi.target === 0)
187
+ return 0;
188
+ return Math.min(1, Math.max(0, kpi.current / kpi.target));
189
+ };
190
+ /**
191
+ * Check if a KPI is on track
192
+ *
193
+ * @param kpi - The KPI
194
+ * @param threshold - Minimum progress to be considered "on track" (default: 0.8)
195
+ * @returns Whether the KPI is on track
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * const kpi = { current: 85, target: 100 }
200
+ * const onTrack = Goals.onTrack(kpi) // true (85% >= 80% threshold)
201
+ * ```
202
+ */
203
+ Goals.onTrack = (kpi, threshold = 0.8) => {
204
+ return Goals.progress(kpi) >= threshold;
205
+ };
206
+ //# sourceMappingURL=goals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"goals.js","sourceRoot":"","sources":["../src/goals.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,MAAM,UAAU,KAAK,CAAC,UAAuB;IAC3C,OAAO,UAAU,CAAA;AACnB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,CAAC,YAAY,GAAG,CAAC,KAAkB,EAAE,IAAY,EAAe,EAAE,CAAC,CAAC;IACvE,GAAG,KAAK;IACR,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC;CACtC,CAAC,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,KAAK,CAAC,WAAW,GAAG,CAAC,KAAkB,EAAE,IAAY,EAAe,EAAE,CAAC,CAAC;IACtE,GAAG,KAAK;IACR,QAAQ,EAAE,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC;CACpC,CAAC,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,KAAK,CAAC,YAAY,GAAG,CAAC,KAAkB,EAAE,IAAY,EAAe,EAAE,CAAC,CAAC;IACvE,GAAG,KAAK;IACR,SAAS,EAAE,CAA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interface for organizing digital work
3
+ *
4
+ * This package provides the foundational abstraction for structuring work
5
+ * independent of whether AI agents or humans perform individual tasks. It
6
+ * defines a unified Worker interface that enables workflows to be designed
7
+ * once and executed by any combination of AI and human workers.
8
+ *
9
+ * Package relationships:
10
+ * - `autonomous-agents` - Implements Worker for AI agents
11
+ * - `human-in-the-loop` - Implements Worker for humans
12
+ * - `ai-workflows` - Uses digital-workers to orchestrate execution
13
+ *
14
+ * The key insight: define WHAT work needs to happen, not WHO does it.
15
+ *
16
+ * ## Worker Actions
17
+ *
18
+ * Worker actions (notify, ask, approve, decide, do) are durable workflow actions
19
+ * that integrate with ai-workflows. They can be invoked via:
20
+ *
21
+ * 1. `$.do('Worker.notify', data)` - Durable action
22
+ * 2. `$.send('Worker.notify', data)` - Fire and forget
23
+ * 3. `$.notify(target, message)` - Convenience method (when using withWorkers)
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { Workflow } from 'ai-workflows'
28
+ * import { registerWorkerActions, withWorkers } from 'digital-workers'
29
+ *
30
+ * const workflow = Workflow($ => {
31
+ * registerWorkerActions($)
32
+ * const worker$ = withWorkers($)
33
+ *
34
+ * $.on.Expense.submitted(async (expense) => {
35
+ * await worker$.notify(finance, `New expense: ${expense.amount}`)
36
+ *
37
+ * const approval = await worker$.approve(
38
+ * `Expense: $${expense.amount}`,
39
+ * manager,
40
+ * { via: 'slack' }
41
+ * )
42
+ *
43
+ * if (approval.approved) {
44
+ * await worker$.notify(expense.submitter, 'Expense approved!')
45
+ * }
46
+ * })
47
+ * })
48
+ * ```
49
+ *
50
+ * @packageDocumentation
51
+ */
52
+ export type * from './types.js';
53
+ export { registerWorkerActions, withWorkers, handleNotify, handleAsk, handleApprove, handleDecide, handleDo, notify as notifyAction, ask as askAction, approve as approveAction, decide as decideAction, } from './actions.js';
54
+ export { Role } from './role.js';
55
+ export { Team } from './team.js';
56
+ export { Goals } from './goals.js';
57
+ export { approve } from './approve.js';
58
+ export { ask } from './ask.js';
59
+ export { do } from './do.js';
60
+ export { decide } from './decide.js';
61
+ export { generate } from './generate.js';
62
+ export { is } from './is.js';
63
+ export { notify } from './notify.js';
64
+ export { kpis, okrs } from './kpis.js';
65
+ export { WorkerVerbs } from './types.js';
66
+ export type { Transport, TransportConfig, MessagePayload, MessageAction, DeliveryResult, Address, TransportHandler, } from './transports.js';
67
+ export { channelToTransport, getWorkerTransports, getTeamTransports, resolveAddress, resolveWorkerAddresses, getPrimaryAddress, registerTransport, getTransportHandler, hasTransport, listTransports, sendViaTransport, sendToMultipleTransports, buildNotifyPayload, buildAskPayload, buildApprovePayload, toDigitalToolsMessage, fromDigitalToolsMessage, MessageTypeMapping, CallTypeMapping, } from './transports.js';
68
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAGH,mBAAmB,YAAY,CAAA;AAG/B,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,MAAM,IAAI,YAAY,EACtB,GAAG,IAAI,SAAS,EAChB,OAAO,IAAI,aAAa,EACxB,MAAM,IAAI,YAAY,GACvB,MAAM,cAAc,CAAA;AAGrB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM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