()
| 108 | |
| 109 | // Example 4: Workflow execution with streaming |
| 110 | async function streamingExample() { |
| 111 | const client = new SimStudioClient({ |
| 112 | apiKey: process.env.SIM_API_KEY!, |
| 113 | }) |
| 114 | |
| 115 | try { |
| 116 | const result = await client.executeWorkflow('your-workflow-id', { |
| 117 | input: { |
| 118 | message: 'Count to five', |
| 119 | }, |
| 120 | stream: true, |
| 121 | selectedOutputs: ['agent1.content'], // Use blockName.attribute format |
| 122 | timeout: 60000, |
| 123 | }) |
| 124 | |
| 125 | if (result.success) { |
| 126 | console.log('✅ Workflow executed successfully!') |
| 127 | console.log('Output:', result.output) |
| 128 | console.log('Duration:', result.metadata?.duration, 'ms') |
| 129 | } else { |
| 130 | console.log('❌ Workflow failed:', result.error) |
| 131 | } |
| 132 | } catch (error) { |
| 133 | if (error instanceof SimStudioError) { |
| 134 | console.error('SDK Error:', error.message, 'Code:', error.code) |
| 135 | } else { |
| 136 | console.error('Unexpected error:', error) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // Run examples |
| 142 | if (require.main === module) { |
no test coverage detected