@trim21/personal-pi-extensions 0.0.174 → 0.0.175
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/package.json +1 -1
- package/src/vision-agent.ts +51 -1
package/package.json
CHANGED
package/src/vision-agent.ts
CHANGED
|
@@ -223,6 +223,39 @@ export function isMultimodal(model: { input?: readonly string[] } | undefined):
|
|
|
223
223
|
return !!model && Array.isArray(model.input) && model.input.includes("image");
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/**
|
|
227
|
+
* 把识别结果整理成 pendant 渲染用的 markdown。
|
|
228
|
+
* description 格式为 callVision 拼装的 `[label]\n<正文>\n[模型: ...]`,
|
|
229
|
+
* 第一行是图片标签、最后一行是模型/ token 元信息,中间是视觉模型输出正文。
|
|
230
|
+
*/
|
|
231
|
+
export function buildPendantMarkdown(params: {
|
|
232
|
+
paths: string[];
|
|
233
|
+
prompt: string;
|
|
234
|
+
description: string;
|
|
235
|
+
provider: string;
|
|
236
|
+
model: string;
|
|
237
|
+
}): string {
|
|
238
|
+
const lines = params.description.split("\n");
|
|
239
|
+
const labels = lines[0]?.trim().replaceAll(/^\[|\]$/g, "") ?? "";
|
|
240
|
+
const footer = lines.at(-1)?.trim() ?? "";
|
|
241
|
+
const body = lines.slice(1, -1).join("\n").trim();
|
|
242
|
+
const files = params.paths.map((p) => `\`${basename(p)}\``).join(", ");
|
|
243
|
+
return [
|
|
244
|
+
"## 图片识别",
|
|
245
|
+
"",
|
|
246
|
+
`**图片**: ${files || labels}`,
|
|
247
|
+
`**视觉模型**: \`${params.provider}/${params.model}\``,
|
|
248
|
+
`**Prompt**: ${params.prompt}`,
|
|
249
|
+
"",
|
|
250
|
+
"### 识别结果",
|
|
251
|
+
"",
|
|
252
|
+
body || params.description,
|
|
253
|
+
footer ? `\n---\n${footer}` : "",
|
|
254
|
+
]
|
|
255
|
+
.join("\n")
|
|
256
|
+
.trim();
|
|
257
|
+
}
|
|
258
|
+
|
|
226
259
|
// ── 图片加载与 API 调用 ─────────────────────────────────────────────────────
|
|
227
260
|
|
|
228
261
|
/** 按文件头识别真实图片类型,识别不出返回 undefined */
|
|
@@ -515,6 +548,13 @@ export default function visionAgent(pi: ExtensionAPI) {
|
|
|
515
548
|
prompt,
|
|
516
549
|
signal ?? ctx.signal,
|
|
517
550
|
);
|
|
551
|
+
const markdown = buildPendantMarkdown({
|
|
552
|
+
paths,
|
|
553
|
+
prompt,
|
|
554
|
+
description,
|
|
555
|
+
provider: providerName,
|
|
556
|
+
model: visionConfig.model,
|
|
557
|
+
});
|
|
518
558
|
return {
|
|
519
559
|
content: [{ type: "text", text: description }],
|
|
520
560
|
details: {
|
|
@@ -524,6 +564,10 @@ export default function visionAgent(pi: ExtensionAPI) {
|
|
|
524
564
|
output: description,
|
|
525
565
|
paths,
|
|
526
566
|
count: paths.length,
|
|
567
|
+
pendant: {
|
|
568
|
+
markdown,
|
|
569
|
+
expanded: true,
|
|
570
|
+
},
|
|
527
571
|
},
|
|
528
572
|
};
|
|
529
573
|
} catch (error) {
|
|
@@ -538,7 +582,13 @@ export default function visionAgent(pi: ExtensionAPI) {
|
|
|
538
582
|
return {
|
|
539
583
|
isError: true,
|
|
540
584
|
content: [{ type: "text", text: `识别失败: ${message}` }],
|
|
541
|
-
details: {
|
|
585
|
+
details: {
|
|
586
|
+
error: message,
|
|
587
|
+
pendant: {
|
|
588
|
+
markdown: `## 图片识别失败\n\n${message}`,
|
|
589
|
+
expanded: true,
|
|
590
|
+
},
|
|
591
|
+
},
|
|
542
592
|
};
|
|
543
593
|
}
|
|
544
594
|
},
|