@andreswagner/node-red-contrib-wxo-agent 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +178 -0
- package/README.md +388 -0
- package/WxO.svg +31 -0
- package/nodes/lib/token-manager.js +119 -0
- package/nodes/lib/wxo-client.js +166 -0
- package/nodes/wxo-agent/icons/WxO.svg +31 -0
- package/nodes/wxo-agent/icons/watsonxOrchestrate.svg +1 -0
- package/nodes/wxo-agent/icons/wxo-icon.svg +5 -0
- package/nodes/wxo-agent/wxo-agent.html +157 -0
- package/nodes/wxo-agent/wxo-agent.js +188 -0
- package/nodes/wxo-credentials/wxo-credentials.html +47 -0
- package/nodes/wxo-credentials/wxo-credentials.js +20 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(which shall not include Communications that are clearly marked or
|
|
39
|
+
otherwise designated in writing by the copyright owner as "Not a Work").
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is clearly marked or otherwise designated
|
|
61
|
+
in writing by the copyright owner as "Not a Contribution".
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed as
|
|
122
|
+
modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# node-red-contrib-wxo-agent
|
|
2
|
+
|
|
3
|
+
Node-RED node for invoking IBM watsonx Orchestrate agents. Easily integrate AI orchestration capabilities into your Node-RED flows with support for multi-turn conversations and flexible input formats.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install from npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install node-red-contrib-wxo-agent
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install via Node-RED's Manage Palette:
|
|
14
|
+
1. Open Node-RED
|
|
15
|
+
2. Go to ☰ → Manage palette
|
|
16
|
+
3. Search for `node-red-contrib-wxo-agent`
|
|
17
|
+
4. Click Install
|
|
18
|
+
|
|
19
|
+
After installation, restart Node-RED to load the new nodes.
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
1. **Install the package** (see Installation above)
|
|
24
|
+
2. **Add credentials**: Drag the WxO Agent node to your flow, edit it, and configure your IBM Cloud API Key and Watson Orchestrate instance URL
|
|
25
|
+
3. **Select an agent**: The agent dropdown will populate automatically
|
|
26
|
+
4. **Send a message**: Use `msg.payload = "Hello"` to send a simple message
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### 1. Configure Credentials
|
|
31
|
+
|
|
32
|
+
1. Drag the **WxO Agent** node onto your flow
|
|
33
|
+
2. Double-click to edit
|
|
34
|
+
3. Click the pencil icon next to Credentials to add new credentials
|
|
35
|
+
4. Enter your IBM Cloud API Key
|
|
36
|
+
5. Enter your Watson Orchestrate API URL (full instance URL, e.g., `https://api.us-south.watson-orchestrate.cloud.ibm.com/instances/your-instance-id`)
|
|
37
|
+
|
|
38
|
+
### 2. Select an Agent
|
|
39
|
+
|
|
40
|
+
After configuring credentials, the Agent dropdown will automatically populate with available agents. Click the refresh button to reload the list.
|
|
41
|
+
|
|
42
|
+
### 3. Send Messages
|
|
43
|
+
|
|
44
|
+
You can send messages in two formats:
|
|
45
|
+
|
|
46
|
+
**Simple string** (recommended for basic use):
|
|
47
|
+
```javascript
|
|
48
|
+
msg.payload = "What can you help me with?";
|
|
49
|
+
return msg;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Full API request object** (for advanced use with additional parameters):
|
|
53
|
+
```javascript
|
|
54
|
+
msg.payload = {
|
|
55
|
+
"messages": [
|
|
56
|
+
{
|
|
57
|
+
"role": "user",
|
|
58
|
+
"content": "Hello"
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"additional_parameters": {
|
|
62
|
+
"id": 4013386960470016
|
|
63
|
+
},
|
|
64
|
+
"context": {
|
|
65
|
+
"id": 4234274192490496
|
|
66
|
+
},
|
|
67
|
+
"stream": false
|
|
68
|
+
};
|
|
69
|
+
return msg;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4. Multi-turn Conversations
|
|
73
|
+
|
|
74
|
+
The node outputs `msg.topic` with the thread ID, which is automatically used in subsequent messages to continue the conversation:
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
// First message starts a new conversation
|
|
78
|
+
msg.payload = "Hello";
|
|
79
|
+
return msg;
|
|
80
|
+
|
|
81
|
+
// Subsequent messages use the thread ID from msg.topic
|
|
82
|
+
msg.payload = "Tell me more";
|
|
83
|
+
// msg.topic is automatically preserved for conversation continuity
|
|
84
|
+
return msg;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
To force a new conversation:
|
|
88
|
+
```javascript
|
|
89
|
+
msg.wxo_new_session = true;
|
|
90
|
+
msg.payload = "Start fresh";
|
|
91
|
+
return msg;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Example Flows
|
|
95
|
+
|
|
96
|
+
### Multi-turn Conversation Example
|
|
97
|
+
|
|
98
|
+
This example demonstrates a complete multi-turn conversation with automatic thread ID preservation and error handling.
|
|
99
|
+
|
|
100
|
+
**To use this flow:**
|
|
101
|
+
|
|
102
|
+
1. Copy the flow JSON below
|
|
103
|
+
2. In Node-RED, go to ☰ → Import
|
|
104
|
+
3. Paste the JSON and click "Import"
|
|
105
|
+
4. Configure the flow:
|
|
106
|
+
- Edit each **WxO Agent** node
|
|
107
|
+
- Replace `YOUR_CREDENTIALS_ID` with your actual credentials configuration ID
|
|
108
|
+
- Replace `YOUR_AGENT_ID` with your agent ID
|
|
109
|
+
- Update `Your Agent Name` with your agent's display name
|
|
110
|
+
5. Deploy and click the **Start Conversation** inject button
|
|
111
|
+
|
|
112
|
+
**What this flow demonstrates:**
|
|
113
|
+
- Simple string input to start a conversation
|
|
114
|
+
- Automatic thread ID preservation in `msg.topic` for conversation continuity
|
|
115
|
+
- Multi-turn conversation where the agent remembers context from previous messages
|
|
116
|
+
- Error handling with a Catch node
|
|
117
|
+
- Debug output showing just the agent's response text
|
|
118
|
+
|
|
119
|
+
**Flow JSON:**
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
[
|
|
123
|
+
{
|
|
124
|
+
"id": "flow-example-1",
|
|
125
|
+
"type": "tab",
|
|
126
|
+
"label": "WxO Agent Example - Multi-turn Conversation",
|
|
127
|
+
"disabled": false,
|
|
128
|
+
"info": "Example flow demonstrating multi-turn conversation with thread ID preservation",
|
|
129
|
+
"env": []
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "inject-1",
|
|
133
|
+
"type": "inject",
|
|
134
|
+
"z": "flow-example-1",
|
|
135
|
+
"name": "Start Conversation",
|
|
136
|
+
"props": [{"p": "payload"}],
|
|
137
|
+
"repeat": "",
|
|
138
|
+
"crontab": "",
|
|
139
|
+
"once": false,
|
|
140
|
+
"onceDelay": 0.1,
|
|
141
|
+
"topic": "",
|
|
142
|
+
"payload": "Hi, my name is Bob!",
|
|
143
|
+
"payloadType": "str",
|
|
144
|
+
"x": 140,
|
|
145
|
+
"y": 100,
|
|
146
|
+
"wires": [["wxo-agent-1"]]
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"id": "wxo-agent-1",
|
|
150
|
+
"type": "wxo-agent",
|
|
151
|
+
"z": "flow-example-1",
|
|
152
|
+
"name": "WxO Agent",
|
|
153
|
+
"wxoCredentials": "YOUR_CREDENTIALS_ID",
|
|
154
|
+
"agentId": "YOUR_AGENT_ID",
|
|
155
|
+
"agentName": "Your Agent Name",
|
|
156
|
+
"timeout": 30000,
|
|
157
|
+
"x": 350,
|
|
158
|
+
"y": 100,
|
|
159
|
+
"wires": [["debug-1", "function-1"]]
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"id": "debug-1",
|
|
163
|
+
"type": "debug",
|
|
164
|
+
"z": "flow-example-1",
|
|
165
|
+
"name": "Agent Response",
|
|
166
|
+
"active": true,
|
|
167
|
+
"tosidebar": true,
|
|
168
|
+
"console": false,
|
|
169
|
+
"tostatus": false,
|
|
170
|
+
"complete": "payload.choices[0].message.content",
|
|
171
|
+
"targetType": "msg",
|
|
172
|
+
"statusVal": "",
|
|
173
|
+
"statusType": "auto",
|
|
174
|
+
"x": 550,
|
|
175
|
+
"y": 100,
|
|
176
|
+
"wires": []
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"id": "function-1",
|
|
180
|
+
"type": "function",
|
|
181
|
+
"z": "flow-example-1",
|
|
182
|
+
"name": "Continue Conversation",
|
|
183
|
+
"func": "// msg.topic contains the thread ID from the previous response\n// This is automatically preserved for conversation continuity\nmsg.payload = \"What's my name?\";\nreturn msg;",
|
|
184
|
+
"outputs": 1,
|
|
185
|
+
"timeout": 0,
|
|
186
|
+
"noerr": 0,
|
|
187
|
+
"initialize": "",
|
|
188
|
+
"finalize": "",
|
|
189
|
+
"libs": [],
|
|
190
|
+
"x": 200,
|
|
191
|
+
"y": 180,
|
|
192
|
+
"wires": [["wxo-agent-2"]]
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"id": "wxo-agent-2",
|
|
196
|
+
"type": "wxo-agent",
|
|
197
|
+
"z": "flow-example-1",
|
|
198
|
+
"name": "WxO Agent",
|
|
199
|
+
"wxoCredentials": "YOUR_CREDENTIALS_ID",
|
|
200
|
+
"agentId": "YOUR_AGENT_ID",
|
|
201
|
+
"agentName": "Your Agent Name",
|
|
202
|
+
"timeout": 30000,
|
|
203
|
+
"x": 350,
|
|
204
|
+
"y": 180,
|
|
205
|
+
"wires": [["debug-2"]]
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"id": "debug-2",
|
|
209
|
+
"type": "debug",
|
|
210
|
+
"z": "flow-example-1",
|
|
211
|
+
"name": "Follow-up Response",
|
|
212
|
+
"active": true,
|
|
213
|
+
"tosidebar": true,
|
|
214
|
+
"console": false,
|
|
215
|
+
"tostatus": false,
|
|
216
|
+
"complete": "payload.choices[0].message.content",
|
|
217
|
+
"targetType": "msg",
|
|
218
|
+
"statusVal": "",
|
|
219
|
+
"statusType": "auto",
|
|
220
|
+
"x": 570,
|
|
221
|
+
"y": 180,
|
|
222
|
+
"wires": []
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"id": "catch-1",
|
|
226
|
+
"type": "catch",
|
|
227
|
+
"z": "flow-example-1",
|
|
228
|
+
"name": "Error Handler",
|
|
229
|
+
"scope": ["wxo-agent-1", "wxo-agent-2"],
|
|
230
|
+
"uncaught": false,
|
|
231
|
+
"x": 350,
|
|
232
|
+
"y": 260,
|
|
233
|
+
"wires": [["debug-error"]]
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"id": "debug-error",
|
|
237
|
+
"type": "debug",
|
|
238
|
+
"z": "flow-example-1",
|
|
239
|
+
"name": "Error Output",
|
|
240
|
+
"active": true,
|
|
241
|
+
"tosidebar": true,
|
|
242
|
+
"console": false,
|
|
243
|
+
"tostatus": false,
|
|
244
|
+
"complete": "error",
|
|
245
|
+
"targetType": "msg",
|
|
246
|
+
"statusVal": "",
|
|
247
|
+
"statusType": "auto",
|
|
248
|
+
"x": 550,
|
|
249
|
+
"y": 260,
|
|
250
|
+
"wires": []
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Note:** The `msg.topic` property is automatically set by the WxO Agent node with the thread ID from the API response. When you pass `msg` to the next agent node, the thread ID is automatically preserved, enabling conversation continuity. The function node in this example demonstrates this - it receives the message with `msg.topic` already set and simply updates the payload for the follow-up question.
|
|
256
|
+
|
|
257
|
+
## Input
|
|
258
|
+
|
|
259
|
+
| Property | Type | Description |
|
|
260
|
+
|----------|------|-------------|
|
|
261
|
+
| `payload` | string/object | Message to send to the agent. Can be:<br>- Simple string (e.g., `"Hello"`)<br>- Full API request object with `messages` array (see official API docs) |
|
|
262
|
+
| `topic` | string | (Optional) Thread ID for conversation continuation |
|
|
263
|
+
| `wxo_new_session` | boolean | (Optional) Force new conversation |
|
|
264
|
+
|
|
265
|
+
## Output
|
|
266
|
+
|
|
267
|
+
| Property | Type | Description |
|
|
268
|
+
|----------|------|-------------|
|
|
269
|
+
| `payload` | object | Full API response object (OpenAI-compatible format) |
|
|
270
|
+
| `topic` | string | Thread ID for conversation continuation |
|
|
271
|
+
|
|
272
|
+
The `payload` object is the complete API response and includes:
|
|
273
|
+
- `id`: string - Unique response identifier
|
|
274
|
+
- `object`: string - Response type (e.g., "chat.completion")
|
|
275
|
+
- `created`: number - Unix timestamp
|
|
276
|
+
- `model`: string - Model used for response
|
|
277
|
+
- `choices`: array - Response choices containing:
|
|
278
|
+
- `message`: object with `role` and `content` (the agent's response text)
|
|
279
|
+
- `finish_reason`: string
|
|
280
|
+
- `thread_id`: string - Conversation thread ID for multi-turn
|
|
281
|
+
|
|
282
|
+
Access the agent's response text via: `msg.payload.choices[0].message.content`
|
|
283
|
+
|
|
284
|
+
## Error Handling
|
|
285
|
+
|
|
286
|
+
On error, the node outputs:
|
|
287
|
+
|
|
288
|
+
```javascript
|
|
289
|
+
msg.error = {
|
|
290
|
+
code: "ERROR_CODE",
|
|
291
|
+
message: "Human readable message",
|
|
292
|
+
details: { /* API response */ },
|
|
293
|
+
recoverable: true/false
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Use a Catch node to handle errors in your flow.
|
|
298
|
+
|
|
299
|
+
## Features
|
|
300
|
+
|
|
301
|
+
- ✅ Simple string or full API request object input
|
|
302
|
+
- ✅ Automatic authentication with IBM Cloud IAM
|
|
303
|
+
- ✅ Multi-turn conversation support via `msg.topic`
|
|
304
|
+
- ✅ Agent selection from dropdown
|
|
305
|
+
- ✅ Comprehensive error handling
|
|
306
|
+
- ✅ OpenAI-compatible response format
|
|
307
|
+
|
|
308
|
+
## Requirements
|
|
309
|
+
|
|
310
|
+
- Node-RED 3.0.0 or higher
|
|
311
|
+
- Node.js 18.0.0 or higher
|
|
312
|
+
- IBM Cloud account with watsonx Orchestrate access
|
|
313
|
+
- Valid IBM Cloud API Key
|
|
314
|
+
|
|
315
|
+
## Development
|
|
316
|
+
|
|
317
|
+
For developers contributing to this package:
|
|
318
|
+
|
|
319
|
+
### Running Tests
|
|
320
|
+
|
|
321
|
+
1. Copy the environment template:
|
|
322
|
+
```bash
|
|
323
|
+
cp .env.example .env
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
2. Edit `.env` with your actual credentials:
|
|
327
|
+
```
|
|
328
|
+
# Required for API integration tests
|
|
329
|
+
IBM_CLOUD_API_KEY=your-api-key
|
|
330
|
+
WXO_BASE_URL=https://api.us-south.watson-orchestrate.cloud.ibm.com/instances/your-instance-id
|
|
331
|
+
|
|
332
|
+
# Optional: Required only for NPM publication testing (T031)
|
|
333
|
+
NPM_USERNAME=your-npm-username
|
|
334
|
+
NPM_TOKEN=your-npm-token
|
|
335
|
+
# NPM_REGISTRY=https://registry.npmjs.org/ # Optional: if using private registry
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
3. Run the tests:
|
|
339
|
+
```bash
|
|
340
|
+
npm install
|
|
341
|
+
npm test
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Test Structure
|
|
345
|
+
|
|
346
|
+
The test suite includes:
|
|
347
|
+
|
|
348
|
+
- **Unit Tests** (`tests/unit/`): Component/library tests for underlying logic
|
|
349
|
+
- Token manager, API client, input parsing, etc.
|
|
350
|
+
- These test the core functionality without Node-RED runtime
|
|
351
|
+
|
|
352
|
+
- **Integration Tests** (`tests/integration/`): Node-RED node tests using `node-red-node-test-helper`
|
|
353
|
+
- Test the actual node behavior in Node-RED runtime
|
|
354
|
+
- Create test flows and assert node properties and output
|
|
355
|
+
- Follow Node-RED's recommended testing approach
|
|
356
|
+
|
|
357
|
+
The tests use real API calls to verify functionality. Tests will skip gracefully if credentials are not configured.
|
|
358
|
+
|
|
359
|
+
### NPM Publication
|
|
360
|
+
|
|
361
|
+
For instructions on testing and publishing the package to NPM, see [NPM_PUBLICATION.md](./NPM_PUBLICATION.md).
|
|
362
|
+
|
|
363
|
+
Quick verification:
|
|
364
|
+
```bash
|
|
365
|
+
# Setup package metadata (author and repository) - auto-detects from git
|
|
366
|
+
npm run setup-metadata
|
|
367
|
+
|
|
368
|
+
# Verify NPM publication requirements
|
|
369
|
+
npm run verify-npm
|
|
370
|
+
|
|
371
|
+
# Verify Node-RED Library requirements (includes LICENSE, author, repository)
|
|
372
|
+
npm run verify-library
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**Important**: After publishing to NPM, register your node with the [Node-RED Flow Library](https://flows.nodered.org/add/node) to make it discoverable in Node-RED's Manage Palette.
|
|
376
|
+
|
|
377
|
+
## Support
|
|
378
|
+
|
|
379
|
+
For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/your-username/node-red-contrib-wxo-agent) (update with actual repository URL when available).
|
|
380
|
+
|
|
381
|
+
## License
|
|
382
|
+
|
|
383
|
+
Apache-2.0
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
**Note**: This package is published to npm as `node-red-contrib-wxo-agent`. For development installation from a local path, see the Development section above.
|
|
388
|
+
|
package/WxO.svg
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<svg id="watsonxOrchestrate" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 32 32">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="91vs45zuba" x1="-1255.959" y1="-5638.355" x2="-1255.959" y2="-5630.355" gradientTransform="matrix(1 0 0 -1 1259.459 -5613.355)" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop offset="0" stop-opacity="0"/>
|
|
5
|
+
<stop offset=".83"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="q8jdu6hf5b" x1="-1236.667" y1="-5652.015" x2="-1239.915" y2="-5646.39" gradientTransform="matrix(1 0 0 -1 1255.541 -5629.251)" gradientUnits="userSpaceOnUse">
|
|
8
|
+
<stop offset="0" stop-opacity="0"/>
|
|
9
|
+
<stop offset=".7"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
<linearGradient id="1ai661jxzc" x1="-1817.959" y1="-1524.355" x2="-1817.959" y2="-1516.355" gradientTransform="matrix(1 0 0 -1 1846.459 -1509.355)" xlink:href="#91vs45zuba"/>
|
|
12
|
+
<linearGradient id="ho9vmd9vod" x1="-1798.667" y1="-1538.015" x2="-1801.915" y2="-1532.39" gradientTransform="matrix(-1 0 0 1 -1785.541 1547.251)" xlink:href="#q8jdu6hf5b"/>
|
|
13
|
+
<linearGradient id="7wtfcdzjif" x1="0" y1="32" x2="32" y2="0" gradientUnits="userSpaceOnUse">
|
|
14
|
+
<stop offset=".1" stop-color="#a56eff"/>
|
|
15
|
+
<stop offset=".9" stop-color="#0f62fe"/>
|
|
16
|
+
</linearGradient>
|
|
17
|
+
<mask id="blf0dpbsne" x="0" y="0" width="32" height="32" maskUnits="userSpaceOnUse">
|
|
18
|
+
<path d="M30.851 14H28.83C27.863 7.78 22.487 3 16 3 11.38 3 7.326 5.429 5.02 9.07A7.939 7.939 0 0 1 9 8c3.719 0 6.845 2.555 7.737 6H14.65c-.826-2.327-3.043-4-5.65-4a5.958 5.958 0 0 0-4.78 2.407l-2.525-.842C3.591 5.456 9.275 1 16 1c7.591 0 13.868 5.674 14.851 13zm-3.071 5.593A5.957 5.957 0 0 1 23 22c-2.607 0-4.824-1.673-5.65-4h-2.087c.892 3.445 4.017 6 7.737 6a7.941 7.941 0 0 0 3.98-1.07C24.674 26.571 20.62 29 16 29 9.513 29 4.137 24.22 3.17 18H1.149C2.132 25.326 8.408 31 16 31c6.725 0 12.409-4.456 14.305-10.565l-2.525-.842z" style="fill:#fff;stroke-width:0"/>
|
|
19
|
+
<path style="fill:url(#91vs45zuba);stroke-width:0" d="M0 17h7v8H0z"/>
|
|
20
|
+
<path style="fill:url(#q8jdu6hf5b);stroke-width:0" d="M21 17.5h-6V25l6-3.5v-4z"/>
|
|
21
|
+
<path transform="rotate(-180 28.5 11)" style="fill:url(#1ai661jxzc);stroke-width:0" d="M25 7h7v8h-7z"/>
|
|
22
|
+
<path style="fill:url(#ho9vmd9vod);stroke-width:0" d="M11 14.5h6V7l-6 3.5v4z"/>
|
|
23
|
+
</mask>
|
|
24
|
+
</defs>
|
|
25
|
+
<g style="mask:url(#blf0dpbsne)">
|
|
26
|
+
<path style="fill:url(#7wtfcdzjif);stroke-width:0" d="M0 0h32v32H0z"/>
|
|
27
|
+
</g>
|
|
28
|
+
<circle cx="30" cy="16" r="2" style="fill:#001d6c;stroke-width:0"/>
|
|
29
|
+
<circle cx="2" cy="16" r="2" style="fill:#001d6c;stroke-width:0"/>
|
|
30
|
+
<circle cx="16" cy="16" r="2" style="fill:#001d6c;stroke-width:0"/>
|
|
31
|
+
</svg>
|