68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { loadEnvironmentFromNodeEnv } from "../src/common/env-loader.js";
|
|
|
|
loadEnvironmentFromNodeEnv();
|
|
|
|
const { initLogger, getLogger } = await import("../src/observability/logger.js");
|
|
initLogger();
|
|
const logger = getLogger();
|
|
const { GarnetClient } = await import("../src/common/garnet.js");
|
|
const { getRawSecret } = await import("../src/common/secret-manager.js");
|
|
const { initMongoDB, closeMongoDB } = await import("../src/common/mongodb.js");
|
|
const { createMemoryService } = await import("../src/memory/memory-service.js");
|
|
const { ingestMarkdownResources } = await import("../src/memory/knowledge-ingest.js");
|
|
|
|
function firstNonEmpty(
|
|
...values: Array<string | null | undefined>
|
|
): string | undefined {
|
|
for (const value of values) {
|
|
if (value?.trim()) {
|
|
return value.trim();
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
const dryRun = process.argv.includes("--dry-run");
|
|
const mongoConnectionString = firstNonEmpty(
|
|
getRawSecret("MONGODB_CONNECTION_STRING"),
|
|
process.env["MONGODB_CONNECTION_STRING"],
|
|
);
|
|
|
|
if (!mongoConnectionString) {
|
|
throw new Error("MONGODB_CONNECTION_STRING is required for knowledge ingest");
|
|
}
|
|
|
|
const garnetClient = new GarnetClient();
|
|
await garnetClient.connect();
|
|
|
|
try {
|
|
const mongoConnection = await initMongoDB(mongoConnectionString);
|
|
const memoryService = createMemoryService({
|
|
garnetClient,
|
|
mongooseConnection: mongoConnection,
|
|
});
|
|
|
|
const [onboarding, moderation] = await Promise.all([
|
|
ingestMarkdownResources(memoryService, {
|
|
baseDir: "src/skills/onboarding/resources",
|
|
category: "onboarding-step",
|
|
dryRun,
|
|
skill: "onboarding",
|
|
}),
|
|
ingestMarkdownResources(memoryService, {
|
|
baseDir: "src/skills/moderation/resources",
|
|
category: "rule",
|
|
dryRun,
|
|
skill: "moderation",
|
|
}),
|
|
]);
|
|
|
|
logger.info(
|
|
{ dryRun, moderation, onboarding },
|
|
"✓ Knowledge ingest completed",
|
|
);
|
|
} finally {
|
|
await closeMongoDB();
|
|
await garnetClient.close();
|
|
}
|