{ "kind": "open-flow-workflow", "version": 1, "name": "Translate Random Cocktail Instructions", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_1d7777be1b3812d6": { "name": "Get a random recipe", "kind": "start", "inputDefs": [] }, "n_1a883d0f448660e5": { "inputs": { "initialUrl": { "kind": "value", "value": "https://www.thecocktaildb.com/api/json/v1/1/random.php" }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7d43a8c8d0c26ec2", "output": "state" } ] } }, "name": "Prepare CocktailDB URL", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "initialUrl" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" } ], "name": "Prepare CocktailDB URL", "moduleId": "n_c7728fff5d86014b", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_3ae321c93796591d": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1a883d0f448660e5", "output": "url" } ] } }, "name": "Get a random cocktail", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Get a random cocktail", "executor": { "method": "GET", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "none", "authentication": { "type": "none" }, "responseFormat": "text", "statusPolicy": "all", "kind": "http-request" } } }, "n_7d43a8c8d0c26ec2": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_1a883d0f448660e5", "output": "url" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3ae321c93796591d", "output": "statusCode" } ] }, "headers": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3ae321c93796591d", "output": "headers" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3ae321c93796591d", "output": "body" } ] }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7d43a8c8d0c26ec2", "output": "state" } ] } }, "name": "Select the instructions", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" }, { "jsonSchema": { "type": "string" }, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "redirect" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "text" } ], "name": "Select the instructions", "moduleId": "n_babf9690b95b5251", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_5d38b1807f47a99f": { "inputs": {}, "name": "Follow redirect?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "follow", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_7d43a8c8d0c26ec2", "output": "redirect" } }, "operator": "isTrue" } ] } ] } ] }, "n_b6430392730d554f": { "inputs": { "q": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7d43a8c8d0c26ec2", "output": "text" } ] }, "target": { "kind": "value", "value": "it" }, "format": { "kind": "value", "value": "text" } }, "name": "Translate to Italian", "kind": "task", "task": { "inputs": [ { "description": "The text values to translate with Lingvanex.", "jsonSchema": { "anyOf": [ { "type": "string", "minLength": 1, "description": "One text value to process." }, { "type": "array", "items": { "type": "string", "minLength": 1, "description": "One text value to process." }, "minItems": 1, "maxItems": 128, "description": "A list of up to 128 text values to translate in one request." } ], "description": "The text values to translate with Lingvanex." }, "nullable": false, "handle": "q" }, { "description": "The target language code for the translation.", "jsonSchema": { "type": "string", "minLength": 1, "description": "The target language code for the translation." }, "nullable": false, "handle": "target" }, { "description": "The source language code. Lingvanex detects the source language when omitted.", "jsonSchema": { "type": "string", "minLength": 1, "description": "The source language code. Lingvanex detects the source language when omitted." }, "nullable": true, "handle": "source", "value": null }, { "description": "The source text format.", "jsonSchema": { "type": "string", "enum": [ "html", "text" ], "description": "The source text format." }, "nullable": true, "handle": "format", "value": null }, { "description": "The optional translation model passed to Lingvanex.", "jsonSchema": { "type": "string", "minLength": 1, "description": "The optional translation model passed to Lingvanex." }, "nullable": true, "handle": "model", "value": null } ], "outputs": [ { "description": "The translations returned by Lingvanex.", "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "translatedText": { "type": "string", "description": "The translated text." }, "detectedSourceLanguage": { "type": [ "string", "null" ], "description": "The detected source language when source was not provided." }, "model": { "type": [ "string", "null" ], "description": "The translation model when returned by Lingvanex." }, "raw": { "type": "object", "properties": {}, "additionalProperties": true, "description": "The raw object returned by Lingvanex." } }, "required": [ "translatedText", "detectedSourceLanguage", "model", "raw" ], "additionalProperties": false, "description": "One translation returned by Lingvanex." }, "description": "The translations returned by Lingvanex." }, "nullable": false, "handle": "translations" }, { "description": "The raw object returned by Lingvanex.", "jsonSchema": { "type": "object", "properties": {}, "additionalProperties": true, "description": "The raw object returned by Lingvanex." }, "nullable": false, "handle": "raw" } ], "name": "Translate to Italian", "executor": { "kind": "connector", "action": "lingvanex_translation_api.translate_text" } } }, "n_a0cce619a9d9b16c": { "inputs": { "translations": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b6430392730d554f", "output": "translations" } ] }, "text": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_7d43a8c8d0c26ec2", "output": "text" } ] } }, "name": "Read the translation", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "translatedText": { "type": "string", "description": "The translated text." }, "detectedSourceLanguage": { "type": [ "string", "null" ], "description": "The detected source language when source was not provided." }, "model": { "type": [ "string", "null" ], "description": "The translation model when returned by Lingvanex." }, "raw": { "type": "object", "properties": {}, "additionalProperties": true, "description": "The raw object returned by Lingvanex." } }, "required": [ "translatedText", "detectedSourceLanguage", "model", "raw" ], "additionalProperties": false, "description": "One translation returned by Lingvanex." }, "description": "The translations returned by Lingvanex." }, "nullable": false, "handle": "translations" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "text" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "sourceInstructions" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "italianInstructions" } ], "name": "Read the translation", "moduleId": "n_963da9825e738c70", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_3dd991476a1e7e6c": { "name": "Cocktail instructions", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "sourceInstructions" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "italianInstructions" } ], "outputMappings": { "sourceInstructions": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a0cce619a9d9b16c", "output": "sourceInstructions" } ] }, "italianInstructions": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a0cce619a9d9b16c", "output": "italianInstructions" } ] } } } }, "edges": [ { "source": "n_1d7777be1b3812d6", "target": "n_1a883d0f448660e5" }, { "source": "n_1a883d0f448660e5", "target": "n_3ae321c93796591d" }, { "source": "n_3ae321c93796591d", "target": "n_7d43a8c8d0c26ec2" }, { "source": "n_7d43a8c8d0c26ec2", "target": "n_5d38b1807f47a99f" }, { "source": "n_5d38b1807f47a99f", "target": "n_1a883d0f448660e5", "sourceHandle": "follow" }, { "source": "n_5d38b1807f47a99f", "target": "n_b6430392730d554f", "sourceHandle": "otherwise" }, { "source": "n_b6430392730d554f", "target": "n_a0cce619a9d9b16c" }, { "source": "n_a0cce619a9d9b16c", "target": "n_3dd991476a1e7e6c" } ] } }, "modules": { "n_c7728fff5d86014b": { "name": "Prepare CocktailDB URL", "imports": [], "source": "export default function hop({initialUrl,previousState}) {const candidate=previousState?.nextUrl||initialUrl;let url;try{url=new URL(candidate)}catch{throw Error('Configure a valid HTTP or HTTPS target URL')}if(!['http:','https:'].includes(url.protocol)||url.username||url.password)throw Error('Configure an HTTP or HTTPS URL without credentials');return{url:url.toString()};}\n" }, "n_babf9690b95b5251": { "name": "Select the instructions", "imports": [], "source": "export default function check({url,statusCode,headers,body,previousState}){const hops=previousState?.hops??0;if(!Number.isInteger(statusCode)||statusCode<100||statusCode>599||!Number.isInteger(hops)||hops<0)throw Error('Invalid response');if(statusCode>=300&&statusCode<400&&typeof headers?.location==='string'&&headers.location){if(hops>=21)throw Error('Too many redirects');let target;try{target=new URL(headers.location,url)}catch{throw Error('Invalid redirect')}if(!['http:','https:'].includes(target.protocol)||target.username||target.password)throw Error('Invalid redirect');return{state:{hops:hops+1,nextUrl:target.toString()},redirect:true,text:'redirect'}}if(statusCode<200||statusCode>=300)throw Error('Cocktail API request failed');let data;try{data=JSON.parse(body)}catch{throw Error('Invalid cocktail JSON')}const text=data?.drinks?.[0]?.strInstructions;if(typeof text!=='string'||!text.trim())throw Error('Missing cocktail instructions');return{state:{hops,nextUrl:''},redirect:false,text}}\n" }, "n_963da9825e738c70": { "name": "Read the translation", "imports": [], "source": "export default function result({translations,text}){if(!Array.isArray(translations)||translations.length!==1||typeof translations[0]?.translatedText!=='string')throw Error('Translation was not returned');return {sourceInstructions:text,italianInstructions:translations[0].translatedText}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }