claude-skills/

Anthropic公式スキル・プラグインの日本語ディレクトリ

last sync 22h ago
スキルOfficialdevelopment

🔄output-dev-workflow-function

プラグイン
outputai

説明

Output SDK ワークフロー用の `workflow.ts` ファイルを作成します。 次のような場合に使用: - ワークフロー関数を定義するとき - ステップをオーケストレーションするとき - ワークフローの構造上の問題を修正するとき

原文を表示

Create workflow.ts files for Output SDK workflows. Use when defining workflow functions, orchestrating steps, or fixing workflow structure issues.

ユースケース

  • ワークフロー関数を定義するとき
  • ステップをオーケストレーションするとき
  • ワークフローの構造上の問題を修正するとき

本文(日本語訳)

workflow.ts ファイルの作成

概要

このスキルは、Output SDK ワークフロー用の workflow.ts ファイルを作成する方法を説明します。
ワークフローファイルには、ステップの実行を調整するメインのオーケストレーションロジックが含まれます。

次のような場合に使用

  • 新しいワークフローのメイン定義を作成する
  • ワークフロー構造の要件を理解する
  • ワークフローのオーケストレーションに関する問題をデバッグする
  • 既存のワークフローロジックをリファクタリングする

重要なルール

1. インポートパターン

// 正しい - @outputai/core からインポートする
import { workflow, z } from '@outputai/core';

// 誤り - zod から z をインポートしない
import { z } from 'zod';

2. ES モジュールのインポート

すべてのインポートには .js 拡張子が必須です:

// 正しい
import { stepName } from './steps.js';
import { WorkflowInputSchema } from './types.js';

// 誤り - .js 拡張子が不足している
import { stepName } from './steps';
import { WorkflowInputSchema } from './types';

3. 決定論的処理の要件

重要: ワークフローの fn は決定論的でなければなりません。
ワークフロー関数内での直接的な I/O 操作は禁止されています。

// 誤り - ワークフロー内で直接 I/O を実行している
export default workflow( {
  // ...
  fn: async input => {
    const response = await fetch( 'https://api.example.com' ); // 絶対に行わないこと!
    return response.json();
  }
} );

// 正しい - I/O はステップに委譲する
export default workflow( {
  // ...
  fn: async input => {
    const result = await fetchDataStep( input ); // I/O はステップで処理する
    return result;
  }
} );

関連スキル: output-error-nondeterminism

基本構造

import { workflow, z } from '@outputai/core';

import { stepOne, stepTwo } from './steps.js';
import { WorkflowInputSchema, WorkflowOutput } from './types.js';

export default workflow( {
  name: 'workflowName',
  description: 'ワークフローの内容を簡潔に説明する文章',
  inputSchema: WorkflowInputSchema,
  outputSchema: z.object( { /* 出力の形状 */ } ),
  fn: async ( input ): Promise<WorkflowOutput> => {
    // ステップ呼び出しのオーケストレーション
    const result = await stepOne( input );
    const final = await stepTwo( result );
    return final;
  }
} );

必須プロパティ

name(文字列)

ワークフローの一意な識別子。キャメルケースを使用します。

name: 'contentUtilsImageInfographicNano'

description(文字列)

ワークフローの目的を人が読みやすい形で記述します。

description: 'Generate high-quality infographic images using AI-powered ideation'

inputSchema(Zod スキーマ)

ワークフローの入力を検証するためのスキーマ。types.ts からインポートします。

inputSchema: WorkflowInputSchema

関連スキル: output-dev-types-file

outputSchema(Zod スキーマ)

ワークフローの出力を検証するためのスキーマ。

outputSchema: z.object( {
  results: z.array( z.string() ),
  metadata: z.object( {
    processedAt: z.string()
  } )
} )

fn(非同期関数)

ワークフローの実行関数。決定論的でなければなりません。

fn: async ( input ): Promise<WorkflowOutput> => {
  // ステップのオーケストレーションのみ - 直接 I/O は行わない
  const result = await processStep( input );
  return result;
}

完全な実装例

実際のワークフロー(image_infographic_nano)をもとにした例:

