mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-02 08:10:10 +08:00
- Endpoints: new cross-region key feishuHookWsUrl (wss:). The released manifests leave it empty, so the entry stays hidden until the service is deployed. - Hook control: a feishu lane on the provider-neutral state machine. Hello declares provider-bind / provider-prefs / session-picker / provider:feishu only; topic lanes count as group turns; official Feishu turns keep origin hook (never the personal bot's trusted im source); bind and AppLink URLs are allowlisted (feishuDeepLink.ts). - Settings → IM bots: the official Feishu / Lark card (authorize page, one-time bind code, open bot, unlink, app-changed notice), workspace preferences and settings search; 12 locales and glossary. - cindy://settings/im-bot?group=cindy|personal deep link, used by the bot's "open Cindy settings" button. Signed-off-by: xd-bobo <caojianbo@xd.com>
89 lines
4.0 KiB
JavaScript
89 lines
4.0 KiB
JavaScript
/**
|
|
* endpoint-local-file.mjs — local 模式端点清单(config/endpoint.local.json)生成器。
|
|
*
|
|
* 背景:dev 默认读仓内 Global 正本 config/endpoint.global.json(远程生产/测试值);
|
|
* 「连本地 server」的 local 模式改由本文件生成的 endpoint.local.json 承载——
|
|
* auth / device-link / oss / model-access / voice / github / skillhub / plugin 指向 localhost
|
|
* 八件套(oss / model-access / voice / github / skillhub / plugin 必须跟 auth 同侧:都用
|
|
* AUTH_ISSUER 验签,本地 auth 签发的 token 过不了生产侧验签);官方飞书 hook 同理指向
|
|
* 本地 feishu-hook-server(ws://localhost:8794),它也按本地 auth 验桌面 token,
|
|
* 其余字段(oauth broker / heartbeat / slack hook / website / 网关 / 更新链
|
|
* CDN)照抄所选 region 正本(本地不起这些服务,沿用远程值,消费方各自的
|
|
* "连不上就跳过"分支继续生效)。
|
|
* 主进程经 XDT_ENDPOINT_MANIFEST_FILE 指到该文件(clientEndpointsService
|
|
* 的 file 模式,allowHttp 放行 localhost http)。
|
|
*
|
|
* 文件 gitignored、**每次调用整文件重写**(幂等;手改会在下次 restart:local
|
|
* 时丢失——需要长期自定义时改用 XDT_ENDPOINT_MANIFEST_FILE 指向自己的文件)。
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const LOCAL_AUTH_BASE_URL = 'http://localhost:3344';
|
|
const LOCAL_DEVICE_LINK_BASE_URL = 'http://localhost:3335';
|
|
const LOCAL_OSS_BASE_URL = 'http://localhost:3340';
|
|
const LOCAL_MODEL_ACCESS_BASE_URL = 'http://localhost:3339';
|
|
const LOCAL_VOICE_BASE_URL = 'http://localhost:3342';
|
|
const LOCAL_GITHUB_BASE_URL = 'http://localhost:3336';
|
|
const LOCAL_SKILLHUB_BASE_URL = 'http://localhost:3341';
|
|
const LOCAL_CINDY_SKILLHUB_BASE_URL = 'http://localhost:3345';
|
|
const LOCAL_PLUGIN_BASE_URL = 'http://localhost:3343';
|
|
const LOCAL_FEISHU_HOOK_WS_URL = 'ws://localhost:8794';
|
|
|
|
/**
|
|
* 从所选 region 正本生成 endpoint.local.json,返回生成文件的绝对路径。
|
|
* 正本缺失/非法直接抛错(fail closed,不造半截配置)。
|
|
* @param {{ repoRoot: string, region?: 'cn' | 'global' | 'dev' }} options
|
|
*/
|
|
export function generateEndpointLocalFile({ repoRoot, region = 'global' }) {
|
|
const fileName = {
|
|
cn: 'endpoint.json',
|
|
global: 'endpoint.global.json',
|
|
dev: 'endpoint.dev.json',
|
|
}[region];
|
|
if (!fileName) {
|
|
throw new Error(`Invalid Cindy auth region: ${region}; expected cn, global or dev`);
|
|
}
|
|
const sourcePath = path.join(repoRoot, 'config', fileName);
|
|
const targetPath = path.join(repoRoot, 'config', 'endpoint.local.json');
|
|
const relativeSourcePath = `config/${fileName}`;
|
|
let sourceText;
|
|
try {
|
|
sourceText = fs.readFileSync(sourcePath, 'utf8');
|
|
} catch (error) {
|
|
if (error?.code === 'ENOENT') {
|
|
const devHint =
|
|
region === 'dev'
|
|
? ' Copy config/endpoint.dev.json.example to config/endpoint.dev.json first.'
|
|
: '';
|
|
throw new Error(`Missing endpoint manifest ${relativeSourcePath}.${devHint}`);
|
|
}
|
|
throw new Error(`Failed to read endpoint manifest ${relativeSourcePath}: ${error.message}`);
|
|
}
|
|
|
|
let source;
|
|
try {
|
|
source = JSON.parse(sourceText);
|
|
} catch (error) {
|
|
throw new Error(`Invalid JSON in endpoint manifest ${relativeSourcePath}: ${error.message}`);
|
|
}
|
|
const local = {
|
|
_note:
|
|
'由 scripts/shared/endpoint-local-file.mjs 生成(restart:desktop:local / dev:desktop),' +
|
|
`每次启动整文件重写,手改会丢;localhost 八件套之外的字段照抄 config/${fileName}。`,
|
|
...source,
|
|
authApiBaseUrl: LOCAL_AUTH_BASE_URL,
|
|
deviceLinkApiBaseUrl: LOCAL_DEVICE_LINK_BASE_URL,
|
|
ossApiBaseUrl: LOCAL_OSS_BASE_URL,
|
|
modelAccessApiBaseUrl: LOCAL_MODEL_ACCESS_BASE_URL,
|
|
voiceApiBaseUrl: LOCAL_VOICE_BASE_URL,
|
|
githubApiBaseUrl: LOCAL_GITHUB_BASE_URL,
|
|
skillhubApiBaseUrl: LOCAL_SKILLHUB_BASE_URL,
|
|
cindySkillHubApiBaseUrl: LOCAL_CINDY_SKILLHUB_BASE_URL,
|
|
pluginApiBaseUrl: LOCAL_PLUGIN_BASE_URL,
|
|
feishuHookWsUrl: LOCAL_FEISHU_HOOK_WS_URL,
|
|
};
|
|
fs.writeFileSync(targetPath, `${JSON.stringify(local, null, 2)}\n`);
|
|
return targetPath;
|
|
}
|