ข้ามไปยังเนื้อหา
AggregaAggregaAggregaAggrega
เลือกภาษา: ไทย
หน้านี้ถูกแปลด้วยเครื่อง อ่านต้นฉบับภาษาอังกฤษ

นำเข้า workflow ของ n8n

บทแนะนำทีละขั้นตอนนี้นำเข้า workflow ที่ส่งออกจาก n8n ซึ่งเป็นเอเจนต์ AI ที่ตอบข้อความแชตด้วยโมเดลแชตของ OpenAI และหน่วยความจำ ไปเป็น Aggregate, Release และ Manifest ที่บิลด์ n8n พร้อม workflow สำหรับ Docker Compose ตามที่เขียนไว้ จากนั้นบิลด์และรันผลที่ได้ ทุกไฟล์และทุกบล็อกเอาต์พุตด้านล่างมาจากการรันจริง workflow และแต่ละขั้นตอนของบทแนะนำอยู่ในตัวอย่าง import-n8n ซึ่งสคริปต์ตรวจสอบรันการนำเข้าอีกครั้ง เปรียบเทียบสิ่งที่การนำเข้าเขียน สิ่งที่พิมพ์ และบล็อกที่หน้านี้อ้างถึงกับไฟล์ที่เก็บไว้ที่นั่น แล้วตรวจสอบความถูกต้องและบิลด์สิ่งที่การนำเข้าเขียน

ร่างตัวอย่าง

คุณรันการนำเข้านี้ด้วยคำสั่งในหน้านี้ได้ หรือ ให้ผู้ช่วย AI ของคุณรันให้

เขียนตัวอย่างลงในโฟลเดอร์ใหม่ที่ตั้งชื่อตามตัวอย่าง:

Terminal window
aggrega draft --example import-n8n

จากนั้นจะพิมพ์คำสั่งที่ต้องรันต่อ คำสั่งแรกเปลี่ยนเข้าโฟลเดอร์ใหม่ ส่วนคำสั่งถัดไปด้านล่างเปลี่ยนเข้าโฟลเดอร์ source ซึ่งมีสิ่งที่หน้านี้นำเข้าและเป็นที่ที่การนำเข้ารัน:

Terminal window
cd import-n8n

โฟลเดอร์ source ของตัวอย่างที่ร่างไว้เปิดอยู่ใน Visual Studio Code แสดงการส่งออก workflow ของ n8n ของเอเจนต์ฝ่ายสนับสนุน โดยเปิดที่โหนด chat trigger และ AI Agent

workflow

support-agent.json ซึ่งเขียนขึ้นสำหรับบทแนะนำนี้ในรูปแบบที่ n8n ส่งออก workflow มีโหนดสี่โหนด ได้แก่ chat trigger และ AI Agent ที่มีข้อความระบบสั้นๆ โหนด OpenAI Chat Model ที่เลือก gpt-4o-mini และโหนด Simple Memory เชื่อมกันด้วยการเชื่อมต่อที่ n8n ระบุตามชื่อของโหนดต้นทางของแต่ละการเชื่อมต่อ chat trigger เป็นแบบสาธารณะ ข้อความแชตที่ส่งไปยัง URL ของ chat trigger จึงเริ่ม workflow และ chat trigger ขอผู้ใช้และรหัสผ่านจากผู้ส่ง ซึ่งตรวจสอบกับข้อมูลรับรองแบบ basic authentication ที่ n8n เก็บไว้:

