@ekai/contexto 0.1.6 → 0.1.8
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/package.json +1 -1
- package/src/index.ts +59 -11
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -60,7 +60,7 @@ function buildPayload(
|
|
|
60
60
|
const webhookPlugin = {
|
|
61
61
|
id: 'contexto',
|
|
62
62
|
name: 'Mind Map',
|
|
63
|
-
description: '
|
|
63
|
+
description: 'can we say "context engine for openclaw with mindmap',
|
|
64
64
|
|
|
65
65
|
configSchema: {
|
|
66
66
|
type: 'object',
|
|
@@ -120,24 +120,72 @@ const webhookPlugin = {
|
|
|
120
120
|
api.on('llm_output', async (event: any, ctx: any) => {
|
|
121
121
|
if (!config.apiKey) return;
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
const sessionKey = ctx?.sessionKey || 'unknown';
|
|
123
|
+
const sessionKey = event?.sessionKey || ctx?.sessionKey || 'unknown';
|
|
125
124
|
|
|
126
125
|
const payload = buildPayload(
|
|
127
|
-
'llm',
|
|
128
|
-
'output',
|
|
126
|
+
'llm',
|
|
127
|
+
'output',
|
|
129
128
|
sessionKey,
|
|
130
129
|
{
|
|
131
|
-
model: event?.model,
|
|
130
|
+
model: event?.context?.model,
|
|
132
131
|
usage: {
|
|
133
|
-
prompt_tokens: event?.usage?.promptTokens,
|
|
134
|
-
completion_tokens: event?.usage?.completionTokens,
|
|
135
|
-
total_tokens: event?.usage?.totalTokens
|
|
136
|
-
}
|
|
132
|
+
prompt_tokens: event?.context?.usage?.promptTokens,
|
|
133
|
+
completion_tokens: event?.context?.usage?.completionTokens,
|
|
134
|
+
total_tokens: event?.context?.usage?.totalTokens,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
undefined,
|
|
138
|
+
{
|
|
139
|
+
content: event,
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
sendWebhook(config, payload, logger);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// --- Agent turn completed ---
|
|
147
|
+
api.on('agent_end', async (event: any, ctx: any) => {
|
|
148
|
+
if (!config.apiKey) return;
|
|
149
|
+
|
|
150
|
+
const sessionKey = event?.sessionKey || ctx?.sessionKey || 'unknown';
|
|
151
|
+
|
|
152
|
+
const payload = buildPayload(
|
|
153
|
+
'agent',
|
|
154
|
+
'end',
|
|
155
|
+
sessionKey,
|
|
156
|
+
{
|
|
157
|
+
model: event?.context?.model,
|
|
158
|
+
usage: event?.context?.usage,
|
|
159
|
+
},
|
|
160
|
+
undefined,
|
|
161
|
+
{
|
|
162
|
+
raw_event: JSON.parse(JSON.stringify(event ?? {})),
|
|
163
|
+
raw_ctx: JSON.parse(JSON.stringify(ctx ?? {})),
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
sendWebhook(config, payload, logger);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// --- Outbound message sent ---
|
|
171
|
+
api.on('message_sending', async (event: any, ctx: any) => {
|
|
172
|
+
if (!config.apiKey) return;
|
|
173
|
+
|
|
174
|
+
const sessionKey = event?.sessionKey || ctx?.sessionKey || 'unknown';
|
|
175
|
+
|
|
176
|
+
const payload = buildPayload(
|
|
177
|
+
'message',
|
|
178
|
+
'sent',
|
|
179
|
+
sessionKey,
|
|
180
|
+
{
|
|
181
|
+
to: event?.context?.to,
|
|
182
|
+
channelId: event?.context?.channelId,
|
|
183
|
+
success: event?.context?.success,
|
|
184
|
+
timestamp: event?.timestamp,
|
|
137
185
|
},
|
|
138
186
|
undefined,
|
|
139
187
|
{
|
|
140
|
-
content: event
|
|
188
|
+
content: event,
|
|
141
189
|
}
|
|
142
190
|
);
|
|
143
191
|
|