digital-workers 2.1.1 → 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.
- package/CHANGELOG.md +23 -0
- package/README.md +136 -180
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +34 -21
- package/dist/actions.js.map +1 -1
- package/dist/agent-comms.d.ts +438 -0
- package/dist/agent-comms.d.ts.map +1 -0
- package/dist/agent-comms.js +677 -0
- package/dist/agent-comms.js.map +1 -0
- package/dist/approve.d.ts +40 -8
- package/dist/approve.d.ts.map +1 -1
- package/dist/approve.js +86 -20
- package/dist/approve.js.map +1 -1
- package/dist/ask.d.ts +38 -7
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +85 -25
- package/dist/ask.js.map +1 -1
- package/dist/browse.d.ts +223 -0
- package/dist/browse.d.ts.map +1 -0
- package/dist/browse.js +392 -0
- package/dist/browse.js.map +1 -0
- package/dist/capability-tiers.d.ts +230 -0
- package/dist/capability-tiers.d.ts.map +1 -0
- package/dist/capability-tiers.js +388 -0
- package/dist/capability-tiers.js.map +1 -0
- package/dist/cascade-context.d.ts +523 -0
- package/dist/cascade-context.d.ts.map +1 -0
- package/dist/cascade-context.js +494 -0
- package/dist/cascade-context.js.map +1 -0
- package/dist/client.d.ts +162 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +64 -0
- package/dist/client.js.map +1 -0
- package/dist/decide.d.ts +42 -6
- package/dist/decide.d.ts.map +1 -1
- package/dist/decide.js +54 -11
- package/dist/decide.js.map +1 -1
- package/dist/do.d.ts +36 -7
- package/dist/do.d.ts.map +1 -1
- package/dist/do.js +82 -39
- package/dist/do.js.map +1 -1
- package/dist/error-escalation.d.ts +416 -0
- package/dist/error-escalation.d.ts.map +1 -0
- package/dist/error-escalation.js +656 -0
- package/dist/error-escalation.js.map +1 -0
- package/dist/generate.d.ts +48 -7
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +49 -8
- package/dist/generate.js.map +1 -1
- package/dist/goals.d.ts +10 -9
- package/dist/goals.d.ts.map +1 -1
- package/dist/goals.js +30 -24
- package/dist/goals.js.map +1 -1
- package/dist/image.d.ts +189 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +528 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +59 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +92 -2
- package/dist/index.js.map +1 -1
- package/dist/is.d.ts +45 -10
- package/dist/is.d.ts.map +1 -1
- package/dist/is.js +56 -21
- package/dist/is.js.map +1 -1
- package/dist/kpis.d.ts +24 -15
- package/dist/kpis.d.ts.map +1 -1
- package/dist/kpis.js +16 -14
- package/dist/kpis.js.map +1 -1
- package/dist/load-balancing.d.ts +395 -0
- package/dist/load-balancing.d.ts.map +1 -0
- package/dist/load-balancing.js +991 -0
- package/dist/load-balancing.js.map +1 -0
- package/dist/logger.d.ts +76 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +39 -0
- package/dist/logger.js.map +1 -0
- package/dist/notify.d.ts +38 -9
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +72 -17
- package/dist/notify.js.map +1 -1
- package/dist/role.d.ts +5 -4
- package/dist/role.d.ts.map +1 -1
- package/dist/role.js +13 -10
- package/dist/role.js.map +1 -1
- package/dist/runtime.d.ts +310 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +510 -0
- package/dist/runtime.js.map +1 -0
- package/dist/team.d.ts +11 -6
- package/dist/team.d.ts.map +1 -1
- package/dist/team.js +22 -15
- package/dist/team.js.map +1 -1
- package/dist/transports/email.d.ts +318 -0
- package/dist/transports/email.d.ts.map +1 -0
- package/dist/transports/email.js +779 -0
- package/dist/transports/email.js.map +1 -0
- package/dist/transports/slack.d.ts +515 -0
- package/dist/transports/slack.d.ts.map +1 -0
- package/dist/transports/slack.js +844 -0
- package/dist/transports/slack.js.map +1 -0
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +44 -25
- package/dist/transports.js.map +1 -1
- package/dist/types.d.ts +149 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/id.d.ts +19 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/dist/utils/id.js +21 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/video.d.ts +203 -0
- package/dist/video.d.ts.map +1 -0
- package/dist/video.js +528 -0
- package/dist/video.js.map +1 -0
- package/dist/worker.d.ts +343 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +698 -0
- package/dist/worker.js.map +1 -0
- package/package.json +24 -5
- package/src/actions.ts +48 -38
- package/src/agent-comms.ts +1200 -0
- package/src/approve.ts +91 -20
- package/src/ask.ts +99 -25
- package/src/browse.ts +627 -0
- package/src/capability-tiers.ts +545 -0
- package/src/cascade-context.ts +648 -0
- package/src/client.ts +221 -0
- package/src/decide.ts +81 -35
- package/src/do.ts +98 -52
- package/src/error-escalation.ts +1123 -0
- package/src/generate.ts +52 -18
- package/src/goals.ts +36 -27
- package/src/image.ts +816 -0
- package/src/index.ts +410 -2
- package/src/is.ts +59 -25
- package/src/kpis.ts +41 -36
- package/src/load-balancing.ts +1467 -0
- package/src/logger.ts +93 -0
- package/src/notify.ts +78 -17
- package/src/role.ts +30 -20
- package/src/runtime.ts +796 -0
- package/src/team.ts +24 -19
- package/src/transports/email.ts +1160 -0
- package/src/transports/slack.ts +1320 -0
- package/src/transports.ts +58 -43
- package/src/types.ts +182 -46
- package/src/utils/id.ts +21 -0
- package/src/video.ts +906 -0
- package/src/worker.ts +1007 -0
- package/test/agent-comms.test.ts +1397 -0
- package/test/approve.test.ts +305 -0
- package/test/ask.test.ts +274 -0
- package/test/browse.test.ts +361 -0
- package/test/capability-tiers.test.ts +631 -0
- package/test/cascade-context.test.ts +692 -0
- package/test/decide.test.ts +252 -0
- package/test/do.test.ts +144 -0
- package/test/error-escalation.test.ts +1205 -0
- package/test/error-logging.test.ts +357 -0
- package/test/generate.test.ts +319 -0
- package/test/image.test.ts +398 -0
- package/test/is.test.ts +287 -0
- package/test/load-balancing-safety.test.ts +404 -0
- package/test/load-balancing-thread-safety.test.ts +464 -0
- package/test/load-balancing.test.ts +1145 -0
- package/test/notify.test.ts +434 -0
- package/test/primitives.test.ts +320 -0
- package/test/runtime-integration.test.ts +892 -0
- package/test/transports/crypto.test.ts +230 -0
- package/test/transports/email.test.ts +866 -0
- package/test/transports/id-generation.test.ts +91 -0
- package/test/transports/slack.test.ts +760 -0
- package/test/type-safety.test.ts +834 -0
- package/test/types.test.ts +95 -2
- package/test/video.test.ts +530 -0
- package/test/worker.test.ts +1433 -0
- package/tsconfig.json +4 -1
- package/vitest.config.ts +42 -0
- package/wrangler.jsonc +36 -0
- package/.turbo/turbo-build.log +0 -5
- package/src/actions.js +0 -436
- package/src/approve.js +0 -234
- package/src/ask.js +0 -226
- package/src/decide.js +0 -244
- package/src/do.js +0 -227
- package/src/generate.js +0 -298
- package/src/goals.js +0 -205
- package/src/index.js +0 -68
- package/src/is.js +0 -317
- package/src/kpis.js +0 -270
- package/src/notify.js +0 -219
- package/src/role.js +0 -110
- package/src/team.js +0 -130
- package/src/transports.js +0 -357
- package/src/types.js +0 -71
package/dist/client.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RPC Client for Digital Workers
|
|
3
|
+
*
|
|
4
|
+
* Provides a typed RPC client that connects to the deployed
|
|
5
|
+
* digital-workers worker using rpc.do for remote procedure calls.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createDigitalWorkersClient } from 'digital-workers/client'
|
|
10
|
+
*
|
|
11
|
+
* const client = createDigitalWorkersClient('https://digital-workers.workers.dev')
|
|
12
|
+
* const worker = await client.spawn({ name: 'my-agent', type: 'agent' })
|
|
13
|
+
* await client.send(worker.id, otherWorkerId, 'task', { data: 'hello' })
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
import { RPC, http } from 'rpc.do';
|
|
19
|
+
// ==================== Client Factory ====================
|
|
20
|
+
/** Default URL for the digital-workers worker */
|
|
21
|
+
const DEFAULT_URL = 'https://digital-workers.workers.dev';
|
|
22
|
+
/**
|
|
23
|
+
* Create a typed RPC client for the digital-workers worker
|
|
24
|
+
*
|
|
25
|
+
* @param url - The URL of the deployed digital-workers worker
|
|
26
|
+
* @param options - Optional client configuration
|
|
27
|
+
* @returns A typed RPC client with all DigitalWorkersServiceCore methods
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createDigitalWorkersClient } from 'digital-workers/client'
|
|
32
|
+
*
|
|
33
|
+
* // Connect to production
|
|
34
|
+
* const client = createDigitalWorkersClient('https://digital-workers.workers.dev')
|
|
35
|
+
*
|
|
36
|
+
* // Spawn and manage workers
|
|
37
|
+
* const agent = await client.spawn({ name: 'my-agent', type: 'agent' })
|
|
38
|
+
* const human = await client.spawn({ name: 'reviewer', type: 'human' })
|
|
39
|
+
*
|
|
40
|
+
* // Send messages between workers
|
|
41
|
+
* await client.send(agent.id, human.id, 'review-request', { content: 'Please review' })
|
|
42
|
+
* const messages = await client.receive(human.id, { type: 'review-request' })
|
|
43
|
+
*
|
|
44
|
+
* // Coordinate multiple workers
|
|
45
|
+
* const task = await client.fanOut(agent.id, [worker1.id, worker2.id], 'process', data)
|
|
46
|
+
* const status = await client.getTaskStatus(task.id)
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function createDigitalWorkersClient(url = DEFAULT_URL, options) {
|
|
50
|
+
return RPC(http(url, options?.token));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Default client instance connected to the production digital-workers worker
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import client from 'digital-workers/client'
|
|
58
|
+
*
|
|
59
|
+
* const worker = await client.spawn({ name: 'my-agent' })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
const client = createDigitalWorkersClient();
|
|
63
|
+
export default client;
|
|
64
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAuJlC,2DAA2D;AAE3D,iDAAiD;AACjD,MAAM,WAAW,GAAG,qCAAqC,CAAA;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAAc,WAAW,EACzB,OAAqC;IAErC,OAAO,GAAG,CAAoB,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,GAAG,0BAA0B,EAAE,CAAA;AAE3C,eAAe,MAAM,CAAA"}
|
package/dist/decide.d.ts
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Decision-making functionality for digital workers
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: Worker-Assisted Decisions vs LLM Judging
|
|
5
|
+
* ----------------------------------------------------
|
|
6
|
+
* This module provides structured decision-making that can involve human
|
|
7
|
+
* decision-makers, NOT simple LLM-based option selection.
|
|
8
|
+
*
|
|
9
|
+
* - `digital-workers.decide()` - Structured decision-making with criteria
|
|
10
|
+
* evaluation, confidence scoring, and optional human approval routing.
|
|
11
|
+
*
|
|
12
|
+
* - `ai-functions.decide()` - LLM as judge - compares options and picks
|
|
13
|
+
* the best one based on criteria (curried function pattern).
|
|
14
|
+
*
|
|
15
|
+
* Use digital-workers when you need:
|
|
16
|
+
* - Multi-criteria decision analysis
|
|
17
|
+
* - Confidence scores and alternative rankings
|
|
18
|
+
* - Human approval for critical decisions
|
|
19
|
+
* - Audit trail of decision reasoning
|
|
20
|
+
*
|
|
21
|
+
* Use ai-functions when you need:
|
|
22
|
+
* - Simple "pick the best" comparison
|
|
23
|
+
* - LLM judging between options
|
|
24
|
+
* - Curried decision function pattern
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
3
27
|
*/
|
|
4
28
|
import type { Decision, DecideOptions } from './types.js';
|
|
5
29
|
/**
|
|
6
|
-
* Make a decision
|
|
30
|
+
* Make a structured decision with criteria evaluation and optional human routing.
|
|
7
31
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
32
|
+
* **Key Difference from ai-functions.decide():**
|
|
33
|
+
* Unlike `ai-functions.decide()` which is a curried LLM judge function
|
|
34
|
+
* (e.g., `decide\`criteria\`(optionA, optionB)`), this function provides
|
|
35
|
+
* comprehensive decision analysis with:
|
|
36
|
+
* - Multi-criteria scoring
|
|
37
|
+
* - Confidence levels
|
|
38
|
+
* - Alternative rankings
|
|
39
|
+
* - Optional human approval routing via `decide.withApproval()`
|
|
10
40
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
41
|
+
* This is a **decision framework**, not a simple LLM comparison primitive.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Decision options including choices, context, and criteria
|
|
44
|
+
* @returns Promise resolving to decision with choice, reasoning, confidence, and alternatives
|
|
13
45
|
*
|
|
14
46
|
* @example
|
|
15
47
|
* ```ts
|
|
48
|
+
* // Structured decision with criteria evaluation
|
|
16
49
|
* const decision = await decide({
|
|
17
50
|
* options: ['Option A', 'Option B', 'Option C'],
|
|
18
51
|
* context: 'We need to choose a technology stack for our new project',
|
|
@@ -26,7 +59,8 @@ import type { Decision, DecideOptions } from './types.js';
|
|
|
26
59
|
*
|
|
27
60
|
* console.log(`Decision: ${decision.choice}`)
|
|
28
61
|
* console.log(`Reasoning: ${decision.reasoning}`)
|
|
29
|
-
* console.log(`Confidence: ${decision.confidence}`)
|
|
62
|
+
* console.log(`Confidence: ${decision.confidence}`) // 0-1 score
|
|
63
|
+
* console.log(`Alternatives:`, decision.alternatives)
|
|
30
64
|
* ```
|
|
31
65
|
*
|
|
32
66
|
* @example
|
|
@@ -47,6 +81,8 @@ import type { Decision, DecideOptions } from './types.js';
|
|
|
47
81
|
* criteria: ['Cost', 'Time to market', 'Risk', 'Scalability'],
|
|
48
82
|
* })
|
|
49
83
|
* ```
|
|
84
|
+
*
|
|
85
|
+
* @see {@link ai-functions#decide} for LLM-as-judge option comparison
|
|
50
86
|
*/
|
|
51
87
|
export declare function decide<T = string>(options: DecideOptions<T>): Promise<Decision<T>>;
|
|
52
88
|
export declare namespace decide {
|
package/dist/decide.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decide.d.ts","sourceRoot":"","sources":["../src/decide.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decide.d.ts","sourceRoot":"","sources":["../src/decide.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,wBAAsB,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CA8ExF;yBA9EqB,MAAM;0BAwGhB,MAAM,YACN,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzC,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;qBA+BP,CAAC,kBACnB,CAAC,EAAE,YACA,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,aAChC,MAAM,EAAE,KACjB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;uBAkFpB,CAAC,oBACnB,aAAa,CAAC,CAAC,CAAC,YACf,MAAM,KACf,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC"}
|
package/dist/decide.js
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Decision-making functionality for digital workers
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: Worker-Assisted Decisions vs LLM Judging
|
|
5
|
+
* ----------------------------------------------------
|
|
6
|
+
* This module provides structured decision-making that can involve human
|
|
7
|
+
* decision-makers, NOT simple LLM-based option selection.
|
|
8
|
+
*
|
|
9
|
+
* - `digital-workers.decide()` - Structured decision-making with criteria
|
|
10
|
+
* evaluation, confidence scoring, and optional human approval routing.
|
|
11
|
+
*
|
|
12
|
+
* - `ai-functions.decide()` - LLM as judge - compares options and picks
|
|
13
|
+
* the best one based on criteria (curried function pattern).
|
|
14
|
+
*
|
|
15
|
+
* Use digital-workers when you need:
|
|
16
|
+
* - Multi-criteria decision analysis
|
|
17
|
+
* - Confidence scores and alternative rankings
|
|
18
|
+
* - Human approval for critical decisions
|
|
19
|
+
* - Audit trail of decision reasoning
|
|
20
|
+
*
|
|
21
|
+
* Use ai-functions when you need:
|
|
22
|
+
* - Simple "pick the best" comparison
|
|
23
|
+
* - LLM judging between options
|
|
24
|
+
* - Curried decision function pattern
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
3
27
|
*/
|
|
4
28
|
import { generateObject } from 'ai-functions';
|
|
5
29
|
/**
|
|
6
|
-
* Make a decision
|
|
30
|
+
* Make a structured decision with criteria evaluation and optional human routing.
|
|
7
31
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
32
|
+
* **Key Difference from ai-functions.decide():**
|
|
33
|
+
* Unlike `ai-functions.decide()` which is a curried LLM judge function
|
|
34
|
+
* (e.g., `decide\`criteria\`(optionA, optionB)`), this function provides
|
|
35
|
+
* comprehensive decision analysis with:
|
|
36
|
+
* - Multi-criteria scoring
|
|
37
|
+
* - Confidence levels
|
|
38
|
+
* - Alternative rankings
|
|
39
|
+
* - Optional human approval routing via `decide.withApproval()`
|
|
10
40
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
41
|
+
* This is a **decision framework**, not a simple LLM comparison primitive.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Decision options including choices, context, and criteria
|
|
44
|
+
* @returns Promise resolving to decision with choice, reasoning, confidence, and alternatives
|
|
13
45
|
*
|
|
14
46
|
* @example
|
|
15
47
|
* ```ts
|
|
48
|
+
* // Structured decision with criteria evaluation
|
|
16
49
|
* const decision = await decide({
|
|
17
50
|
* options: ['Option A', 'Option B', 'Option C'],
|
|
18
51
|
* context: 'We need to choose a technology stack for our new project',
|
|
@@ -26,7 +59,8 @@ import { generateObject } from 'ai-functions';
|
|
|
26
59
|
*
|
|
27
60
|
* console.log(`Decision: ${decision.choice}`)
|
|
28
61
|
* console.log(`Reasoning: ${decision.reasoning}`)
|
|
29
|
-
* console.log(`Confidence: ${decision.confidence}`)
|
|
62
|
+
* console.log(`Confidence: ${decision.confidence}`) // 0-1 score
|
|
63
|
+
* console.log(`Alternatives:`, decision.alternatives)
|
|
30
64
|
* ```
|
|
31
65
|
*
|
|
32
66
|
* @example
|
|
@@ -47,9 +81,11 @@ import { generateObject } from 'ai-functions';
|
|
|
47
81
|
* criteria: ['Cost', 'Time to market', 'Risk', 'Scalability'],
|
|
48
82
|
* })
|
|
49
83
|
* ```
|
|
84
|
+
*
|
|
85
|
+
* @see {@link ai-functions#decide} for LLM-as-judge option comparison
|
|
50
86
|
*/
|
|
51
87
|
export async function decide(options) {
|
|
52
|
-
const { options: choices, context, criteria = [], includeReasoning = true
|
|
88
|
+
const { options: choices, context, criteria = [], includeReasoning = true } = options;
|
|
53
89
|
// Format context for the prompt
|
|
54
90
|
const contextStr = typeof context === 'string'
|
|
55
91
|
? context
|
|
@@ -85,7 +121,9 @@ export async function decide(options) {
|
|
|
85
121
|
},
|
|
86
122
|
system: `You are a decision-making expert. Analyze the options carefully and make the best choice based on the context and criteria provided.
|
|
87
123
|
|
|
88
|
-
${criteria.length > 0
|
|
124
|
+
${criteria.length > 0
|
|
125
|
+
? `Evaluation Criteria:\n${criteria.map((c, i) => `${i + 1}. ${c}`).join('\n')}`
|
|
126
|
+
: ''}`,
|
|
89
127
|
prompt: `Make a decision based on the following:
|
|
90
128
|
|
|
91
129
|
Context:
|
|
@@ -94,7 +132,9 @@ ${contextStr}
|
|
|
94
132
|
Options:
|
|
95
133
|
${choicesStr}
|
|
96
134
|
|
|
97
|
-
${criteria.length > 0
|
|
135
|
+
${criteria.length > 0
|
|
136
|
+
? `\nEvaluate each option against these criteria:\n${criteria.join(', ')}`
|
|
137
|
+
: ''}
|
|
98
138
|
|
|
99
139
|
Provide your decision with clear reasoning.`,
|
|
100
140
|
});
|
|
@@ -181,7 +221,9 @@ decide.prioritize = async (items, context, criteria = []) => {
|
|
|
181
221
|
},
|
|
182
222
|
system: `You are a prioritization expert. Rank items by priority based on the context and criteria.
|
|
183
223
|
|
|
184
|
-
${criteria.length > 0
|
|
224
|
+
${criteria.length > 0
|
|
225
|
+
? `Prioritization Criteria:\n${criteria.map((c, i) => `${i + 1}. ${c}`).join('\n')}`
|
|
226
|
+
: ''}`,
|
|
185
227
|
prompt: `Prioritize the following items:
|
|
186
228
|
|
|
187
229
|
Context:
|
|
@@ -236,10 +278,11 @@ decide.withApproval = async (options, approver) => {
|
|
|
236
278
|
context: options.context,
|
|
237
279
|
},
|
|
238
280
|
});
|
|
281
|
+
const approvedBy = approval.approvedBy?.id ?? approval.approvedBy?.name;
|
|
239
282
|
return {
|
|
240
283
|
...decision,
|
|
241
284
|
approved: approval.approved,
|
|
242
|
-
approvedBy
|
|
285
|
+
...(approvedBy !== undefined && { approvedBy }),
|
|
243
286
|
};
|
|
244
287
|
};
|
|
245
288
|
//# sourceMappingURL=decide.js.map
|
package/dist/decide.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decide.js","sourceRoot":"","sources":["../src/decide.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decide.js","sourceRoot":"","sources":["../src/decide.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAa,OAAyB;IAChE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,GAAG,EAAE,EAAE,gBAAgB,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;IAErF,gCAAgC;IAChC,MAAM,UAAU,GACd,OAAO,OAAO,KAAK,QAAQ;QACzB,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAClC,CAAC,CAAC,gCAAgC,CAAA;IAEtC,gCAAgC;IAChC,MAAM,UAAU,GAAG,OAAO;SACvB,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACjB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAClD,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAA;QAC9C,CAAC;QACD,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE,CAAA;IAC9B,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CA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5B,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,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,IAAI,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAA;IACvE,OAAO;QACL,GAAG,QAAQ;QACX,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,CAAC;KAChD,CAAA;AACH,CAAC,CAAA"}
|
package/dist/do.d.ts
CHANGED
|
@@ -1,20 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Task execution functionality for digital workers
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: Worker Routing vs Direct LLM Calls
|
|
5
|
+
* ---------------------------------------------
|
|
6
|
+
* This module provides worker-routed task execution, NOT direct LLM calls.
|
|
7
|
+
*
|
|
8
|
+
* - `digital-workers.do()` - Routes tasks to Workers (AI Agents or Humans)
|
|
9
|
+
* based on capability matching, load balancing, and escalation policies.
|
|
10
|
+
*
|
|
11
|
+
* - `ai-functions.do()` - Directly calls the LLM to describe task execution.
|
|
12
|
+
*
|
|
13
|
+
* Use digital-workers when you need:
|
|
14
|
+
* - Task routing to appropriate workers
|
|
15
|
+
* - Human-in-the-loop escalation
|
|
16
|
+
* - Capability-based worker selection
|
|
17
|
+
* - Retry and timeout handling across workers
|
|
18
|
+
*
|
|
19
|
+
* Use ai-functions when you need:
|
|
20
|
+
* - Direct LLM text generation
|
|
21
|
+
* - Simple AI task description
|
|
22
|
+
* - No worker coordination required
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
3
25
|
*/
|
|
4
26
|
import type { TaskResult, DoOptions } from './types.js';
|
|
5
27
|
/**
|
|
6
|
-
* Execute a task
|
|
28
|
+
* Execute a task by routing to an appropriate Worker (AI Agent or Human).
|
|
7
29
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
30
|
+
* **Key Difference from ai-functions.do():**
|
|
31
|
+
* Unlike `ai-functions.do()` which directly calls the LLM to describe what
|
|
32
|
+
* actions would be taken, this function routes the task to a Worker (Agent
|
|
33
|
+
* or Human) based on capability matching. The Worker then executes the task
|
|
34
|
+
* using their specific tools and capabilities.
|
|
35
|
+
*
|
|
36
|
+
* This is a **worker coordination primitive**, not a direct LLM primitive.
|
|
10
37
|
*
|
|
11
38
|
* @param task - Description of the task to execute
|
|
12
39
|
* @param options - Execution options (retries, timeout, background, etc.)
|
|
13
|
-
* @returns Promise resolving to task result
|
|
40
|
+
* @returns Promise resolving to task result with execution details
|
|
14
41
|
*
|
|
15
42
|
* @example
|
|
16
43
|
* ```ts
|
|
17
|
-
* //
|
|
44
|
+
* // Route task to appropriate worker based on capability
|
|
18
45
|
* const result = await do('Generate monthly sales report', {
|
|
19
46
|
* timeout: 60000, // 1 minute
|
|
20
47
|
* context: {
|
|
@@ -30,7 +57,7 @@ import type { TaskResult, DoOptions } from './types.js';
|
|
|
30
57
|
*
|
|
31
58
|
* @example
|
|
32
59
|
* ```ts
|
|
33
|
-
* // Execute with retries
|
|
60
|
+
* // Execute with retries across workers
|
|
34
61
|
* const result = await do('Sync data to backup server', {
|
|
35
62
|
* maxRetries: 3,
|
|
36
63
|
* timeout: 30000,
|
|
@@ -43,7 +70,7 @@ import type { TaskResult, DoOptions } from './types.js';
|
|
|
43
70
|
*
|
|
44
71
|
* @example
|
|
45
72
|
* ```ts
|
|
46
|
-
* // Execute in background
|
|
73
|
+
* // Execute in background (worker handles async)
|
|
47
74
|
* const result = await do('Process large dataset', {
|
|
48
75
|
* background: true,
|
|
49
76
|
* context: {
|
|
@@ -52,6 +79,8 @@ import type { TaskResult, DoOptions } from './types.js';
|
|
|
52
79
|
* },
|
|
53
80
|
* })
|
|
54
81
|
* ```
|
|
82
|
+
*
|
|
83
|
+
* @see {@link ai-functions#do} for direct LLM task description
|
|
55
84
|
*/
|
|
56
85
|
export declare function doTask<T = unknown>(task: string, options?: DoOptions): Promise<TaskResult<T>>;
|
|
57
86
|
export declare namespace doTask {
|
package/dist/do.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"do.d.ts","sourceRoot":"","sources":["../src/do.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"do.d.ts","sourceRoot":"","sources":["../src/do.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,wBAAsB,MAAM,CAAC,CAAC,GAAG,OAAO,EACtC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,SAAc,GACtB,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAmHxB;yBAtHqB,MAAM;mBAgJH,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
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Task execution functionality for digital workers
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: Worker Routing vs Direct LLM Calls
|
|
5
|
+
* ---------------------------------------------
|
|
6
|
+
* This module provides worker-routed task execution, NOT direct LLM calls.
|
|
7
|
+
*
|
|
8
|
+
* - `digital-workers.do()` - Routes tasks to Workers (AI Agents or Humans)
|
|
9
|
+
* based on capability matching, load balancing, and escalation policies.
|
|
10
|
+
*
|
|
11
|
+
* - `ai-functions.do()` - Directly calls the LLM to describe task execution.
|
|
12
|
+
*
|
|
13
|
+
* Use digital-workers when you need:
|
|
14
|
+
* - Task routing to appropriate workers
|
|
15
|
+
* - Human-in-the-loop escalation
|
|
16
|
+
* - Capability-based worker selection
|
|
17
|
+
* - Retry and timeout handling across workers
|
|
18
|
+
*
|
|
19
|
+
* Use ai-functions when you need:
|
|
20
|
+
* - Direct LLM text generation
|
|
21
|
+
* - Simple AI task description
|
|
22
|
+
* - No worker coordination required
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
3
25
|
*/
|
|
4
|
-
import { define } from 'ai-functions';
|
|
5
26
|
/**
|
|
6
|
-
* Execute a task
|
|
27
|
+
* Execute a task by routing to an appropriate Worker (AI Agent or Human).
|
|
7
28
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
29
|
+
* **Key Difference from ai-functions.do():**
|
|
30
|
+
* Unlike `ai-functions.do()` which directly calls the LLM to describe what
|
|
31
|
+
* actions would be taken, this function routes the task to a Worker (Agent
|
|
32
|
+
* or Human) based on capability matching. The Worker then executes the task
|
|
33
|
+
* using their specific tools and capabilities.
|
|
34
|
+
*
|
|
35
|
+
* This is a **worker coordination primitive**, not a direct LLM primitive.
|
|
10
36
|
*
|
|
11
37
|
* @param task - Description of the task to execute
|
|
12
38
|
* @param options - Execution options (retries, timeout, background, etc.)
|
|
13
|
-
* @returns Promise resolving to task result
|
|
39
|
+
* @returns Promise resolving to task result with execution details
|
|
14
40
|
*
|
|
15
41
|
* @example
|
|
16
42
|
* ```ts
|
|
17
|
-
* //
|
|
43
|
+
* // Route task to appropriate worker based on capability
|
|
18
44
|
* const result = await do('Generate monthly sales report', {
|
|
19
45
|
* timeout: 60000, // 1 minute
|
|
20
46
|
* context: {
|
|
@@ -30,7 +56,7 @@ import { define } from 'ai-functions';
|
|
|
30
56
|
*
|
|
31
57
|
* @example
|
|
32
58
|
* ```ts
|
|
33
|
-
* // Execute with retries
|
|
59
|
+
* // Execute with retries across workers
|
|
34
60
|
* const result = await do('Sync data to backup server', {
|
|
35
61
|
* maxRetries: 3,
|
|
36
62
|
* timeout: 30000,
|
|
@@ -43,7 +69,7 @@ import { define } from 'ai-functions';
|
|
|
43
69
|
*
|
|
44
70
|
* @example
|
|
45
71
|
* ```ts
|
|
46
|
-
* // Execute in background
|
|
72
|
+
* // Execute in background (worker handles async)
|
|
47
73
|
* const result = await do('Process large dataset', {
|
|
48
74
|
* background: true,
|
|
49
75
|
* context: {
|
|
@@ -52,55 +78,72 @@ import { define } from 'ai-functions';
|
|
|
52
78
|
* },
|
|
53
79
|
* })
|
|
54
80
|
* ```
|
|
81
|
+
*
|
|
82
|
+
* @see {@link ai-functions#do} for direct LLM task description
|
|
55
83
|
*/
|
|
56
84
|
export async function doTask(task, options = {}) {
|
|
57
|
-
const { maxRetries = 0, timeout, background = false, context
|
|
85
|
+
const { maxRetries = 0, timeout, background = false, context } = options;
|
|
58
86
|
const startTime = Date.now();
|
|
59
87
|
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
88
|
let retries = 0;
|
|
84
89
|
let lastError;
|
|
85
90
|
while (retries <= maxRetries) {
|
|
86
91
|
try {
|
|
92
|
+
// Use generateObject directly for more reliable execution
|
|
93
|
+
const { generateObject } = await import('ai-functions');
|
|
94
|
+
const executeTask = async () => {
|
|
95
|
+
const response = await generateObject({
|
|
96
|
+
model: 'sonnet',
|
|
97
|
+
schema: {
|
|
98
|
+
result: 'The result of executing the task - provide a detailed response',
|
|
99
|
+
steps: [
|
|
100
|
+
{
|
|
101
|
+
action: 'Description of what was done in this step',
|
|
102
|
+
result: 'Outcome of this step',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
success: 'Whether the task was completed successfully (boolean)',
|
|
106
|
+
},
|
|
107
|
+
system: `You are a capable AI worker executing tasks. You have access to the following context:
|
|
108
|
+
|
|
109
|
+
${context ? JSON.stringify(context, null, 2) : 'No additional context provided.'}
|
|
110
|
+
|
|
111
|
+
Execute the task step-by-step, documenting each action you take.
|
|
112
|
+
Provide detailed, actionable results that can be used directly.`,
|
|
113
|
+
prompt: `Execute the following task and provide the result:
|
|
114
|
+
|
|
115
|
+
Task: ${task}
|
|
116
|
+
|
|
117
|
+
Work through this task carefully:
|
|
118
|
+
1. Analyze what needs to be done
|
|
119
|
+
2. Execute each step
|
|
120
|
+
3. Provide the final result
|
|
121
|
+
|
|
122
|
+
Return a detailed result that fulfills the task requirements.`,
|
|
123
|
+
});
|
|
124
|
+
const obj = response.object;
|
|
125
|
+
if (!obj.success) {
|
|
126
|
+
throw new Error('Task execution failed');
|
|
127
|
+
}
|
|
128
|
+
return { result: obj.result, steps: obj.steps };
|
|
129
|
+
};
|
|
87
130
|
const response = await Promise.race([
|
|
88
|
-
|
|
131
|
+
executeTask(),
|
|
89
132
|
timeout
|
|
90
133
|
? new Promise((_, reject) => setTimeout(() => reject(new Error('Task timeout')), timeout))
|
|
91
134
|
: new Promise(() => { }), // Never resolves if no timeout
|
|
92
135
|
]);
|
|
93
|
-
const typedResponse = response;
|
|
94
136
|
// Track steps if provided
|
|
95
|
-
if (
|
|
96
|
-
steps.push(...
|
|
97
|
-
|
|
137
|
+
if (response.steps) {
|
|
138
|
+
steps.push(...response.steps.map((step) => ({
|
|
139
|
+
action: String(step.action),
|
|
140
|
+
result: step.result,
|
|
98
141
|
timestamp: new Date(),
|
|
99
142
|
})));
|
|
100
143
|
}
|
|
101
144
|
const duration = Date.now() - startTime;
|
|
102
145
|
return {
|
|
103
|
-
result:
|
|
146
|
+
result: response.result,
|
|
104
147
|
success: true,
|
|
105
148
|
duration,
|
|
106
149
|
steps,
|
|
@@ -179,7 +222,7 @@ doTask.sequence = async (tasks, options = {}) => {
|
|
|
179
222
|
const result = await doTask(task, options);
|
|
180
223
|
results.push(result);
|
|
181
224
|
// Stop if a task fails (unless we're continuing on error)
|
|
182
|
-
if (!result.success && !options.context?.continueOnError) {
|
|
225
|
+
if (!result.success && !options.context?.['continueOnError']) {
|
|
183
226
|
break;
|
|
184
227
|
}
|
|
185
228
|
}
|
package/dist/do.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"do.js","sourceRoot":"","sources":["../src/do.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"do.js","sourceRoot":"","sources":["../src/do.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,IAAY,EACZ,UAAqB,EAAE;IAEvB,MAAM,EAAE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