"parameters": {
"public": true,
"authentication": "basicAuth",
"options": {}
},
[… omitted: the node's identifier, name, type, version, position and webhook identifier]
"credentials": {
"httpBasicAuth": {
"id": "Vx3mQ8rLb2Nk7Tz5",
"name": "Chat basic auth"
}
}

โหนดโมเดลเลือกข้อมูลรับรองด้วยวิธีเดียวกัน คือโดยการอ้างอิง การส่งออกมีตัวระบุและชื่อของข้อมูลรับรองแต่ละรายการ ไม่มีผู้ใช้ รหัสผ่าน หรือคีย์เลย:

"parameters": {
"model": {
"__rl": true,
"value": "gpt-4o-mini",
"mode": "list",
"cachedResultName": "gpt-4o-mini"
},
"options": {}
},
"id": "6f1d2c3a-7b4e-4a8f-9c21-0d3e5f6a7b03",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [120, 220],
"credentials": {
"openAiApi": {
"id": "Rb7nW2xQ9kT4mZ1c",
"name": "OpenAI account"
}
}

ข้าง workflow .aggrega-config.yaml ทำให้โฟลเดอร์เป็นพื้นที่ทำงาน:

# The workspace key marks this directory as the workspace root, so an import run
# here writes its drafts beside support-agent.json.
workspace: {}
# The registry the importer is fetched from the first time an import needs it.
default_registry: hub.aggrega.ai

และ import-answers.yaml เก็บคำตอบสำหรับสิ่งที่ workflow เก็บไม่ได้ การนำเข้าสำหรับ Docker Compose ไม่ต้องใช้คำตอบเลย: แนบคีย์ OpenAI ด้วยการอ้างอิงตัวแปรที่ Docker Compose เติมจาก shell ของคุณ การนำเข้าสำหรับ Kubernetes แนบคีย์ด้วยชื่อของ Secret ใน Kubernetes ซึ่งมีเพียงคุณที่ตั้งชื่อได้ ไฟล์จึงระบุชื่อ Secret นั้น (ดู บน Kubernetes):

# Values the import could not draft from the source, keyed by the drafted file and the key path inside
# it. Write each one beside its key; an import of the same source, and a sync, read them from here and
# ask nothing. A secret is never written here: its key asks where the secret comes from — a variable
# name, ${NAME}, or the name of a Kubernetes Secret.
release.yaml:
# The origin of the secret value, written by the operator in the Release. Read exactly as
# values.origin is. Write it here or in values.origin, never in both. A secret: name where it comes
# from, never the value.
spec.components.n8n.uses.model.openai-chat-model.features.credential.infra.origin: "openai-api-key"

ไฟล์คำตอบของการนำเข้า อธิบายไฟล์โดยละเอียด

การนำเข้าเทียบโหนดแต่ละโหนดกับ Components ของแค็ตตาล็อกของพื้นที่ทำงาน และ --target ร่าง Manifest จาก Recipes ของแค็ตตาล็อกนั้น พื้นที่ทำงานไม่ระบุโฟลเดอร์แค็ตตาล็อกใดเลย การนำเข้าจึงอ่านแค็ตตาล็อกของไลบรารีมาตรฐานจากรีจิสทรีที่ใช้ดึงตัวนำเข้า คือสแนปช็อตที่ลงนามของแค็ตตาล็อกที่เผยแพร่ ซึ่งการนำเข้าครั้งแรกดึงมา ตรวจสอบ และเก็บไว้ในแคชเนื้อหาของพื้นที่ทำงาน และระบุด้วยไดเจสต์ในบันทึกที่การนำเข้าเขียนไว้ข้างฉบับร่าง พื้นที่ทำงานที่ระบุโฟลเดอร์แค็ตตาล็อกของตนเอง — ใน AGGREGA_CATALOG_DIRS หรือใต้ workspace.catalog_dirs — จะนำเข้าเทียบกับโฟลเดอร์เหล่านั้นแทน เปลี่ยนไดเรกทอรีไปที่ source:

Terminal window
cd source

รันการนำเข้า

Terminal window
aggrega import support-agent.json --target compose

ที่เอาต์พุตมาตรฐาน การนำเข้าแสดงสิ่งที่เขียน:

wrote aggregate.yaml
wrote release.yaml
wrote manifest.yaml
wrote .aggrega-import.json

ที่ข้อผิดพลาดมาตรฐาน โดยที่ <workspace> แทนโฟลเดอร์ที่คุณรัน:

[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]
read as the n8n format, with drafted paths relative to <workspace>
warn: the value of credentials.httpBasicAuth.id of node When chat message received is carried as written in the flow the draft carries: its format marks the field as a credential, and setting empty_credentials to marked or all writes it empty
warn: the value of credentials.openAiApi.id of node OpenAI Chat Model is carried as written in the flow the draft carries: its format marks the field as a credential, and setting empty_credentials to marked or all writes it empty
warn: node OpenAI Chat Model reaches openai-chat-model, wired to the model socket of core/ai-agent/n8n as openai-chat-model, other than through that connection: an n8n @n8n/n8n-nodes-langchain.lmChatOpenAi node reaches the part at the address the stored credential it selects, or its own parameters, give; the platform delivers this connection as OPENAI_BASE_URL and OPENAI_API_KEY, but an n8n workflow reads a variable of the platform's environment only through an expression reading $env, which the platform refuses while values.allow_env_access_in_nodes is false, the value the draft leaves it at; setting it true lets every workflow, and every user who can edit one, read every variable of the platform's environment, the delivered credentials included
made no choice for When chat message received (@n8n/n8n-nodes-langchain.chatTrigger)
made no choice for AI Agent (@n8n/n8n-nodes-langchain.agent)
mapped OpenAI Chat Model (@n8n/n8n-nodes-langchain.lmChatOpenAi) to core/ai-model/openai as a reference, HIGH at 0.9143
made no choice for Simple Memory (@n8n/n8n-nodes-langchain.memoryBufferWindow)
warning: node "n8n" (provider "compose"): artifact "n8n-flow.compose-fragment.yaml": skipped provenance label injection — the fragment declares no compose service. Compose carries build provenance as service labels, so a fragment contributing only top-level networks, volumes or configs carries none; the services this component emits elsewhere carry the full set.
Pull complete: <workspace>/release.lock (entities=8, source_artifacts=0, external_inputs=0)

การนำเข้าที่รันจากตัวแก้ไข: Aggregate, Release และ Manifest ที่ร่างไว้ปรากฏข้างไฟล์ที่ส่งออกของเวิร์กโฟลว์ เอาต์พุตของ Aggrega แสดงการแมปของแต่ละโหนดและไฟล์ที่เขียน และการแจ้งเตือนบอกว่าการนำเข้าร่างไฟล์ 3 ไฟล์ โดยรู้จักว่าเป็น n8n

  • บรรทัด mapped บอกว่าโหนด OpenAI Chat Model กลายเป็นโมเดล OpenAI ของไลบรารีมาตรฐาน core/ai-model/openai โดยอ้างอิงแทนการร่าง เพราะตรงกันในระดับสูงที่ 0.9143 เป็นส่วนประกอบของตัวเองที่เชื่อมโยงกับซ็อกเก็ต model ของแพลตฟอร์ม
  • บรรทัด made no choice บอกว่าทริกเกอร์ เอเจนต์ และหน่วยความจำอยู่ภายในเวิร์กโฟลว์ ซึ่ง n8n รันเอง
  • สองบรรทัด warn แรก ระบุตัวระบุของข้อมูลรับรองที่จัดเก็บไว้ ซึ่งทริกเกอร์และโหนดโมเดลเลือกใช้ และ n8n ทำเครื่องหมายว่าเป็นข้อมูลรับรอง การอ้างอิงเหล่านี้ไม่ใช่ข้อมูลลับ และถูกคงไว้ตามที่เขียน
  • บรรทัด warn ที่สาม คือบรรทัดที่ควรอ่านให้ละเอียด โหนดโมเดลเข้าถึง OpenAI ด้วยข้อมูลรับรองที่จัดเก็บไว้ซึ่งโหนดเลือก ไม่ใช่ผ่านการเชื่อมต่อที่ฉบับร่างเชื่อมโยงไว้ แพลตฟอร์มส่งมอบการเชื่อมต่อไปยังสภาพแวดล้อมของ n8n และ n8n ปฏิเสธการอ่านสภาพแวดล้อมของเวิร์กโฟลว์ ตราบที่ Aggregate ตั้ง values.allow_env_access_in_nodes ไว้ที่ false ตามที่ฉบับร่างทำ การตั้งเป็น true ทำให้เวิร์กโฟลว์ทุกรายการ และทุกคนที่แก้ไขเวิร์กโฟลว์ได้ อ่านทุกตัวแปรของแพลตฟอร์มได้ รวมถึงคีย์ที่ส่งมอบ ดังนั้นคีย์ที่เวิร์กโฟลว์ใช้คือคีย์ที่ n8n จัดเก็บ ดังที่ วิธีรัน แสดง
  • สองบรรทัดสุดท้าย คือขั้นตอน pull ไม่มีคำถามเหลือให้ตอบ การนำเข้าจึง pull การพึ่งพาของ Release ที่ร่างไว้ เหมือนที่ aggrega pull ทำ และเขียน release.lock บิลด์ด้านล่างไม่ต้องใช้อะไรเพิ่ม บรรทัด warning เป็นบรรทัดที่บิลด์พิมพ์เช่นกัน และ ตรวจสอบความถูกต้องและบิลด์ อธิบายบรรทัดนั้น

ไฟล์คำตอบระบุ Secret ที่การนำเข้านี้ไม่ได้ถาม จึงไม่ได้เว้นช่องว่างใดไว้สำหรับ Secret นั้น การนำเข้าจึงไม่นำคำตอบใดไปใช้และปล่อยไฟล์ไว้ตามเดิม

สิ่งที่การนำเข้าเขียน

Aggregate, Release และ Manifest ตั้งชื่อว่า imported/support-agent ตามชื่อของเวิร์กโฟลว์เอง Support agent ที่ลดรูปเป็น support-agent — เวิร์กโฟลว์ที่ไม่มีชื่อตั้งชื่อตามไฟล์ของตน — ภายใต้เนมสเปซที่การตั้งค่า target_namespace ของตัวนำเข้ากำหนด ซึ่งเป็น imported เว้นแต่คุณตั้งค่าอื่น (การตั้งค่า)

aggregate.yaml — อินสแตนซ์หนึ่งรายการของแพลตฟอร์ม n8n ในไลบรารีมาตรฐาน core/ai-agent/n8n ที่บรรจุเวิร์กโฟลว์ตามที่ส่งออกมา โดยตัดส่วนใหญ่ออกไว้ที่นี่ และโมเดลที่เชื่อมโยงกับซ็อกเก็ต model ของอินสแตนซ์นั้น:

apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/support-agent
version: 0.1.0
description: Draft Aggregate imported from a source in the n8n format.
spec:
components:
n8n:
type: core/ai-agent/n8n
values:
workflow_id: 'sQ4vT8nKp2LmX7bR'
flow_definition: |
{
"id": "sQ4vT8nKp2LmX7bR",
"name": "Support agent",
[… omitted: the rest of the workflow, as exported]
}
uses:
model:
openai-chat-model:
target: openai-chat-model
# For the compose target, the lines below declare credential on openai-chat-model: a secret the Release alone attaches arrives under the key value, so each is declared with a key of its own and no two arrive under one; the Release attaches its origin, naming this type or none.
features:
credential:
type: core/secret-value
values:
key: OPENAI_API_KEY
# swap to core/ai-model/azure-openai (score 0.4125) by setting type: core/ai-model/azure-openai
openai-chat-model:
type: core/ai-model/openai
values:
model: |-
gpt-4o-mini

workflow_id คือตัวระบุที่การส่งออกกำหนดให้เวิร์กโฟลว์ โมเดลคือ core/ai-model/openai โดยใช้โมเดลที่โหนดเลือกคือ gpt-4o-mini ความคิดเห็นเหนือโมเดลระบุ Component อีกรายการของแค็ตตาล็อกที่โหนดคล้ายกัน พร้อมคะแนน คีย์ OpenAI ที่แพลตฟอร์มแสดงต่อโมเดลถูกประกาศที่การเชื่อมต่อ พร้อมตัวแปรที่คีย์นั้นมาถึงในสภาพแวดล้อมของ n8n คือ OPENAI_API_KEY ส่วน Release ระบุว่าคีย์มาจากที่ใด

release.yaml — Release ซึ่งปรับใช้ Aggregate ด้วย Manifest:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/support-agent
# environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to.
environment: development
version: 0.1.0
description: Draft Release imported from a source in the n8n format.
spec:
aggregate: imported/support-agent
manifest: imported/support-agent
components:
n8n:
infra:
# The image running core/ai-agent/n8n, at the version this importer drafts, which the catalog's Recipes for it are known to run; the import does not raise or lower it to follow the source.
image: "n8nio/n8n:1.110.1"
# Published on this machine's loopback address, 127.0.0.1: reachable from this machine only, by any process running on it. Delete this line to keep the service internal.
published_port: 5678
uses:
model:
openai-chat-model:
features:
credential:
type: core/secret-value
infra:
# Attached by reference, never as a value: the credential n8n presents to openai-chat-model on its model connection, read from the variable OPENAI_API_KEY, which a target substituting variable references, as Docker Compose does when the stack starts, reads from the environment, so no file carries the value.
origin: "${OPENAI_API_KEY}"
openai-chat-model: {}
  • environment คือ development ซึ่งเป็นค่าเริ่มต้นที่ความคิดเห็นด้านบนบอกให้เปลี่ยนเป็นสภาพแวดล้อมที่ Release ปรับใช้
  • อิมเมจ คือ n8n 1.110.1 ซึ่งเป็นเวอร์ชันที่ Recipes ของแค็ตตาล็อกสำหรับ n8n รัน
  • published_port คือ 5678 พอร์ตที่ n8n ให้บริการ ตัวแก้ไขจึงตอบที่ http://127.0.0.1:5678 บนเครื่องของคุณ ตามที่ความคิดเห็นของบรรทัดนั้นบอก ทุกกระบวนการบนเครื่องนี้เข้าถึงได้ที่นั่นและไม่มีสิ่งอื่นเข้าถึงได้ ลบบรรทัดนั้นเพื่อให้ n8n อยู่บนเครือข่ายของสแตกเท่านั้น published_port ที่ไม่ใช่ 5678 ต้องมี infra.external_base_url: http://127.0.0.1:<published_port> อยู่ข้างกัน มิฉะนั้น n8n จะรายงานที่อยู่ของตัวแก้ไขและ webhook บน localhost:5678
  • คีย์ คือการอ้างอิงตัวแปร ${OPENAI_API_KEY} ซึ่ง Docker Compose เติมจาก shell ของคุณเมื่อสแตกเริ่มทำงาน โมเดล OpenAI ของไลบรารีมาตรฐานเป็นบริการแบบโฮสต์ และการเชื่อมต่อไปยังโมเดลนั้นต้องมีข้อมูลรับรอง Release จึงแนบข้อมูลรับรองไว้ แม้เวิร์กโฟลว์จะอ่านคีย์จากที่จัดเก็บของ n8n

manifest.yaml — Recipes แบบ Compose ของแพลตฟอร์มและโมเดล และการทำให้เป็นรูปธรรมที่เขียนการอ้างอิงตัวแปรของคีย์ลงในไฟล์ Compose ตามที่เขียน:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/support-agent
version: 0.1.0
spec:
mappings:
components:
type:
core/ai-agent/n8n: compose/n8n
core/ai-model/openai: compose/openai
features:
type:
core/secret-value: compose/dotenv-secret

.aggrega-import.json คือบันทึกของสิ่งที่การนำเข้าเขียน ซึ่ง aggrega import --sync ครั้งต่อมาอ่าน และ release.lock ปักหมุดเอนทิตีแค็ตตาล็อกทุกรายการที่ Release หาค่าไปถึง ด้วยเวอร์ชันและไดเจสต์

ตรวจสอบความถูกต้องและบิลด์

Terminal window
aggrega validate --release release.yaml
aggrega build --release release.yaml

Release ที่ร่างไว้เปิดอยู่ในตัวแก้ไขหลังตรวจสอบความถูกต้อง โดยเอาต์พุตของ Aggrega และการแจ้งเตือนต่างรายงานว่าไม่พบปัญหา

การบิลด์ Release ที่ร่างไว้: โฟลเดอร์ dist ปรากฏใน Explorer เอาต์พุตของ Aggrega แสดงไฟล์ Docker Compose ที่เขียน และการแจ้งเตือนบอกว่าเขียนไฟล์แล้ว

การตรวจสอบความถูกต้องพิมพ์:

notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)
release dependency validation passed: release.yaml (schema-pillar + dependency pillars)