import { workflow, z } from '@outputai/core';

import {
  generateImageIdeas,
  generateImages,
  validateReferenceImages
} from './steps.js';
import {
  WorkflowInput,
  WorkflowInputSchema,
  WorkflowOutput
} from './types.js';
import { normalizeReferenceImageUrls } from './utils.js';

export default workflow( {
  name: 'contentUtilsImageInfographicNano',
  description: 'Generate high-quality infographic images using Google Gemini 3 Pro Image model with AI-powered ideation',
  inputSchema: WorkflowInputSchema,
  outputSchema: z.array( z.string() ),
  fn: async ( rawInput: WorkflowInput ): Promise<WorkflowOutput> => {
    // 入力の前処理(純粋関数 - ワークフロー内で許可)
    const input = {
      ...rawInput,
      referenceImageUrls: normalizeReferenceImageUrls( rawInput.referenceImageUrls )
    };

    // 条件付きステップ実行
    if ( input.referenceImageUrls && input.referenceImageUrls.length > 0 ) {
      await validateReferenceImages( {
        referenceImageUrls: input.referenceImageUrls as string[]
      } );
    }

    // 逐次ステップ実行
    const ideas = await generateImageIdeas( {
      content: input.content,
      numberOfIdeas: input.numberOfIdeas,
      colorPalette: input.colorPalette,
      artDirection: input.artDirection
    } );

    // 並列ステップ実行
    const generations = await Promise.all(
      ideas.map( idea =>
        generateImages( {
          input: {
            referenceImageUrls: input.referenceImageUrls,
            aspectRatio: input.aspectRatio,
            resolution: input.resolution,
            numberOfGenerations: input.numberOfGenerations,
            storageNamespace: input.storageNamespace
          },
          prompt: idea
        } )
      )
    );

    return generations.flat();
  }
} );

オーケストレーションパターン

逐次実行

ステップを順番に実行する:

fn: async input => {
  const step1Result = await stepOne( input );
  const step2Result = await stepTwo( step1Result );
  const step3Result = await stepThree( step2Result );
  return step3Result;
}

並列実行

独立したステップを並行して実行する:

fn: async input => {
  const [ resultA, resultB, resultC ] = await Promise.all( [
    stepA( input ),
    stepB( input ),
    stepC( input )
  ] );
  return { resultA, resultB, resultC };
}

条件付き実行

条件に基づいてステップを実行する:

fn: async input => {
  if ( input.includeImages ) {
    await processImages( input );
  }

  const result = input.mode === 'fast' ?
    await quickProcess( input ) :
    await detailedProcess( input );

  return result;
}

ファンアウトパターン

複数のアイテムを並列処理する:

fn: async input => {
  const results = await Promise.all(
    input.items.map( item => processItem( { item } ) )
  );
  return { processedItems: results };
}

パイプラインパターン

複数の変換処理を連鎖させる:

fn: async input => {
  const extracted = await extractData( input );
  const transformed = await transformData( extracted );
  const validated = await validateData( transformed );
  const enriched = await enrichData( validated );
  return enriched;
}

ワークフロー fn 内で許可される操作

許可される操作(決定論的な処理)

  • ステップ関数の呼び出し
  • 純粋なデータ変換
  • 入力に基づく条件分岐ロジック
  • 配列操作(map、filter、reduce)
  • オブジェクトの分割代入と構築
  • 並列ステップ用の Promise.all
  • 制御フロー(if/else、ループ)

許可されない操作(非決定論的な処理)

  • HTTP リクエスト(ステップを使用すること)
  • データベースクエリ(ステップを使用すること)
  • ファイルシステム操作(ステップを使用すること)
  • 乱数の生成
  • 現在の日時へのアクセス
  • 環境変数へのアクセス
  • 外部サービスへの呼び出し全般

