pi-tsgw 1.3.0 → 1.3.1

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/README.md CHANGED
@@ -25,6 +25,6 @@ pi install npm:pi-tsgw
25
25
  将占位地址替换为实际网关地址,通过 `/login` 选择 `tsgw` 配置密钥,然后执行 `/reload`。
26
26
  使用 `/tsgw` 查看目录状态,`/tsgw-refresh` 强制刷新。图片与分类能力需要 Pi 1.2+。
27
27
 
28
- `/insagent` 显式安装标准子代理并自动重载当前会话:覆盖代理目录中的当前定义,再删除已退出插件清单的 `tsgw-*.md` 文件;其他文件不动。
28
+ `/insagent` 显式安装标准子代理:覆盖当前定义,删除已退出清单的 `tsgw-*.md`,在代理目录的 `settings.json` 中启用 Agent 并停用 Pi Web 内置代理,最后自动重载当前会话;其他自定义代理和无关设置保留。
29
29
 
30
30
  开发维护约定见 [AGENTS.md](https://github.com/tossp/pi-tsgw/blob/main/AGENTS.md)。
@@ -9,7 +9,7 @@ function report(ctx: ExtensionCommandContext, message: string, level: "info" | "
9
9
  /** 仅显式命令写入代理目录,不在启动或重载事件中同步。 */
10
10
  export function registerAgentInstallCommand(pi: ExtensionAPI): void {
11
11
  pi.registerCommand("insagent", {
12
- description: "覆盖安装 TSGW 标准子代理、清理旧 tsgw-*.md 定义并重载当前会话",
12
+ description: "覆盖安装 TSGW 标准子代理、清理旧定义、停用内置代理并重载当前会话",
13
13
  handler: async (args, ctx) => {
14
14
  if (args.trim()) {
15
15
  report(ctx, "用法:/insagent(不接收参数)。", "error");
@@ -25,7 +25,7 @@ export function registerAgentInstallCommand(pi: ExtensionAPI): void {
25
25
  return;
26
26
  }
27
27
  report(ctx, `已写入 ${result.installed.length} 个 TSGW 子代理,清理 ${result.removed.length} 个旧定义:` +
28
- `${result.directory}。正在重载当前会话;其他已打开的主会话需各自重载。`, "info");
28
+ `${result.directory}。已停用 Pi Web 内置代理,正在重载当前会话;其他已打开的主会话需各自重载。`, "info");
29
29
  // 重载使旧上下文失效,之后不再访问 ctx 或旧运行器。
30
30
  await ctx.reload();
31
31
  },
@@ -1,4 +1,4 @@
1
- import { mkdirSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { standardAgentProfiles } from "./profiles.ts";
4
4
 
@@ -8,7 +8,31 @@ export interface AgentInstallation {
8
8
  removed: string[];
9
9
  }
10
10
 
11
- /** 先覆盖当前定义,全部写入成功后才清理退出清单的旧定义;不维护额外状态。 */
11
+ /** 沿用 Pi Web 的设置:启用 Agent 工具,按名称停用内置档案,不关闭整个功能。 */
12
+ function disableBuiltInProfiles(directory: string): void {
13
+ const path = join(directory, "settings.json");
14
+ let stored: unknown = {};
15
+ if (existsSync(path)) {
16
+ try {
17
+ stored = JSON.parse(readFileSync(path, "utf8"));
18
+ } catch (error) {
19
+ throw new Error("无法读取或解析子代理 settings.json", { cause: error });
20
+ }
21
+ }
22
+ if (stored === null || typeof stored !== "object" || Array.isArray(stored)) {
23
+ throw new Error("子代理 settings.json 必须是 JSON 对象");
24
+ }
25
+ const settings = stored as Record<string, unknown>;
26
+ const disabled = Array.isArray(settings.disabledBuiltIns) ? [...settings.disabledBuiltIns] : [];
27
+ for (const name of ["general-purpose", "explore", "plan"]) {
28
+ if (!disabled.some(entry => typeof entry === "string" && entry.trim().toLowerCase() === name)) disabled.push(name);
29
+ }
30
+ writeFileSync(path, `${JSON.stringify({
31
+ ...settings, version: 1, builtInEnabled: true, disabledBuiltIns: disabled,
32
+ }, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
33
+ }
34
+
35
+ /** 先写当前定义并清理旧定义,再更新宿主设置;不维护额外状态。 */
12
36
  export function installStandardAgents(agentDir: string): AgentInstallation {
13
37
  const directory = join(agentDir, "agents");
14
38
  const profiles = standardAgentProfiles();
@@ -23,5 +47,6 @@ export function installStandardAgents(agentDir: string): AgentInstallation {
23
47
  unlinkSync(join(directory, name));
24
48
  removed.push(name);
25
49
  }
50
+ disableBuiltInProfiles(directory);
26
51
  return { directory, installed: [...currentFiles], removed };
27
52
  }
@@ -1,4 +1,5 @@
1
1
  import { Type } from "typebox";
2
+ import { StringEnum } from "@earendil-works/pi-ai";
2
3
  import { normalizeImageParameters, type ImageOperation } from "#tsgw/models/adapter/images/parameters";
3
4
 
4
5
  export const DEFAULT_IMAGE_MODEL = "gpt-image-2.5-sunburst";
@@ -13,16 +14,17 @@ export const imageSourceSchema = Type.Union([
13
14
  Type.Object({ file_id: Type.String({ minLength: 1, description: "上游已有图片的文件 ID。" }) }, { additionalProperties: false }),
14
15
  ], { description: "恰好一个来源:path、image_url 或 file_id;不可混用。" });
15
16
 
17
+ // Type.Enum 仅输出 enum;Moonshot 拒绝联合分支中缺 type 的枚举,使用宿主显式 string 表达。
16
18
  const common = {
17
19
  prompt: Type.String({ minLength: 1, maxLength: 32_000, description: "图片生成或编辑要求,最多32000字符。" }),
18
- model: Type.Optional(Type.Enum(IMAGE_MODELS, { description: "默认 gpt-image-2.5-sunburst,适合成稿;AI 草稿任务可选 gpt-image-2.5-flare,常配 quality=low。" })),
19
- quality: optional(Type.Enum(["auto", "low", "medium", "high", "xhigh", "max"], { description: "质量,默认 auto;选择 Flare 不会自动改为 low。" })),
20
+ model: Type.Optional(StringEnum(IMAGE_MODELS, { description: "默认 gpt-image-2.5-sunburst,适合成稿;AI 草稿任务可选 gpt-image-2.5-flare,常配 quality=low。" })),
21
+ quality: optional(StringEnum(["auto", "low", "medium", "high", "xhigh", "max"], { description: "质量,默认 auto;选择 Flare 不会自动改为 low。" })),
20
22
  size: optional(Type.String({ description: "默认 auto;也可宽x高,均为16倍数、边≤3840、宽高比≤3、像素655360..8294400。" })),
21
- background: optional(Type.Enum(["auto", "opaque", "transparent"], { description: "背景,默认 auto。透明背景需 PNG/WebP。" })),
22
- output_format: optional(Type.Enum(["png", "jpeg", "webp"], { description: "输出格式,默认 png;原始字节不转码。" })),
23
+ background: optional(StringEnum(["auto", "opaque", "transparent"], { description: "背景,默认 auto。透明背景需 PNG/WebP。" })),
24
+ output_format: optional(StringEnum(["png", "jpeg", "webp"], { description: "输出格式,默认 png;原始字节不转码。" })),
23
25
  output_compression: optional(Type.Integer({ minimum: 0, maximum: 100, description: "仅用于 JPEG/WebP 的压缩质量;省略采用上游默认100。" })),
24
26
  n: optional(Type.Integer({ minimum: 1, maximum: 10, description: "返回图片数量;默认1,最多10。" })),
25
- moderation: optional(Type.Enum(["auto", "low"], { description: "审核强度,默认 auto。" })),
27
+ moderation: optional(StringEnum(["auto", "low"], { description: "审核强度,默认 auto。" })),
26
28
  stream: optional(Type.Boolean({ description: "默认 false;支持解析流式响应,不承诺界面渐进预览。" })),
27
29
  partial_images: optional(Type.Integer({ minimum: 0, maximum: 3, description: "仅 stream=true 时使用;默认0。最终仅返回完成图。" })),
28
30
  safety_identifier: optional(Type.String({ maxLength: 128, description: "可选安全标识,最长128字符。" })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-tsgw",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "面向 TOSSP AIH gateway 的 Pi 扩展:按厂商维护聊天与图片模型目录及思考策略,支持四种聊天协议、图片生成与编辑工具,以及原生 System One 分类模型。",
5
5
  "type": "module",
6
6
  "keywords": [