

























@@ -72,96 +72,98 @@ export async function dispatchSynologyChatInboundTurn(params: {
7272userId: params.msg.from,
7373});
747475-await resolved.rt.channel.turn.runResolved({
75+await resolved.rt.channel.turn.run({
7676channel: CHANNEL_ID,
7777accountId: params.account.accountId,
7878raw: params.msg,
79-input: (msg) => ({
80-id: `${params.account.accountId}:${msg.from}`,
81-timestamp: Date.now(),
82-rawText: msg.body,
83-textForAgent: msg.body,
84-textForCommands: msg.body,
85-raw: msg,
86-}),
87-resolveTurn: (input) => {
88-const chatKind =
89-params.msg.chatType === "group" || params.msg.chatType === "channel"
90- ? params.msg.chatType
91- : "direct";
92-const msgCtx = resolved.rt.channel.turn.buildContext({
93-channel: CHANNEL_ID,
94-accountId: params.account.accountId,
95-timestamp: input.timestamp,
96-from: `synology-chat:${params.msg.from}`,
97-sender: {
98-id: params.msg.from,
99-name: params.msg.senderName,
100-},
101-conversation: {
102-kind: chatKind,
103-id: params.msg.from,
104-label: params.msg.senderName || params.msg.from,
105-routePeer: {
106-kind: "direct",
79+adapter: {
80+ingest: (msg) => ({
81+id: `${params.account.accountId}:${msg.from}`,
82+timestamp: Date.now(),
83+rawText: msg.body,
84+textForAgent: msg.body,
85+textForCommands: msg.body,
86+raw: msg,
87+}),
88+resolveTurn: (input) => {
89+const chatKind =
90+params.msg.chatType === "group" || params.msg.chatType === "channel"
91+ ? params.msg.chatType
92+ : "direct";
93+const msgCtx = resolved.rt.channel.turn.buildContext({
94+channel: CHANNEL_ID,
95+accountId: params.account.accountId,
96+timestamp: input.timestamp,
97+from: `synology-chat:${params.msg.from}`,
98+sender: {
10799id: params.msg.from,
100+name: params.msg.senderName,
101+},
102+conversation: {
103+kind: chatKind,
104+id: params.msg.from,
105+label: params.msg.senderName || params.msg.from,
106+routePeer: {
107+kind: "direct",
108+id: params.msg.from,
109+},
110+},
111+route: {
112+agentId: resolved.route.agentId,
113+accountId: params.account.accountId,
114+routeSessionKey: resolved.sessionKey,
115+dispatchSessionKey: resolved.sessionKey,
108116},
109-},
110-route: {
117+reply: {
118+to: `synology-chat:${params.msg.from}`,
119+originatingTo: `synology-chat:${params.msg.from}`,
120+},
121+message: {
122+rawBody: input.rawText,
123+commandBody: input.textForCommands,
124+bodyForAgent: input.textForAgent,
125+envelopeFrom: params.msg.senderName,
126+},
127+extra: {
128+ChatType: params.msg.chatType,
129+CommandAuthorized: params.msg.commandAuthorized,
130+},
131+});
132+const storePath = resolved.rt.channel.session.resolveStorePath(currentCfg.session?.store, {
111133agentId: resolved.route.agentId,
134+});
135+return {
136+cfg: currentCfg,
137+channel: CHANNEL_ID,
112138accountId: params.account.accountId,
113-routeSessionKey: resolved.sessionKey,
114-dispatchSessionKey: resolved.sessionKey,
115-},
116-reply: {
117-to: `synology-chat:${params.msg.from}`,
118-originatingTo: `synology-chat:${params.msg.from}`,
119-},
120-message: {
121-rawBody: input.rawText,
122-commandBody: input.textForCommands,
123-bodyForAgent: input.textForAgent,
124-envelopeFrom: params.msg.senderName,
125-},
126-extra: {
127-ChatType: params.msg.chatType,
128-CommandAuthorized: params.msg.commandAuthorized,
129-},
130-});
131-const storePath = resolved.rt.channel.session.resolveStorePath(currentCfg.session?.store, {
132-agentId: resolved.route.agentId,
133-});
134-return {
135-cfg: currentCfg,
136-channel: CHANNEL_ID,
137-accountId: params.account.accountId,
138-agentId: resolved.route.agentId,
139-routeSessionKey: resolved.route.sessionKey,
140- storePath,
141-ctxPayload: msgCtx,
142-recordInboundSession: resolved.rt.channel.session.recordInboundSession,
143-dispatchReplyWithBufferedBlockDispatcher:
144-resolved.rt.channel.reply.dispatchReplyWithBufferedBlockDispatcher,
145-delivery: {
146-deliver: async (payload) => {
147-await deliverSynologyChatReply({
148-account: params.account,
149- sendUserId,
150- payload,
151-});
139+agentId: resolved.route.agentId,
140+routeSessionKey: resolved.route.sessionKey,
141+ storePath,
142+ctxPayload: msgCtx,
143+recordInboundSession: resolved.rt.channel.session.recordInboundSession,
144+dispatchReplyWithBufferedBlockDispatcher:
145+resolved.rt.channel.reply.dispatchReplyWithBufferedBlockDispatcher,
146+delivery: {
147+deliver: async (payload) => {
148+await deliverSynologyChatReply({
149+account: params.account,
150+ sendUserId,
151+ payload,
152+});
153+},
152154},
153-},
154-dispatcherOptions: {
155-onReplyStart: () => {
156-params.log?.info?.(`Agent reply started for ${params.msg.from}`);
155+ dispatcherOptions: {
156+ onReplyStart: () => {
157+ params.log?.info?.(`Agent reply started for ${params.msg.from}`);
158+},
157159},
158-},
159-record: {
160-onRecordError: (err) => {
161-params.log?.info?.(`Session metadata update failed for ${params.msg.from}`, err);
160+ record: {
161+ onRecordError: (err) => {
162+ params.log?.info?.(`Session metadata update failed for ${params.msg.from}`, err);
163+},
162164},
163-},
164-};
165+};
166+},
165167},
166168});
167169此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。