import { definePlugin, databaseHostToken } from 'zhin.js'; import { defineGithubOauthUsersTable } from './src/oauth-users.js'; import { createGithubConsoleRpc } from './src/console.js'; /** * github_subscriptions — repo event subscriptions per chat channel * (used by github_subscriptions agent tool; schema is registered through DatabaseHost). */ const GITHUB_SUBSCRIPTIONS_SCHEMA = { id: { type: 'integer', primary: true }, repo: { type: 'text', nullable: false }, events: { type: 'json', default: [] }, target_id: { type: 'text', nullable: false }, target_type: { type: 'text', nullable: false }, adapter: { type: 'text', nullable: false }, endpoint: { type: 'text', nullable: false }, } as const; /** * Plugin Runtime GitHub adapter. * - Endpoint: `adapters/github/index.ts` * - OAuth user tokens: define `github_oauth_users` when DatabaseHost is present */ export default definePlugin({ name: 'github', configUpdate: { featurePaths: [['nickname'], ['profile'], ['endpoints']] }, setup(context) { if (context.resources.has(databaseHostToken)) { const host = context.resources.use(databaseHostToken); defineGithubOauthUsersTable(host); host.define('github_subscriptions', { ...GITHUB_SUBSCRIPTIONS_SCHEMA }); } // 运行中 endpoint 注册表(github endpoint list 的"运行中"数据源) return { consoleRpc: createGithubConsoleRpc(context.resources, () => context.config.get()), }; }, });