mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-12 11:50:45 +08:00
feat: secure Telegram access and connect AI Office
This commit is contained in:
parent
e3ae772106
commit
b0606159e0
30 changed files with 2045 additions and 302 deletions
44
plugin-src/client/channels/office/api.js
Normal file
44
plugin-src/client/channels/office/api.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import {
|
||||
OFFICE_PROTOCOL_VERSION,
|
||||
OFFICE_RPC_CHANNEL,
|
||||
OFFICE_RPC_ENDPOINTS,
|
||||
officeHookUrls,
|
||||
} from '../../../../src/channels/office/protocol.mjs';
|
||||
|
||||
function record(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
|
||||
|
||||
export function unwrapOfficeRpc(result) {
|
||||
if (!record(result) || typeof result.ok !== 'boolean') throw new Error('AI Office 服务返回了无法识别的响应');
|
||||
if (!result.ok) {
|
||||
const error = new Error(typeof result.error?.message === 'string' ? result.error.message : 'AI Office 操作失败');
|
||||
error.code = typeof result.error?.code === 'string' ? result.error.code : 'office-rpc-error';
|
||||
throw error;
|
||||
}
|
||||
return result.value;
|
||||
}
|
||||
|
||||
export function normalizeOfficeStatus(value) {
|
||||
if (!record(value) || value.configured !== true) {
|
||||
return { configured: false, connected: false, state: 'unconfigured', config: null, health: null };
|
||||
}
|
||||
const config = record(value.config) ? value.config : {};
|
||||
return {
|
||||
configured: true,
|
||||
connected: value.connected === true,
|
||||
state: typeof value.state === 'string' ? value.state : 'idle',
|
||||
tokenConfigured: value.tokenConfigured === true,
|
||||
config: {
|
||||
protocolVersion: config.protocolVersion ?? OFFICE_PROTOCOL_VERSION,
|
||||
baseUrl: typeof config.baseUrl === 'string' ? config.baseUrl : '',
|
||||
deviceId: typeof config.deviceId === 'string' ? config.deviceId : '',
|
||||
maxConcurrency: Number(config.maxConcurrency ?? 1),
|
||||
heartbeatSeconds: Number(config.heartbeatSeconds ?? 30),
|
||||
workspaces: record(config.workspaces) ? config.workspaces : {},
|
||||
instructionPresets: record(config.instructionPresets) ? config.instructionPresets : {},
|
||||
hooks: record(config.hooks) ? config.hooks : {},
|
||||
},
|
||||
health: record(value.health) ? value.health : null,
|
||||
};
|
||||
}
|
||||
|
||||
export { OFFICE_PROTOCOL_VERSION, OFFICE_RPC_CHANNEL, OFFICE_RPC_ENDPOINTS, officeHookUrls };
|
||||
Loading…
Add table
Add a link
Reference in a new issue