Skip to content

Commit 9f0e86d

Browse files
committed
fix(discovery-plugin): handle smallcaps # prefix in readResponseKind
CapData bodies are smallcaps-encoded JSON with a leading '#' marker, so the previous JSON.parse(body) always threw and the catch returned undefined — making 'kind !== public' true for every response and rejecting every public contact as non-public. Match the kind field by regex against the raw body, the same way extractKref reaches into it.
1 parent 968b095 commit 9f0e86d

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

packages/agentmask/openclaw-plugin-discovery/tools/initiate-contact.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import type { OpenClawPluginApi, ToolResponse } from '../types.ts';
1111

1212
/**
1313
* Pull the `kind` discriminator out of a raw CapData-style response.
14-
* The body is a JSON string with the field at the top level.
14+
* The body is a smallcaps-encoded JSON string with a leading `#` marker,
15+
* so naive `JSON.parse(body)` always throws — match the field by regex
16+
* instead, the same way `extractKref` reaches into the body.
1517
*
1618
* @param raw - The raw response from `daemon.queueMessage`.
1719
* @returns The `kind` string if found, otherwise `undefined`.
@@ -24,12 +26,7 @@ function readResponseKind(raw: unknown): string | undefined {
2426
if (typeof body !== 'string') {
2527
return undefined;
2628
}
27-
try {
28-
const parsed = JSON.parse(body) as { kind?: unknown };
29-
return typeof parsed.kind === 'string' ? parsed.kind : undefined;
30-
} catch {
31-
return undefined;
32-
}
29+
return /"kind"\s*:\s*"([^"]+)"/u.exec(body)?.[1];
3330
}
3431

3532
/**

0 commit comments

Comments
 (0)