diff --git a/apps/docs/content/docs/de/sdks/python.mdx b/apps/docs/content/docs/de/sdks/python.mdx index 368010f430b..c185733f851 100644 --- a/apps/docs/content/docs/de/sdks/python.mdx +++ b/apps/docs/content/docs/de/sdks/python.mdx @@ -387,7 +387,7 @@ Behandeln Sie verschiedene Fehlertypen, die während der Workflow-Ausführung au from simstudio import SimStudioClient, SimStudioError import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_with_error_handling(): try: @@ -600,7 +600,7 @@ Führe Workflows mit Echtzeit-Streaming-Antworten aus: from simstudio import SimStudioClient import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_with_streaming(): """Execute workflow with streaming enabled.""" diff --git a/apps/docs/content/docs/de/sdks/typescript.mdx b/apps/docs/content/docs/de/sdks/typescript.mdx index 55e36ce7e26..a72ff0c7c30 100644 --- a/apps/docs/content/docs/de/sdks/typescript.mdx +++ b/apps/docs/content/docs/de/sdks/typescript.mdx @@ -821,7 +821,9 @@ async function checkUsage() { Execute workflows with real-time streaming responses: -```typescript +``` + +typescript import { SimStudioClient } from 'simstudio-ts-sdk'; const client = new SimStudioClient({ @@ -842,11 +844,13 @@ async function executeWithStreaming() { console.error('Fehler:', error); } } + ``` The streaming response follows the Server-Sent Events (SSE) format: ``` + data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", zwei"} @@ -854,11 +858,14 @@ data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", zwei"} data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} data: [DONE] + ``` **React Streaming Example:** -```typescript +``` + +typescript import { useState, useEffect } from 'react'; function StreamingWorkflow() { @@ -926,6 +933,7 @@ function StreamingWorkflow() { ); } + ``` ## Getting Your API Key @@ -961,7 +969,9 @@ function StreamingWorkflow() { The SDK is written in TypeScript and provides full type safety: -```typescript +``` + +typescript import { SimStudioClient, WorkflowExecutionResult, @@ -987,4 +997,296 @@ const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); ## License +Apache-2.0 + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Execution complete:', parsed.metadata); + } + } catch (e) { + // Skip invalid JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## Getting Your API Key + + + + Navigate to [Sim](https://sim.ai) and log in to your account. + + + Navigate to the workflow you want to execute programmatically. + + + Click on "Deploy" to deploy your workflow if it hasn't been deployed yet. + + + During the deployment process, select or create an API key. + + + Copy the API key to use in your TypeScript/JavaScript application. + + + + + Keep your API key secure and never commit it to version control. Use environment variables or secure configuration management. + + +## Requirements + +- Node.js 16+ +- TypeScript 5.0+ (for TypeScript projects) + +## TypeScript Support + +The SDK is written in TypeScript and provides full type safety: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Typsichere Client-Initialisierung +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Typsichere Workflow-Ausführung +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hallo, TypeScript!' + } +}); + +// Typsichere Statusprüfung +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## License + +Apache-2.0 + limits.usage.limit.toFixed(2)); + console.log('Plan:', limits.usage.plan); + + const percentUsed = (limits.usage.currentPeriodCost / limits.usage.limit) * 100; + console.log('Usage: ' + percentUsed.toFixed(1) + '%'); + + if (percentUsed > 80) { + console.warn('⚠️ Warning: You are approaching your usage limit!'); + } + } catch (error) { + console.error('Error checking usage:', error); + } +} + +checkUsage(); +``` + +### Streaming-Workflow-Ausführung + +Führen Sie Workflows mit Echtzeit-Streaming-Antworten aus: + +```typescript +import { SimStudioClient } from 'simstudio-ts-sdk'; + +const client = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +async function executeWithStreaming() { + try { + // Enable streaming for specific block outputs + const result = await client.executeWorkflow('workflow-id', { + input: { message: 'Count to five' }, + stream: true, + selectedOutputs: ['agent1.content'] // Use blockName.attribute format + }); + + console.log('Workflow result:', result); + } catch (error) { + console.error('Error:', error); + } +} +``` + +Die Streaming-Antwort folgt dem Server-Sent Events (SSE) Format: + +``` +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} + +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} + +data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} + +data: [DONE] +``` + +**React Streaming-Beispiel:** + +```typescript +import { useState, useEffect } from 'react'; + +function StreamingWorkflow() { + const [output, setOutput] = useState(''); + const [loading, setLoading] = useState(false); + + const executeStreaming = async () => { + setLoading(true); + setOutput(''); + + // IMPORTANT: Make this API call from your backend server, not the browser + // Never expose your API key in client-side code + const response = await fetch('https://sim.ai/api/workflows/WORKFLOW_ID/execute', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': process.env.SIM_API_KEY! // Server-side environment variable only + }, + body: JSON.stringify({ + message: 'Generate a story', + stream: true, + selectedOutputs: ['agent1.content'] + }) + }); + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Execution complete:', parsed.metadata); + } + } catch (e) { + // Skip invalid JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## Ihren API-Schlüssel erhalten + + + + Navigieren Sie zu [Sim](https://sim.ai) und melden Sie sich bei Ihrem Konto an. + + + Navigieren Sie zu dem Workflow, den Sie programmatisch ausführen möchten. + + + Klicken Sie auf "Deploy", um Ihren Workflow zu deployen, falls dies noch nicht geschehen ist. + + + Wählen Sie während des Deployment-Prozesses einen API-Schlüssel aus oder erstellen Sie einen neuen. + + + Kopieren Sie den API-Schlüssel zur Verwendung in Ihrer TypeScript/JavaScript-Anwendung. + + + + + Halte deinen API-Schlüssel sicher und committe ihn niemals in die Versionskontrolle. Verwende Umgebungsvariablen oder sicheres Konfigurationsmanagement. + + +## Anforderungen + +- Node.js 16+ +- TypeScript 5.0+ (für TypeScript-Projekte) + +## TypeScript-Unterstützung + +Das SDK ist in TypeScript geschrieben und bietet vollständige Typsicherheit: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Type-safe client initialization +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Type-safe workflow execution +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hello, TypeScript!' + } +}); + +// Type-safe status checking +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## Lizenz + Apache-2.0 \ No newline at end of file diff --git a/apps/docs/content/docs/es/sdks/python.mdx b/apps/docs/content/docs/es/sdks/python.mdx index 2edb110394b..75b4f3777a6 100644 --- a/apps/docs/content/docs/es/sdks/python.mdx +++ b/apps/docs/content/docs/es/sdks/python.mdx @@ -609,7 +609,7 @@ Ejecuta flujos de trabajo con respuestas en tiempo real: from simstudio import SimStudioClient import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_with_streaming(): """Execute workflow with streaming enabled.""" diff --git a/apps/docs/content/docs/es/sdks/typescript.mdx b/apps/docs/content/docs/es/sdks/typescript.mdx index fca8a9805fa..fee55cec302 100644 --- a/apps/docs/content/docs/es/sdks/typescript.mdx +++ b/apps/docs/content/docs/es/sdks/typescript.mdx @@ -821,7 +821,9 @@ async function checkUsage() { Execute workflows with real-time streaming responses: -```typescript +``` + +typescript import { SimStudioClient } from 'simstudio-ts-sdk'; const client = new SimStudioClient({ @@ -842,11 +844,13 @@ async function executeWithStreaming() { console.error('Error:', error); } } + ``` The streaming response follows the Server-Sent Events (SSE) format: ``` + data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", dos"} @@ -854,11 +858,14 @@ data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", dos"} data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} data: [DONE] + ``` **React Streaming Example:** -```typescript +``` + +typescript import { useState, useEffect } from 'react'; function StreamingWorkflow() { @@ -926,6 +933,7 @@ function StreamingWorkflow() { ); } + ``` ## Getting Your API Key @@ -961,7 +969,9 @@ function StreamingWorkflow() { The SDK is written in TypeScript and provides full type safety: -```typescript +``` + +typescript import { SimStudioClient, WorkflowExecutionResult, @@ -987,5 +997,296 @@ const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); ## License +Apache-2.0 + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Ejecución completada:', parsed.metadata); + } + } catch (e) { + // Omitir JSON inválido + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## Getting Your API Key + + + + Navigate to [Sim](https://sim.ai) and log in to your account. + + + Navigate to the workflow you want to execute programmatically. + + + Click on "Deploy" to deploy your workflow if it hasn't been deployed yet. + + + During the deployment process, select or create an API key. + + + Copy the API key to use in your TypeScript/JavaScript application. + + + + + Keep your API key secure and never commit it to version control. Use environment variables or secure configuration management. + + +## Requirements + +- Node.js 16+ +- TypeScript 5.0+ (for TypeScript projects) + +## TypeScript Support + +The SDK is written in TypeScript and provides full type safety: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Inicialización del cliente con seguridad de tipos +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Ejecución de flujo de trabajo con seguridad de tipos +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hola, TypeScript!' + } +}); + +// Verificación de estado con seguridad de tipos +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## License + +Apache-2.0 + limits.usage.limit.toFixed(2)); + console.log('Plan:', limits.usage.plan); + + const percentUsed = (limits.usage.currentPeriodCost / limits.usage.limit) * 100; + console.log('Usage: ' + percentUsed.toFixed(1) + '%'); + + if (percentUsed > 80) { + console.warn('⚠️ Warning: You are approaching your usage limit!'); + } + } catch (error) { + console.error('Error checking usage:', error); + } +} + +checkUsage(); +``` + +### Ejecución de flujo de trabajo en streaming + +Ejecuta flujos de trabajo con respuestas en tiempo real: + +```typescript +import { SimStudioClient } from 'simstudio-ts-sdk'; + +const client = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +async function executeWithStreaming() { + try { + // Enable streaming for specific block outputs + const result = await client.executeWorkflow('workflow-id', { + input: { message: 'Count to five' }, + stream: true, + selectedOutputs: ['agent1.content'] // Use blockName.attribute format + }); + + console.log('Workflow result:', result); + } catch (error) { + console.error('Error:', error); + } +} +``` + +La respuesta en streaming sigue el formato de eventos enviados por el servidor (SSE): + +``` +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} + +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} + +data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} + +data: [DONE] +``` + +**Ejemplo de streaming en React:** + +```typescript +import { useState, useEffect } from 'react'; + +function StreamingWorkflow() { + const [output, setOutput] = useState(''); + const [loading, setLoading] = useState(false); + + const executeStreaming = async () => { + setLoading(true); + setOutput(''); + + // IMPORTANT: Make this API call from your backend server, not the browser + // Never expose your API key in client-side code + const response = await fetch('https://sim.ai/api/workflows/WORKFLOW_ID/execute', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': process.env.SIM_API_KEY! // Server-side environment variable only + }, + body: JSON.stringify({ + message: 'Generate a story', + stream: true, + selectedOutputs: ['agent1.content'] + }) + }); + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Execution complete:', parsed.metadata); + } + } catch (e) { + // Skip invalid JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## Obtener tu clave API + + + + Navega a [Sim](https://sim.ai) e inicia sesión en tu cuenta. + + + Navega al flujo de trabajo que quieres ejecutar programáticamente. + + + Haz clic en "Desplegar" para desplegar tu flujo de trabajo si aún no ha sido desplegado. + + + Durante el proceso de despliegue, selecciona o crea una clave API. + + + Copia la clave API para usarla en tu aplicación TypeScript/JavaScript. + + + + + Mantén tu clave API segura y nunca la incluyas en el control de versiones. Utiliza variables de entorno o gestión de configuración segura. + + +## Requisitos + +- Node.js 16+ +- TypeScript 5.0+ (para proyectos TypeScript) + +## Soporte para TypeScript + +El SDK está escrito en TypeScript y proporciona seguridad de tipos completa: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Type-safe client initialization +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Type-safe workflow execution +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hello, TypeScript!' + } +}); + +// Type-safe status checking +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## Licencia Apache-2.0 diff --git a/apps/docs/content/docs/fr/sdks/python.mdx b/apps/docs/content/docs/fr/sdks/python.mdx index faf5f4b2030..d3a8f11dccf 100644 --- a/apps/docs/content/docs/fr/sdks/python.mdx +++ b/apps/docs/content/docs/fr/sdks/python.mdx @@ -387,7 +387,7 @@ Gérez différents types d'erreurs qui peuvent survenir pendant l'exécution du from simstudio import SimStudioClient, SimStudioError import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_with_error_handling(): try: @@ -433,7 +433,7 @@ Exécutez plusieurs workflows efficacement : from simstudio import SimStudioClient import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_workflows_batch(workflow_data_pairs): """Execute multiple workflows with different input data.""" @@ -609,7 +609,7 @@ Exécutez des workflows avec des réponses en streaming en temps réel : from simstudio import SimStudioClient import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_with_streaming(): """Execute workflow with streaming enabled.""" diff --git a/apps/docs/content/docs/fr/sdks/typescript.mdx b/apps/docs/content/docs/fr/sdks/typescript.mdx index ca572c346e2..35efab136c6 100644 --- a/apps/docs/content/docs/fr/sdks/typescript.mdx +++ b/apps/docs/content/docs/fr/sdks/typescript.mdx @@ -821,7 +821,9 @@ async function checkUsage() { Execute workflows with real-time streaming responses: -```typescript +``` + +typescript import { SimStudioClient } from 'simstudio-ts-sdk'; const client = new SimStudioClient({ @@ -842,11 +844,13 @@ async function executeWithStreaming() { console.error('Erreur :', error); } } + ``` The streaming response follows the Server-Sent Events (SSE) format: ``` + data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", deux"} @@ -854,11 +858,14 @@ data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", deux"} data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} data: [DONE] + ``` **React Streaming Example:** -```typescript +``` + +typescript import { useState, useEffect } from 'react'; function StreamingWorkflow() { @@ -926,6 +933,7 @@ function StreamingWorkflow() { ); } + ``` ## Getting Your API Key @@ -961,7 +969,9 @@ function StreamingWorkflow() { The SDK is written in TypeScript and provides full type safety: -```typescript +``` + +typescript import { SimStudioClient, WorkflowExecutionResult, @@ -987,5 +997,296 @@ const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); ## License +Apache-2.0 + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Exécution terminée :', parsed.metadata); + } + } catch (e) { + // Ignorer le JSON invalide + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## Getting Your API Key + + + + Navigate to [Sim](https://sim.ai) and log in to your account. + + + Navigate to the workflow you want to execute programmatically. + + + Click on "Deploy" to deploy your workflow if it hasn't been deployed yet. + + + During the deployment process, select or create an API key. + + + Copy the API key to use in your TypeScript/JavaScript application. + + + + + Keep your API key secure and never commit it to version control. Use environment variables or secure configuration management. + + +## Requirements + +- Node.js 16+ +- TypeScript 5.0+ (for TypeScript projects) + +## TypeScript Support + +The SDK is written in TypeScript and provides full type safety: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Initialisation du client avec typage sécurisé +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Exécution de workflow avec typage sécurisé +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hello, TypeScript!' + } +}); + +// Vérification de statut avec typage sécurisé +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## License + +Apache-2.0 + limits.usage.limit.toFixed(2)); + console.log('Plan:', limits.usage.plan); + + const percentUsed = (limits.usage.currentPeriodCost / limits.usage.limit) * 100; + console.log('Usage: ' + percentUsed.toFixed(1) + '%'); + + if (percentUsed > 80) { + console.warn('⚠️ Warning: You are approaching your usage limit!'); + } + } catch (error) { + console.error('Error checking usage:', error); + } +} + +checkUsage(); +``` + +### Exécution de workflow en streaming + +Exécutez des workflows avec des réponses en streaming en temps réel : + +```typescript +import { SimStudioClient } from 'simstudio-ts-sdk'; + +const client = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +async function executeWithStreaming() { + try { + // Enable streaming for specific block outputs + const result = await client.executeWorkflow('workflow-id', { + input: { message: 'Count to five' }, + stream: true, + selectedOutputs: ['agent1.content'] // Use blockName.attribute format + }); + + console.log('Workflow result:', result); + } catch (error) { + console.error('Error:', error); + } +} +``` + +La réponse en streaming suit le format Server-Sent Events (SSE) : + +``` +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} + +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} + +data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} + +data: [DONE] +``` + +**Exemple de streaming avec React :** + +```typescript +import { useState, useEffect } from 'react'; + +function StreamingWorkflow() { + const [output, setOutput] = useState(''); + const [loading, setLoading] = useState(false); + + const executeStreaming = async () => { + setLoading(true); + setOutput(''); + + // IMPORTANT: Make this API call from your backend server, not the browser + // Never expose your API key in client-side code + const response = await fetch('https://sim.ai/api/workflows/WORKFLOW_ID/execute', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': process.env.SIM_API_KEY! // Server-side environment variable only + }, + body: JSON.stringify({ + message: 'Generate a story', + stream: true, + selectedOutputs: ['agent1.content'] + }) + }); + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Execution complete:', parsed.metadata); + } + } catch (e) { + // Skip invalid JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## Obtenir votre clé API + + + + Accédez à [Sim](https://sim.ai) et connectez-vous à votre compte. + + + Accédez au workflow que vous souhaitez exécuter par programmation. + + + Cliquez sur « Déployer » pour déployer votre workflow s'il n'a pas encore été déployé. + + + Pendant le processus de déploiement, sélectionnez ou créez une clé API. + + + Copiez la clé API pour l'utiliser dans votre application TypeScript/JavaScript. + + + + + Gardez votre clé API sécurisée et ne la soumettez jamais au contrôle de version. Utilisez des variables d'environnement ou une gestion de configuration sécurisée. + + +## Prérequis + +- Node.js 16+ +- TypeScript 5.0+ (pour les projets TypeScript) + +## Support TypeScript + +Le SDK est écrit en TypeScript et offre une sécurité de typage complète : + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Type-safe client initialization +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Type-safe workflow execution +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hello, TypeScript!' + } +}); + +// Type-safe status checking +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## Licence Apache-2.0 diff --git a/apps/docs/content/docs/ja/sdks/python.mdx b/apps/docs/content/docs/ja/sdks/python.mdx index b667a9f3d8e..39fa75470d1 100644 --- a/apps/docs/content/docs/ja/sdks/python.mdx +++ b/apps/docs/content/docs/ja/sdks/python.mdx @@ -433,7 +433,7 @@ with SimStudioClient(api_key=os.getenv("SIM_API_KEY")) as client: from simstudio import SimStudioClient import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_workflows_batch(workflow_data_pairs): """Execute multiple workflows with different input data.""" @@ -660,7 +660,7 @@ def stream_workflow(): 'https://sim.ai/api/workflows/WORKFLOW_ID/execute', headers={ 'Content-Type': 'application/json', - 'X-API-Key': os.getenv('SIM_API_KEY') + 'X-API-Key': os.getenv('SIM_API_KEY') }, json={ 'message': 'Generate a story', diff --git a/apps/docs/content/docs/ja/sdks/typescript.mdx b/apps/docs/content/docs/ja/sdks/typescript.mdx index 785f60b29d5..c65e30a0fcf 100644 --- a/apps/docs/content/docs/ja/sdks/typescript.mdx +++ b/apps/docs/content/docs/ja/sdks/typescript.mdx @@ -821,7 +821,9 @@ async function checkUsage() { Execute workflows with real-time streaming responses: -```typescript +``` + +typescript import { SimStudioClient } from 'simstudio-ts-sdk'; const client = new SimStudioClient({ @@ -842,11 +844,13 @@ async function executeWithStreaming() { console.error('エラー:', error); } } + ``` The streaming response follows the Server-Sent Events (SSE) format: ``` + data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} @@ -854,11 +858,14 @@ data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} data: [DONE] + ``` **React Streaming Example:** -```typescript +``` + +typescript import { useState, useEffect } from 'react'; function StreamingWorkflow() { @@ -926,6 +933,7 @@ function StreamingWorkflow() { ); } + ``` ## Getting Your API Key @@ -961,7 +969,9 @@ function StreamingWorkflow() { The SDK is written in TypeScript and provides full type safety: -```typescript +``` + +typescript import { SimStudioClient, WorkflowExecutionResult, @@ -987,5 +997,296 @@ const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); ## License +Apache-2.0 + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Execution complete:', parsed.metadata); + } + } catch (e) { + // Skip invalid JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## Getting Your API Key + + + + Navigate to [Sim](https://sim.ai) and log in to your account. + + + Navigate to the workflow you want to execute programmatically. + + + Click on "Deploy" to deploy your workflow if it hasn't been deployed yet. + + + During the deployment process, select or create an API key. + + + Copy the API key to use in your TypeScript/JavaScript application. + + + + + Keep your API key secure and never commit it to version control. Use environment variables or secure configuration management. + + +## Requirements + +- Node.js 16+ +- TypeScript 5.0+ (for TypeScript projects) + +## TypeScript Support + +The SDK is written in TypeScript and provides full type safety: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// 型安全なクライアント初期化 +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// 型安全なワークフロー実行 +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hello, TypeScript!' + } +}); + +// 型安全なステータス確認 +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## License + +Apache-2.0 + limits.usage.limit.toFixed(2)); + console.log('Plan:', limits.usage.plan); + + const percentUsed = (limits.usage.currentPeriodCost / limits.usage.limit) * 100; + console.log('Usage: ' + percentUsed.toFixed(1) + '%'); + + if (percentUsed > 80) { + console.warn('⚠️ Warning: You are approaching your usage limit!'); + } + } catch (error) { + console.error('Error checking usage:', error); + } +} + +checkUsage(); +``` + +### ストリーミングワークフロー実行 + +リアルタイムストリーミングレスポンスでワークフローを実行します: + +```typescript +import { SimStudioClient } from 'simstudio-ts-sdk'; + +const client = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +async function executeWithStreaming() { + try { + // Enable streaming for specific block outputs + const result = await client.executeWorkflow('workflow-id', { + input: { message: 'Count to five' }, + stream: true, + selectedOutputs: ['agent1.content'] // Use blockName.attribute format + }); + + console.log('Workflow result:', result); + } catch (error) { + console.error('Error:', error); + } +} +``` + +ストリーミングレスポンスはServer-Sent Events(SSE)形式に従います: + +``` +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} + +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} + +data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} + +data: [DONE] +``` + +**Reactストリーミング例:** + +```typescript +import { useState, useEffect } from 'react'; + +function StreamingWorkflow() { + const [output, setOutput] = useState(''); + const [loading, setLoading] = useState(false); + + const executeStreaming = async () => { + setLoading(true); + setOutput(''); + + // IMPORTANT: Make this API call from your backend server, not the browser + // Never expose your API key in client-side code + const response = await fetch('https://sim.ai/api/workflows/WORKFLOW_ID/execute', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': process.env.SIM_API_KEY! // Server-side environment variable only + }, + body: JSON.stringify({ + message: 'Generate a story', + stream: true, + selectedOutputs: ['agent1.content'] + }) + }); + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Execution complete:', parsed.metadata); + } + } catch (e) { + // Skip invalid JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## APIキーの取得方法 + + + + [Sim](https://sim.ai)に移動してアカウントにログインします。 + + + プログラムで実行したいワークフローに移動します。 + + + まだデプロイされていない場合は、「デプロイ」をクリックしてワークフローをデプロイします。 + + + デプロイプロセス中に、APIキーを選択または作成します。 + + + TypeScript/JavaScriptアプリケーションで使用するAPIキーをコピーします。 + + + + + APIキーは安全に保管し、バージョン管理にコミットしないでください。環境変数や安全な設定管理を使用してください。 + + +## 要件 + +- Node.js 16以上 +- TypeScript 5.0以上(TypeScriptプロジェクトの場合) + +## TypeScriptサポート + +SDKはTypeScriptで書かれており、完全な型安全性を提供します: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Type-safe client initialization +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Type-safe workflow execution +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hello, TypeScript!' + } +}); + +// Type-safe status checking +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## ライセンス Apache-2.0 diff --git a/apps/docs/content/docs/zh/sdks/python.mdx b/apps/docs/content/docs/zh/sdks/python.mdx index 8ca6874295b..5a59d69d700 100644 --- a/apps/docs/content/docs/zh/sdks/python.mdx +++ b/apps/docs/content/docs/zh/sdks/python.mdx @@ -433,7 +433,7 @@ with SimStudioClient(api_key=os.getenv("SIM_API_KEY")) as client: from simstudio import SimStudioClient import os -client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) +client = SimStudioClient(api_key=os.getenv("SIM_API_KEY")) def execute_workflows_batch(workflow_data_pairs): """Execute multiple workflows with different input data.""" @@ -660,7 +660,7 @@ def stream_workflow(): 'https://sim.ai/api/workflows/WORKFLOW_ID/execute', headers={ 'Content-Type': 'application/json', - 'X-API-Key': os.getenv('SIM_API_KEY') + 'X-API-Key': os.getenv('SIM_API_KEY') }, json={ 'message': 'Generate a story', diff --git a/apps/docs/content/docs/zh/sdks/typescript.mdx b/apps/docs/content/docs/zh/sdks/typescript.mdx index ba561204597..0f57e115303 100644 --- a/apps/docs/content/docs/zh/sdks/typescript.mdx +++ b/apps/docs/content/docs/zh/sdks/typescript.mdx @@ -821,7 +821,9 @@ async function checkUsage() { Execute workflows with real-time streaming responses: -```typescript +``` + +typescript import { SimStudioClient } from 'simstudio-ts-sdk'; const client = new SimStudioClient({ @@ -842,11 +844,13 @@ async function executeWithStreaming() { console.error('错误:', error); } } + ``` The streaming response follows the Server-Sent Events (SSE) format: ``` + data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} @@ -854,11 +858,14 @@ data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} data: [DONE] + ``` **React Streaming Example:** -```typescript +``` + +typescript import { useState, useEffect } from 'react'; function StreamingWorkflow() { @@ -926,6 +933,114 @@ function StreamingWorkflow() { ); } + +``` + +## Getting Your API Key + + + + Navigate to [Sim](https://sim.ai) and log in to your account. + + + Navigate to the workflow you want to execute programmatically. + + + Click on "Deploy" to deploy your workflow if it hasn't been deployed yet. + + + During the deployment process, select or create an API key. + + + Copy the API key to use in your TypeScript/JavaScript application. + + + + + Keep your API key secure and never commit it to version control. Use environment variables or secure configuration management. + + +## Requirements + +- Node.js 16+ +- TypeScript 5.0+ (for TypeScript projects) + +## TypeScript Support + +The SDK is written in TypeScript and provides full type safety: + +``` + +typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// 类型安全的客户端初始化 +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// 类型安全的工作流执行 +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: '你好,TypeScript!' + } +}); + +// 类型安全的状态检查 +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + +## 许可证 + +Apache-2.0 + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('执行完成:', parsed.metadata); + } + } catch (e) { + // 跳过无效的 JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} ``` ## Getting Your API Key @@ -985,6 +1100,193 @@ const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-i const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); ``` +## License + +Apache-2.0 + limits.usage.limit.toFixed(2)); + console.log('Plan:', limits.usage.plan); + + const percentUsed = (limits.usage.currentPeriodCost / limits.usage.limit) * 100; + console.log('Usage: ' + percentUsed.toFixed(1) + '%'); + + if (percentUsed > 80) { + console.warn('⚠️ Warning: You are approaching your usage limit!'); + } + } catch (error) { + console.error('Error checking usage:', error); + } +} + +checkUsage(); +``` + +### 流式工作流执行 + +通过实时流式响应执行工作流: + +```typescript +import { SimStudioClient } from 'simstudio-ts-sdk'; + +const client = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +async function executeWithStreaming() { + try { + // Enable streaming for specific block outputs + const result = await client.executeWorkflow('workflow-id', { + input: { message: 'Count to five' }, + stream: true, + selectedOutputs: ['agent1.content'] // Use blockName.attribute format + }); + + console.log('Workflow result:', result); + } catch (error) { + console.error('Error:', error); + } +} +``` + +流式响应遵循服务器发送事件 (SSE) 格式: + +``` +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":"One"} + +data: {"blockId":"7b7735b9-19e5-4bd6-818b-46aae2596e9f","chunk":", two"} + +data: {"event":"done","success":true,"output":{},"metadata":{"duration":610}} + +data: [DONE] +``` + +**React 流式示例:** + +```typescript +import { useState, useEffect } from 'react'; + +function StreamingWorkflow() { + const [output, setOutput] = useState(''); + const [loading, setLoading] = useState(false); + + const executeStreaming = async () => { + setLoading(true); + setOutput(''); + + // IMPORTANT: Make this API call from your backend server, not the browser + // Never expose your API key in client-side code + const response = await fetch('https://sim.ai/api/workflows/WORKFLOW_ID/execute', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-Key': process.env.SIM_API_KEY! // Server-side environment variable only + }, + body: JSON.stringify({ + message: 'Generate a story', + stream: true, + selectedOutputs: ['agent1.content'] + }) + }); + + const reader = response.body?.getReader(); + const decoder = new TextDecoder(); + + while (reader) { + const { done, value } = await reader.read(); + if (done) break; + + const chunk = decoder.decode(value); + const lines = chunk.split('\n\n'); + + for (const line of lines) { + if (line.startsWith('data: ')) { + const data = line.slice(6); + if (data === '[DONE]') { + setLoading(false); + break; + } + + try { + const parsed = JSON.parse(data); + if (parsed.chunk) { + setOutput(prev => prev + parsed.chunk); + } else if (parsed.event === 'done') { + console.log('Execution complete:', parsed.metadata); + } + } catch (e) { + // Skip invalid JSON + } + } + } + } + }; + + return ( +
+ +
{output}
+
+ ); +} +``` + +## 获取您的 API 密钥 + + + + 访问 [Sim](https://sim.ai) 并登录您的账户。 + + + 导航到您想要以编程方式执行的工作流。 + + + 如果尚未部署,请点击“部署”以部署您的工作流。 + + + 在部署过程中,选择或创建一个 API 密钥。 + + + 复制 API 密钥以在您的 TypeScript/JavaScript 应用程序中使用。 + + + + + 请确保您的 API 密钥安全,切勿将其提交到版本控制中。请使用环境变量或安全配置管理。 + + +## 要求 + +- Node.js 16+ +- TypeScript 5.0+(适用于 TypeScript 项目) + +## TypeScript 支持 + +该 SDK 使用 TypeScript 编写,并提供完整的类型安全: + +```typescript +import { + SimStudioClient, + WorkflowExecutionResult, + WorkflowStatus, + SimStudioError +} from 'simstudio-ts-sdk'; + +// Type-safe client initialization +const client: SimStudioClient = new SimStudioClient({ + apiKey: process.env.SIM_API_KEY! +}); + +// Type-safe workflow execution +const result: WorkflowExecutionResult = await client.executeWorkflow('workflow-id', { + input: { + message: 'Hello, TypeScript!' + } +}); + +// Type-safe status checking +const status: WorkflowStatus = await client.getWorkflowStatus('workflow-id'); +``` + ## 许可证 Apache-2.0 diff --git a/apps/docs/i18n.lock b/apps/docs/i18n.lock index 4ef71f624ca..89154965217 100644 --- a/apps/docs/i18n.lock +++ b/apps/docs/i18n.lock @@ -2479,16 +2479,16 @@ checksums: content/76: 33b9b1e9744318597da4b925b0995be2 content/77: 6afe3b62e6d53c3dcd07149abcab4c05 content/78: b6363faee219321c16d41a9c3f8d3bdd - content/79: 08410ce9f0ec358b3c7230a56bc66399 + content/79: 3c5b351d25fb0639559eacdad545a0ed content/80: b8b23ab79a7eb32c6f8d5f49f43c51f6 content/81: be358297e2bbb9ab4689d11d072611d1 - content/82: 09fea7c0d742a0eefa77e982e848de6c + content/82: 414b9bf7d35039c6a17f4fb03d6b7431 content/83: 7d098f0349c782f389431377ee512e92 content/84: 22b39537f6a104803389469d211154e4 content/85: d9ec74ab28b264d76f797fdae7c8f3d3 content/86: f29d6bfd74ba3fee0b90180f620b4f47 content/87: 2a59466500b62e57481fe27692a3ed0f - content/88: cbbb123fc3a12bf2ab72dc1bbe373a6e + content/88: 94965695a02aea6c753448c21fd66b18 content/89: 7873aa7487bc3e8a4826d65c1760a4a0 content/90: 98182d9aabe14d5bad43a5ee76a75eab content/91: 67bfa8ae3e22d9a949f08c79a40b8df5 @@ -2500,11 +2500,11 @@ checksums: content/97: dae96b41f0c029b464f02ac65d3c5796 content/98: 41c2bb95317d7c0421817a2b1a68cc09 content/99: 4c95f9fa55f698f220577380dff95011 - content/100: 6695bd47a05f9963134d8a71abb3d298 + content/100: e674c5e6ecaf4dae9fc93e328b8a57c4 content/101: 100e12673551d4ceb5b906b1b9c65059 content/102: ce253674cd7c49320203cda2bdd3685b content/103: 94d4346a735149c2a83f6d2a21b8ab4c - content/104: 3ee4b16b8204ef3b5b7c0322ff636fab + content/104: 869fd72c8911057ee0696f068fa22e35 content/105: 450265802cb0ba5b435b74b9cac1bf23 content/106: b735ede8764e4b2dfb25967e33ab5143 content/107: 0f881e586a03c4b916456c73fad48358