確認チェックリスト

  • [ ] workflowz@outputai/core からインポートされている
  • [ ] すべてのインポートに .js 拡張子が付いている
  • [ ] ワークフローがデフォルトエクスポートされている
  • [ ] name がキャメルケースかつ一意である
  • [ ] description がワークフローの内容を明確に説明している
  • [ ] inputSchematypes.ts からインポートされている
  • [ ] outputSchema が実際の戻り値の型と一致している
  • [ ] fn が決定論的である(直接 I/O を行っていない)
  • [ ] すべての I/O がステップ関数に委譲されている
  • [ ] コードがスタイル規約に従っている(output-dev-code-style 参照)

関連スキル

  • output-dev-step-function - I/O を処理するステップ関数の作成
  • output-dev-evaluator-function - evaluator 関数でのステップ使用
  • output-dev-types-file - 入出力スキーマの定義
  • output-dev-folder-structure - workflow.ts の配置場所
  • output-error-nondeterminism - 決定論的処理違反の修正
  • output-error-zod-import - スキーマインポートに関する問題の修正
  • output-dev-code-style
原文(English)を表示

Creating workflow.ts Files

Overview

This skill documents how to create workflow.ts files for Output SDK workflows. The workflow file contains the main orchestration logic that coordinates step execution.

When to Use This Skill

  • Creating a new workflow's main definition
  • Understanding workflow structure requirements
  • Debugging workflow orchestration issues
  • Refactoring existing workflow logic

Critical Rules

1. Import Pattern

// CORRECT - Import from @outputai/core
import { workflow, z } from '@outputai/core';

// WRONG - Never import z from zod
import { z } from 'zod';

2. ES Module Imports

All imports MUST use .js extension:

// CORRECT
import { stepName } from './steps.js';
import { WorkflowInputSchema } from './types.js';

// WRONG - Missing .js extension
import { stepName } from './steps';
import { WorkflowInputSchema } from './types';

3. Determinism Requirement

CRITICAL: The workflow fn must be deterministic. No direct I/O operations are allowed in the workflow function.

// WRONG - Direct I/O in workflow
export default workflow( {
  // ...
  fn: async input => {
    const response = await fetch( 'https://api.example.com' ); // NEVER do this!
    return response.json();
  }
} );

// CORRECT - Delegate I/O to steps
export default workflow( {
  // ...
  fn: async input => {
    const result = await fetchDataStep( input ); // Steps handle I/O
    return result;
  }
} );

Related Skill: output-error-nondeterminism

Basic Structure

import { workflow, z } from '@outputai/core';

import { stepOne, stepTwo } from './steps.js';
import { WorkflowInputSchema, WorkflowOutput } from './types.js';

export default workflow( {
  name: 'workflowName',
  description: 'Brief description of what the workflow does',
  inputSchema: WorkflowInputSchema,
  outputSchema: z.object( { /* output shape */ } ),
  fn: async ( input ): Promise<WorkflowOutput> => {
    // Orchestrate step calls
    const result = await stepOne( input );
    const final = await stepTwo( result );
    return final;
  }
} );

Required Properties

name (string)

Unique identifier for the workflow. Use camelCase.

name: 'contentUtilsImageInfographicNano'

description (string)

Human-readable description of the workflow's purpose.

description: 'Generate high-quality infographic images using AI-powered ideation'

inputSchema (Zod schema)

Schema for validating workflow input. Import from types.ts.

inputSchema: WorkflowInputSchema

Related Skill: output-dev-types-file

outputSchema (Zod schema)

Schema for validating workflow output.

outputSchema: z.object( {
  results: z.array( z.string() ),
  metadata: z.object( {
    processedAt: z.string()
  } )
} )

fn (async function)

The workflow execution function. Must be deterministic.

fn: async ( input ): Promise<WorkflowOutput> => {
  // Step orchestration only - no direct I/O
  const result = await processStep( input );
  return result;
}

Complete Example

Based on a real workflow (image_infographic_nano):

import { workflow, z } from '@outputai/core';

import {
  generateImageIdeas,
  generateImages,
  validateReferenceImages
} from './steps.js';
import {
  WorkflowInput,
  WorkflowInputSchema,
  WorkflowOutput
} from './types.js';
import { normalizeReferenceImageUrls } from './utils.js';

