app:
  description: SKUごとの売上・在庫・リードタイムを元に補充優先度と発注数量の目安を提示するワークフロー
  icon: 📦
  icon_background: '#E6F7FF'
  mode: workflow
  name: 在庫補充優先判定
  use_icon_as_answer_icon: false
kind: app
version: 0.6.0
workflow:
  conversation_variables: []
  environment_variables: []
  features:
    file_upload:
      image:
        enabled: false
    opening_statement: ''
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
  graph:
    edges:
    - data:
        sourceType: start
        targetType: code
      id: start-to-code1
      source: start
      target: code1
    - data:
        sourceType: code
        targetType: llm
      id: code1-to-llm1
      source: code1
      target: llm1
    - data:
        sourceType: llm
        targetType: end
      id: llm1-to-end
      source: llm1
      target: end
    nodes:
    - data:
        title: 開始
        type: start
        variables:
        - label: query
          max_length: 2048
          options: []
          required: true
          type: paragraph
          variable: query
      height: 90
      id: start
      position:
        x: 80
        y: 282
      type: custom
      width: 244
    - data:
        title: 優先度計算
        type: code
        code_language: python3
        code: "def _safe_str(v):\n    \"\"\"Convert any value to string safely.\"\"\
          \"\n    if v is None:\n        return \"\"\n    if isinstance(v, list):\n\
          \        return \"\\n\".join(str(i) for i in v)\n    return str(v)\n\ndef\
          \ _safe_list(v):\n    \"\"\"Ensure value is a list.\"\"\"\n    if v is None:\n\
          \        return []\n    if isinstance(v, str):\n        return [v]\n   \
          \ if isinstance(v, list):\n        return v\n    return [v]\n\ndef main(**kwargs)\
          \ -> dict:\n    inputs = kwargs\n    import json\n    text = str(inputs.get(\"\
          query\", \"\")).strip()\n    lines = [l.strip() for l in text.splitlines()\
          \ if l.strip()]\n    results = []\n    for line in lines:\n        parts\
          \ = [p.strip() for p in line.split(\",\")]\n        if len(parts) < 4:\n\
          \            # 期待フォーマット: SKU, 売上(期間あたり), 在庫, リードタイム(期間)\n            continue\n\
          \        sku = parts[0]\n        try:\n            sales = float(parts[1])\n\
          \        except:\n            sales = 0.0\n        try:\n            stock\
          \ = float(parts[2])\n        except:\n            stock = 0.0\n        try:\n\
          \            lead = float(parts[3])\n        except:\n            lead =\
          \ 0.0\n        safety = 1.2\n        target = sales * lead * safety\n  \
          \      suggested = int(round(max(0.0, target - stock)))\n        priority_score\
          \ = 0.0\n        if (stock + 1.0) > 0.0:\n            priority_score = (sales\
          \ / (stock + 1.0)) * lead\n        results.append(dict(\n            sku=sku,\n\
          \            sales=sales,\n            stock=stock,\n            lead_time=lead,\n\
          \            target_stock=round(target, 2),\n            suggested_order=suggested,\n\
          \            priority_score=round(priority_score, 2)\n        ))\n    #\
          \ 正規化して 0-100 の優先度に変換\n    maxp = 0.0\n    for r in results:\n        v\
          \ = r.get(\"priority_score\", 0.0)\n        if v > maxp:\n            maxp\
          \ = v\n    if maxp == 0.0:\n        maxp = 1.0\n    for r in results:\n\
          \        r[\"priority\"] = int(round(r.get(\"priority_score\", 0.0) / maxp\
          \ * 100))\n    return dict(output=json.dumps(results, ensure_ascii=False))\n"
        variables:
        - value_selector:
          - start
          - query
          variable: query
        outputs:
          output:
            type: string
            children: null
      height: 90
      id: code1
      position:
        x: 380
        y: 282
      type: custom
      width: 244
    - data:
        title: レポート生成
        type: llm
        model:
          provider: openai
          name: gpt-5-mini
          mode: chat
          completion_params:
            temperature: 0.6
        prompt_template:
        - role: system
          text: あなたは小売在庫管理の専門家です。与えられたSKUごとの計算結果を基に、補充優先度の解説とアクション要約（推奨発注数量、理由、優先度ランク）を日本語で作成してください。出力は箇条書きで各SKUを見出しにして示し、短い実務的な推奨を含めてください。
        - role: user
          text: '元データ（ユーザー入力）:

            {{#start.query#}}


            前処理結果（JSON形式）:

            {{#code1.output#}}


            要件:

            - 各SKUについて「優先度(0-100)」「推奨発注数量」「理由」を含めること。

            - 優先度の高い上位3件は特に短い改善アクションを提示すること。'
        vision:
          enabled: false
        memory: null
        context:
          enabled: false
      height: 90
      id: llm1
      position:
        x: 680
        y: 282
      type: custom
      width: 244
    - data:
        title: 終了
        type: end
        outputs:
        - value_selector:
          - llm1
          - text
          variable: result
      height: 90
      id: end
      position:
        x: 980
        y: 282
      type: custom
      width: 244
  hash: null
