تخطَّ إلى المحتوى
AggregaAggregaAggregaAggrega
اختر لغة: العربية
تُرجمت هذه الصفحة آليًا. اقرأ الأصل الإنجليزي.

استيراد سير عمل n8n

يستورد هذا الشرح العملي سير عمل مصدَّرًا من n8n — وكيل ذكاء اصطناعي يجيب عن رسائل الدردشة بنموذج دردشة من OpenAI وذاكرة — إلى Aggregate و Release و Manifest تبني معًا n8n حاملًا سير العمل من أجل Docker Compose كما هي مكتوبة، ثم يبنيها ويشغّل النتيجة. يأتي كل ملف وكل كتلة إخراج أدناه من تشغيل فعلي؛ ويوجد سير العمل وكل مرحلة من مراحل الشرح العملي في المثال import-n8n، حيث يعيد نص فحص برمجي تشغيل الاستيراد، ويقارن ما يكتبه وما يطبعه والكتل التي تنقلها هذه الصفحة بالملفات المحفوظة هناك، ويتحقق مما كتبه الاستيراد ويبنيه.

صُغ مسودة المثال

يمكنك تشغيل هذا الاستيراد بالأوامر الواردة في هذه الصفحة، أو اجعل مساعد الذكاء الاصطناعي يشغّله نيابةً عنك.

اكتب المثال في مجلد جديد يحمل اسمه:

Terminal window
aggrega draft --example import-n8n

ثم يطبع الأوامر التي تُشغَّل بعد ذلك. يدخل الأول إلى المجلد الجديد؛ ويدخل الذي يليه، أدناه، إلى مجلد source الخاص به، الذي يحوي ما تستورده هذه الصفحة وهو المكان الذي يجري فيه الاستيراد:

Terminal window
cd import-n8n

مجلد source للمثال المصوغ مفتوحًا في Visual Studio Code، ويعرض تصدير سير عمل n8n لوكيل دعم، يبدأ بعقدتي chat trigger و AI Agent.

سير العمل

يحتوي support-agent.json، المكتوب لهذا الشرح العملي بالشكل الذي يصدّر به n8n سير العمل، على أربع عقد: عقدة chat trigger، وعقدة AI Agent برسالة نظام قصيرة، وعقدة OpenAI Chat Model تختار gpt-4o-mini، وعقدة Simple Memory، موصولة بالاتصالات التي يسردها n8n باسم العقدة التي يخرج منها كل اتصال. عقدة chat trigger عامة، فرسالة دردشة تُرسل إلى عنوان URL الخاص بها تبدأ سير العمل، وهي تطلب من المرسل اسم مستخدم وكلمة مرور، وتتحقق منهما مقابل بيانات اعتماد مصادقة أساسية يخزنها 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"
}
}

بجانب سير العمل، يجعل ملف .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 الإجابات عن كل ما لا يستطيع أي سير عمل حمله. لا يحتاج استيراد من أجل 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 الخاصة بها. لا تسمّي مساحة العمل أي مجلد كتالوج، لذا يقرأ الاستيراد كتالوج المكتبة القياسية من registry الذي يجلب منه مستورِده: لقطة موقَّعة للكتالوج المطروح، تُجلب وتُتحقق وتُحفظ في ذاكرة التخزين المؤقت لمحتوى مساحة العمل عند أول استيراد، ويسمّيها ملخّصها في الملف الذي يسجّل ما كتبه الاستيراد بجانب مسوداته. وتُستورد مساحة العمل التي تسمّي مجلدات كتالوج خاصة بها — في 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 لا يسأل عنه هذا الاستيراد: فهو لا يترك له شيئًا فارغًا، لذا لا يطبّق أي إجابة ويترك الملف كما هو.

ما يكتبه

يُسمّى كل من 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 نفسه، كما يقرأ chat trigger اسم المستخدم وكلمة المرور، ويخزنهما التشغيل أدناه معًا. ولا يطرح Recipe Compose الخاص بمنصة n8n منفذًا على جهازك إلا حيث يضبط Release قيمة published_port في infra الذي يخص المنصة، ثم على عنوان الحلقة الراجعة، 127.0.0.1، وحده؛ ودونه لا يُوصل إلى الخدمة إلا على شبكة المكدس.

مع مساعد الذكاء الاصطناعي

يستطيع مساعد الذكاء الاصطناعي المُعَدّ بأدوات Aggrega أن يفعل الشيء نفسه: الصق هذا الموجِّه فيه.

استخدم أدوات Aggrega فقط، ولا تنشئ أي مجلد بنفسك. إذا كان مجلد مساحة العمل لا يحتوي بعد على مجلد `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، في لوحة الأوامر، مكوِّنات 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.

لا يقبل chat trigger رسالة إلا مع اسم المستخدم وكلمة المرور المخزنين أعلاه؛ وبدونهما يجيب 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

من طرفية أخرى، أنشئ حساب المالك عبر واجهة 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.