Skip to content

Commit fb0e8b1

Browse files
authored
refactor: consolidate final mechanical audit paths (#125165)
1 parent 657b6e8 commit fb0e8b1

9 files changed

Lines changed: 195 additions & 392 deletions

‎extensions/msteams/src/channel.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
33
import { describe, expect, it } from "vitest";
44
import { MSTeamsConfigSchema } from "../config-api.js";
5+
import { msteamsDirectoryContractPlugin } from "../directory-contract-api.js";
56
import { msTeamsApprovalAuth } from "./approval-auth.js";
67
import { msteamsPlugin } from "./channel.js";
78
import { msteamsSetupPlugin } from "./channel.setup.js";
@@ -34,8 +35,11 @@ describe("msteamsPlugin", () => {
3435
).toMatchObject({ chatType: "direct" });
3536
});
3637

37-
it("shares account and metadata contracts with the lightweight setup plugin", () => {
38+
it("shares setup and directory contracts with the lightweight artifacts", () => {
3839
expect(msteamsSetupPlugin.meta).toEqual(msteamsPlugin.meta);
40+
expect(msteamsPlugin.capabilities).toBe(msteamsSetupPlugin.capabilities);
41+
expect(msteamsPlugin.reload).toBe(msteamsSetupPlugin.reload);
42+
expect(msteamsPlugin.configSchema).toBe(msteamsSetupPlugin.configSchema);
3943

4044
for (const key of [
4145
"listAccountIds",
@@ -49,6 +53,14 @@ describe("msteamsPlugin", () => {
4953
] as const) {
5054
expect(msteamsSetupPlugin.config[key]).toBe(msteamsPlugin.config[key]);
5155
}
56+
57+
expect(msteamsPlugin.directory?.self).toBe(msteamsDirectoryContractPlugin.directory.self);
58+
expect(msteamsPlugin.directory?.listPeers).toBe(
59+
msteamsDirectoryContractPlugin.directory.listPeers,
60+
);
61+
expect(msteamsPlugin.directory?.listGroups).toBe(
62+
msteamsDirectoryContractPlugin.directory.listGroups,
63+
);
5264
});
5365

5466
it("preserves the default account and allowlist across runtime and setup", () => {

‎extensions/msteams/src/channel.ts‎

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Msteams plugin module implements channel behavior.
2-
import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
32
import type {
43
ChannelMessageActionAdapter,
54
ChannelMessageToolDiscovery,
@@ -18,7 +17,6 @@ import {
1817
import {
1918
createChannelDirectoryAdapter,
2019
createRuntimeDirectoryLiveAdapter,
21-
listDirectoryEntriesFromSources,
2220
} from "openclaw/plugin-sdk/directory-runtime";
2321
import { normalizeMessagePresentation } from "openclaw/plugin-sdk/interactive-runtime";
2422
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
@@ -28,6 +26,7 @@ import {
2826
normalizeStringEntries,
2927
} from "openclaw/plugin-sdk/string-coerce-runtime";
3028
import { Type } from "typebox";
29+
import { msteamsDirectoryContractPlugin } from "../directory-contract-api.js";
3130
import type {
3231
ChannelMessageActionName,
3332
ChannelOutboundAdapter,
@@ -47,12 +46,8 @@ import {
4746
resolveMSTeamsAutoThreadId,
4847
} from "./action-threading.js";
4948
import { msTeamsApprovalAuth } from "./approval-auth.js";
50-
import {
51-
msteamsConfigAdapter,
52-
msteamsMeta,
53-
type ResolvedMSTeamsAccount,
54-
} from "./channel-config.js";
55-
import { MSTeamsChannelConfigSchema } from "./config-schema.js";
49+
import type { ResolvedMSTeamsAccount } from "./channel-config.js";
50+
import { msteamsSetupPlugin } from "./channel.setup.js";
5651
import { collectMSTeamsMutableAllowlistWarnings } from "./doctor.js";
5752
import { resolveMSTeamsGroupToolPolicy } from "./policy.js";
5853
import { buildMSTeamsPresentationCard, MSTEAMS_PRESENTATION_CAPABILITIES } from "./presentation.js";
@@ -72,8 +67,6 @@ import {
7267
resolveMSTeamsUserAllowlist,
7368
} from "./resolve-allowlist.js";
7469
import { inferMSTeamsTargetChatType, resolveMSTeamsOutboundSessionRoute } from "./session-route.js";
75-
import { msteamsSetupContract } from "./setup-core.js";
76-
import { msteamsSetupWizard } from "./setup-surface.js";
7770
import { resolveMSTeamsCredentials } from "./token.js";
7871

7972
const TEAMS_GRAPH_PERMISSION_HINTS: Record<string, string> = {
@@ -422,18 +415,7 @@ const msteamsMessageAdapter = createChannelMessageAdapterFromOutbound({
422415
export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsResult> =
423416
createChatChannelPlugin({
424417
base: {
425-
id: "msteams",
426-
meta: {
427-
...msteamsMeta,
428-
aliases: [...msteamsMeta.aliases],
429-
},
430-
setupWizard: msteamsSetupWizard,
431-
capabilities: {
432-
chatTypes: ["direct", "channel", "thread"],
433-
polls: true,
434-
threads: true,
435-
media: true,
436-
},
418+
...msteamsSetupPlugin,
437419
streaming: {
438420
blockStreamingCoalesceDefaults: { minChars: 1500, idleMs: 1000 },
439421
},
@@ -446,17 +428,6 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
446428
groups: {
447429
resolveToolPolicy: resolveMSTeamsGroupToolPolicy,
448430
},
449-
reload: { configPrefixes: ["channels.msteams"] },
450-
configSchema: MSTeamsChannelConfigSchema,
451-
config: {
452-
...msteamsConfigAdapter,
453-
isConfigured: (_account, cfg) => Boolean(resolveMSTeamsCredentials(cfg.channels?.msteams)),
454-
describeAccount: (account) =>
455-
describeAccountSnapshot({
456-
account,
457-
configured: account.configured,
458-
}),
459-
},
460431
approvalCapability: msTeamsApprovalAuth,
461432
doctor: {
462433
dmAllowFromMode: "topOnly",
@@ -465,7 +436,6 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
465436
warnOnEmptyGroupSenderAllowlist: true,
466437
collectMutableAllowlistWarnings: collectMSTeamsMutableAllowlistWarnings,
467438
},
468-
setupContract: msteamsSetupContract,
469439
messaging: {
470440
targetPrefixes: ["msteams", "teams"],
471441
directTargetStyle: "user-prefixed",
@@ -479,43 +449,7 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount, ProbeMSTeamsRe
479449
},
480450
message: msteamsMessageAdapter,
481451
directory: createChannelDirectoryAdapter({
482-
self: async ({ cfg }) => {
483-
const creds = resolveMSTeamsCredentials(cfg.channels?.msteams);
484-
if (!creds) {
485-
return null;
486-
}
487-
return { kind: "user" as const, id: creds.appId, name: creds.appId };
488-
},
489-
listPeers: async ({ cfg, query, limit }) =>
490-
listDirectoryEntriesFromSources({
491-
kind: "user",
492-
sources: [
493-
cfg.channels?.msteams?.allowFrom ?? [],
494-
Object.keys(cfg.channels?.msteams?.dms ?? {}),
495-
],
496-
query,
497-
limit,
498-
normalizeId: (raw) => {
499-
const normalized = normalizeMSTeamsMessagingTarget(raw) ?? raw;
500-
const lowered = normalized.toLowerCase();
501-
if (lowered.startsWith("user:") || lowered.startsWith("conversation:")) {
502-
return normalized;
503-
}
504-
return `user:${normalized}`;
505-
},
506-
}),
507-
listGroups: async ({ cfg, query, limit }) =>
508-
listDirectoryEntriesFromSources({
509-
kind: "group",
510-
sources: [
511-
Object.values(cfg.channels?.msteams?.teams ?? {}).flatMap((team) =>
512-
Object.keys(team.channels ?? {}),
513-
),
514-
],
515-
query,
516-
limit,
517-
normalizeId: (raw) => `conversation:${raw.replace(/^conversation:/i, "").trim()}`,
518-
}),
452+
...msteamsDirectoryContractPlugin.directory,
519453
...createRuntimeDirectoryLiveAdapter({
520454
getRuntime: loadMSTeamsChannelRuntime,
521455
listPeersLive: (runtime) => runtime.listMSTeamsDirectoryPeersLive,

‎extensions/nostr/src/nostr-bus.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createDirectDmPreCryptoGuardPolicy,
66
type DirectDmPreCryptoGuardPolicyOverrides,
77
} from "openclaw/plugin-sdk/direct-dm-guard-policy";
8+
import { createFixedWindowRateLimiter } from "openclaw/plugin-sdk/webhook-ingress";
89
import type { NostrProfile } from "./config-schema.js";
910
import { DEFAULT_RELAYS } from "./default-relays.js";
1011
import {
@@ -23,7 +24,6 @@ import {
2324
} from "./nostr-ingress.js";
2425
import { validatePrivateKey } from "./nostr-key-utils.js";
2526
import { publishProfile as publishProfileFn, type ProfilePublishResult } from "./nostr-profile.js";
26-
import { createFixedWindowRateLimiter } from "./nostr-rate-limiter.js";
2727
import { createNostrRelaySubscriptionGroup } from "./nostr-relay-subscription.js";
2828
import {
2929
readNostrBusState,

‎extensions/nostr/src/nostr-rate-limiter.ts‎

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { OpenClawConfig } from "../config/types.openclaw.js";
22
import type { PluginMetadataSnapshot } from "../plugins/plugin-metadata-snapshot.js";
33
import "./models-config.plan.js";
4+
import type { PreparedModelsConfigContext } from "./models-config.plan.js";
45
import type { ProviderConfig } from "./models-config.providers.secrets.js";
56

67
type ResolveImplicitProvidersForModelsJson = (params: {
@@ -16,27 +17,27 @@ type ResolveImplicitProvidersForModelsJson = (params: {
1617
providerDiscoveryEntriesOnly?: boolean;
1718
}) => Promise<Record<string, ProviderConfig>>;
1819

19-
type PlanParams = Parameters<typeof import("./models-config.plan.js").planOpenClawModelsJson>[0];
20+
type PreparedPlanParams = Parameters<
21+
typeof import("./models-config.plan.js").planOpenClawModelsJson
22+
>[0];
23+
type FlatPreparedContext = Omit<
24+
PreparedModelsConfigContext,
25+
"discoveryAuthConfig" | "sourceConfigForSecrets" | "envFingerprint"
26+
> & {
27+
discoveryAuthConfig?: OpenClawConfig;
28+
sourceConfigForSecrets?: OpenClawConfig;
29+
};
30+
type PlanParams = Omit<PreparedPlanParams, "context"> & FlatPreparedContext;
2031
type PlanResult = Awaited<
2132
ReturnType<typeof import("./models-config.plan.js").planOpenClawModelsJson>
2233
>;
23-
type ResolveProvidersParams = {
24-
cfg: OpenClawConfig;
25-
discoveryAuthConfig?: OpenClawConfig;
26-
agentDir: string;
27-
env: NodeJS.ProcessEnv;
28-
workspaceDir?: string;
29-
pluginMetadataSnapshot?: Pick<PluginMetadataSnapshot, "index" | "manifestRegistry" | "owners">;
30-
providerDiscoveryProviderIds?: readonly string[];
31-
providerDiscoveryTimeoutMs?: number;
32-
providerDiscoveryEntriesOnly?: boolean;
33-
};
34+
type ResolveProvidersParams = FlatPreparedContext & { authStore?: PreparedPlanParams["authStore"] };
3435
type PlanDeps = { resolveImplicitProviders?: ResolveImplicitProvidersForModelsJson };
3536

3637
type ModelsConfigPlanTestApi = {
37-
planOpenClawModelsJsonWithDeps(params: PlanParams, deps?: PlanDeps): Promise<PlanResult>;
38+
planOpenClawModelsJsonWithDeps(params: PreparedPlanParams, deps?: PlanDeps): Promise<PlanResult>;
3839
resolveProvidersForModelsJsonWithDeps(
39-
params: ResolveProvidersParams,
40+
params: Pick<PreparedPlanParams, "context" | "authStore">,
4041
deps?: PlanDeps,
4142
): Promise<Record<string, ProviderConfig>>;
4243
};
@@ -47,13 +48,41 @@ function getTestApi(): ModelsConfigPlanTestApi {
4748
] as ModelsConfigPlanTestApi;
4849
}
4950

51+
function prepareTestContext(params: FlatPreparedContext): PreparedModelsConfigContext {
52+
return {
53+
...params,
54+
discoveryAuthConfig: params.discoveryAuthConfig ?? params.cfg,
55+
sourceConfigForSecrets: params.sourceConfigForSecrets ?? params.cfg,
56+
envFingerprint: params.env,
57+
};
58+
}
59+
5060
export const planOpenClawModelsJsonWithDeps = async (
5161
params: PlanParams,
5262
deps?: PlanDeps,
53-
): Promise<PlanResult> => await getTestApi().planOpenClawModelsJsonWithDeps(params, deps);
63+
): Promise<PlanResult> => {
64+
const { authStore, existingRaw, existingParsed, ...contextParams } = params;
65+
return await getTestApi().planOpenClawModelsJsonWithDeps(
66+
{
67+
context: prepareTestContext(contextParams),
68+
...(authStore ? { authStore } : {}),
69+
existingRaw,
70+
existingParsed,
71+
},
72+
deps,
73+
);
74+
};
5475

5576
export const resolveProvidersForModelsJsonWithDeps = async (
5677
params: ResolveProvidersParams,
5778
deps?: PlanDeps,
58-
): Promise<Record<string, ProviderConfig>> =>
59-
await getTestApi().resolveProvidersForModelsJsonWithDeps(params, deps);
79+
): Promise<Record<string, ProviderConfig>> => {
80+
const { authStore, ...contextParams } = params;
81+
return await getTestApi().resolveProvidersForModelsJsonWithDeps(
82+
{
83+
context: prepareTestContext(contextParams),
84+
...(authStore ? { authStore } : {}),
85+
},
86+
deps,
87+
);
88+
};

0 commit comments

Comments
 (0)