mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
refactor: notify/footer 持久配置收编到 config/,chrome bridge 地址固定
仓库规则要求 config/ 为唯一配置来源、不以环境变量作持久默认值: - pi-notify 改读 config/pi-notify.json(逐字段校验回退,复用原 parsers 钳制) - pi-minimal-footer 改读 config/pi-minimal-footer.json - pi-chrome 移除 PI_CHROME_BRIDGE_HOST/PORT,固定 127.0.0.1:17318 (浏览器端 service_worker.js 硬编码同一地址,单侧可配只会断连) Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
0c45b1a438
commit
e996f59469
+11
-17
@@ -1,13 +1,6 @@
|
||||
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
||||
import { extractMessageText, truncateText } from "./messages.ts";
|
||||
import {
|
||||
parseEnabled,
|
||||
parseKittyVisibility,
|
||||
parseMessageMax,
|
||||
parseMessageSource,
|
||||
parseMinDurationMs,
|
||||
parseNotificationAction,
|
||||
} from "./parsers.ts";
|
||||
import { readNotifySettings, type NotifySettings } from "./settings.ts";
|
||||
import { renderTemplate } from "./template.ts";
|
||||
import type { NotificationRuntimeValues, NotifyConfig } from "./types.ts";
|
||||
|
||||
@@ -20,12 +13,13 @@ export function getConfig(
|
||||
messages: unknown[] | undefined,
|
||||
runtime: NotificationRuntimeValues,
|
||||
now = Date.now(),
|
||||
settings: NotifySettings = readNotifySettings(),
|
||||
): NotifyConfig {
|
||||
const durationMs = startedAt === undefined ? 0 : Math.max(0, now - startedAt);
|
||||
const messageMax = parseMessageMax(process.env.PI_NOTIFY_MESSAGE_MAX);
|
||||
const messageMax = settings.messageMax;
|
||||
const userMessage = truncateText(extractMessageText(messages, "user"), messageMax);
|
||||
const assistantMessage = truncateText(extractMessageText(messages, "assistant"), messageMax);
|
||||
const messageSource = parseMessageSource(process.env.PI_NOTIFY_MESSAGE_SOURCE);
|
||||
const messageSource = settings.messageSource;
|
||||
const selectedMessage = messageSource === "user" ? userMessage : messageSource === "assistant" ? assistantMessage : "";
|
||||
const message = selectedMessage || "Ready for input";
|
||||
const toolErrorCount = Math.max(0, runtime.toolErrorCount ?? 0);
|
||||
@@ -39,15 +33,15 @@ export function getConfig(
|
||||
};
|
||||
|
||||
return {
|
||||
enabled: parseEnabled(process.env.PI_NOTIFY_ENABLED),
|
||||
title: renderTemplate(process.env.PI_NOTIFY_TITLE || DEFAULT_TITLE, ctx, durationMs, values),
|
||||
body: renderTemplate(process.env.PI_NOTIFY_BODY || DEFAULT_BODY, ctx, durationMs, values),
|
||||
enabled: settings.enabled,
|
||||
title: renderTemplate(settings.title || DEFAULT_TITLE, ctx, durationMs, values),
|
||||
body: renderTemplate(settings.body || DEFAULT_BODY, ctx, durationMs, values),
|
||||
durationMs,
|
||||
minDurationMs: parseMinDurationMs(process.env.PI_NOTIFY_MIN_SECONDS),
|
||||
minDurationMs: settings.minDurationMs,
|
||||
notificationId: runtime.notificationId,
|
||||
visibility: parseKittyVisibility(process.env.PI_NOTIFY_VISIBILITY),
|
||||
action: parseNotificationAction(process.env.PI_NOTIFY_ACTION),
|
||||
soundCommand: process.env.PI_NOTIFY_SOUND_CMD?.trim() || undefined,
|
||||
visibility: settings.visibility,
|
||||
action: settings.action,
|
||||
soundCommand: settings.soundCommand,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user