-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-workflow.ts
More file actions
121 lines (107 loc) · 3.39 KB
/
Copy pathcreate-workflow.ts
File metadata and controls
121 lines (107 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { SimplexClient, Action, Variable, StructuredOutput } from 'simplex-ts';
import * as dotenv from 'dotenv';
import * as path from 'path';
import * as fs from 'fs';
dotenv.config({ path: path.resolve(__dirname, '.env') });
const WORKFLOW_ID_FILE = path.resolve(__dirname, 'workflow-id.txt');
async function createWorkflow(client: SimplexClient): Promise<string> {
console.log('=== Creating Workflow ===\n');
const variables: Variable[] = [
{
name: 'patient_info',
type: 'object',
required: true,
description: 'Patient demographic information'
},
{
name: 'procedure_info',
type: 'object',
required: true,
description: 'Procedure details'
}
];
const structuredOutput: StructuredOutput[] = [
{
name: 'authorization_number',
type: 'string',
description: 'The prior authorization number received after submission'
},
{
name: 'submission_status',
type: 'enum',
enumValues: ['approved', 'pending', 'denied', 'requires_additional_info'],
description: 'The status of the prior authorization submission'
},
{
name: 'confirmation_code',
type: 'string',
description: 'Any confirmation or reference code provided by the system'
},
{
name: 'file_downloaded',
type: 'boolean',
description: 'Whether a file was successfully downloaded'
},
{
name: 'urgency_level',
type: 'enum',
enumValues: ['routine', 'urgent', 'emergent'],
description: 'The urgency level assigned to the authorization request'
}
];
const actions: Action[] = [
{
function: 'run_beta_agent',
params: {
prompt: 'Read the information on the page.'
},
options: {}
}
];
const workflow = await client.workflows.create({
name: 'Prior Authorization Submission Page',
url: 'https://simplex.sh/authorization-result.html',
actions: actions,
variables: variables,
structured_output: structuredOutput,
metadata: JSON.stringify({ portal: 'Carelon' })
});
console.log('Workflow created:');
console.log(` ID: ${workflow.id}`);
console.log(` Name: ${workflow.name}`);
if (workflow.structured_output && workflow.structured_output.length > 0) {
console.log('\n Structured Output Fields:');
workflow.structured_output.forEach(field => {
if (field.type === 'enum' && field.enumValues) {
console.log(` - ${field.name} (enum: [${field.enumValues.join(', ')}]): ${field.description}`);
} else {
console.log(` - ${field.name} (${field.type}): ${field.description}`);
}
});
}
console.log();
return workflow.id;
}
async function main() {
const apiKey = process.env.SIMPLEX_API_KEY;
if (!apiKey) {
console.error('Please set SIMPLEX_API_KEY in .env');
process.exit(1);
}
const client = new SimplexClient({ apiKey });
try {
const workflowId = await createWorkflow(client);
fs.writeFileSync(WORKFLOW_ID_FILE, workflowId);
console.log(`Workflow ID saved to: ${WORKFLOW_ID_FILE}`);
} catch (error: unknown) {
const err = error as { message: string; statusCode?: number; data?: unknown };
console.error('Error:', err.message);
if (err.statusCode) {
console.error('Status:', err.statusCode);
}
if (err.data) {
console.error('Details:', JSON.stringify(err.data, null, 2));
}
}
}
main().catch(console.error);