export default workflow( {
  name: 'contentUtilsImageInfographicNano',
  description: 'Generate high-quality infographic images using Google Gemini 3 Pro Image model with AI-powered ideation',
  inputSchema: WorkflowInputSchema,
  outputSchema: z.array( z.string() ),
  fn: async ( rawInput: WorkflowInput ): Promise<WorkflowOutput> => {
    // Pre-process input (pure function - OK in workflow)
    const input = {
      ...rawInput,
      referenceImageUrls: normalizeReferenceImageUrls( rawInput.referenceImageUrls )
    };

    // Conditional step execution
    if ( input.referenceImageUrls && input.referenceImageUrls.length > 0 ) {
      await validateReferenceImages( {
        referenceImageUrls: input.referenceImageUrls as string[]
      } );
    }

    // Sequential step execution
    const ideas = await generateImageIdeas( {
      content: input.content,
      numberOfIdeas: input.numberOfIdeas,
      colorPalette: input.colorPalette,
      artDirection: input.artDirection
    } );

    // Parallel step execution
    const generations = await Promise.all(
      ideas.map( idea =>
        generateImages( {
          input: {
            referenceImageUrls: input.referenceImageUrls,
            aspectRatio: input.aspectRatio,
            resolution: input.resolution,
            numberOfGenerations: input.numberOfGenerations,
            storageNamespace: input.storageNamespace
          },
          prompt: idea
        } )
      )
    );

    return generations.flat();
  }
} );

Orchestration Patterns

Sequential Execution

Execute steps one after another:

fn: async input => {
  const step1Result = await stepOne( input );
  const step2Result = await stepTwo( step1Result );
  const step3Result = await stepThree( step2Result );
  return step3Result;
}

Parallel Execution

Execute independent steps concurrently:

fn: async input => {
  const [ resultA, resultB, resultC ] = await Promise.all( [
    stepA( input ),
    stepB( input ),
    stepC( input )
  ] );
  return { resultA, resultB, resultC };
}

Conditional Execution

Execute steps based on conditions:

fn: async input => {
  if ( input.includeImages ) {
    await processImages( input );
  }

  const result = input.mode === 'fast' ?
    await quickProcess( input ) :
    await detailedProcess( input );

  return result;
}

Fan-Out Pattern

Process multiple items in parallel:

fn: async input => {
  const results = await Promise.all(
    input.items.map( item => processItem( { item } ) )
  );
  return { processedItems: results };
}

Pipeline Pattern

Chain multiple transformations:

fn: async input => {
  const extracted = await extractData( input );
  const transformed = await transformData( extracted );
  const validated = await validateData( transformed );
  const enriched = await enrichData( validated );
  return enriched;
}

What is Allowed in Workflow fn

Allowed (Deterministic Operations)

  • Calling step functions
  • Pure data transformations
  • Conditional logic based on input
  • Array operations (map, filter, reduce)
  • Object destructuring and construction
  • Promise.all for parallel steps
  • Control flow (if/else, loops)

NOT Allowed (Non-Deterministic Operations)

  • HTTP requests (use steps)
  • Database queries (use steps)
  • File system operations (use steps)
  • Random number generation
  • Current date/time access
  • Environment variable access
  • Any external service calls

Verification Checklist

  • [ ] workflow and z imported from @outputai/core
  • [ ] All imports use .js extension
  • [ ] Default export used for the workflow
  • [ ] name is camelCase and unique
  • [ ] description clearly explains the workflow
  • [ ] inputSchema imported from types.ts
  • [ ] outputSchema matches actual return type
  • [ ] fn is deterministic (no direct I/O)
  • [ ] All I/O delegated to step functions
  • [ ] Code follows style conventions (see output-dev-code-style)

Related Skills

  • output-dev-step-function - Creating step functions that handle I/O
  • output-dev-evaluator-function - Using steps in evaluator functions
  • output-dev-types-file - Defining input/output schemas
  • output-dev-folder-structure - Where workflow.ts belongs
  • output-error-nondeterminism - Fixing determinism violations
  • output-error-zod-import - Fixing schema import issues
  • output-dev-code-style

原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。