และบิลด์ โดย <workspace> แทนโฟลเดอร์ที่เก็บฉบับร่าง:

warning: node "n8n" (provider "compose"): artifact "n8n-flow.compose-fragment.yaml": skipped provenance label injection — the fragment declares no compose service. Compose carries build provenance as service labels, so a fragment contributing only top-level networks, volumes or configs carries none; the services this component emits elsewhere carry the full set.
notice: LINT: Feature "core/secret-value" at core/secret-value:1.0.0 declares property "origin" in both values: and infra: pillars (path: origin)
[… omitted: a total build time, which differs per run]
Build completed: 1 file written to <workspace>/dist

บรรทัด warning เกี่ยวกับส่วนของไฟล์ Compose ที่บรรจุเวิร์กโฟลว์ ซึ่งเป็นรายการ configs ระดับบนสุดที่ไม่มีบริการให้ประทับป้ายกำกับของการบิลด์ บรรทัด notice เป็นข้อแนะนำ: Feature ข้อมูลลับรับ origin ได้จาก values ของ Aggregate หรือ infra ของ Release และบรรทัดนี้รายงานว่ามีค่าปลายทางหนึ่งค่าที่ประกาศไว้ทั้งสองที่ ทั้งสองบรรทัดไม่เปลี่ยนคำตัดสิน

