feat: execute AI Office jobs in Harness

This commit is contained in:
pompy 2026-08-20 12:22:30 +08:00
parent b0606159e0
commit 3fa2cc05b2
14 changed files with 730 additions and 148 deletions

View file

@ -4,6 +4,8 @@ import { join, resolve } from 'node:path';
import { OfficeConfigStore } from '../../../../src/channels/office/config-store.mjs';
import { OfficeController } from '../../../../src/channels/office/office-controller.mjs';
import { OfficeRuntime } from '../../../../src/channels/office/office-runtime.mjs';
import { HarnessClient } from '../../../../src/channels/shared/harness-client.mjs';
import { harnessOrigin } from '../shared/production.mjs';
export function officePaths(config = {}) {
const dshHome = resolve(config.dshHome ?? process.env.DSH_HOME ?? join(homedir(), '.dsh'));
@ -15,14 +17,28 @@ export async function createProductionController(ctx, config = {}, internals = {
const Store = internals.ConfigStore ?? OfficeConfigStore;
const Controller = internals.Controller ?? OfficeController;
const Runtime = internals.Runtime ?? OfficeRuntime;
const ResolvedHarness = internals.HarnessClient ?? HarnessClient;
const paths = officePaths(config);
const configStore = await new Store(paths.config).load();
const logger = typeof ctx.logger === 'function' ? ctx.logger('dsh-im:office') : (ctx.logger ?? console);
const harnessBaseUrl = harnessOrigin(ctx.webServer, config.harnessBaseUrl);
const createHarness = internals.createHarness ?? (({ workspace }) => new ResolvedHarness({
baseUrl: harnessBaseUrl,
workspace,
autostart: false,
dshBin: config.dshBin ?? 'dsh',
rpcIdPrefix: 'office',
logPrefix: 'dsh-im:office',
}));
const controller = new Controller({
credentials: ctx.credentials,
configStore,
logger,
createRuntime: (options) => new Runtime({ ...options, ...(internals.transport ? { transport: internals.transport } : {}) }),
createRuntime: (options) => new Runtime({
...options,
createHarness,
...(internals.transport ? { transport: internals.transport } : {}),
}),
});
await controller.initialize();
return { controller, close: () => controller.close(), paths };