mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-02 02:57:51 +00:00
feat(discord): add autoThreadName 'generated' strategy (#43366)
* feat(discord): add autoThreadName 'generated' strategy
Adds async thread title generation for auto-created threads:
- autoThread: boolean - enables/disables auto-threading
- autoThreadName: 'message' | 'generated' - naming strategy
- 'generated' uses LLM to create concise 3-6 word titles
- Includes channel name/description context for better titles
- 10s timeout with graceful fallback
* Discord: support non-key auth for generated thread titles
* Discord: skip fallback auto-thread rename
* Discord: normalize generated thread title first content line
* Discord: split thread title generation helpers
* Discord: tidy thread title generation constants and order
* Discord: use runtime fallback model resolution for thread titles
* Discord: resolve thread-title model aliases
* Discord: fallback thread-title model selection to runtime defaults
* Agents: centralize simple completion runtime
* fix(discord): pass apiKey to complete() for thread title generation
The setRuntimeApiKey approach only works for full agent runs that use
authStorage.getApiKey(). The pi-ai complete() function expects apiKey
directly in options or falls back to env vars — it doesn't read from
authStorage.runtimeOverrides.
Fixes thread title generation for Claude/Anthropic users.
* fix(agents): return exchanged Copilot token from prepareSimpleCompletionModel
The recent thread-title fix (3346ba6) passes prepared.auth.apiKey to
complete(). For github-copilot, this was still the raw GitHub token
rather than the exchanged runtime token, causing auth failures.
Now setRuntimeApiKeyForCompletion returns the resolved token and
prepareSimpleCompletionModel includes it in auth.apiKey, so both the
authStorage path and direct apiKey pass-through work correctly.
* fix(agents): catch auth lookup exceptions in completion model prep
getApiKeyForModel can throw for credential issues (missing profile, etc).
Wrap in try/catch to return { error } for fail-soft handling rather than
propagating rejected promises to callers like thread title generation.
* Discord: strip markdown wrappers from generated thread titles
* Discord/agents: align thread-title model and local no-auth completion headers
* Tests: import fresh modules for mocked thread-title/simple-completion suites
* Agents: apply exchanged Copilot baseUrl in simple completions
* Discord: route thread runtime imports through plugin SDK
* Lockfile: add Discord pi-ai runtime dependency
* Lockfile: regenerate Discord pi-ai runtime dependency entries
* Agents: use published Copilot token runtime module
* Discord: refresh config baseline and lockfile
* Tests: split extension runs by isolation
* Discord: add changelog for generated thread titles (#43366) (thanks @davidguttman)
---------
Co-authored-by: Onur Solmaz <onur@textcortex.com>
Co-authored-by: Onur Solmaz <2453968+osolmaz@users.noreply.github.com>
This commit is contained in:
@@ -5,11 +5,13 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { channelTestRoots } from "../vitest.channel-paths.mjs";
|
||||
import { loadTestRunnerBehavior } from "./test-runner-manifest.mjs";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const repoRoot = path.resolve(__dirname, "..");
|
||||
const pnpm = "pnpm";
|
||||
const testRunnerBehavior = loadTestRunnerBehavior();
|
||||
|
||||
function runGit(args, options = {}) {
|
||||
return execFileSync("git", args, {
|
||||
@@ -225,17 +227,69 @@ export function resolveExtensionTestPlan(params = {}) {
|
||||
|
||||
const usesChannelConfig = roots.some((root) => channelTestRoots.includes(root));
|
||||
const config = usesChannelConfig ? "vitest.channels.config.ts" : "vitest.extensions.config.ts";
|
||||
const testFiles = roots.flatMap((root) => collectTestFiles(path.join(repoRoot, root)));
|
||||
const testFiles = roots
|
||||
.flatMap((root) => collectTestFiles(path.join(repoRoot, root)))
|
||||
.map((filePath) => normalizeRelative(path.relative(repoRoot, filePath)));
|
||||
const { isolatedTestFiles, sharedTestFiles } = partitionExtensionTestFiles({ config, testFiles });
|
||||
|
||||
return {
|
||||
config,
|
||||
extensionDir: relativeExtensionDir,
|
||||
extensionId,
|
||||
isolatedTestFiles,
|
||||
roots,
|
||||
testFiles: testFiles.map((filePath) => normalizeRelative(path.relative(repoRoot, filePath))),
|
||||
sharedTestFiles,
|
||||
testFiles,
|
||||
};
|
||||
}
|
||||
|
||||
export function partitionExtensionTestFiles(params) {
|
||||
const testFiles = params.testFiles.map((filePath) => normalizeRelative(filePath));
|
||||
let isolatedEntries = [];
|
||||
let isolatedPrefixes = [];
|
||||
|
||||
if (params.config === "vitest.channels.config.ts") {
|
||||
isolatedEntries = testRunnerBehavior.channels.isolated;
|
||||
isolatedPrefixes = testRunnerBehavior.channels.isolatedPrefixes;
|
||||
} else if (params.config === "vitest.extensions.config.ts") {
|
||||
isolatedEntries = testRunnerBehavior.extensions.isolated;
|
||||
}
|
||||
|
||||
const isolatedEntrySet = new Set(isolatedEntries.map((entry) => entry.file));
|
||||
const isolatedTestFiles = testFiles.filter(
|
||||
(file) =>
|
||||
isolatedEntrySet.has(file) || isolatedPrefixes.some((prefix) => file.startsWith(prefix)),
|
||||
);
|
||||
const isolatedTestFileSet = new Set(isolatedTestFiles);
|
||||
const sharedTestFiles = testFiles.filter((file) => !isolatedTestFileSet.has(file));
|
||||
|
||||
return { isolatedTestFiles, sharedTestFiles };
|
||||
}
|
||||
|
||||
async function runVitestBatch(params) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const child = spawn(
|
||||
pnpm,
|
||||
["exec", "vitest", "run", "--config", params.config, ...params.files, ...params.args],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
stdio: "inherit",
|
||||
shell: process.platform === "win32",
|
||||
env: params.env,
|
||||
},
|
||||
);
|
||||
|
||||
child.on("error", reject);
|
||||
child.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
}
|
||||
resolve(code ?? 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function printUsage() {
|
||||
console.error("Usage: pnpm test:extension <extension-name|path> [vitest args...]");
|
||||
console.error(" node scripts/test-extension.mjs [extension-name|path] [vitest args...]");
|
||||
@@ -352,6 +406,8 @@ async function run() {
|
||||
console.log(`config: ${plan.config}`);
|
||||
console.log(`roots: ${plan.roots.join(", ")}`);
|
||||
console.log(`tests: ${plan.testFiles.length}`);
|
||||
console.log(`shared: ${plan.sharedTestFiles.length}`);
|
||||
console.log(`isolated: ${plan.isolatedTestFiles.length}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -364,24 +420,35 @@ async function run() {
|
||||
`[test-extension] Running ${plan.testFiles.length} test files for ${plan.extensionId} with ${plan.config}`,
|
||||
);
|
||||
|
||||
const child = spawn(
|
||||
pnpm,
|
||||
["exec", "vitest", "run", "--config", plan.config, ...plan.testFiles, ...passthroughArgs],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
stdio: "inherit",
|
||||
shell: process.platform === "win32",
|
||||
env: process.env,
|
||||
},
|
||||
);
|
||||
if (plan.sharedTestFiles.length > 0 && plan.isolatedTestFiles.length > 0) {
|
||||
console.log(
|
||||
`[test-extension] Split into ${plan.sharedTestFiles.length} shared and ${plan.isolatedTestFiles.length} isolated files`,
|
||||
);
|
||||
}
|
||||
|
||||
child.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
return;
|
||||
if (plan.sharedTestFiles.length > 0) {
|
||||
const sharedExitCode = await runVitestBatch({
|
||||
args: passthroughArgs,
|
||||
config: plan.config,
|
||||
env: process.env,
|
||||
files: plan.sharedTestFiles,
|
||||
});
|
||||
if (sharedExitCode !== 0) {
|
||||
process.exit(sharedExitCode);
|
||||
}
|
||||
process.exit(code ?? 1);
|
||||
});
|
||||
}
|
||||
|
||||
if (plan.isolatedTestFiles.length > 0) {
|
||||
const isolatedExitCode = await runVitestBatch({
|
||||
args: passthroughArgs,
|
||||
config: plan.config,
|
||||
env: { ...process.env, OPENCLAW_TEST_ISOLATE: "1" },
|
||||
files: plan.isolatedTestFiles,
|
||||
});
|
||||
process.exit(isolatedExitCode);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const entryHref = process.argv[1] ? pathToFileURL(path.resolve(process.argv[1])).href : "";
|
||||
|
||||
Reference in New Issue
Block a user