Skip to content

Main content

Tool Chain Builder Source Code

Browse the implementation files for Tool Chain Builder.
@tool.io/tools/chain source ↗
tool.ts typescript
import Chain from './Chain.svelte';
import type { ChainDocument } from '@tool.io/tools/chain';
import type { ChainRenderValue } from './render-value';

export const defaultChainDocument = (): ChainDocument => ({
	edges: [],
	nodes: [
		{
			id: 'body-mass-index-1',
			inputs: { heightM: 1.8, weightKg: 70 },
			toolId: 'body-mass-index',
			toolVersion: 1
		}
	],
	version: 1
});

const isChainDocument = (
	value: unknown
): value is ChainDocument =>
	typeof value === 'object' &&
	value !== null &&
	!Array.isArray(value) &&
	(value as { version?: unknown }).version === 1 &&
	Array.isArray((value as { nodes?: unknown }).nodes) &&
	Array.isArray((value as { edges?: unknown }).edges);

export const Tool: TypeTool = {
	embeddedEditor: 'renderer',
	name: 'Tool Chain Builder',
	slug: 'chain',
	intro:
		'Connect compatible Tool.io tools into a reusable, locally executed workflow.',
	tool: (document, mode): ChainRenderValue => ({
		document: isChainDocument(document)
			? document
			: defaultChainDocument(),
		mode: mode === 'live' ? 'live' : 'manual'
	}),
	i: [
		{
			id: 'document',
			label: 'Chain document',
			labelhidden: true,
			placeholder: 'Chain document',
			type: 'hidden',
			value: defaultChainDocument(),
			valueType: { format: 'tool-chain', type: 'object' }
		},
		{
			id: 'mode',
			label: 'Execution mode',
			labelhidden: true,
			placeholder: 'Execution mode',
			type: 'hidden',
			value: 'manual',
			valueType: { format: 'tool-chain-mode', type: 'string' }
		}
	],
	o: [
		{
			id: 'document',
			label: 'Tool chain',
			placeholder: 'Build a tool chain',
			render: 'custom',
			renderas: Chain,
			type: 'object',
			valueType: { format: 'tool-chain', type: 'object' }
		}
	]
};

export default Tool;

Description

Browse the implementation files for Tool Chain Builder.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools