chatccc 0.2.182 → 0.2.184
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/im-skills/feishu-skill/skill.md +2 -1
- package/package.json +1 -1
- package/src/__tests__/agent-delegate-task-rpc.test.ts +165 -0
- package/src/__tests__/codex-reset-actions.test.ts +146 -146
- package/src/__tests__/format-message.test.ts +291 -248
- package/src/agent-delegate-task-rpc.ts +153 -0
- package/src/agent-delegate-task.ts +81 -0
- package/src/codex-reset-actions.ts +184 -184
- package/src/format-message.ts +88 -9
- package/src/index.ts +9 -2
- package/src/orchestrator.ts +136 -237
- package/src/session-name.ts +8 -0
- package/src/session.ts +1 -0
package/src/format-message.ts
CHANGED
|
@@ -40,7 +40,7 @@ export async function formatMessageContent(message: {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
if (message.message_type === "post") {
|
|
43
|
-
return
|
|
43
|
+
return formatPostContentWithImages(content, message.message_id);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (message.message_type === "image") {
|
|
@@ -91,7 +91,7 @@ export async function formatMessageContent(message: {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export function formatPostContent(content: Record<string, unknown>): string {
|
|
94
|
-
const paragraphs = content
|
|
94
|
+
const paragraphs = getPostParagraphs(content);
|
|
95
95
|
if (!Array.isArray(paragraphs)) return "";
|
|
96
96
|
|
|
97
97
|
const parts: string[] = [];
|
|
@@ -100,19 +100,98 @@ export function formatPostContent(content: Record<string, unknown>): string {
|
|
|
100
100
|
for (const elem of line) {
|
|
101
101
|
const el = elem as Record<string, unknown>;
|
|
102
102
|
if (!el || typeof el !== "object") continue;
|
|
103
|
-
const
|
|
103
|
+
const text = formatPostTextElement(el);
|
|
104
|
+
if (text) parts.push(text);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return parts.join("\n").trim();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getPostParagraphs(content: Record<string, unknown>): unknown[][] {
|
|
111
|
+
const direct = content.content;
|
|
112
|
+
if (Array.isArray(direct)) return direct as unknown[][];
|
|
113
|
+
|
|
114
|
+
for (const locale of ["zh_cn", "en_us", "ja_jp"]) {
|
|
115
|
+
const localized = content[locale] as Record<string, unknown> | undefined;
|
|
116
|
+
if (localized && Array.isArray(localized.content)) {
|
|
117
|
+
return localized.content as unknown[][];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function formatPostTextElement(el: Record<string, unknown>): string {
|
|
125
|
+
const t = typeof el.text === "string" ? el.text : "";
|
|
104
126
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
if (el.tag === "code_block") {
|
|
128
|
+
const lang = typeof el.language === "string" ? el.language : "";
|
|
129
|
+
return "```" + lang + "\n" + t + "\n```";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (el.tag === "p" || el.tag === "text") {
|
|
133
|
+
return t;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getPostImageKey(el: Record<string, unknown>): string | undefined {
|
|
140
|
+
const imageKey = el.image_key;
|
|
141
|
+
if (typeof imageKey === "string" && imageKey.trim()) return imageKey;
|
|
142
|
+
|
|
143
|
+
if (el.tag === "img") {
|
|
144
|
+
const fileKey = el.file_key;
|
|
145
|
+
if (typeof fileKey === "string" && fileKey.trim()) return fileKey;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function formatPostContentWithImages(
|
|
152
|
+
content: Record<string, unknown>,
|
|
153
|
+
messageId?: string,
|
|
154
|
+
): Promise<string> {
|
|
155
|
+
const paragraphs = getPostParagraphs(content);
|
|
156
|
+
if (!Array.isArray(paragraphs)) return "";
|
|
157
|
+
|
|
158
|
+
const parts: string[] = [];
|
|
159
|
+
for (const line of paragraphs) {
|
|
160
|
+
if (!Array.isArray(line)) continue;
|
|
161
|
+
for (const elem of line) {
|
|
162
|
+
const el = elem as Record<string, unknown>;
|
|
163
|
+
if (!el || typeof el !== "object") continue;
|
|
164
|
+
|
|
165
|
+
const text = formatPostTextElement(el);
|
|
166
|
+
if (text) parts.push(text);
|
|
167
|
+
|
|
168
|
+
const imageKey = getPostImageKey(el);
|
|
169
|
+
if (imageKey) {
|
|
170
|
+
parts.push(await formatPostImageElement(messageId, imageKey));
|
|
110
171
|
}
|
|
111
172
|
}
|
|
112
173
|
}
|
|
113
174
|
return parts.join("\n").trim();
|
|
114
175
|
}
|
|
115
176
|
|
|
177
|
+
async function formatPostImageElement(
|
|
178
|
+
messageId: string | undefined,
|
|
179
|
+
imageKey: string,
|
|
180
|
+
): Promise<string> {
|
|
181
|
+
if (!messageId) return `[图片: ${imageKey}]`;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const token = await getTenantAccessToken();
|
|
185
|
+
const localPath = await getOrDownloadImage(token, messageId, imageKey);
|
|
186
|
+
return `[图片] ${localPath}`;
|
|
187
|
+
} catch (err) {
|
|
188
|
+
console.error(
|
|
189
|
+
`[${ts()}] [IMAGE] download failed for post image ${imageKey}: ${(err as Error).message}`,
|
|
190
|
+
);
|
|
191
|
+
return `[图片: ${imageKey}]`;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
116
195
|
// ---------------------------------------------------------------------------
|
|
117
196
|
// 合并转发消息格式化
|
|
118
197
|
// ---------------------------------------------------------------------------
|
|
@@ -211,4 +290,4 @@ export async function formatMergeForward(
|
|
|
211
290
|
}
|
|
212
291
|
|
|
213
292
|
return header + "\n" + lines.join("\n");
|
|
214
|
-
}
|
|
293
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -80,6 +80,7 @@ import { SimulatedPlatform, SIM_DEFAULT_CHAT_ID } from "./sim-platform.ts";
|
|
|
80
80
|
import { setMessageHandler } from "./sim-store.ts";
|
|
81
81
|
import { handleAgentImageRequest } from "./agent-image-rpc.ts";
|
|
82
82
|
import { handleAgentFileRequest } from "./agent-file-rpc.ts";
|
|
83
|
+
import { handleAgentDelegateTaskRequest } from "./agent-delegate-task-rpc.ts";
|
|
83
84
|
import { handleAgentStopStuckRequest } from "./agent-stop-stuck.ts";
|
|
84
85
|
import { applyPrivacy } from "./privacy.ts";
|
|
85
86
|
import {
|
|
@@ -707,7 +708,10 @@ async function main(): Promise<void> {
|
|
|
707
708
|
setExtraApiHandler(async (req, res) => {
|
|
708
709
|
const injected = await handleSimInjectMessage(req, res);
|
|
709
710
|
if (injected) return true;
|
|
710
|
-
return (await handleAgentImageRequest(req, res))
|
|
711
|
+
return (await handleAgentImageRequest(req, res))
|
|
712
|
+
|| (await handleAgentFileRequest(req, res))
|
|
713
|
+
|| (await handleAgentDelegateTaskRequest(req, res, feishuPlatform))
|
|
714
|
+
|| (await handleAgentStopStuckRequest(req, res));
|
|
711
715
|
});
|
|
712
716
|
|
|
713
717
|
const simServer = createServer(createUiRouter());
|
|
@@ -766,7 +770,10 @@ async function main(): Promise<void> {
|
|
|
766
770
|
});
|
|
767
771
|
});
|
|
768
772
|
setExtraApiHandler(async (req, res) => {
|
|
769
|
-
return (await handleAgentImageRequest(req, res))
|
|
773
|
+
return (await handleAgentImageRequest(req, res))
|
|
774
|
+
|| (await handleAgentFileRequest(req, res))
|
|
775
|
+
|| (await handleAgentDelegateTaskRequest(req, res, feishuPlatform))
|
|
776
|
+
|| (await handleAgentStopStuckRequest(req, res));
|
|
770
777
|
});
|
|
771
778
|
|
|
772
779
|
console.log(`[启动 2/7] 环境与凭证检查`);
|