Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openclaw.plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"default": "/linq-webhook"
},
"webhookHost": { "type": "string", "minLength": 1 },
"accounts": { "type": "object", "additionalProperties": true },
"accounts": { "type": "object", "additionalProperties": { "$ref": "#" } },
"defaultAccount": { "type": "string", "minLength": 1 }
},
"$defs": {
Expand Down Expand Up @@ -71,7 +71,7 @@
"default": "/linq-webhook"
},
"webhookHost": { "type": "string", "minLength": 1 },
"accounts": { "type": "object", "additionalProperties": true },
"accounts": { "type": "object", "additionalProperties": { "$ref": "#" } },
"defaultAccount": { "type": "string", "minLength": 1 }
},
"$defs": {
Expand Down
428 changes: 297 additions & 131 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"messaging"
],
"peerDependencies": {
"openclaw": ">=2026.6.0"
"openclaw": ">=2026.6.1"
},
"dependencies": {
"zod": "^4.4.3"
Expand Down
4 changes: 2 additions & 2 deletions setup-entry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineSetupPluginEntry } from "openclaw/plugin-sdk/channel-core";
import { linqPlugin } from "./src/channel.js";
import { linqSetupPlugin } from "./src/channel.setup.js";

export default defineSetupPluginEntry(linqPlugin);
export default defineSetupPluginEntry(linqSetupPlugin);
184 changes: 184 additions & 0 deletions src/channel-base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import {
applyAccountNameToChannelSection,
DEFAULT_ACCOUNT_ID,
deleteAccountFromConfigSection,
formatPairingApproveHint,
getChatChannelMeta,
migrateBaseNameToDefaultAccount,
normalizeAccountId,
setAccountEnabledInConfigSection,
type ChannelPlugin,
} from "openclaw/plugin-sdk/core";
import {
listLinqAccountIds,
resolveDefaultLinqAccountId,
resolveLinqAccountForStatus,
type ResolvedLinqAccount,
} from "./linq/accounts.js";
import { LinqChannelConfigSchema } from "./linq/config.js";
import {
collectLinqRuntimeConfigAssignments,
linqSecretTargetRegistryEntries,
} from "./linq/secret-contract.js";
import type { LinqProbe } from "./linq/types.js";
import { linqOnboardingAdapter } from "./onboarding.js";

const meta = getChatChannelMeta("linq");

