fix: Chatbot-Workflows korrigiert und Memory-Bug behoben
- Inline SQL-Expressions statt queryParams (Postgres-Node-Kompatibilität) - CTE-Query garantiert immer eine Zeile (verhindert Abbruch bei neuer Session) - Delete-Workflow ebenfalls auf inline SQL umgestellt Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
60143b8061
commit
a14ea92dad
3 changed files with 15 additions and 21 deletions
|
|
@ -27,8 +27,8 @@
|
|||
"position": [300, 300],
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "SETUP_REQUIRED",
|
||||
"name": "n8n PostgreSQL"
|
||||
"id": "pnmeNZ3ONDWrQP8M",
|
||||
"name": "Postgres account"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -19,10 +19,8 @@
|
|||
{
|
||||
"parameters": {
|
||||
"operation": "executeQuery",
|
||||
"query": "DELETE FROM chat_sessions WHERE session_id = $1 RETURNING session_id",
|
||||
"additionalFields": {
|
||||
"queryParams": "={{ JSON.stringify([$json.body.session_id]) }}"
|
||||
}
|
||||
"query": "=DELETE FROM chat_sessions WHERE session_id = '{{ $json.body.session_id }}' RETURNING session_id",
|
||||
"additionalFields": {}
|
||||
},
|
||||
"id": "node-pg-004",
|
||||
"name": "Delete Session",
|
||||
|
|
@ -31,8 +29,8 @@
|
|||
"position": [300, 300],
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "SETUP_REQUIRED",
|
||||
"name": "n8n PostgreSQL"
|
||||
"id": "pnmeNZ3ONDWrQP8M",
|
||||
"name": "Postgres account"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -29,10 +29,8 @@
|
|||
{
|
||||
"parameters": {
|
||||
"operation": "executeQuery",
|
||||
"query": "SELECT messages FROM chat_sessions WHERE session_id = $1",
|
||||
"additionalFields": {
|
||||
"queryParams": "={{ JSON.stringify([$json.session_id]) }}"
|
||||
}
|
||||
"query": "=WITH ensure AS (INSERT INTO chat_sessions (session_id, messages) VALUES ('{{ $json.session_id }}', '[]') ON CONFLICT (session_id) DO NOTHING) SELECT COALESCE(messages, '[]'::jsonb) AS messages FROM chat_sessions WHERE session_id = '{{ $json.session_id }}'",
|
||||
"additionalFields": {}
|
||||
},
|
||||
"id": "node-pg-001",
|
||||
"name": "Load History",
|
||||
|
|
@ -41,8 +39,8 @@
|
|||
"position": [500, 300],
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "SETUP_REQUIRED",
|
||||
"name": "n8n PostgreSQL"
|
||||
"id": "pnmeNZ3ONDWrQP8M",
|
||||
"name": "Postgres account"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -74,7 +72,7 @@
|
|||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "const build = $('Build Messages').first().json;\nconst resp = $input.first().json;\nconst answer = resp.message.content;\nconst updatedMessages = [...build.messages, { role: 'assistant', content: answer }];\nreturn [{ json: { session_id: build.session_id, messages: updatedMessages, answer, model: resp.model } }];"
|
||||
"jsCode": "const build = $('Build Messages').first().json;\nconst resp = $input.first().json;\nconst answer = resp.message.content;\nconst updatedMessages = [...build.messages, { role: 'assistant', content: answer }];\nconst m = JSON.stringify(updatedMessages).replace(/'/g, \"''\");\nconst upsert_query = `INSERT INTO chat_sessions (session_id, messages, updated_at) VALUES ('${build.session_id}', '${m}'::jsonb, NOW()) ON CONFLICT (session_id) DO UPDATE SET messages = '${m}'::jsonb, updated_at = NOW()`;\nreturn [{ json: { session_id: build.session_id, answer, model: resp.model, upsert_query } }];"
|
||||
},
|
||||
"id": "node-cd-003",
|
||||
"name": "Append Response",
|
||||
|
|
@ -85,10 +83,8 @@
|
|||
{
|
||||
"parameters": {
|
||||
"operation": "executeQuery",
|
||||
"query": "INSERT INTO chat_sessions (session_id, messages, updated_at) VALUES ($1, $2::jsonb, NOW()) ON CONFLICT (session_id) DO UPDATE SET messages = $2::jsonb, updated_at = NOW()",
|
||||
"additionalFields": {
|
||||
"queryParams": "={{ JSON.stringify([$json.session_id, JSON.stringify($json.messages)]) }}"
|
||||
}
|
||||
"query": "={{ $json.upsert_query }}",
|
||||
"additionalFields": {}
|
||||
},
|
||||
"id": "node-pg-002",
|
||||
"name": "Save History",
|
||||
|
|
@ -97,8 +93,8 @@
|
|||
"position": [1300, 300],
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "SETUP_REQUIRED",
|
||||
"name": "n8n PostgreSQL"
|
||||
"id": "pnmeNZ3ONDWrQP8M",
|
||||
"name": "Postgres account"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue