@downcity/agent 1.1.100 → 1.1.104
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/bin/agent/local/Agent.d.ts +2 -2
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/AgentPluginFactory.d.ts +1 -6
- package/bin/agent/local/AgentPluginFactory.d.ts.map +1 -1
- package/bin/agent/local/AgentPluginFactory.js +1 -19
- package/bin/agent/local/AgentPluginFactory.js.map +1 -1
- package/bin/agent/local/AgentRuntimeFactory.d.ts +2 -2
- package/bin/agent/local/AgentRuntimeFactory.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +4 -4
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +5 -6
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/config/AgentInitializer.d.ts.map +1 -1
- package/bin/config/AgentInitializer.js +6 -12
- package/bin/config/AgentInitializer.js.map +1 -1
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +0 -8
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.js.map +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.js.map +1 -1
- package/bin/executor/messages/AssistantFileResource.d.ts +3 -2
- package/bin/executor/messages/AssistantFileResource.d.ts.map +1 -1
- package/bin/executor/messages/AssistantFileResource.js +88 -20
- package/bin/executor/messages/AssistantFileResource.js.map +1 -1
- package/bin/executor/tools/plugin/PluginToolBridge.d.ts +3 -3
- package/bin/executor/tools/plugin/PluginToolBridge.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolBridge.js +1 -1
- package/bin/executor/tools/plugin/PluginToolBridge.js.map +1 -1
- package/bin/index.d.ts +1 -3
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +0 -1
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/BasePlugin.d.ts +0 -14
- package/bin/plugin/core/BasePlugin.d.ts.map +1 -1
- package/bin/plugin/core/BasePlugin.js +0 -22
- package/bin/plugin/core/BasePlugin.js.map +1 -1
- package/bin/plugin/core/Manager.d.ts +1 -1
- package/bin/plugin/core/Manager.d.ts.map +1 -1
- package/bin/plugin/core/Manager.js +1 -1
- package/bin/plugin/core/Manager.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +2 -2
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/plugin/core/PluginStateController.d.ts +1 -9
- package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
- package/bin/plugin/core/PluginStateController.js +0 -12
- package/bin/plugin/core/PluginStateController.js.map +1 -1
- package/bin/plugin/types/Plugin.d.ts +1 -1
- package/bin/plugin/types/Plugin.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +2 -23
- package/bin/types/config/DowncityConfig.d.ts.map +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +2 -2
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +2 -2
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/package.json +2 -2
- package/scripts/image-plugin-job.test.mjs +21 -9
- package/src/agent/local/Agent.ts +2 -2
- package/src/agent/local/AgentPluginFactory.ts +1 -33
- package/src/agent/local/AgentRuntimeFactory.ts +2 -2
- package/src/agent/local/services/AgentAssemblyService.ts +6 -9
- package/src/config/AgentInitializer.ts +6 -12
- package/src/config/DowncitySchema.ts +0 -8
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +3 -3
- package/src/executor/composer/system/default/assets/plugin.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/plugin.prompt.ts.txt +12 -22
- package/src/executor/composer/system/default/assets/task.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/task.prompt.ts.txt +1 -1
- package/src/executor/messages/AssistantFileResource.ts +111 -22
- package/src/executor/tools/plugin/PluginToolBridge.ts +5 -5
- package/src/index.ts +1 -11
- package/src/plugin/core/BasePlugin.ts +0 -27
- package/src/plugin/core/Manager.ts +0 -2
- package/src/plugin/core/PluginRegistry.ts +2 -1
- package/src/plugin/core/PluginStateController.ts +0 -15
- package/src/plugin/types/Plugin.ts +1 -1
- package/src/types/config/DowncityConfig.ts +1 -24
- package/src/types/plugin/PluginRuntime.ts +2 -2
- package/src/types/runtime/agent/AgentContext.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/plugin/core/ImagePlugin.d.ts +0 -57
- package/bin/plugin/core/ImagePlugin.d.ts.map +0 -1
- package/bin/plugin/core/ImagePlugin.js +0 -112
- package/bin/plugin/core/ImagePlugin.js.map +0 -1
- package/bin/types/plugin/ImagePlugin.d.ts +0 -94
- package/bin/types/plugin/ImagePlugin.d.ts.map +0 -1
- package/bin/types/plugin/ImagePlugin.js +0 -10
- package/bin/types/plugin/ImagePlugin.js.map +0 -1
- package/src/plugin/core/ImagePlugin.ts +0 -132
- package/src/types/plugin/ImagePlugin.ts +0 -103
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImagePlugin:Agent 内置图片生成插件。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 对 Agent 只暴露同步体验的 `generate` action。
|
|
6
|
-
* - City / provider 的图片能力通过单个 image 函数注入。
|
|
7
|
-
* - action 返回 AI SDK UIMessage,后续由 plugin tool bridge 抽取 file parts 写回 assistant 消息。
|
|
8
|
-
*/
|
|
9
|
-
import type { AgentContext } from "../../types/runtime/agent/AgentContext.js";
|
|
10
|
-
import type { JsonObject, JsonValue } from "../../types/common/Json.js";
|
|
11
|
-
import type { ImagePluginOptions } from "../../types/plugin/ImagePlugin.js";
|
|
12
|
-
import { BasePlugin } from "../../plugin/core/BasePlugin.js";
|
|
13
|
-
/**
|
|
14
|
-
* Agent 图片生成插件。
|
|
15
|
-
*/
|
|
16
|
-
export declare class ImagePlugin extends BasePlugin {
|
|
17
|
-
/**
|
|
18
|
-
* 当前 plugin 稳定名称。
|
|
19
|
-
*/
|
|
20
|
-
readonly name: string;
|
|
21
|
-
/**
|
|
22
|
-
* 插件标题。
|
|
23
|
-
*/
|
|
24
|
-
readonly title: string;
|
|
25
|
-
/**
|
|
26
|
-
* 插件说明。
|
|
27
|
-
*/
|
|
28
|
-
readonly description: string;
|
|
29
|
-
private readonly image;
|
|
30
|
-
constructor(options: ImagePluginOptions);
|
|
31
|
-
/**
|
|
32
|
-
* 图片插件给模型的最小使用说明。
|
|
33
|
-
*/
|
|
34
|
-
system(_context: AgentContext): string;
|
|
35
|
-
private generate_image;
|
|
36
|
-
/**
|
|
37
|
-
* 显式 action 集合。
|
|
38
|
-
*/
|
|
39
|
-
readonly actions: {
|
|
40
|
-
generate: {
|
|
41
|
-
execute: ({ payload }: {
|
|
42
|
-
payload: JsonValue;
|
|
43
|
-
}) => Promise<{
|
|
44
|
-
success: boolean;
|
|
45
|
-
data: JsonObject;
|
|
46
|
-
message: string;
|
|
47
|
-
error?: undefined;
|
|
48
|
-
} | {
|
|
49
|
-
success: boolean;
|
|
50
|
-
error: string;
|
|
51
|
-
message: string;
|
|
52
|
-
data?: undefined;
|
|
53
|
-
}>;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=ImagePlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImagePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugin/core/ImagePlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAEV,kBAAkB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAqCzD;;GAEG;AACH,qBAAa,WAAY,SAAQ,UAAU;IACzC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2C;gBAErD,OAAO,EAAE,kBAAkB;IAiBvC;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM;YASxB,cAAc;IAI5B;;OAEG;IACH,QAAQ,CAAC,OAAO;;mCAEiB;gBAAE,OAAO,EAAE,SAAS,CAAA;aAAE;;sBAMjB,UAAU;;;;;;;;;;MAY9C;CACH"}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImagePlugin:Agent 内置图片生成插件。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 对 Agent 只暴露同步体验的 `generate` action。
|
|
6
|
-
* - City / provider 的图片能力通过单个 image 函数注入。
|
|
7
|
-
* - action 返回 AI SDK UIMessage,后续由 plugin tool bridge 抽取 file parts 写回 assistant 消息。
|
|
8
|
-
*/
|
|
9
|
-
import { BasePlugin } from "../../plugin/core/BasePlugin.js";
|
|
10
|
-
const DEFAULT_IMAGE_PLUGIN_NAME = "image";
|
|
11
|
-
const DEFAULT_IMAGE_PLUGIN_TITLE = "Image";
|
|
12
|
-
const DEFAULT_IMAGE_PLUGIN_DESCRIPTION = "Generate images and return them as assistant file parts.";
|
|
13
|
-
/**
|
|
14
|
-
* 判断值是否为普通对象。
|
|
15
|
-
*/
|
|
16
|
-
function to_record(value) {
|
|
17
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
18
|
-
return null;
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* 归一化模型传入的图片生成 payload。
|
|
23
|
-
*/
|
|
24
|
-
function normalize_image_payload(payload) {
|
|
25
|
-
const record = to_record(payload ?? {});
|
|
26
|
-
if (!record) {
|
|
27
|
-
throw new TypeError("ImagePlugin.generate payload must be an object");
|
|
28
|
-
}
|
|
29
|
-
return { ...record };
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 校验 image 函数返回的 UIMessage。
|
|
33
|
-
*/
|
|
34
|
-
function normalize_image_result(result) {
|
|
35
|
-
const record = to_record(result);
|
|
36
|
-
if (!record || !Array.isArray(record.parts)) {
|
|
37
|
-
throw new TypeError("ImagePlugin image provider must return an AI SDK UIMessage");
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Agent 图片生成插件。
|
|
43
|
-
*/
|
|
44
|
-
export class ImagePlugin extends BasePlugin {
|
|
45
|
-
/**
|
|
46
|
-
* 当前 plugin 稳定名称。
|
|
47
|
-
*/
|
|
48
|
-
name;
|
|
49
|
-
/**
|
|
50
|
-
* 插件标题。
|
|
51
|
-
*/
|
|
52
|
-
title;
|
|
53
|
-
/**
|
|
54
|
-
* 插件说明。
|
|
55
|
-
*/
|
|
56
|
-
description;
|
|
57
|
-
image;
|
|
58
|
-
constructor(options) {
|
|
59
|
-
super();
|
|
60
|
-
const name = String(options.name || DEFAULT_IMAGE_PLUGIN_NAME).trim();
|
|
61
|
-
if (!name) {
|
|
62
|
-
throw new Error("ImagePlugin requires a non-empty name");
|
|
63
|
-
}
|
|
64
|
-
if (typeof options.image !== "function") {
|
|
65
|
-
throw new Error("ImagePlugin requires an image function");
|
|
66
|
-
}
|
|
67
|
-
this.name = name;
|
|
68
|
-
this.title = String(options.title || DEFAULT_IMAGE_PLUGIN_TITLE).trim();
|
|
69
|
-
this.description = String(options.description || DEFAULT_IMAGE_PLUGIN_DESCRIPTION).trim();
|
|
70
|
-
this.image = options.image;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* 图片插件给模型的最小使用说明。
|
|
74
|
-
*/
|
|
75
|
-
system(_context) {
|
|
76
|
-
return [
|
|
77
|
-
"Image generation is available through the plugin_call tool.",
|
|
78
|
-
`Call plugin "${this.name}" action "generate" when the user asks to create, render, draw, or edit an image.`,
|
|
79
|
-
"Pass a JSON payload with prompt, optional size/aspect_ratio/quality/n, and optional provider_options.",
|
|
80
|
-
"The generated image files will be attached to the final assistant message automatically.",
|
|
81
|
-
].join("\n");
|
|
82
|
-
}
|
|
83
|
-
async generate_image(input) {
|
|
84
|
-
return normalize_image_result(await this.image(input));
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* 显式 action 集合。
|
|
88
|
-
*/
|
|
89
|
-
actions = {
|
|
90
|
-
generate: {
|
|
91
|
-
execute: async ({ payload }) => {
|
|
92
|
-
try {
|
|
93
|
-
const input = normalize_image_payload(payload);
|
|
94
|
-
const message = await this.generate_image(input);
|
|
95
|
-
return {
|
|
96
|
-
success: true,
|
|
97
|
-
data: message,
|
|
98
|
-
message: "image generated",
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
return {
|
|
103
|
-
success: false,
|
|
104
|
-
error: String(error),
|
|
105
|
-
message: String(error),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
//# sourceMappingURL=ImagePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImagePlugin.js","sourceRoot":"","sources":["../../../src/plugin/core/ImagePlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAC1C,MAAM,0BAA0B,GAAG,OAAO,CAAC;AAC3C,MAAM,gCAAgC,GACpC,0DAA0D,CAAC;AAE7D;;GAEG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7E,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,OAA8B;IAC7D,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,EAAE,GAAG,MAAM,EAAsB,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAAC,MAAyB;IACvD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,SAAS,CAAC,4DAA4D,CAAC,CAAC;IACpF,CAAC;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AQ,EAAE;YACR,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAA0B,EAAE,EAAE;gBACrD,IAAI,CAAC;oBACH,MAAM,KAAK,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;oBAC/C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;oBACjD,OAAO;wBACL,OAAO,EAAE,IAAI;wBACb,IAAI,EAAE,OAAgC;wBACtC,OAAO,EAAE,iBAAiB;qBAC3B,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO;wBACL,OAAO,EAAE,KAAK;wBACd,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;wBACpB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;qBACvB,CAAC;gBACJ,CAAC;YACH,CAAC;SACF;KACF,CAAC;CACH"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImagePlugin 类型定义。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里仅定义 agent 对图片能力的最低层协议,不绑定 city 或任意上游 provider。
|
|
6
|
-
* - 图片生成结果使用 AI SDK UIMessage,保证 session 落盘格式与现有消息系统一致。
|
|
7
|
-
* - 字段保持 JSON 可序列化,便于通过 plugin action 与 tool bridge 传递。
|
|
8
|
-
*/
|
|
9
|
-
import type { UIMessage } from "ai";
|
|
10
|
-
import type { JsonObject, JsonValue } from "../../types/common/Json.js";
|
|
11
|
-
/**
|
|
12
|
-
* 图片生成文本内容片段。
|
|
13
|
-
*/
|
|
14
|
-
export interface ImagePluginTextContent {
|
|
15
|
-
/** 内容类型,固定为文本。 */
|
|
16
|
-
type: "text";
|
|
17
|
-
/** 生图提示词或上下文文本。 */
|
|
18
|
-
text: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 图片生成参考图片内容片段。
|
|
22
|
-
*/
|
|
23
|
-
export interface ImagePluginFileContent {
|
|
24
|
-
/** 内容类型,固定为图片。 */
|
|
25
|
-
type: "image";
|
|
26
|
-
/** 远程图片 URL。 */
|
|
27
|
-
url?: string;
|
|
28
|
-
/** data URL 图片内容。 */
|
|
29
|
-
data_url?: string;
|
|
30
|
-
/** 图片 MIME 类型,例如 `image/png`。 */
|
|
31
|
-
media_type?: string;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 图片生成多模态内容片段。
|
|
35
|
-
*/
|
|
36
|
-
export type ImagePluginContent = ImagePluginTextContent | ImagePluginFileContent;
|
|
37
|
-
/**
|
|
38
|
-
* 图片生成上下文消息。
|
|
39
|
-
*/
|
|
40
|
-
export interface ImagePluginMessage {
|
|
41
|
-
/** 消息角色。 */
|
|
42
|
-
role: "system" | "user" | "assistant";
|
|
43
|
-
/** 该消息内的文本与图片内容。 */
|
|
44
|
-
content: ImagePluginContent[];
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* ImagePlugin 调用输入。
|
|
48
|
-
*/
|
|
49
|
-
export interface ImagePluginInput {
|
|
50
|
-
/** 图片模型引用。 */
|
|
51
|
-
model?: string;
|
|
52
|
-
/** 单句快捷提示词。 */
|
|
53
|
-
prompt?: string;
|
|
54
|
-
/** 多轮或多模态图片生成上下文。 */
|
|
55
|
-
messages?: ImagePluginMessage[];
|
|
56
|
-
/** 生成图片数量。 */
|
|
57
|
-
n?: number;
|
|
58
|
-
/** 生成图片数量,兼容部分上游使用的 count 命名。 */
|
|
59
|
-
count?: number;
|
|
60
|
-
/** 图片尺寸,例如 `1024x1024`。 */
|
|
61
|
-
size?: string;
|
|
62
|
-
/** 图片宽高比,例如 `1:1`。 */
|
|
63
|
-
aspect_ratio?: string;
|
|
64
|
-
/** 图片宽高比,兼容部分上游使用的 ratio 命名。 */
|
|
65
|
-
ratio?: string;
|
|
66
|
-
/** 图片质量,例如 `standard`、`hd`、`ultra`、`4k`。 */
|
|
67
|
-
quality?: string;
|
|
68
|
-
/** 随机种子。 */
|
|
69
|
-
seed?: number;
|
|
70
|
-
/** 业务侧任务 ID,用于 provider 侧幂等、追踪和恢复。 */
|
|
71
|
-
client_job_id?: string;
|
|
72
|
-
/** Provider 私有参数,例如 `{ openai: {...}, gemini: {...}, luchi: {...} }`。 */
|
|
73
|
-
provider_options?: JsonObject;
|
|
74
|
-
/** 允许外部 image 函数接收其他 JSON 可序列化参数。 */
|
|
75
|
-
[key: string]: JsonValue | ImagePluginMessage[] | undefined;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* ImagePlugin 生成结果。
|
|
79
|
-
*/
|
|
80
|
-
export type ImagePluginResult = UIMessage;
|
|
81
|
-
/**
|
|
82
|
-
* ImagePlugin 构造参数。
|
|
83
|
-
*/
|
|
84
|
-
export interface ImagePluginOptions {
|
|
85
|
-
/** Plugin 稳定名称,默认 `image`。 */
|
|
86
|
-
name?: string;
|
|
87
|
-
/** Plugin 展示标题,默认 `Image`。 */
|
|
88
|
-
title?: string;
|
|
89
|
-
/** Plugin 用途说明。 */
|
|
90
|
-
description?: string;
|
|
91
|
-
/** 图片生成函数,通常传入 `(input) => city.ai.image(input)`。 */
|
|
92
|
-
image?: (input: ImagePluginInput) => Promise<ImagePluginResult> | ImagePluginResult;
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=ImagePlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImagePlugin.d.ts","sourceRoot":"","sources":["../../../src/types/plugin/ImagePlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;A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AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;CACrF"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImagePlugin 类型定义。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里仅定义 agent 对图片能力的最低层协议,不绑定 city 或任意上游 provider。
|
|
6
|
-
* - 图片生成结果使用 AI SDK UIMessage,保证 session 落盘格式与现有消息系统一致。
|
|
7
|
-
* - 字段保持 JSON 可序列化,便于通过 plugin action 与 tool bridge 传递。
|
|
8
|
-
*/
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=ImagePlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ImagePlugin.js","sourceRoot":"","sources":["../../../src/types/plugin/ImagePlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImagePlugin:Agent 内置图片生成插件。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 对 Agent 只暴露同步体验的 `generate` action。
|
|
6
|
-
* - City / provider 的图片能力通过单个 image 函数注入。
|
|
7
|
-
* - action 返回 AI SDK UIMessage,后续由 plugin tool bridge 抽取 file parts 写回 assistant 消息。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
11
|
-
import type { JsonObject, JsonValue } from "@/types/common/Json.js";
|
|
12
|
-
import type {
|
|
13
|
-
ImagePluginInput,
|
|
14
|
-
ImagePluginOptions,
|
|
15
|
-
ImagePluginResult,
|
|
16
|
-
} from "@/types/plugin/ImagePlugin.js";
|
|
17
|
-
import { BasePlugin } from "@/plugin/core/BasePlugin.js";
|
|
18
|
-
|
|
19
|
-
const DEFAULT_IMAGE_PLUGIN_NAME = "image";
|
|
20
|
-
const DEFAULT_IMAGE_PLUGIN_TITLE = "Image";
|
|
21
|
-
const DEFAULT_IMAGE_PLUGIN_DESCRIPTION =
|
|
22
|
-
"Generate images and return them as assistant file parts.";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 判断值是否为普通对象。
|
|
26
|
-
*/
|
|
27
|
-
function to_record(value: unknown): Record<string, unknown> | null {
|
|
28
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
29
|
-
return value as Record<string, unknown>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 归一化模型传入的图片生成 payload。
|
|
34
|
-
*/
|
|
35
|
-
function normalize_image_payload(payload: JsonValue | undefined): ImagePluginInput {
|
|
36
|
-
const record = to_record(payload ?? {});
|
|
37
|
-
if (!record) {
|
|
38
|
-
throw new TypeError("ImagePlugin.generate payload must be an object");
|
|
39
|
-
}
|
|
40
|
-
return { ...record } as ImagePluginInput;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 校验 image 函数返回的 UIMessage。
|
|
45
|
-
*/
|
|
46
|
-
function normalize_image_result(result: ImagePluginResult): ImagePluginResult {
|
|
47
|
-
const record = to_record(result);
|
|
48
|
-
if (!record || !Array.isArray(record.parts)) {
|
|
49
|
-
throw new TypeError("ImagePlugin image provider must return an AI SDK UIMessage");
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Agent 图片生成插件。
|
|
56
|
-
*/
|
|
57
|
-
export class ImagePlugin extends BasePlugin {
|
|
58
|
-
/**
|
|
59
|
-
* 当前 plugin 稳定名称。
|
|
60
|
-
*/
|
|
61
|
-
readonly name: string;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 插件标题。
|
|
65
|
-
*/
|
|
66
|
-
readonly title: string;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 插件说明。
|
|
70
|
-
*/
|
|
71
|
-
readonly description: string;
|
|
72
|
-
|
|
73
|
-
private readonly image: NonNullable<ImagePluginOptions["image"]>;
|
|
74
|
-
|
|
75
|
-
constructor(options: ImagePluginOptions) {
|
|
76
|
-
super();
|
|
77
|
-
const name = String(options.name || DEFAULT_IMAGE_PLUGIN_NAME).trim();
|
|
78
|
-
if (!name) {
|
|
79
|
-
throw new Error("ImagePlugin requires a non-empty name");
|
|
80
|
-
}
|
|
81
|
-
if (typeof options.image !== "function") {
|
|
82
|
-
throw new Error("ImagePlugin requires an image function");
|
|
83
|
-
}
|
|
84
|
-
this.name = name;
|
|
85
|
-
this.title = String(options.title || DEFAULT_IMAGE_PLUGIN_TITLE).trim();
|
|
86
|
-
this.description = String(
|
|
87
|
-
options.description || DEFAULT_IMAGE_PLUGIN_DESCRIPTION,
|
|
88
|
-
).trim();
|
|
89
|
-
this.image = options.image;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 图片插件给模型的最小使用说明。
|
|
94
|
-
*/
|
|
95
|
-
system(_context: AgentContext): string {
|
|
96
|
-
return [
|
|
97
|
-
"Image generation is available through the plugin_call tool.",
|
|
98
|
-
`Call plugin "${this.name}" action "generate" when the user asks to create, render, draw, or edit an image.`,
|
|
99
|
-
"Pass a JSON payload with prompt, optional size/aspect_ratio/quality/n, and optional provider_options.",
|
|
100
|
-
"The generated image files will be attached to the final assistant message automatically.",
|
|
101
|
-
].join("\n");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private async generate_image(input: ImagePluginInput): Promise<ImagePluginResult> {
|
|
105
|
-
return normalize_image_result(await this.image(input));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 显式 action 集合。
|
|
110
|
-
*/
|
|
111
|
-
readonly actions = {
|
|
112
|
-
generate: {
|
|
113
|
-
execute: async ({ payload }: { payload: JsonValue }) => {
|
|
114
|
-
try {
|
|
115
|
-
const input = normalize_image_payload(payload);
|
|
116
|
-
const message = await this.generate_image(input);
|
|
117
|
-
return {
|
|
118
|
-
success: true,
|
|
119
|
-
data: message as unknown as JsonObject,
|
|
120
|
-
message: "image generated",
|
|
121
|
-
};
|
|
122
|
-
} catch (error) {
|
|
123
|
-
return {
|
|
124
|
-
success: false,
|
|
125
|
-
error: String(error),
|
|
126
|
-
message: String(error),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImagePlugin 类型定义。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里仅定义 agent 对图片能力的最低层协议,不绑定 city 或任意上游 provider。
|
|
6
|
-
* - 图片生成结果使用 AI SDK UIMessage,保证 session 落盘格式与现有消息系统一致。
|
|
7
|
-
* - 字段保持 JSON 可序列化,便于通过 plugin action 与 tool bridge 传递。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { UIMessage } from "ai";
|
|
11
|
-
import type { JsonObject, JsonValue } from "@/types/common/Json.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 图片生成文本内容片段。
|
|
15
|
-
*/
|
|
16
|
-
export interface ImagePluginTextContent {
|
|
17
|
-
/** 内容类型,固定为文本。 */
|
|
18
|
-
type: "text";
|
|
19
|
-
/** 生图提示词或上下文文本。 */
|
|
20
|
-
text: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 图片生成参考图片内容片段。
|
|
25
|
-
*/
|
|
26
|
-
export interface ImagePluginFileContent {
|
|
27
|
-
/** 内容类型,固定为图片。 */
|
|
28
|
-
type: "image";
|
|
29
|
-
/** 远程图片 URL。 */
|
|
30
|
-
url?: string;
|
|
31
|
-
/** data URL 图片内容。 */
|
|
32
|
-
data_url?: string;
|
|
33
|
-
/** 图片 MIME 类型,例如 `image/png`。 */
|
|
34
|
-
media_type?: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 图片生成多模态内容片段。
|
|
39
|
-
*/
|
|
40
|
-
export type ImagePluginContent =
|
|
41
|
-
| ImagePluginTextContent
|
|
42
|
-
| ImagePluginFileContent;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 图片生成上下文消息。
|
|
46
|
-
*/
|
|
47
|
-
export interface ImagePluginMessage {
|
|
48
|
-
/** 消息角色。 */
|
|
49
|
-
role: "system" | "user" | "assistant";
|
|
50
|
-
/** 该消息内的文本与图片内容。 */
|
|
51
|
-
content: ImagePluginContent[];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* ImagePlugin 调用输入。
|
|
56
|
-
*/
|
|
57
|
-
export interface ImagePluginInput {
|
|
58
|
-
/** 图片模型引用。 */
|
|
59
|
-
model?: string;
|
|
60
|
-
/** 单句快捷提示词。 */
|
|
61
|
-
prompt?: string;
|
|
62
|
-
/** 多轮或多模态图片生成上下文。 */
|
|
63
|
-
messages?: ImagePluginMessage[];
|
|
64
|
-
/** 生成图片数量。 */
|
|
65
|
-
n?: number;
|
|
66
|
-
/** 生成图片数量,兼容部分上游使用的 count 命名。 */
|
|
67
|
-
count?: number;
|
|
68
|
-
/** 图片尺寸,例如 `1024x1024`。 */
|
|
69
|
-
size?: string;
|
|
70
|
-
/** 图片宽高比,例如 `1:1`。 */
|
|
71
|
-
aspect_ratio?: string;
|
|
72
|
-
/** 图片宽高比,兼容部分上游使用的 ratio 命名。 */
|
|
73
|
-
ratio?: string;
|
|
74
|
-
/** 图片质量,例如 `standard`、`hd`、`ultra`、`4k`。 */
|
|
75
|
-
quality?: string;
|
|
76
|
-
/** 随机种子。 */
|
|
77
|
-
seed?: number;
|
|
78
|
-
/** 业务侧任务 ID,用于 provider 侧幂等、追踪和恢复。 */
|
|
79
|
-
client_job_id?: string;
|
|
80
|
-
/** Provider 私有参数,例如 `{ openai: {...}, gemini: {...}, luchi: {...} }`。 */
|
|
81
|
-
provider_options?: JsonObject;
|
|
82
|
-
/** 允许外部 image 函数接收其他 JSON 可序列化参数。 */
|
|
83
|
-
[key: string]: JsonValue | ImagePluginMessage[] | undefined;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* ImagePlugin 生成结果。
|
|
88
|
-
*/
|
|
89
|
-
export type ImagePluginResult = UIMessage;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* ImagePlugin 构造参数。
|
|
93
|
-
*/
|
|
94
|
-
export interface ImagePluginOptions {
|
|
95
|
-
/** Plugin 稳定名称,默认 `image`。 */
|
|
96
|
-
name?: string;
|
|
97
|
-
/** Plugin 展示标题,默认 `Image`。 */
|
|
98
|
-
title?: string;
|
|
99
|
-
/** Plugin 用途说明。 */
|
|
100
|
-
description?: string;
|
|
101
|
-
/** 图片生成函数,通常传入 `(input) => city.ai.image(input)`。 */
|
|
102
|
-
image?: (input: ImagePluginInput) => Promise<ImagePluginResult> | ImagePluginResult;
|
|
103
|
-
}
|