@clawchatsai/connector 0.0.48 → 0.0.49

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.
Files changed (2) hide show
  1. package/dist/index.js +35 -30
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -964,36 +964,41 @@ const plugin = {
964
964
  const mediaStash = new Map();
965
965
  // Capture MEDIA: paths from exec tool results before the gateway strips them from message text.
966
966
  // Fires after every tool call; we filter to exec only and check for MEDIA: lines.
967
- api.registerTypedHook('after_tool_call', (event, ctx) => {
968
- // Diagnostic: log every tool call so we can confirm hook fires + see real tool names
969
- console.log(`[clawchats] hook:after_tool_call toolName=${String(event.toolName)} sessionKey=${String(ctx.sessionKey)}`);
970
- if (event.toolName !== 'exec')
971
- return;
972
- // result is { content: [{ type: 'text', text: '...' }] } — extract text defensively
973
- const result = event.result;
974
- let text = '';
975
- if (typeof result?.text === 'string') {
976
- text = result.text;
977
- }
978
- else if (Array.isArray(result?.content)) {
979
- text = result.content
980
- .filter(c => c.type === 'text' && typeof c.text === 'string')
981
- .map(c => c.text)
982
- .join('\n');
983
- }
984
- else if (result != null) {
985
- text = String(result);
986
- }
987
- const paths = [...text.matchAll(/^MEDIA:\s*(\S+)/gm)].map(m => m[1].trim());
988
- if (paths.length === 0)
989
- return;
990
- const sessionKey = ctx.sessionKey;
991
- if (!sessionKey)
992
- return;
993
- const existing = mediaStash.get(sessionKey) ?? [];
994
- mediaStash.set(sessionKey, [...existing, ...paths]);
995
- console.log(`[clawchats] media-capture: stashed ${paths.length} path(s) for ${sessionKey}:`, paths);
996
- }, { name: 'clawchats-media-capture', description: 'Captures MEDIA: paths from exec results for inline image rendering' });
967
+ // Guard: registerTypedHook may not exist in older OpenClaw versions.
968
+ if (typeof api.registerTypedHook !== 'function') {
969
+ console.warn('[clawchats] api.registerTypedHook not available — MEDIA: path capture disabled (update OpenClaw to enable)');
970
+ }
971
+ else
972
+ api.registerTypedHook('after_tool_call', (event, ctx) => {
973
+ // Diagnostic: log every tool call so we can confirm hook fires + see real tool names
974
+ console.log(`[clawchats] hook:after_tool_call toolName=${String(event.toolName)} sessionKey=${String(ctx.sessionKey)}`);
975
+ if (event.toolName !== 'exec')
976
+ return;
977
+ // result is { content: [{ type: 'text', text: '...' }] } — extract text defensively
978
+ const result = event.result;
979
+ let text = '';
980
+ if (typeof result?.text === 'string') {
981
+ text = result.text;
982
+ }
983
+ else if (Array.isArray(result?.content)) {
984
+ text = result.content
985
+ .filter(c => c.type === 'text' && typeof c.text === 'string')
986
+ .map(c => c.text)
987
+ .join('\n');
988
+ }
989
+ else if (result != null) {
990
+ text = String(result);
991
+ }
992
+ const paths = [...text.matchAll(/^MEDIA:\s*(\S+)/gm)].map(m => m[1].trim());
993
+ if (paths.length === 0)
994
+ return;
995
+ const sessionKey = ctx.sessionKey;
996
+ if (!sessionKey)
997
+ return;
998
+ const existing = mediaStash.get(sessionKey) ?? [];
999
+ mediaStash.set(sessionKey, [...existing, ...paths]);
1000
+ console.log(`[clawchats] media-capture: stashed ${paths.length} path(s) for ${sessionKey}:`, paths);
1001
+ }, { name: 'clawchats-media-capture', description: 'Captures MEDIA: paths from exec results for inline image rendering' });
997
1002
  // Background service: signaling + gateway bridge + future WebRTC
998
1003
  api.registerService({
999
1004
  id: 'connector-service',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawchatsai/connector",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "type": "module",
5
5
  "description": "ClawChats OpenClaw plugin — P2P tunnel + local API bridge",
6
6
  "main": "dist/index.js",