autonomous-agents 0.1.0 → 2.0.1
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 +9 -0
- package/README.md +260 -96
- package/dist/actions.d.ts +136 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +303 -0
- package/dist/actions.js.map +1 -0
- package/dist/agent.d.ts +49 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +452 -0
- package/dist/agent.js.map +1 -0
- package/dist/goals.d.ts +138 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +342 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics.d.ts +245 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +436 -0
- package/dist/metrics.js.map +1 -0
- package/dist/role.d.ts +122 -0
- package/dist/role.d.ts.map +1 -0
- package/dist/role.js +393 -0
- package/dist/role.js.map +1 -0
- package/dist/team.d.ts +152 -0
- package/dist/team.d.ts.map +1 -0
- package/dist/team.js +347 -0
- package/dist/team.js.map +1 -0
- package/dist/types.d.ts +327 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -36
- package/src/actions.ts +366 -0
- package/src/agent.ts +548 -0
- package/src/goals.ts +435 -0
- package/src/index.ts +135 -0
- package/src/metrics.ts +591 -0
- package/src/role.ts +422 -0
- package/src/team.ts +466 -0
- package/src/types.ts +356 -0
- package/test/actions.test.ts +522 -0
- package/test/agent.test.ts +490 -0
- package/test/goals.test.ts +570 -0
- package/test/metrics.test.ts +707 -0
- package/test/role.test.ts +423 -0
- package/test/team.test.ts +708 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.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AAM,CAAA;IACxB,mBAAmB;IACnB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa;IACb,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,CAAA;CAC5D;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,iBAAiB;IACjB,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,2BAA2B;IAC3B,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAA;IACtD,iBAAiB;IACjB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,eAAe;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,sBAAsB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/package.json
CHANGED
|
@@ -1,43 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autonomous-agents",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Primitives for building and orchestrating autonomous AI agents",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"test": "vitest",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint .",
|
|
20
|
+
"clean": "rm -rf dist"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"ai-functions": "workspace:*",
|
|
24
|
+
"digital-workers": "workspace:*",
|
|
25
|
+
"rpc.do": "^0.1.0"
|
|
26
|
+
},
|
|
11
27
|
"keywords": [
|
|
12
|
-
"
|
|
28
|
+
"ai",
|
|
29
|
+
"agents",
|
|
13
30
|
"autonomous",
|
|
14
|
-
"
|
|
31
|
+
"primitives"
|
|
15
32
|
],
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"tsup": "^8.0.0",
|
|
20
|
-
"typescript": "^5.0.0",
|
|
21
|
-
"vitest": "^3.1.3"
|
|
22
|
-
},
|
|
23
|
-
"tsup": {
|
|
24
|
-
"entry": [
|
|
25
|
-
"src/index.ts"
|
|
26
|
-
],
|
|
27
|
-
"format": [
|
|
28
|
-
"cjs",
|
|
29
|
-
"esm"
|
|
30
|
-
],
|
|
31
|
-
"dts": true,
|
|
32
|
-
"splitting": false,
|
|
33
|
-
"sourcemap": true,
|
|
34
|
-
"clean": true
|
|
35
|
-
},
|
|
36
|
-
"scripts": {
|
|
37
|
-
"build": "tsup",
|
|
38
|
-
"dev": "tsup --watch",
|
|
39
|
-
"lint": "eslint src/**/*.ts",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"test:watch": "vitest"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
33
|
+
"license": "MIT"
|
|
34
|
+
}
|
package/src/actions.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Actions - Core action functions for autonomous agents
|
|
3
|
+
*
|
|
4
|
+
* These are standalone functions that can be used independently
|
|
5
|
+
* or as part of an agent's capabilities.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { generateObject, type AIGenerateOptions, type SimpleSchema } from 'ai-functions'
|
|
11
|
+
import type {
|
|
12
|
+
ApprovalRequest,
|
|
13
|
+
ApprovalResult,
|
|
14
|
+
ApprovalStatus,
|
|
15
|
+
NotificationOptions,
|
|
16
|
+
} from './types.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Execute a task using AI
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { do as doTask } from 'autonomous-agents'
|
|
24
|
+
*
|
|
25
|
+
* const result = await doTask('Analyze customer feedback and provide insights', {
|
|
26
|
+
* feedback: ['Great product!', 'Needs improvement', 'Love the features'],
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export async function doAction<TResult = unknown>(
|
|
31
|
+
task: string,
|
|
32
|
+
context?: unknown,
|
|
33
|
+
options?: AIGenerateOptions
|
|
34
|
+
): Promise<TResult> {
|
|
35
|
+
const result = await generateObject({
|
|
36
|
+
model: options?.model || 'sonnet',
|
|
37
|
+
schema: options?.schema || { result: 'The result of the task' },
|
|
38
|
+
system: options?.system || 'You are a helpful AI assistant. Execute tasks accurately and thoroughly.',
|
|
39
|
+
prompt: `Task: ${task}\n\nContext: ${JSON.stringify(context || {})}`,
|
|
40
|
+
temperature: options?.temperature ?? 0.7,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return (result.object as { result: TResult }).result || result.object as TResult
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Ask a question and get an answer
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { ask } from 'autonomous-agents'
|
|
52
|
+
*
|
|
53
|
+
* const answer = await ask('What are the key benefits of our product?', {
|
|
54
|
+
* product: 'AI Assistant',
|
|
55
|
+
* features: ['smart automation', 'natural language', 'context awareness'],
|
|
56
|
+
* })
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export async function ask<TResult = unknown>(
|
|
60
|
+
question: string,
|
|
61
|
+
context?: unknown,
|
|
62
|
+
options?: AIGenerateOptions
|
|
63
|
+
): Promise<TResult> {
|
|
64
|
+
const result = await generateObject({
|
|
65
|
+
model: options?.model || 'sonnet',
|
|
66
|
+
schema: options?.schema || {
|
|
67
|
+
answer: 'The answer to the question',
|
|
68
|
+
reasoning: 'Supporting reasoning',
|
|
69
|
+
},
|
|
70
|
+
system: options?.system || 'You are a knowledgeable AI assistant. Provide clear, accurate answers.',
|
|
71
|
+
prompt: `Question: ${question}\n\nContext: ${JSON.stringify(context || {})}`,
|
|
72
|
+
temperature: options?.temperature ?? 0.7,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const response = result.object as { answer: TResult; reasoning: string }
|
|
76
|
+
return response.answer
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Make a decision between options
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { decide } from 'autonomous-agents'
|
|
85
|
+
*
|
|
86
|
+
* const choice = await decide(
|
|
87
|
+
* ['option A', 'option B', 'option C'],
|
|
88
|
+
* 'Which option has the highest ROI?'
|
|
89
|
+
* )
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export async function decide<T extends string>(
|
|
93
|
+
options: T[],
|
|
94
|
+
context?: string,
|
|
95
|
+
settings?: AIGenerateOptions
|
|
96
|
+
): Promise<T> {
|
|
97
|
+
const result = await generateObject({
|
|
98
|
+
model: settings?.model || 'sonnet',
|
|
99
|
+
schema: {
|
|
100
|
+
decision: options.join(' | '),
|
|
101
|
+
reasoning: 'Reasoning for this decision',
|
|
102
|
+
confidence: 'Confidence level 0-100 (number)',
|
|
103
|
+
} as SimpleSchema,
|
|
104
|
+
system: settings?.system || 'You are a strategic decision-maker. Evaluate options carefully and provide clear reasoning.',
|
|
105
|
+
prompt: `Make a decision between these options:\n${options.map((o, i) => `${i + 1}. ${o}`).join('\n')}\n\nContext: ${context || 'No additional context'}`,
|
|
106
|
+
temperature: settings?.temperature ?? 0.7,
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const response = result.object as unknown as {
|
|
110
|
+
decision: T
|
|
111
|
+
reasoning: string
|
|
112
|
+
confidence: number
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return response.decision
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Request approval for an action or decision
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { approve } from 'autonomous-agents'
|
|
124
|
+
*
|
|
125
|
+
* const approval = await approve({
|
|
126
|
+
* title: 'Budget Request',
|
|
127
|
+
* description: 'Request $50k for marketing campaign',
|
|
128
|
+
* data: { amount: 50000, campaign: 'Q1 Launch' },
|
|
129
|
+
* approver: 'manager@company.com',
|
|
130
|
+
* priority: 'high',
|
|
131
|
+
* })
|
|
132
|
+
*
|
|
133
|
+
* if (approval.status === 'approved') {
|
|
134
|
+
* // Proceed with the action
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export async function approve<TResult = unknown>(
|
|
139
|
+
request: ApprovalRequest
|
|
140
|
+
): Promise<ApprovalResult<TResult>> {
|
|
141
|
+
return executeApproval(request)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Execute approval request (internal implementation)
|
|
146
|
+
*/
|
|
147
|
+
export async function executeApproval<TResult = unknown>(
|
|
148
|
+
request: ApprovalRequest
|
|
149
|
+
): Promise<ApprovalResult<TResult>> {
|
|
150
|
+
// Generate approval UI based on channel
|
|
151
|
+
const uiSchema = getApprovalUISchema(request.channel || 'web')
|
|
152
|
+
|
|
153
|
+
const result = await generateObject({
|
|
154
|
+
model: 'sonnet',
|
|
155
|
+
schema: uiSchema,
|
|
156
|
+
system: `Generate ${request.channel || 'web'} UI/content for an approval request.`,
|
|
157
|
+
prompt: `Approval Request: ${request.title}
|
|
158
|
+
|
|
159
|
+
Description: ${request.description}
|
|
160
|
+
|
|
161
|
+
Data to be approved:
|
|
162
|
+
${JSON.stringify(request.data, null, 2)}
|
|
163
|
+
|
|
164
|
+
Priority: ${request.priority || 'medium'}
|
|
165
|
+
Approver: ${request.approver || 'any authorized approver'}
|
|
166
|
+
|
|
167
|
+
${request.responseSchema ? `Expected response format:\n${JSON.stringify(request.responseSchema)}` : ''}
|
|
168
|
+
|
|
169
|
+
Generate the appropriate UI/content to collect approval or rejection with optional notes.`,
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
// In a real implementation, this would:
|
|
173
|
+
// 1. Send the generated UI to the specified channel
|
|
174
|
+
// 2. Wait for human response (with timeout)
|
|
175
|
+
// 3. Return the validated response
|
|
176
|
+
|
|
177
|
+
// For now, return a pending approval with generated artifacts
|
|
178
|
+
return {
|
|
179
|
+
status: 'pending' as ApprovalStatus,
|
|
180
|
+
response: undefined,
|
|
181
|
+
timestamp: new Date(),
|
|
182
|
+
} as ApprovalResult<TResult>
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get approval UI schema based on channel
|
|
187
|
+
*/
|
|
188
|
+
function getApprovalUISchema(channel: string): SimpleSchema {
|
|
189
|
+
const schemas: Record<string, SimpleSchema> = {
|
|
190
|
+
slack: {
|
|
191
|
+
blocks: ['Slack BlockKit blocks as JSON array'],
|
|
192
|
+
text: 'Plain text fallback',
|
|
193
|
+
},
|
|
194
|
+
email: {
|
|
195
|
+
subject: 'Email subject line',
|
|
196
|
+
html: 'Email HTML body with approval buttons',
|
|
197
|
+
text: 'Plain text fallback',
|
|
198
|
+
},
|
|
199
|
+
web: {
|
|
200
|
+
component: 'React component code for approval form',
|
|
201
|
+
schema: 'JSON schema for the form fields',
|
|
202
|
+
},
|
|
203
|
+
sms: {
|
|
204
|
+
text: 'SMS message text (max 160 chars)',
|
|
205
|
+
responseFormat: 'Expected response format',
|
|
206
|
+
},
|
|
207
|
+
custom: {
|
|
208
|
+
data: 'Structured data for custom implementation',
|
|
209
|
+
instructions: 'Instructions for the approver',
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return schemas[channel] || schemas.custom!
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Generate content using AI
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { generate } from 'autonomous-agents'
|
|
222
|
+
*
|
|
223
|
+
* const content = await generate({
|
|
224
|
+
* model: 'sonnet',
|
|
225
|
+
* schema: {
|
|
226
|
+
* title: 'Blog post title',
|
|
227
|
+
* content: 'Blog post content',
|
|
228
|
+
* tags: ['List of tags'],
|
|
229
|
+
* },
|
|
230
|
+
* prompt: 'Write a blog post about AI automation',
|
|
231
|
+
* })
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export async function generate<TResult = unknown>(
|
|
235
|
+
options: AIGenerateOptions
|
|
236
|
+
): Promise<TResult> {
|
|
237
|
+
const result = await generateObject({
|
|
238
|
+
model: options.model || 'sonnet',
|
|
239
|
+
schema: (options.schema || { result: 'Generated content' }) as SimpleSchema,
|
|
240
|
+
system: options.system || 'You are a creative AI assistant. Generate high-quality content.',
|
|
241
|
+
prompt: options.prompt || '',
|
|
242
|
+
temperature: options.temperature ?? 0.8,
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
return result.object as TResult
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Type checking and validation
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* import { is } from 'autonomous-agents'
|
|
254
|
+
*
|
|
255
|
+
* const isValid = await is(
|
|
256
|
+
* { email: 'test@example.com' },
|
|
257
|
+
* 'valid email address'
|
|
258
|
+
* )
|
|
259
|
+
*
|
|
260
|
+
* const matchesSchema = await is(
|
|
261
|
+
* { name: 'John', age: 30 },
|
|
262
|
+
* { name: 'string', age: 'number' }
|
|
263
|
+
* )
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
export async function is(
|
|
267
|
+
value: unknown,
|
|
268
|
+
type: string | SimpleSchema
|
|
269
|
+
): Promise<boolean> {
|
|
270
|
+
const schema = typeof type === 'string'
|
|
271
|
+
? { isValid: `Is this value a valid ${type}? (boolean)`, reason: 'Explanation' }
|
|
272
|
+
: { isValid: 'Does this value match the schema? (boolean)', reason: 'Explanation' }
|
|
273
|
+
|
|
274
|
+
const result = await generateObject({
|
|
275
|
+
model: 'sonnet',
|
|
276
|
+
schema,
|
|
277
|
+
system: 'You are a type validator. Determine if the value matches the expected type or schema.',
|
|
278
|
+
prompt: `Value: ${JSON.stringify(value)}\n\nExpected type: ${typeof type === 'string' ? type : JSON.stringify(type)}`,
|
|
279
|
+
temperature: 0,
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
return (result.object as unknown as { isValid: boolean; reason: string }).isValid
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Send a notification
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* import { notify } from 'autonomous-agents'
|
|
291
|
+
*
|
|
292
|
+
* await notify({
|
|
293
|
+
* message: 'Task completed successfully!',
|
|
294
|
+
* channel: 'slack',
|
|
295
|
+
* recipients: ['#general'],
|
|
296
|
+
* priority: 'high',
|
|
297
|
+
* data: { taskId: '123', duration: '5 minutes' },
|
|
298
|
+
* })
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
export async function notify(options: NotificationOptions): Promise<void> {
|
|
302
|
+
const {
|
|
303
|
+
message,
|
|
304
|
+
channel = 'web',
|
|
305
|
+
recipients = [],
|
|
306
|
+
priority = 'medium',
|
|
307
|
+
data = {},
|
|
308
|
+
} = options
|
|
309
|
+
|
|
310
|
+
// Generate channel-specific notification format
|
|
311
|
+
const notificationSchema = getNotificationSchema(channel)
|
|
312
|
+
|
|
313
|
+
const result = await generateObject({
|
|
314
|
+
model: 'sonnet',
|
|
315
|
+
schema: notificationSchema,
|
|
316
|
+
system: `Generate ${channel} notification content.`,
|
|
317
|
+
prompt: `Notification message: ${message}
|
|
318
|
+
|
|
319
|
+
Recipients: ${recipients.join(', ') || 'default recipients'}
|
|
320
|
+
Priority: ${priority}
|
|
321
|
+
|
|
322
|
+
Additional data:
|
|
323
|
+
${JSON.stringify(data, null, 2)}
|
|
324
|
+
|
|
325
|
+
Generate the appropriate ${channel} notification format.`,
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
// In a real implementation, this would send via the specified channel
|
|
329
|
+
console.log(`[Notification] [${channel}] ${message}`, result.object)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Get notification schema based on channel
|
|
334
|
+
*/
|
|
335
|
+
function getNotificationSchema(channel: string): SimpleSchema {
|
|
336
|
+
const schemas: Record<string, SimpleSchema> = {
|
|
337
|
+
slack: {
|
|
338
|
+
blocks: ['Slack BlockKit blocks'],
|
|
339
|
+
text: 'Plain text fallback',
|
|
340
|
+
},
|
|
341
|
+
email: {
|
|
342
|
+
subject: 'Email subject',
|
|
343
|
+
html: 'Email HTML body',
|
|
344
|
+
text: 'Plain text version',
|
|
345
|
+
},
|
|
346
|
+
web: {
|
|
347
|
+
title: 'Notification title',
|
|
348
|
+
message: 'Notification message',
|
|
349
|
+
type: 'success | info | warning | error',
|
|
350
|
+
},
|
|
351
|
+
sms: {
|
|
352
|
+
text: 'SMS message (max 160 chars)',
|
|
353
|
+
},
|
|
354
|
+
custom: {
|
|
355
|
+
format: 'Custom notification format',
|
|
356
|
+
content: 'Notification content',
|
|
357
|
+
},
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return schemas[channel] || schemas.custom!
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Export the 'do' function with an alias to avoid keyword conflict
|
|
365
|
+
*/
|
|
366
|
+
export { doAction as do }
|