@hellolynk-ai/openclaw-channel 0.0.0-stage → 0.2.101
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 +92 -0
- package/README.md +101 -2
- package/bin/hellolynk-client-setup.mjs +2748 -0
- package/bin/hellolynk-mcp-config-shape.mjs +23 -0
- package/clients/core/hellolynk-agent-configurator.mjs +701 -0
- package/clients/core/hellolynk-client-account.mjs +180 -0
- package/clients/core/hellolynk-client-core.mjs +770 -0
- package/clients/core/hellolynk-client-profile.mjs +191 -0
- package/clients/core/hellolynk-client-update-entry.mjs +31 -0
- package/clients/core/hellolynk-client-update-runtime.mjs +600 -0
- package/clients/core/hellolynk-client-update.mjs +453 -0
- package/clients/core/hellolynk-contact-request-e2ee.mjs +867 -0
- package/clients/core/hellolynk-device-enrollment.mjs +435 -0
- package/clients/core/hellolynk-direct-text-e2ee-client.mjs +1964 -0
- package/clients/core/hellolynk-direct-text-e2ee.mjs +1207 -0
- package/clients/core/hellolynk-host-auth.mjs +347 -0
- package/clients/core/hellolynk-host-protected-store.mjs +2721 -0
- package/clients/core/hellolynk-host-transport-client.mjs +946 -0
- package/clients/core/hellolynk-host.mjs +2374 -0
- package/clients/core/hellolynk-human-confirmation-ledger.mjs +256 -0
- package/clients/core/hellolynk-human-relationship-controller.mjs +1234 -0
- package/clients/core/hellolynk-inbox-read-state.mjs +11 -0
- package/clients/core/hellolynk-indexed-message-store.mjs +1558 -0
- package/clients/core/hellolynk-instance-conversation.mjs +185 -0
- package/clients/core/hellolynk-local-contact-requests.mjs +1733 -0
- package/clients/core/hellolynk-local-contacts.mjs +1228 -0
- package/clients/core/hellolynk-local-data-migration.mjs +766 -0
- package/clients/core/hellolynk-local-data-protection.mjs +747 -0
- package/clients/core/hellolynk-local-identity-trust.mjs +274 -0
- package/clients/core/hellolynk-local-messaging.mjs +3043 -0
- package/clients/core/hellolynk-local-peer-transport.mjs +103 -0
- package/clients/core/hellolynk-local-process-lock.mjs +157 -0
- package/clients/core/hellolynk-model-inbox.mjs +230 -0
- package/clients/core/hellolynk-model-notices.cjs +60 -0
- package/clients/core/hellolynk-native-addressing-tools.cjs +231 -0
- package/clients/core/hellolynk-native-conversations.mjs +280 -0
- package/clients/core/hellolynk-native-human-confirmation-broker.mjs +1036 -0
- package/clients/core/hellolynk-native-inbox-runtime.mjs +553 -0
- package/clients/core/hellolynk-native-notice.mjs +50 -0
- package/clients/core/hellolynk-native-reply-routes.mjs +96 -0
- package/clients/core/hellolynk-native-worker-lease.mjs +84 -0
- package/clients/core/hellolynk-neutral-host-assembly.mjs +955 -0
- package/clients/core/hellolynk-neutral-host-installation-store.mjs +765 -0
- package/clients/core/hellolynk-neutral-host-launcher.mjs +665 -0
- package/clients/core/hellolynk-neutral-host-process.mjs +4374 -0
- package/clients/core/hellolynk-neutral-host-store-adapters.mjs +548 -0
- package/clients/core/hellolynk-neutral-host-workbench-read-model.mjs +1365 -0
- package/clients/core/hellolynk-platform-credential-store.mjs +773 -0
- package/clients/core/hellolynk-relay-client-cli.mjs +232 -0
- package/clients/core/hellolynk-release-retention.mjs +277 -0
- package/clients/core/hellolynk-runtime-safety.cjs +471 -0
- package/clients/core/hellolynk-workbench-action-grants.mjs +457 -0
- package/clients/core/hellolynk-workbench-connection.mjs +234 -0
- package/clients/platform/windows/configure-agent.ps1 +281 -0
- package/clients/platform/windows/credential-store.ps1 +844 -0
- package/clients/platform/windows/hellolynk-host-protected-store.ps1 +2866 -0
- package/clients/platform/windows/hellolynk-human-confirmation-ledger.ps1 +155 -0
- package/clients/platform/windows/hellolynk-local-data-key.ps1 +300 -0
- package/clients/platform/windows/hellolynk-native-human-confirmation-broker.ps1 +216 -0
- package/clients/workbench/contract.mjs +1314 -0
- package/clients/workbench/service.mjs +485 -0
- package/hellolynk-client-pack-manifest.json +854 -0
- package/hellolynk-client-pack-pin.json +4 -0
- package/integrations/openclaw-channel/dist/control-ui/index.js +63 -0
- package/integrations/openclaw-channel/index.mjs +5 -0
- package/integrations/openclaw-channel/openclaw.plugin.json +57 -0
- package/integrations/openclaw-channel/package.json +50 -0
- package/integrations/openclaw-channel/setup-entry.mjs +4 -0
- package/integrations/openclaw-channel/skills/hellolynk-messaging/SKILL.md +9 -0
- package/integrations/openclaw-channel/src/authorized-messaging-tools.mjs +423 -0
- package/integrations/openclaw-channel/src/channel-dispatch.mjs +657 -0
- package/integrations/openclaw-channel/src/channel.mjs +368 -0
- package/integrations/openclaw-channel/src/config-schema.mjs +33 -0
- package/integrations/openclaw-channel/src/control-ui.mjs +411 -0
- package/integrations/openclaw-channel/src/inbound-policy.mjs +44 -0
- package/integrations/openclaw-channel/src/native-origins.mjs +53 -0
- package/integrations/openclaw-channel/src/neutral-host-adapter.mjs +826 -0
- package/integrations/openclaw-channel/src/neutral-read-runtime.mjs +469 -0
- package/integrations/openclaw-channel/src/runtime-primitives.mjs +12 -0
- package/integrations/openclaw-channel/src/transcript-attribution.mjs +140 -0
- package/package.json +69 -4
- package/runtime/connect-activate.mjs +837 -0
- package/runtime/core/hellolynk-agent-configurator.mjs +701 -0
- package/runtime/core/hellolynk-client-account.mjs +180 -0
- package/runtime/core/hellolynk-client-core.mjs +770 -0
- package/runtime/core/hellolynk-client-profile.mjs +191 -0
- package/runtime/core/hellolynk-client-update-entry.mjs +31 -0
- package/runtime/core/hellolynk-client-update-runtime.mjs +600 -0
- package/runtime/core/hellolynk-client-update.mjs +453 -0
- package/runtime/core/hellolynk-contact-request-e2ee.mjs +867 -0
- package/runtime/core/hellolynk-device-enrollment.mjs +435 -0
- package/runtime/core/hellolynk-direct-text-e2ee-client.mjs +1964 -0
- package/runtime/core/hellolynk-direct-text-e2ee.mjs +1207 -0
- package/runtime/core/hellolynk-host-auth.mjs +347 -0
- package/runtime/core/hellolynk-host-protected-store.mjs +2721 -0
- package/runtime/core/hellolynk-host-transport-client.mjs +946 -0
- package/runtime/core/hellolynk-host.mjs +2374 -0
- package/runtime/core/hellolynk-human-confirmation-ledger.mjs +256 -0
- package/runtime/core/hellolynk-human-relationship-controller.mjs +1234 -0
- package/runtime/core/hellolynk-inbox-read-state.mjs +11 -0
- package/runtime/core/hellolynk-indexed-message-store.mjs +1558 -0
- package/runtime/core/hellolynk-instance-conversation.mjs +185 -0
- package/runtime/core/hellolynk-local-contact-requests.mjs +1733 -0
- package/runtime/core/hellolynk-local-contacts.mjs +1228 -0
- package/runtime/core/hellolynk-local-data-migration.mjs +766 -0
- package/runtime/core/hellolynk-local-data-protection.mjs +747 -0
- package/runtime/core/hellolynk-local-identity-trust.mjs +274 -0
- package/runtime/core/hellolynk-local-messaging.mjs +3043 -0
- package/runtime/core/hellolynk-local-peer-transport.mjs +103 -0
- package/runtime/core/hellolynk-local-process-lock.mjs +157 -0
- package/runtime/core/hellolynk-model-inbox.mjs +230 -0
- package/runtime/core/hellolynk-model-notices.cjs +60 -0
- package/runtime/core/hellolynk-native-addressing-tools.cjs +231 -0
- package/runtime/core/hellolynk-native-conversations.mjs +280 -0
- package/runtime/core/hellolynk-native-human-confirmation-broker.mjs +1036 -0
- package/runtime/core/hellolynk-native-inbox-runtime.mjs +553 -0
- package/runtime/core/hellolynk-native-notice.mjs +50 -0
- package/runtime/core/hellolynk-native-reply-routes.mjs +96 -0
- package/runtime/core/hellolynk-native-worker-lease.mjs +84 -0
- package/runtime/core/hellolynk-neutral-host-assembly.mjs +955 -0
- package/runtime/core/hellolynk-neutral-host-installation-store.mjs +765 -0
- package/runtime/core/hellolynk-neutral-host-launcher.mjs +665 -0
- package/runtime/core/hellolynk-neutral-host-process.mjs +4374 -0
- package/runtime/core/hellolynk-neutral-host-store-adapters.mjs +548 -0
- package/runtime/core/hellolynk-neutral-host-workbench-read-model.mjs +1365 -0
- package/runtime/core/hellolynk-platform-credential-store.mjs +773 -0
- package/runtime/core/hellolynk-relay-client-cli.mjs +232 -0
- package/runtime/core/hellolynk-release-retention.mjs +277 -0
- package/runtime/core/hellolynk-runtime-safety.cjs +471 -0
- package/runtime/core/hellolynk-workbench-action-grants.mjs +457 -0
- package/runtime/core/hellolynk-workbench-connection.mjs +234 -0
- package/runtime/neutral-host-bootstrap.mjs +57 -0
- package/runtime/neutral-host-release-entry.mjs +81 -0
- package/runtime/neutral-host-release-loader.mjs +156 -0
- package/runtime/neutral-host-release-manifest.json +302 -0
- package/runtime/neutral-host-release-pin.json +4 -0
- package/runtime/platform/windows/configure-agent.ps1 +281 -0
- package/runtime/platform/windows/credential-store.ps1 +844 -0
- package/runtime/platform/windows/hellolynk-host-protected-store.ps1 +2866 -0
- package/runtime/platform/windows/hellolynk-human-confirmation-ledger.ps1 +155 -0
- package/runtime/platform/windows/hellolynk-local-data-key.ps1 +300 -0
- package/runtime/platform/windows/hellolynk-native-human-confirmation-broker.ps1 +216 -0
- package/runtime/workbench/candidate-bootstrap.mjs +54 -0
- package/runtime/workbench/contract.mjs +1314 -0
- package/runtime/workbench/hellolynk-workbench-build.json +215 -0
- package/runtime/workbench/host-capabilities.mjs +80 -0
- package/runtime/workbench/i18n.mjs +1127 -0
- package/runtime/workbench/loopback-surface.mjs +740 -0
- package/runtime/workbench/mcp-app-bundle.mjs +97 -0
- package/runtime/workbench/service.mjs +485 -0
- package/runtime/workbench/state.mjs +421 -0
- package/runtime/workbench/transports.mjs +171 -0
- package/runtime/workbench/ui/app.mjs +6120 -0
- package/runtime/workbench/ui/connection-form.mjs +155 -0
- package/runtime/workbench/ui/hellolynk-mark.png +0 -0
- package/runtime/workbench/ui/http-transport.mjs +247 -0
- package/runtime/workbench/ui/icons/arrow-left.svg +3 -0
- package/runtime/workbench/ui/icons/close.svg +3 -0
- package/runtime/workbench/ui/icons/contacts.svg +3 -0
- package/runtime/workbench/ui/icons/inbox.svg +3 -0
- package/runtime/workbench/ui/icons/refresh.svg +3 -0
- package/runtime/workbench/ui/icons/search.svg +3 -0
- package/runtime/workbench/ui/icons/security.svg +3 -0
- package/runtime/workbench/ui/icons/settings.svg +3 -0
- package/runtime/workbench/ui/index.html +139 -0
- package/runtime/workbench/ui/loopback-entry.mjs +26 -0
- package/runtime/workbench/ui/mcp-app-client.mjs +151 -0
- package/runtime/workbench/ui/mcp-app-entry.mjs +452 -0
- package/runtime/workbench/ui/styles.css +686 -0
- package/tools/hellolynk-activate-neutral-host-clients.mjs +837 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Hand-authored browser entry; OpenClaw requires this dedicated dist directory.
|
|
2
|
+
// This dependency-free native page runs only after
|
|
3
|
+
// the operator enables OpenClaw's official Custom plugin UI setting.
|
|
4
|
+
const plugin = {
|
|
5
|
+
id: "hellolynk",
|
|
6
|
+
activate(host) {
|
|
7
|
+
return host.ui.registerPage({ id: "hellolynk-inbox", label: "HelloLynk 通讯", mount });
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function mount(container, context) {
|
|
12
|
+
const document = container.ownerDocument;
|
|
13
|
+
const root = document.createElement("div");
|
|
14
|
+
root.style.cssText = "display:flex;flex-direction:column;height:100%;min-height:360px;width:100%";
|
|
15
|
+
const status = document.createElement("p");
|
|
16
|
+
status.setAttribute("role", "status");
|
|
17
|
+
const retry = document.createElement("button");
|
|
18
|
+
retry.type = "button";
|
|
19
|
+
retry.textContent = "重新打开 / Reopen";
|
|
20
|
+
root.append(status, retry);
|
|
21
|
+
container.append(root);
|
|
22
|
+
let disposed = false;
|
|
23
|
+
let opening = false;
|
|
24
|
+
let frame;
|
|
25
|
+
async function open() {
|
|
26
|
+
if (disposed || opening || context.signal.aborted) return;
|
|
27
|
+
opening = true;
|
|
28
|
+
retry.hidden = true;
|
|
29
|
+
status.textContent = "正在打开 HelloLynk… / Opening HelloLynk…";
|
|
30
|
+
try {
|
|
31
|
+
const result = await context.host.request("hellolynk.workbench.open", {});
|
|
32
|
+
if (disposed || context.signal.aborted) return;
|
|
33
|
+
const parent = new URL(document.defaultView.location.href);
|
|
34
|
+
const target = new URL(result.url);
|
|
35
|
+
if (parent.protocol !== "http:" || !["127.0.0.1", "localhost"].includes(parent.hostname)
|
|
36
|
+
|| target.protocol !== "http:" || target.hostname !== parent.hostname || target.origin === parent.origin
|
|
37
|
+
|| !target.port || target.pathname !== "/workbench" || target.search || target.hash
|
|
38
|
+
|| target.username || target.password) throw new Error("Invalid local page");
|
|
39
|
+
frame?.remove();
|
|
40
|
+
frame = document.createElement("iframe");
|
|
41
|
+
frame.title = "HelloLynk 通讯";
|
|
42
|
+
// This frame has its own loopback origin; it cannot read the Gateway DOM
|
|
43
|
+
// or its credentials. Same-origin here refers to the workbench itself.
|
|
44
|
+
frame.setAttribute("sandbox", "allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox");
|
|
45
|
+
frame.referrerPolicy = "origin";
|
|
46
|
+
frame.style.cssText = "width:100%;flex:1;min-height:360px;border:0";
|
|
47
|
+
frame.src = target.href;
|
|
48
|
+
status.hidden = true;
|
|
49
|
+
root.append(frame);
|
|
50
|
+
} catch {
|
|
51
|
+
if (!disposed && !context.signal.aborted) {
|
|
52
|
+
status.hidden = false;
|
|
53
|
+
status.textContent = "HelloLynk 暂时无法打开,请确认本机 Gateway 已连接后重试。 / HelloLynk could not open. Check the local Gateway connection and retry.";
|
|
54
|
+
retry.hidden = false;
|
|
55
|
+
}
|
|
56
|
+
} finally { opening = false; }
|
|
57
|
+
}
|
|
58
|
+
retry.addEventListener("click", open);
|
|
59
|
+
void open();
|
|
60
|
+
return { dispose() { disposed = true; retry.removeEventListener("click", open); root.remove(); } };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default plugin;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "hellolynk",
|
|
3
|
+
"activation": { "onStartup": false },
|
|
4
|
+
"channels": ["hellolynk"],
|
|
5
|
+
"skills": ["./skills"],
|
|
6
|
+
"controlUi": { "entry": "dist/control-ui/index.js" },
|
|
7
|
+
"contracts": {
|
|
8
|
+
"tools": [
|
|
9
|
+
"hellolynk_open_inbox",
|
|
10
|
+
"hellolynk_get_unread_count",
|
|
11
|
+
"hellolynk_list_authorized_contacts",
|
|
12
|
+
"hellolynk_send_authorized_message",
|
|
13
|
+
"hellolynk_list_authorized_inbox_messages",
|
|
14
|
+
"hellolynk_read_authorized_inbox_message",
|
|
15
|
+
"hellolynk_list_authorized_contact_requests",
|
|
16
|
+
"hellolynk_read_authorized_contact_request",
|
|
17
|
+
"hellolynk_list_pending_messages",
|
|
18
|
+
"hellolynk_claim_message",
|
|
19
|
+
"hellolynk_reply_authorized_message"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"channelEnvVars": { "hellolynk": [] },
|
|
23
|
+
"engines": { "openclaw": ">=2026.9.3" },
|
|
24
|
+
"configSchema": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"additionalProperties": false,
|
|
27
|
+
"properties": {}
|
|
28
|
+
},
|
|
29
|
+
"channelConfigs": {
|
|
30
|
+
"hellolynk": {
|
|
31
|
+
"label": "HelloLynk 通讯",
|
|
32
|
+
"description": "HelloLynk Messaging attached to the local neutral HelloLynk Host.",
|
|
33
|
+
"schema": {
|
|
34
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
35
|
+
"type": "object",
|
|
36
|
+
"additionalProperties": false,
|
|
37
|
+
"required": ["enabled", "hostMode", "bindingRef"],
|
|
38
|
+
"properties": {
|
|
39
|
+
"enabled": { "type": "boolean" },
|
|
40
|
+
"hostMode": { "type": "string", "const": "neutral" },
|
|
41
|
+
"bindingRef": { "type": "string", "const": "protected-store:openclaw" },
|
|
42
|
+
"nativeModel": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"description": "Requests a model and thinking level for HelloLynk turns. OpenClaw may select another model; nativeModelSelection.hostObservation is session-level and is not correlated to this turn.",
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"required": ["provider", "model"],
|
|
47
|
+
"properties": {
|
|
48
|
+
"provider": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{0,79}$" },
|
|
49
|
+
"model": { "type": "string", "minLength": 1, "maxLength": 240, "pattern": "^[^\\s\\x00-\\x1f\\x7f]+$" },
|
|
50
|
+
"thinkingLevel": { "type": "string", "pattern": "^[a-z][a-z0-9_-]{0,31}$" }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hellolynk-ai/openclaw-channel",
|
|
3
|
+
"version": "0.2.101",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "HelloLynk Messaging channel plugin for the public OpenClaw Windows client",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.mjs",
|
|
9
|
+
"./setup-entry": "./setup-entry.mjs",
|
|
10
|
+
"./src/channel": "./src/channel.mjs",
|
|
11
|
+
"./src/neutral-host-adapter": "./src/neutral-host-adapter.mjs",
|
|
12
|
+
"./src/control-ui": "./src/control-ui.mjs",
|
|
13
|
+
"./src/authorized-messaging-tools": "./src/authorized-messaging-tools.mjs"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"smoke": "node test/phase-f-workbench-registration-smoke.mjs && node test/openclaw-runtime-load-smoke.mjs && node test/neutral-host-smoke.mjs && node test/neutral-active-graph-smoke.mjs && node test/neutral-read-runtime-smoke.mjs && node --test test/native-origins.test.mjs test/control-ui-native.test.mjs && node test/workbench-candidate-smoke.mjs",
|
|
17
|
+
"test": "node test/phase-f-workbench-registration-smoke.mjs && node test/openclaw-runtime-load-smoke.mjs && node test/neutral-host-smoke.mjs && node test/neutral-active-graph-smoke.mjs && node test/neutral-read-runtime-smoke.mjs && node --test test/native-origins.test.mjs test/control-ui-native.test.mjs && node test/workbench-candidate-smoke.mjs"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"openclaw": ">=2026.9.3"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"openclaw": {
|
|
24
|
+
"optional": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"openclaw": {
|
|
28
|
+
"extensions": [
|
|
29
|
+
"./index.mjs"
|
|
30
|
+
],
|
|
31
|
+
"setupEntry": "./setup-entry.mjs",
|
|
32
|
+
"channel": {
|
|
33
|
+
"id": "hellolynk",
|
|
34
|
+
"label": "HelloLynk 通讯",
|
|
35
|
+
"selectionLabel": "HelloLynk 通讯",
|
|
36
|
+
"detailLabel": "HelloLynk 通讯 · 本机 Host",
|
|
37
|
+
"docsPath": "/channels/hellolynk",
|
|
38
|
+
"docsLabel": "hellolynk",
|
|
39
|
+
"blurb": "HelloLynk Messaging attached to the local neutral HelloLynk Host.",
|
|
40
|
+
"systemImage": "bubble.left.and.bubble.right",
|
|
41
|
+
"markdownCapable": true,
|
|
42
|
+
"preferSessionLookupForAnnounceTarget": true,
|
|
43
|
+
"order": 86,
|
|
44
|
+
"commands": {
|
|
45
|
+
"nativeCommandsAutoEnabled": false,
|
|
46
|
+
"nativeSkillsAutoEnabled": false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hellolynk-messaging
|
|
3
|
+
description: 在 OpenClaw 中打开和使用 HelloLynk 通讯;不用于邮件。
|
|
4
|
+
---
|
|
5
|
+
# HelloLynk 通讯
|
|
6
|
+
HelloLynk 是本人授权的 AI 通讯。接着已有来往用 hellolynk_reply_authorized_message,沿用来信的 localMessageId 和 conversationKey;发起新通信用 hellolynk_send_authorized_message,contact 填对方名字。每条新消息用新的 clientMessageId;发送失败或结果未知时保留编号并停止,不重发;参数无效时改正后重新调用。收到本聊天的 HelloLynk 自动提醒时,用 hellolynk_claim_message 按 batchId 读一次。没有本聊天的提醒或本人查信要求时,不主动查信。用户要看全部来信时,打开本客户端的 HelloLynk 界面供本人查看。
|
|
7
|
+
## 打开
|
|
8
|
+
1. 调用 hellolynk_open_inbox(空参数)一次。
|
|
9
|
+
2. 在 OpenClaw 左侧打开“HelloLynk 通讯”。
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { prepareModelInboxInvocation, isModelInboxTool } from "../../../clients/core/hellolynk-model-inbox.mjs";
|
|
2
|
+
import { openClawModelInboxCaller } from "./native-origins.mjs";
|
|
3
|
+
import { nativeTool, optionalTarget, nativeAddressingError, replyHint, firstSendReceipt, paramText, resultText, sendArgumentKeys, sendRecipient, findContacts, writeFailure, failureText } from "../../../clients/core/hellolynk-native-addressing-tools.cjs";
|
|
4
|
+
import { withHelloLynkModelNotices } from "../../../clients/core/hellolynk-model-notices.cjs";
|
|
5
|
+
import { projectInboxReadState } from "../../../clients/core/hellolynk-inbox-read-state.mjs";
|
|
6
|
+
import { rememberOpenClawOrigin } from "./native-origins.mjs";
|
|
7
|
+
// Host owns the selected batch and every reply target / authorization check.
|
|
8
|
+
|
|
9
|
+
const WRITE_ID = Object.freeze({ type: "string", minLength: 3, maxLength: 128, pattern: "^[A-Za-z0-9][A-Za-z0-9_.:-]{2,127}$" });
|
|
10
|
+
const WRITE_ID_PATTERN = new RegExp(WRITE_ID.pattern);
|
|
11
|
+
const CLIENT_MESSAGE_ID = Object.freeze({ ...WRITE_ID, examples: ["msg-a1b2c3-01"], description: paramText.clientMessageId });
|
|
12
|
+
const MESSAGE_TEXT = Object.freeze({ type: "string", minLength: 1, maxLength: 20000, description: paramText.text });
|
|
13
|
+
|
|
14
|
+
// nativeTool adds the titles and descriptions every client shares; the agent tools below pass on only the description.
|
|
15
|
+
export const OPENCLAW_AUTHORIZED_MESSAGING_TOOLS = Object.freeze([
|
|
16
|
+
Object.freeze({
|
|
17
|
+
name: "hellolynk_open_inbox",
|
|
18
|
+
inputSchema: Object.freeze({ type: "object", additionalProperties: false, properties: {} }),
|
|
19
|
+
}),
|
|
20
|
+
Object.freeze({
|
|
21
|
+
name: "hellolynk_get_unread_count",
|
|
22
|
+
inputSchema: Object.freeze({ type: "object", additionalProperties: false, properties: {} }),
|
|
23
|
+
}),
|
|
24
|
+
Object.freeze({
|
|
25
|
+
name: "hellolynk_list_authorized_contacts",
|
|
26
|
+
inputSchema: Object.freeze({ type: "object", additionalProperties: false, properties: {} }),
|
|
27
|
+
}),
|
|
28
|
+
Object.freeze({
|
|
29
|
+
name: "hellolynk_send_authorized_message",
|
|
30
|
+
inputSchema: Object.freeze({
|
|
31
|
+
type: "object", additionalProperties: false,
|
|
32
|
+
required: ["clientMessageId", "text"],
|
|
33
|
+
properties: Object.freeze({
|
|
34
|
+
contactId: Object.freeze({ type: "string", minLength: 3, maxLength: 200 }),
|
|
35
|
+
recipientDelegateId: Object.freeze({ type: "string", minLength: 3, maxLength: 200 }),
|
|
36
|
+
clientMessageId: CLIENT_MESSAGE_ID,
|
|
37
|
+
text: MESSAGE_TEXT,
|
|
38
|
+
}),
|
|
39
|
+
}),
|
|
40
|
+
}),
|
|
41
|
+
Object.freeze({
|
|
42
|
+
name: "hellolynk_list_authorized_inbox_messages",
|
|
43
|
+
inputSchema: Object.freeze({ type: "object", additionalProperties: false, properties: Object.freeze({
|
|
44
|
+
before: Object.freeze({ type: "string", minLength: 3, maxLength: 240, description: paramText.before }),
|
|
45
|
+
}) }),
|
|
46
|
+
}),
|
|
47
|
+
Object.freeze({
|
|
48
|
+
name: "hellolynk_read_authorized_inbox_message",
|
|
49
|
+
inputSchema: strictConversationSchema("localMessageId"),
|
|
50
|
+
}),
|
|
51
|
+
Object.freeze({
|
|
52
|
+
name: "hellolynk_list_authorized_contact_requests",
|
|
53
|
+
inputSchema: Object.freeze({ type: "object", additionalProperties: false, properties: {} }),
|
|
54
|
+
}),
|
|
55
|
+
Object.freeze({
|
|
56
|
+
name: "hellolynk_read_authorized_contact_request",
|
|
57
|
+
inputSchema: strictConversationSchema("localRecordId"),
|
|
58
|
+
}),
|
|
59
|
+
Object.freeze({
|
|
60
|
+
name: "hellolynk_list_pending_messages",
|
|
61
|
+
inputSchema: Object.freeze({ type: "object", additionalProperties: false, properties: {} }),
|
|
62
|
+
}),
|
|
63
|
+
Object.freeze({
|
|
64
|
+
name: "hellolynk_claim_message",
|
|
65
|
+
inputSchema: pendingClaimSchema(),
|
|
66
|
+
}),
|
|
67
|
+
Object.freeze({
|
|
68
|
+
name: "hellolynk_reply_authorized_message",
|
|
69
|
+
inputSchema: { type: "object", additionalProperties: false, required: ["localMessageId", "conversationKey", "clientMessageId", "text"], properties: {
|
|
70
|
+
localMessageId: { ...WRITE_ID, description: paramText.localMessageId }, conversationKey: { ...WRITE_ID, description: paramText.conversationKey },
|
|
71
|
+
clientMessageId: CLIENT_MESSAGE_ID, text: MESSAGE_TEXT,
|
|
72
|
+
} },
|
|
73
|
+
}),
|
|
74
|
+
].map(nativeTool));
|
|
75
|
+
|
|
76
|
+
export function createOpenClawAuthorizedMessagingToolHandlers(options = {}) {
|
|
77
|
+
const original = createUnscopedMessagingToolHandlers(options);
|
|
78
|
+
return Object.freeze(Object.fromEntries(Object.entries(original).map(([name, handler]) => [name,
|
|
79
|
+
!isModelInboxTool(name) ? handler : async (args = {}, attempt) => {
|
|
80
|
+
const adapter = await options.adapterProvider();
|
|
81
|
+
const invocation = await prepareModelInboxInvocation(adapter, { name, args,
|
|
82
|
+
caller: openClawModelInboxCaller(options.toolContext) });
|
|
83
|
+
const handlers = createUnscopedMessagingToolHandlers({ ...options, adapterProvider: async () => invocation.adapter });
|
|
84
|
+
return invocation.finish(await handlers[name](invocation.args, attempt));
|
|
85
|
+
},
|
|
86
|
+
])));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function createUnscopedMessagingToolHandlers(options = {}) {
|
|
90
|
+
if (typeof options.adapterProvider !== "function") throw codeError("authorized_messaging_adapter_provider_required");
|
|
91
|
+
// Manual single-message claim: the model names one message by its two ids.
|
|
92
|
+
async function claimSingle(args) {
|
|
93
|
+
assertExact(args, ["localMessageId", "conversationKey"]);
|
|
94
|
+
for (const key of ["localMessageId", "conversationKey"]) {
|
|
95
|
+
if (typeof args[key] !== "string" || !PENDING_ID.test(args[key])) throw codeError("arguments_invalid");
|
|
96
|
+
}
|
|
97
|
+
const adapter = await options.adapterProvider();
|
|
98
|
+
const result = await adapter.claimMessage(args.localMessageId, args.conversationKey);
|
|
99
|
+
if (result?.claimed === false && result.claimId === null && result.message === null) {
|
|
100
|
+
return { claimed: false, claimId: null, message: null, notice: "此来信已被领取或处理。" };
|
|
101
|
+
}
|
|
102
|
+
if (result?.claimed !== true || typeof result.claimId !== "string" || !/^inclaim_[a-f0-9]{48}$/.test(result.claimId)) throw codeError("host_app_response_invalid");
|
|
103
|
+
const message = projectRead(result.message);
|
|
104
|
+
if (message.localMessageId !== args.localMessageId || message.conversationKey !== args.conversationKey
|
|
105
|
+
|| result.message?.wakeEligible !== true) throw codeError("host_app_response_invalid");
|
|
106
|
+
return { claimed: true, claimId: result.claimId, message: { ...message, wakeEligible: true } };
|
|
107
|
+
}
|
|
108
|
+
return Object.freeze({
|
|
109
|
+
async hellolynk_list_pending_messages(args = {}) {
|
|
110
|
+
assertEmpty(args);
|
|
111
|
+
const adapter = await options.adapterProvider();
|
|
112
|
+
return { messages: projectPendingMessages(await adapter.listPendingMessages()) };
|
|
113
|
+
},
|
|
114
|
+
async hellolynk_claim_message(args = {}) {
|
|
115
|
+
if (!!args && typeof args === "object" && !Array.isArray(args) && !Object.hasOwn(args, "batchId")) return claimSingle(args);
|
|
116
|
+
assertExact(args, ["batchId"]);
|
|
117
|
+
if (!/^inbatch_[a-f0-9]{48}$/.test(args.batchId || "")) throw codeError("arguments_invalid");
|
|
118
|
+
const adapter = await options.adapterProvider();
|
|
119
|
+
const result = await adapter.claimBatch(args.batchId);
|
|
120
|
+
if (!Array.isArray(result?.messages) || result.claimed !== (result.messages.length > 0)
|
|
121
|
+
|| !Number.isSafeInteger(result.expiredCount) || result.expiredCount < 0) throw codeError("host_app_response_invalid");
|
|
122
|
+
const messages = result.messages.map(projectRead);
|
|
123
|
+
if (messages.reduce((total, message) => total + [...message.text].length, 0) > 20_000) throw codeError("host_app_response_invalid");
|
|
124
|
+
return { batchId: args.batchId, claimed: result.claimed, messages, expiredCount: result.expiredCount,
|
|
125
|
+
...(result.claimed ? {} : { notice: "这批来信已读取,无需重复读取。" }) };
|
|
126
|
+
},
|
|
127
|
+
async hellolynk_reply_authorized_message(args = {}, attempt = { phase: "input_validation" }) {
|
|
128
|
+
assertExact(args, ["localMessageId", "conversationKey", "clientMessageId", "text"]);
|
|
129
|
+
for (const key of ["localMessageId", "conversationKey", "clientMessageId"]) {
|
|
130
|
+
if (typeof args[key] !== "string" || !WRITE_ID_PATTERN.test(args[key])) throw codeError("arguments_invalid");
|
|
131
|
+
}
|
|
132
|
+
const input = { ...args, text: safeBody(args.text, 20_000, true) };
|
|
133
|
+
attempt.clientMessageId = input.clientMessageId;
|
|
134
|
+
attempt.phase = "preparation";
|
|
135
|
+
const adapter = await options.adapterProvider();
|
|
136
|
+
await adapter.assertModelInboxReply(input);
|
|
137
|
+
options.toolContext?.assertInvocationCurrent?.();
|
|
138
|
+
attempt.phase = "adapter_call";
|
|
139
|
+
const result = await adapter.replyAuthorizedMessage(input);
|
|
140
|
+
attempt.phase = "response_validation";
|
|
141
|
+
if (result?.accepted !== true || result.ok === false || result.authorization !== "contact_delegate_allowlist"
|
|
142
|
+
|| result.clientMessageId !== input.clientMessageId
|
|
143
|
+
|| !["accepted", "delivered_to_live_connection", "acknowledged_by_recipient_local_store"].includes(result.status)) throw codeError("host_app_send_result_unknown");
|
|
144
|
+
// Route registration follows successful send and cannot cause a replay.
|
|
145
|
+
const originRegistered = await rememberOpenClawOrigin(adapter, options.toolContext, input);
|
|
146
|
+
return { accepted: true, contactId: result.contactId, clientMessageId: result.clientMessageId, status: result.status, originRegistered };
|
|
147
|
+
},
|
|
148
|
+
async hellolynk_open_inbox(args = {}) {
|
|
149
|
+
assertEmpty(args);
|
|
150
|
+
return {
|
|
151
|
+
controlUiId: "hellolynk-inbox",
|
|
152
|
+
label: "HelloLynk 通讯",
|
|
153
|
+
action: "open_sidebar_control",
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
async hellolynk_list_authorized_contacts(args = {}) {
|
|
157
|
+
const adapter = await options.adapterProvider();
|
|
158
|
+
const result = await findContacts(args, query => adapter.listAuthorizedContacts(query));
|
|
159
|
+
return { contacts: safeContactList(result?.contacts), ...(result?.nativeConversations ? { nativeConversations: result.nativeConversations } : {}) };
|
|
160
|
+
},
|
|
161
|
+
async hellolynk_send_authorized_message(args = {}, attempt = { phase: "input_validation" }) {
|
|
162
|
+
assertExact(args, sendArgumentKeys(args));
|
|
163
|
+
if (Object.values(args).some(value => typeof value !== "string")) throw codeError("arguments_invalid");
|
|
164
|
+
if (!Object.hasOwn(args, "contact")) {
|
|
165
|
+
safeText(args.contactId, "contact_id_invalid", 200);
|
|
166
|
+
safeText(args.recipientDelegateId, "recipient_delegate_id_invalid", 200);
|
|
167
|
+
}
|
|
168
|
+
optionalTarget(args);
|
|
169
|
+
if (!WRITE_ID_PATTERN.test(args.clientMessageId)) throw codeError("client_message_id_invalid");
|
|
170
|
+
attempt.clientMessageId = args.clientMessageId;
|
|
171
|
+
const text = safeBody(args.text, 20_000, true);
|
|
172
|
+
attempt.phase = "preparation";
|
|
173
|
+
const adapter = await options.adapterProvider();
|
|
174
|
+
const { contactId, recipientDelegateId } = await sendRecipient(args, query => adapter.listAuthorizedContacts(query));
|
|
175
|
+
const input = {
|
|
176
|
+
...optionalTarget(args),
|
|
177
|
+
contactId: safeText(contactId, "contact_id_invalid", 200),
|
|
178
|
+
recipientDelegateId: safeText(recipientDelegateId, "recipient_delegate_id_invalid", 200),
|
|
179
|
+
clientMessageId: safeText(args.clientMessageId, "client_message_id_invalid", 200),
|
|
180
|
+
text,
|
|
181
|
+
};
|
|
182
|
+
const originRegistered = await rememberOpenClawOrigin(adapter, options.toolContext, input);
|
|
183
|
+
options.toolContext?.assertInvocationCurrent?.();
|
|
184
|
+
attempt.phase = "adapter_call";
|
|
185
|
+
const result = await adapter.sendAuthorizedMessage(input);
|
|
186
|
+
attempt.phase = "response_validation";
|
|
187
|
+
if (result?.accepted !== true || result.ok === false || result.authorization !== "contact_delegate_allowlist"
|
|
188
|
+
|| result.contactId !== input.contactId || result.clientMessageId !== input.clientMessageId
|
|
189
|
+
|| !["accepted", "delivered_to_live_connection", "acknowledged_by_recipient_local_store"].includes(result.status)) throw codeError("host_app_send_result_unknown");
|
|
190
|
+
return {
|
|
191
|
+
accepted: true,
|
|
192
|
+
contactId: result.contactId,
|
|
193
|
+
recipientDelegateId: input.recipientDelegateId,
|
|
194
|
+
clientMessageId: result.clientMessageId,
|
|
195
|
+
status: result.status,
|
|
196
|
+
destination: firstSendReceipt(input, result.status).destination,
|
|
197
|
+
originRegistered,
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
async hellolynk_get_unread_count(args = {}) {
|
|
201
|
+
assertEmpty(args);
|
|
202
|
+
const result = await (await options.adapterProvider()).readUnreadCount();
|
|
203
|
+
if (!Number.isSafeInteger(result?.unreadCount) || result.unreadCount < 0) throw codeError("authorized_inbox_response_invalid");
|
|
204
|
+
return { unreadCount: result.unreadCount };
|
|
205
|
+
},
|
|
206
|
+
async hellolynk_list_authorized_inbox_messages(args = {}) {
|
|
207
|
+
const older = !!args && typeof args === "object" && Object.hasOwn(args, "before");
|
|
208
|
+
if (older) assertExact(args, ["before"]); else assertEmpty(args);
|
|
209
|
+
const adapter = await options.adapterProvider();
|
|
210
|
+
const result = await adapter.listAuthorizedInboxMessages(older
|
|
211
|
+
? { before: safeText(args.before, "authorized_inbox_message_id_invalid", 240) } : {});
|
|
212
|
+
return { messages: (result?.messages || []).map(value => ({ ...projectMetadata(value), ...replyHint(value) })) };
|
|
213
|
+
},
|
|
214
|
+
async hellolynk_read_authorized_inbox_message(args = {}) {
|
|
215
|
+
assertExact(args, ["conversationKey", "localMessageId"]);
|
|
216
|
+
const adapter = await options.adapterProvider();
|
|
217
|
+
return projectRead(await adapter.readAuthorizedInboxMessage(
|
|
218
|
+
safeText(args.localMessageId, "authorized_inbox_message_id_invalid", 240),
|
|
219
|
+
safeText(args.conversationKey, "authorized_inbox_conversation_key_invalid", 240),
|
|
220
|
+
));
|
|
221
|
+
},
|
|
222
|
+
async hellolynk_list_authorized_contact_requests(args = {}) {
|
|
223
|
+
assertEmpty(args);
|
|
224
|
+
const adapter = await options.adapterProvider();
|
|
225
|
+
const result = await adapter.listAuthorizedContactRequests();
|
|
226
|
+
return { requests: (result?.requests || []).map(projectContactRequestMetadata) };
|
|
227
|
+
},
|
|
228
|
+
async hellolynk_read_authorized_contact_request(args = {}) {
|
|
229
|
+
assertExact(args, ["conversationKey", "localRecordId"]);
|
|
230
|
+
const adapter = await options.adapterProvider();
|
|
231
|
+
return projectContactRequestRead(await adapter.readAuthorizedContactRequest(
|
|
232
|
+
safeText(args.localRecordId, "authorized_contact_request_id_invalid", 240),
|
|
233
|
+
safeText(args.conversationKey, "authorized_contact_request_conversation_key_invalid", 240),
|
|
234
|
+
));
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function createOpenClawAuthorizedMessagingAgentTools(options = {}) {
|
|
240
|
+
const handlers = createOpenClawAuthorizedMessagingToolHandlers(options);
|
|
241
|
+
// OpenClaw wraps registered tools with a policy Proxy that replaces
|
|
242
|
+
// `execute`. Freezing each tool makes that Proxy violate the JavaScript
|
|
243
|
+
// invariant for a non-configurable, read-only data property. Keep the array
|
|
244
|
+
// immutable while leaving its runtime tool records proxy-compatible.
|
|
245
|
+
return Object.freeze(OPENCLAW_AUTHORIZED_MESSAGING_TOOLS.map((definition) => ({
|
|
246
|
+
name: definition.name,
|
|
247
|
+
description: definition.description,
|
|
248
|
+
parameters: definition.inputSchema,
|
|
249
|
+
async execute(_toolCallId, params = {}) {
|
|
250
|
+
return withHelloLynkModelNotices(async () => {
|
|
251
|
+
const attempt = ["hellolynk_send_authorized_message", "hellolynk_reply_authorized_message"].includes(definition.name) ? { phase: "input_validation" } : null;
|
|
252
|
+
try {
|
|
253
|
+
const result = await handlers[definition.name](params, attempt);
|
|
254
|
+
return {
|
|
255
|
+
content: renderToolResult(definition.name, result, params).map((text) => ({ type: "text", text })),
|
|
256
|
+
details: result,
|
|
257
|
+
};
|
|
258
|
+
} catch (error) {
|
|
259
|
+
const nativeError = nativeAddressingError(error, attempt);
|
|
260
|
+
if (nativeError) return { content: nativeError.content, details: nativeError.structuredContent, isError: true };
|
|
261
|
+
const code = safeErrorCode(error);
|
|
262
|
+
if (!attempt) return { content: [{ type: "text", text: failureText(code) }], details: { ok: false, errorCode: code }, isError: true };
|
|
263
|
+
// Phase and retry policy come only from this invocation, never from an adapter error.
|
|
264
|
+
const { text, ...outcome } = writeFailure(code, attempt.phase);
|
|
265
|
+
return { content: [{ type: "text", text }], details: { ok: false, errorCode: code, ...outcome, phase: attempt.phase,
|
|
266
|
+
...(attempt.clientMessageId ? { clientMessageId: attempt.clientMessageId } : {}) }, isError: true };
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
})));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// The sentence comes first; tools that return records follow it with the records as JSON.
|
|
274
|
+
function renderToolResult(name, result, params) {
|
|
275
|
+
if (name === "hellolynk_get_unread_count") return [`当前对话:人类未读 ${result.humanUnreadCount} 条;AI 待处理 ${result.aiPendingCount} 条。`, JSON.stringify(result)];
|
|
276
|
+
if (name === "hellolynk_open_inbox") return ["HelloLynk 已就绪,在左侧打开“HelloLynk 通讯”。"];
|
|
277
|
+
if (name === "hellolynk_list_authorized_contacts") return [resultText.contacts(result.contacts.length),
|
|
278
|
+
JSON.stringify({ contacts: result.contacts, ...(result.nativeConversations ? { nativeConversations: result.nativeConversations } : {}) })];
|
|
279
|
+
if (name === "hellolynk_list_authorized_inbox_messages") return [resultText.inbox(result.messages.length, Object.hasOwn(params, "before")), JSON.stringify(result)];
|
|
280
|
+
if (name === "hellolynk_list_pending_messages") return [resultText.pending(result.messages.length), JSON.stringify(result)];
|
|
281
|
+
if (name === "hellolynk_claim_message") return result.claimed ? [resultText.claimed(result.messages?.length ?? 1, result.expiredCount), JSON.stringify(result)] : [JSON.stringify(result)];
|
|
282
|
+
if (name === "hellolynk_read_authorized_inbox_message") return ["已读取来信。", JSON.stringify(result)];
|
|
283
|
+
if (name === "hellolynk_read_authorized_contact_request") return ["已读取联系申请。", JSON.stringify(result)];
|
|
284
|
+
if (name === "hellolynk_list_authorized_contact_requests") return [`联系申请 ${result.requests.length} 条。`, JSON.stringify({ requests: result.requests })];
|
|
285
|
+
return [resultText.sent(result.status, result.clientMessageId)];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function safeContactList(value) {
|
|
289
|
+
if (!Array.isArray(value)) return [];
|
|
290
|
+
return value.map((item) => ({
|
|
291
|
+
contactId: safeText(item?.contactId, "contact_id_invalid", 200),
|
|
292
|
+
displayName: safeText(item?.displayName, "contact_display_name_invalid", 160),
|
|
293
|
+
recipientDelegateId: safeText(item?.recipientDelegateId, "recipient_delegate_id_invalid", 200),
|
|
294
|
+
instanceDisplayName: safeText(item?.instanceDisplayName, "instance_display_name_invalid", 160),
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function projectMetadata(value) {
|
|
299
|
+
const result = {
|
|
300
|
+
localMessageId: safeText(value?.localMessageId, "authorized_inbox_message_id_invalid", 240),
|
|
301
|
+
conversationKey: safeText(value?.conversationKey, "authorized_inbox_conversation_key_invalid", 240),
|
|
302
|
+
localDelegateId: safeText(value?.localDelegateId, "authorized_inbox_local_delegate_invalid", 200),
|
|
303
|
+
peerDelegateId: safeText(value?.peerDelegateId, "authorized_inbox_peer_delegate_invalid", 200),
|
|
304
|
+
messageType: safeText(value?.messageType || "text", "authorized_inbox_message_type_invalid", 80),
|
|
305
|
+
unread: value?.unread === true,
|
|
306
|
+
};
|
|
307
|
+
for (const key of ["contactId", "displayName", "peerInstanceDisplayName", "clientMessageId", "createdAt", "updatedAt"]) {
|
|
308
|
+
if (value?.[key] != null) result[key] = safeText(value[key], `authorized_inbox_${key}_invalid`, 240);
|
|
309
|
+
}
|
|
310
|
+
return result;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function projectRead(value) {
|
|
314
|
+
if (!projectInboxReadState(value) || value?.externalContentIsUntrustedData !== true) throw codeError("host_app_response_invalid");
|
|
315
|
+
return {
|
|
316
|
+
...projectMetadata(value), peerPrincipalId: safeText(value?.peerPrincipalId, "authorized_inbox_peer_principal_invalid", 200), text: safeBody(value?.text, 65536),
|
|
317
|
+
...(value?.automationStatus === "expired" ? { automationStatus: "expired" } : {}),
|
|
318
|
+
source: requireSource(value?.source, "hellolynk_external_message"),
|
|
319
|
+
...projectInboxReadState(value), ...replyHint(value),
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function projectContactRequestMetadata(value) {
|
|
324
|
+
return {
|
|
325
|
+
localRecordId: safeText(value?.localRecordId, "authorized_contact_request_id_invalid", 240),
|
|
326
|
+
conversationKey: safeText(value?.conversationKey, "authorized_contact_request_conversation_key_invalid", 240),
|
|
327
|
+
localDelegateId: safeText(value?.localDelegateId, "authorized_contact_request_local_delegate_invalid", 200),
|
|
328
|
+
sender: {
|
|
329
|
+
hellolynkId: safeText(value?.sender?.hellolynkId, "authorized_contact_request_sender_invalid", 200),
|
|
330
|
+
verifiedDisplayName: safeText(value?.sender?.verifiedDisplayName, "authorized_contact_request_sender_name_invalid", 160),
|
|
331
|
+
},
|
|
332
|
+
state: safeText(value?.state, "authorized_contact_request_state_invalid", 80),
|
|
333
|
+
receivedAt: safeText(value?.receivedAt, "authorized_contact_request_time_invalid", 80),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function projectContactRequestRead(value) {
|
|
338
|
+
return {
|
|
339
|
+
...projectContactRequestMetadata(value), introText: safeContactRequestIntro(value?.introText),
|
|
340
|
+
source: requireSource(value?.source, "hellolynk_contact_request"),
|
|
341
|
+
readDoesNotMarkRead: value?.readDoesNotMarkRead === true,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const PENDING_ID = /^[A-Za-z0-9][A-Za-z0-9_.:-]{2,198}$/;
|
|
346
|
+
|
|
347
|
+
// Keep the model-facing schema flat across providers. The handler enforces
|
|
348
|
+
// batchId OR the exact localMessageId + conversationKey pair before the Host.
|
|
349
|
+
function pendingClaimSchema() {
|
|
350
|
+
return { type: "object", additionalProperties: false,
|
|
351
|
+
properties: { batchId: { type: "string", pattern: "^inbatch_[a-f0-9]{48}$", description: paramText.batchId },
|
|
352
|
+
localMessageId: { type: "string", pattern: "^[A-Za-z0-9][A-Za-z0-9_.:-]{2,198}$", description: paramText.localMessageId },
|
|
353
|
+
conversationKey: { type: "string", pattern: "^[A-Za-z0-9][A-Za-z0-9_.:-]{2,198}$", description: paramText.conversationKey } } };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function projectPendingMessages(result) {
|
|
357
|
+
if (!Array.isArray(result?.messages) || result.messages.length > 1000) throw codeError("host_app_response_invalid");
|
|
358
|
+
return result.messages.map((value) => {
|
|
359
|
+
const ids = [value?.localMessageId, value?.conversationKey, value?.localDelegateId, value?.peerDelegateId, ...(value?.contactId === null ? [] : [value?.contactId])];
|
|
360
|
+
if (value?.wakeEligible !== true || typeof value.unread !== "boolean" || ids.some((id) => typeof id !== "string" || !PENDING_ID.test(id))
|
|
361
|
+
|| typeof value.displayName !== "string" || !value.displayName || value.displayName.length > 160 || /[\r\n\0]/.test(value.displayName)
|
|
362
|
+
|| typeof value.createdAt !== "string" || value.createdAt.length > 80 || !Number.isFinite(Date.parse(value.createdAt))) throw codeError("host_app_response_invalid");
|
|
363
|
+
return { ...Object.fromEntries(["localMessageId", "conversationKey", "localDelegateId", "peerDelegateId", "contactId", "displayName", "unread", "createdAt", "wakeEligible"].map((key) => [key, value[key]])),
|
|
364
|
+
...(value.peerInstanceDisplayName == null ? {} : { peerInstanceDisplayName: safeText(value.peerInstanceDisplayName, "instance_display_name_invalid", 160) }) };
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function strictConversationSchema(id) {
|
|
369
|
+
const message = id === "localMessageId";
|
|
370
|
+
return Object.freeze({ type: "object", additionalProperties: false, required: Object.freeze([id, "conversationKey"]), properties: Object.freeze({
|
|
371
|
+
[id]: Object.freeze({ type: "string", minLength: 3, maxLength: 240, ...(message ? { description: paramText.localMessageId } : {}) }),
|
|
372
|
+
conversationKey: Object.freeze({ type: "string", minLength: 3, maxLength: 240, ...(message ? { description: paramText.conversationKey } : {}) }),
|
|
373
|
+
}) });
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function requireSource(value, expected) {
|
|
377
|
+
if (value !== expected) throw codeError("external_content_source_invalid");
|
|
378
|
+
return expected;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function safeContactRequestIntro(value) {
|
|
382
|
+
return value === "" ? "" : safeBody(value);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function safeBody(value, maximum = 20_000, countCodePoints = false) {
|
|
386
|
+
const text = String(value ?? "");
|
|
387
|
+
if (!text || text.includes("\u0000") || (countCodePoints ? [...text].length : text.length) > maximum || Buffer.byteLength(text, "utf8") > (maximum === 20_000 ? 20 * 1024 : maximum)) {
|
|
388
|
+
throw codeError("message_text_invalid");
|
|
389
|
+
}
|
|
390
|
+
return text;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function safeText(value, code, maximum) {
|
|
394
|
+
const text = String(value ?? "").trim();
|
|
395
|
+
if (!text || text.length > maximum || /[\r\n\u0000-\u001f\u007f]/.test(text)) throw codeError(code);
|
|
396
|
+
return text;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function assertEmpty(value) {
|
|
400
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length) {
|
|
401
|
+
throw codeError("arguments_invalid");
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function assertExact(value, keys) {
|
|
406
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw codeError("arguments_invalid");
|
|
407
|
+
const actual = Object.keys(value || {}).sort();
|
|
408
|
+
const expected = [...keys].sort();
|
|
409
|
+
if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
|
|
410
|
+
throw codeError("arguments_invalid");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function codeError(code) {
|
|
415
|
+
const error = new Error(code);
|
|
416
|
+
error.code = code;
|
|
417
|
+
return error;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function safeErrorCode(error) {
|
|
421
|
+
const code = String(error?.code || error?.message || "hellolynk_operation_failed").trim();
|
|
422
|
+
return /^[a-z0-9_:-]{1,120}$/i.test(code) ? code : "hellolynk_operation_failed";
|
|
423
|
+
}
|