export function createLinqPluginBase(): ChannelPlugin<ResolvedLinqAccount, LinqProbe> {
return {
id: "linq",
meta: {
...meta,
aliases: ["linq-imessage"],
},
setupWizard: linqOnboardingAdapter,
capabilities: {
chatTypes: ["direct"],
reactions: false,
media: true,
},
reload: { configPrefixes: ["channels.linq"] },
configSchema: LinqChannelConfigSchema,
config: {
listAccountIds: (cfg) => listLinqAccountIds(cfg),
resolveAccount: (cfg, accountId) => resolveLinqAccountForStatus({ cfg, accountId }),
defaultAccountId: (cfg) => resolveDefaultLinqAccountId(cfg),
setAccountEnabled: ({ cfg, accountId, enabled }) =>
setAccountEnabledInConfigSection({
cfg,
sectionKey: "linq",
accountId,
enabled,
allowTopLevel: true,
}),
deleteAccount: ({ cfg, accountId }) =>
deleteAccountFromConfigSection({
cfg,
sectionKey: "linq",
accountId,
clearBaseFields: ["apiToken", "tokenFile", "fromPhone", "name"],
}),
isConfigured: (account) => Boolean(account.token?.trim()),
describeAccount: (account) => ({
accountId: account.accountId,
name: account.name,
enabled: account.enabled,
configured: Boolean(account.token?.trim()),
tokenSource: account.tokenSource,
webhookSecretSource: account.webhookSecretSource,
fromPhone: account.fromPhone,
}),
resolveAllowFrom: ({ cfg, accountId }) =>
(resolveLinqAccountForStatus({ cfg, accountId }).config.allowFrom ?? []).map((entry) =>
String(entry),
),
formatAllowFrom: ({ allowFrom }) =>
allowFrom.map((entry) => String(entry).trim()).filter(Boolean),
},
security: {
resolveDmPolicy: ({ cfg, accountId, account }) => {
const resolvedAccountId = accountId ?? account.accountId ?? DEFAULT_ACCOUNT_ID;
const linqSection = (cfg.channels as Record<string, unknown> | undefined)?.linq as
| Record<string, unknown>
| undefined;
const useAccountPath = Boolean(
(linqSection?.accounts as Record<string, unknown> | undefined)?.[resolvedAccountId],
);
const basePath = useAccountPath
? `channels.linq.accounts.${resolvedAccountId}.`
: "channels.linq.";
return {
policy: account.config.dmPolicy ?? "open",
allowFrom: account.config.allowFrom ?? [],
policyPath: `${basePath}dmPolicy`,
allowFromPath: basePath,
approveHint: formatPairingApproveHint("linq"),
};
},
},
setup: {
resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
applyAccountName: ({ cfg, accountId, name }) =>
applyAccountNameToChannelSection({
cfg,
channelKey: "linq",
accountId,
name,
}),
validateInput: ({ accountId, input }) => {
if (input.useEnv && accountId !== DEFAULT_ACCOUNT_ID) {
return "LINQ_API_TOKEN can only be used for the default account.";
}
if (!input.useEnv && !input.token && !input.tokenFile) {
return "Linq requires an API token or --token-file (or --use-env).";
}
return null;
},
applyAccountConfig: ({ cfg, accountId, input }) => {
const namedConfig = applyAccountNameToChannelSection({
cfg,
channelKey: "linq",
accountId,
name: input.name,
});
const next =
accountId !== DEFAULT_ACCOUNT_ID
? migrateBaseNameToDefaultAccount({ cfg: namedConfig, channelKey: "linq" })
: namedConfig;
if (accountId === DEFAULT_ACCOUNT_ID) {
return {
...next,
channels: {
...next.channels,
linq: {
...((next.channels as Record<string, unknown> | undefined)?.linq as
| Record<string, unknown>
| undefined),
enabled: true,
...(input.useEnv
? {}
: input.tokenFile
? { tokenFile: input.tokenFile }
: input.token
? { apiToken: input.token }
: {}),
},
},
};
}
const linqSection = (next.channels as Record<string, unknown> | undefined)?.linq as
| Record<string, unknown>
| undefined;
return {
...next,
channels: {
...next.channels,
linq: {
...linqSection,
enabled: true,
accounts: {
...(linqSection?.accounts as Record<string, unknown> | undefined),
[accountId]: {
...((linqSection?.accounts as Record<string, unknown> | undefined)?.[
accountId
] as Record<string, unknown> | undefined),
enabled: true,
...(input.tokenFile
? { tokenFile: input.tokenFile }
: input.token
? { apiToken: input.token }
: {}),
},
},
},
},
};
},
},
secrets: {
secretTargetRegistryEntries: linqSecretTargetRegistryEntries,
collectRuntimeConfigAssignments: collectLinqRuntimeConfigAssignments,
},
};
}
3 changes: 3 additions & 0 deletions src/channel.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createLinqPluginBase } from "./channel-base.js";

export const linqSetupPlugin = createLinqPluginBase();
12 changes: 10 additions & 2 deletions src/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import linqSetupEntry from "../setup-entry.js";
import { linqPlugin } from "./channel.js";
import { linqSetupPlugin } from "./channel.setup.js";

describe("Linq channel discovery", () => {
it("exposes the channel plugin to setup-only discovery", () => {
expect(linqSetupEntry.plugin).toBe(linqPlugin);
it("exposes a runtime-free channel plugin to setup-only discovery", () => {
expect(linqSetupEntry.plugin).toBe(linqSetupPlugin);
expect(linqSetupEntry.plugin).not.toBe(linqPlugin);
expect(linqSetupPlugin.setupWizard).toBe(linqPlugin.setupWizard);
expect(linqSetupPlugin.setup).toBeDefined();
expect(linqSetupPlugin.configSchema).toBe(linqPlugin.configSchema);
expect(linqSetupPlugin).not.toHaveProperty("gateway");
expect(linqSetupPlugin).not.toHaveProperty("outbound");
expect(linqSetupPlugin).not.toHaveProperty("message");
});

it("declares the setup entry and channel catalog metadata", async () => {
Expand Down
Loading