dist/compose/docker-compose.yaml มี n8n และบริการที่นำเข้าเวิร์กโฟลว์ก่อน n8n เริ่มทำงาน:

services:
n8n:
image: n8nio/n8n:1.110.1
environment:
OPENAI_BASE_URL: https://api.openai.com/v1
OPENAI_API_KEY: ${OPENAI_API_KEY}
N8N_BLOCK_ENV_ACCESS_IN_NODE: "true"
ports:
- 127.0.0.1:5678:5678
[… omitted: the labels the build writes on every service, naming the Aggregate, the component, the environment and the compiler's version]
volumes:
- type: volume
source: n8n--data
target: /home/node/.n8n
networks:
- compose
depends_on:
n8n--import-flow:
condition: service_completed_successfully
[… omitted: the service's health check]
n8n--import-flow:
image: n8nio/n8n:1.110.1
command:
- import:workflow
- --input=/flows/workflow.json
entrypoint:
- n8n
[… omitted: the labels the build writes on every service]
volumes:
- type: volume
source: n8n--data
target: /home/node/.n8n
networks:
- compose
restart: "no"
configs:
- source: n8n-flow
target: /flows/workflow.json

เวิร์กโฟลว์เข้าถึง n8n ผ่าน n8n import:workflow ที่รันบนวอลุมข้อมูลเดียวกันทุกครั้งที่สแตกเริ่มทำงาน ก่อน n8n เอง N8N_BLOCK_ENV_ACCESS_IN_NODE เป็น "true" ซึ่งเป็นการปิดกั้นของ n8n ไม่ให้เวิร์กโฟลว์อ่านสภาพแวดล้อมของตน เพราะ Aggregate ตั้ง allow_env_access_in_nodes ไว้ที่ false โหนด OpenAI Chat Model จึงอ่านคีย์จากที่จัดเก็บข้อมูลรับรองของ n8n เอง เช่นเดียวกับที่ทริกเกอร์แชตอ่านผู้ใช้และรหัสผ่าน และการรันด้านล่างจัดเก็บทั้งสองอย่าง Recipe แบบ Compose ของ n8n เผยแพร่พอร์ตบนเครื่องของคุณเฉพาะเมื่อ Release ตั้ง published_port ใน infra ของ n8n และเผยแพร่บนที่อยู่ลูปแบ็ก 127.0.0.1 เท่านั้น หากไม่มี บริการจะเข้าถึงได้บนเครือข่ายของสแตกเท่านั้น

กับผู้ช่วย AI

ผู้ช่วย AI ที่ ตั้งค่าด้วยเครื่องมือของ Aggrega ทำสิ่งเดียวกันได้: วางพรอมต์นี้ลงไป

ใช้เครื่องมือของ Aggrega เท่านั้น และอย่าสร้างโฟลเดอร์เอง หากโฟลเดอร์ Workspace ยังไม่มีโฟลเดอร์ `import-n8n` ให้เรียกเครื่องมือ `draft` หนึ่งครั้งโดยตั้ง `example` เป็น `import-n8n` และไม่ระบุ `dir` เครื่องมือนี้จะเขียนตัวอย่างลงในโฟลเดอร์ `import-n8n` ใหม่ ซึ่งโฟลเดอร์ `source` ของโฟลเดอร์นั้นมีสิ่งที่หน้านี้นำเข้า จากนั้นเรียกเครื่องมือ `import` โดยตั้ง `workspace_root` เป็น `import-n8n/source` ตั้ง `source` เป็น `support-agent.json` และตั้ง `target` เป็น `compose` เครื่องมือนี้จะอ่านคำตอบที่ต้องใช้จาก `import-answers.yaml` ที่อยู่ข้าง `support-agent.json` เขียนฉบับร่างลงใน `import-n8n/source` และ pull สิ่งที่ฉบับร่างต้องใช้ จากนั้นเรียกเครื่องมือ `validate` โดยตั้ง `workspace_root` เป็น `import-n8n/source` และตั้ง `release` เป็น `release.yaml` และเรียกเครื่องมือ `build` โดยตั้ง `workspace_root` เป็น `import-n8n/source` ตั้ง `release` เป็น `release.yaml` และตั้ง `write` เป็น true บอกฉันว่าการบิลด์เขียนไฟล์ใดบ้าง ไฟล์เหล่านั้นอยู่ใน `import-n8n/source/dist/`

เปิดใน VS Code

เมื่อติดตั้ง ส่วนขยาย Aggrega สำหรับ Visual Studio Code แล้ว ให้เปิดโฟลเดอร์ import-n8n/source ใน VS Code ซึ่งเป็นที่ที่การนำเข้าเขียนฉบับร่าง โฟลเดอร์นี้มี Release หนึ่งรายการคือ release.yaml ที่ร่างไว้ ตัวแก้ไขจึงเลือกให้คุณ และตรวจสอบฉบับร่างเทียบกับ Release นั้นขณะที่คุณแก้ไข โดยทำเครื่องหมายสิ่งที่พบในไฟล์และในแผง Problems Aggrega: Show topology graph ใน Command Palette วาดส่วนประกอบของ Release และการเชื่อมต่อระหว่างส่วนประกอบเหล่านั้น Aggrega: Build, Aggrega: Preview build และ Aggrega: Pull ทำงานกับ Release เดียวกัน และแต่ละคำสั่งยังเป็นปุ่มบนแผง Commands ของมุมมอง Aggrega ในแถบกิจกรรมด้วย Build เขียนไฟล์ลงใน dist/ ของโฟลเดอร์ ใช้ Aggrega ใน Visual Studio Code ครอบคลุมส่วนที่เหลือ

วิธีรัน

n8n อ่านข้อมูลรับรองทั้งสองรายการที่เวิร์กโฟลว์เลือกจากที่จัดเก็บของตนเอง ตามตัวระบุ คือคีย์ OpenAI ภายใต้ Rb7nW2xQ9kT4mZ1c และผู้ใช้กับรหัสผ่านของแชตภายใต้ Vx3mQ8rLb2Nk7Tz5 บรรทัดคำสั่งของ n8n เองจัดเก็บข้อมูลรับรองเหล่านี้ภายใต้ตัวระบุเหล่านั้นจากไฟล์ เขียนลงใน credentials.json พร้อมค่าของคุณเอง:

[
{"id": "Rb7nW2xQ9kT4mZ1c", "name": "OpenAI account", "type": "openAiApi", "data": {"apiKey": "your OpenAI key"}},
{"id": "Vx3mQ8rLb2Nk7Tz5", "name": "Chat basic auth", "type": "httpBasicAuth", "data": {"user": "a user of your own", "password": "a password of your own"}}
]

ตั้งค่าคีย์ใน shell ของคุณตามที่ Release ที่ร่างไว้อ่าน แล้วเริ่มสแตก:

Terminal window
export OPENAI_API_KEY='your OpenAI key'
docker compose -p support-agent -f dist/compose/docker-compose.yaml up -d --wait

-p ระบุชื่อโปรเจกต์ ตามที่ขั้นตอนรันของ วิธีที่การนำเข้าทำงาน อธิบาย --wait คืนค่าเมื่อ n8n รายงานว่าสมบูรณ์ดี หลังจากบริการที่นำเข้าเวิร์กโฟลว์รันและออกแล้ว คัดลอกข้อมูลรับรองเข้าคอนเทนเนอร์ของ n8n นำเข้า แล้วลบสำเนา:

Terminal window
docker compose -p support-agent -f dist/compose/docker-compose.yaml exec -T n8n sh -c 'umask 077; cat > /tmp/credentials.json' < credentials.json
docker compose -p support-agent -f dist/compose/docker-compose.yaml exec n8n n8n import:credentials --input=/tmp/credentials.json
docker compose -p support-agent -f dist/compose/docker-compose.yaml exec n8n rm /tmp/credentials.json
[… omitted: n8n's notices about its settings file's permissions, error tracking and deprecated settings]
Successfully imported 2 credentials.

ตอนนี้ n8n เก็บข้อมูลรับรองทั้งสองรายการแล้ว จึงลบ credentials.json:

Terminal window
rm credentials.json

จากนั้นเปิดใช้งานเวิร์กโฟลว์ และรีสตาร์ท n8n เพื่อให้การเปิดใช้งานมีผล:

Terminal window
docker compose -p support-agent -f dist/compose/docker-compose.yaml exec n8n n8n update:workflow --id=sQ4vT8nKp2LmX7bR --active=true
docker compose -p support-agent -f dist/compose/docker-compose.yaml restart n8n

เมื่อ docker compose -p support-agent -f dist/compose/docker-compose.yaml ps n8n แสดง n8n เป็น (healthy) อีกครั้ง docker compose -p support-agent -f dist/compose/docker-compose.yaml logs n8n จะอ่านได้ว่า Activated workflow "Support agent" (ID: sQ4vT8nKp2LmX7bR)

ทดสอบ

เปิด http://127.0.0.1:5678 ที่อยู่ที่ published_port เผยแพร่ ตัวแก้ไขของ n8n จะขอบัญชีเจ้าของในการเข้าครั้งแรก แล้วแสดง Support agent

ทริกเกอร์แชตรับข้อความเฉพาะเมื่อมีผู้ใช้และรหัสผ่านที่จัดเก็บไว้ข้างต้น หากไม่มี จะตอบ HTTP/1.1 401 Unauthorized และ Authorization is required! และหากรหัสผ่านผิดจะตอบ HTTP/1.1 403 Forbidden เมื่อมีทั้งสองอย่างใน CHAT_USER และ CHAT_PASSWORD curl จะอ่านจากอินพุตมาตรฐาน จึงไม่ปรากฏในบรรทัดคำสั่งใดเลย:

Terminal window
printf 'user = "%s:%s"\n' "$CHAT_USER" "$CHAT_PASSWORD" | curl --config - -sS -i -X POST \
http://127.0.0.1:5678/webhook/a3c9e1f2-4b5d-4e6f-8a7b-9c0d1e2f3a04/chat -H 'Content-Type: application/json' \
-d '{"action": "sendMessage", "sessionId": "s1", "chatInput": "In one short sentence: what does a support plan cover?"}'
HTTP/1.1 500 Internal Server Error
[… omitted: the response's other headers]
{"message":"Error in workflow"}

การรันจัดเก็บค่าตัวแทนสำหรับคีย์ OpenAI เวิร์กโฟลว์จึงหยุดที่การเรียกโมเดล n8n เก็บการรันไว้ ซึ่งตัวแก้ไขแสดงรายการไว้ใต้การรันของเวิร์กโฟลว์ พร้อมการปฏิเสธจาก OpenAI: Incorrect API key provided: sk-place*****************-key. เมื่อใช้คีย์ของคุณ การตอบกลับคือ HTTP/1.1 200 OK และคำตอบของเอเจนต์ ในรูป {"output": "…"}

บน Kubernetes เมื่อนำการบิลด์ที่ บน Kubernetes อธิบายไปใช้แล้ว n8n เก็บข้อมูลไว้ในวอลุมที่อยู่ได้นานเท่า pod ของตน pod ใหม่จึงเริ่มโดยไม่มีสิ่งที่คุณจัดเก็บไว้ ให้จัดเก็บข้อมูลรับรองและเปิดใช้งานเวิร์กโฟลว์บนอินสแตนซ์ที่กำลังรันแทน เขียน credentials.json ตามที่ วิธีรัน ทำ นำเข้าผ่าน kubectl exec จากอินพุตมาตรฐาน ในเนมสเปซที่คุณนำไปใช้ แล้วลบทิ้งภายหลัง:

Terminal window
kubectl exec -i -n <namespace> deploy/n8n -- n8n import:credentials --input=/dev/stdin < credentials.json
Defaulted container "main" out of: main, import-flow (init)
[… omitted: n8n's notices about its settings file's permissions, error tracking and deprecated settings]
Successfully imported 2 credentials.

ส่งต่อพอร์ตภายในเครื่องไปยัง Service ของ n8n คือ n8n-default และปล่อยให้คำสั่งรันต่อไป:

Terminal window
kubectl port-forward -n <namespace> svc/n8n-default 5678:5678

จากเทอร์มินัลอื่น ตั้งค่าบัญชีเจ้าของผ่าน API ของ n8n ซึ่งจะลงชื่อเข้าใช้ให้คุณและเก็บเซสชันไว้ใน cookies.txt แล้วเปิดใช้งานเวิร์กโฟลว์:

Terminal window
curl -sS -c cookies.txt -X POST http://127.0.0.1:5678/rest/owner/setup -H 'Content-Type: application/json' \
-d '{"email": "owner@example.com", "firstName": "Your", "lastName": "Name", "password": "a password of your own"}'
curl -sS -b cookies.txt -X PATCH http://127.0.0.1:5678/rest/workflows/sQ4vT8nKp2LmX7bR \
-H 'Content-Type: application/json' -d '{"active": true}'

การตอบกลับที่สองคือเวิร์กโฟลว์ พร้อม "active":true ข้อความแชตข้างต้นจึงเข้าถึงเวิร์กโฟลว์ที่ที่อยู่เดิมโดยไม่เปลี่ยนแปลง การรันได้ {"message":"Error in workflow"} เหมือนเดิมและการปฏิเสธเดียวกันในการรัน

หยุดสแตกด้วยคำสั่งด้านล่าง -v ลบวอลุมข้อมูลของ n8n ด้วย และลบข้อมูลรับรองที่จัดเก็บไว้และการเปิดใช้งานไปพร้อมกัน:

Terminal window
docker compose -p support-agent -f dist/compose/docker-compose.yaml down -v

บน Kubernetes

เวิร์กโฟลว์เดียวกันนำเข้าสำหรับ Kubernetes ได้ด้วยเป้าหมาย helm ฉบับร่างสำหรับ Docker Compose อยู่ใน source แล้ว และการนำเข้าไม่เขียนทับ Aggregate ที่นั่นเลย จึงให้ร่างชุดนี้ลงในโฟลเดอร์ของตนเองด้วย --output-dir แล้วตรวจสอบความถูกต้องและบิลด์จากโฟลเดอร์นั้น:

Terminal window
aggrega import support-agent.json --target helm --output-dir helm
cd helm
aggrega validate --release release.yaml
aggrega build --release release.yaml

ฉบับร่างต่างกันตรงที่เป้าหมายต่างกัน Manifest แมปแพลตฟอร์มไปยัง helm/n8n โมเดลไปยัง helm/openai และคีย์ไปยัง helm/k8s-existing-secret ซึ่งอ่านคีย์จาก Secret ที่มีอยู่แล้วในเนมสเปซ Release แนบคีย์เป็น core/referenced-secret โดยระบุ Secret นั้นคือ openai-api-key จากไฟล์คำตอบ

การบิลด์เขียนแมนิเฟสต์ Kubernetes ธรรมดาไว้ใต้ dist/helm/ ที่รูทของพื้นที่ทำงานคือ source ซึ่งจาก helm คือ ../dist/helm/ สร้าง Secret ในเนมสเปซที่คุณนำไปใช้ โดยเก็บคีย์ไว้ใต้คีย์ข้อมูล value แล้วนำโฟลเดอร์ไปใช้ตามที่ขั้นตอนรันของ วิธีที่การนำเข้าทำงาน อธิบาย เวิร์กโฟลว์ยังอ่านข้อมูลรับรองจากที่จัดเก็บของ n8n เอง ซึ่ง ทดสอบ เติมบน Kubernetes