Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(orca): 图片参数兜住单元素折叠形态 {item:string} 与裸字符串

Zhang Yunjinf9e1999c6b6f
diff --git a/packages/lizi-mcps/src/__tests__/createWorkerTool.test.ts b/packages/lizi-mcps/src/__tests__/createWorkerTool.test.ts
index c4638957e0..a128036492 100644
--- a/packages/lizi-mcps/src/__tests__/createWorkerTool.test.ts
+++ b/packages/lizi-mcps/src/__tests__/createWorkerTool.test.ts
@@ -122,6 +122,28 @@ describe('create_worker tool', () => {
}));
});
+ it('wraps a single-element-collapsed {item:string} and bare string into an array', async () => {
+ // 实测形态: 单图时 <item> 单实例被兼容层折叠成标量 —— scout 单图 4 连拒的根因。
+ const { registry, createWorker } = setup();
+ const wrapped = await registry.call('create_worker', {
+ role: 'developer', agent: 'codex', label: 'w1',
+ initial_task: 'review', images: { item: 'cindy-media://blobs/a.png' },
+ });
+ expect(wrapped.isError).toBeFalsy();
+ expect(createWorker).toHaveBeenCalledWith(expect.objectContaining({
+ initialTaskImages: ['cindy-media://blobs/a.png'],
+ }));
+
+ const bare = await registry.call('create_worker', {
+ role: 'developer', agent: 'codex', label: 'w2',
+ initial_task: 'review', images: 'cindy-media://blobs/a.png',
+ });
+ expect(bare.isError).toBeFalsy();
+ expect(vi.mocked(createWorker).mock.calls[1]?.[0]).toMatchObject({
+ initialTaskImages: ['cindy-media://blobs/a.png'],
+ });
+ });
+
it('still rejects non-string image entries after flattening', async () => {
const { registry, createWorker } = setup();
const result = await registry.call('create_worker', {
diff --git a/packages/lizi-mcps/src/xdt-helper/create_worker.ts b/packages/lizi-mcps/src/xdt-helper/create_worker.ts
index 87102a4bb9..868c16b13c 100644
--- a/packages/lizi-mcps/src/xdt-helper/create_worker.ts
+++ b/packages/lizi-mcps/src/xdt-helper/create_worker.ts
@@ -82,22 +82,25 @@ export interface CreateWorkerDeps {
/**
* 图片地址列表的共享形状(send_to_worker / create_worker / create_workers 共用)。
- * 要求扁平字符串数组;实测两类误传形态自愈而不是报参数错:
+ * 要求扁平字符串数组;实测两类误传形态自愈而不是报参数错(glm 等 openai-completions 兼容层
+ * 把数组参数序列化成 <item> 重复标签,单元素时会折叠成标量):
* 1. 多套一层:[[a],[b]] → 拍平;
- * 2. XML 风格包装:{item:[a,b]}(模型/兼容层把数组参数输出成 <item> 重复标签)→ 取 item。
+ * 2. XML 风格包装:{item:[a,b]} → 取 item;单元素折叠 {item:a} → [a];裸标量 a → [a]。
*/
export const imagesListSchema = z.preprocess(
(value) => {
if (Array.isArray(value)) {
return value.some((item) => Array.isArray(item)) ? (value as unknown[]).flat(1) : value;
}
- if (
- value
- && typeof value === 'object'
- && Array.isArray((value as { item?: unknown }).item)
- ) {
- return (value as { item: unknown[] }).item;
+ if (value && typeof value === 'object') {
+ const item = (value as { item?: unknown }).item;
+ if (item === undefined) return value;
+ value = item;
+ if (Array.isArray(value)) {
+ return value.some((x) => Array.isArray(x)) ? (value as unknown[]).flat(1) : value;
+ }
}
+ if (typeof value === 'string' && value.trim().length > 0) return [value];
return value;
},
z.array(z.string().min(1)).max(8),