integrations are updated automatically on model refresh.

This commit is contained in:
redshift
2026-04-03 14:56:40 +02:00
parent 557489ba4f
commit d1574b6e9c
3 changed files with 57 additions and 1 deletions
+23 -1
View File
@@ -20,6 +20,7 @@ import { createWalletAdapter } from "./wallet";
import { createCocodClient } from "./wallet/cocod-client";
import { createModelService } from "./models";
import { createDaemonRequestHandler } from "./http";
import { runIntegrationsForClients } from "../integrations";
import { RoutstrClient } from "@routstr/sdk";
async function main(): Promise<void> {
@@ -104,6 +105,17 @@ async function main(): Promise<void> {
try {
await getRoutstr21Models(true);
logger.log("Scheduled model refresh completed successfully.");
// Refresh integrations for all registered clients
const state = store.getState();
const clientIds = state.clientIds || [];
if (clientIds.length > 0) {
logger.log(
`Refreshing ${clientIds.length} client integration(s)...`,
);
await runIntegrationsForClients(clientIds, updatedConfig, store);
logger.log("Client integrations refreshed.");
}
} catch (error) {
logger.error("Scheduled model refresh failed:", error);
}
@@ -203,8 +215,18 @@ async function main(): Promise<void> {
logger.log("Running initial model refresh...");
return getRoutstr21Models(true);
})
.then(() => {
.then(async () => {
logger.log("Initial model refresh completed.");
// Refresh integrations for all registered clients after initial bootstrap
const state = store.getState();
const clientIds = state.clientIds || [];
if (clientIds.length > 0) {
logger.log(
`Refreshing ${clientIds.length} client integration(s)...`,
);
await runIntegrationsForClients(clientIds, updatedConfig, store);
logger.log("Client integrations refreshed.");
}
})
.catch((error) => {
logger.error("Initial model refresh failed:", error);
+1
View File
@@ -4,6 +4,7 @@ import { installOpencodeIntegration } from "./opencode";
import { installOpenClawIntegration } from "./openclaw";
import { installPiIntegration } from "./pi";
import type { SdkStore } from "@routstr/sdk";
export { CLIENT_INTEGRATIONS, runIntegrationsForClients } from "./registry";
function ask(question: string): Promise<string> {
process.stdout.write(question);
+33
View File
@@ -0,0 +1,33 @@
import type { RoutstrdConfig } from "../utils/config";
import type { SdkStore } from "@routstr/sdk";
import { installOpencodeIntegration } from "./opencode";
import { installPiIntegration } from "./pi";
import { installOpenClawIntegration } from "./openclaw";
export type IntegrationFn = (
config: RoutstrdConfig,
store: SdkStore,
) => Promise<void>;
export const CLIENT_INTEGRATIONS: Record<string, IntegrationFn> = {
opencode: installOpencodeIntegration,
"pi-agent": installPiIntegration,
openclaw: installOpenClawIntegration,
};
export async function runIntegrationsForClients(
clientIds: Array<{ clientId: string }>,
config: RoutstrdConfig,
store: SdkStore,
): Promise<void> {
for (const client of clientIds) {
const integrationFn = CLIENT_INTEGRATIONS[client.clientId];
if (integrationFn) {
try {
await integrationFn(config, store);
} catch (error) {
console.error(`Integration failed for ${client.clientId}:`, error);
}
}
}
}