agent-loft 0.2.56 → 0.2.57
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/agents/codex/driver.ts +44 -1
- package/src/core/config.ts +6 -0
- package/web/settings/agents.js +10 -0
package/package.json
CHANGED
|
@@ -107,7 +107,50 @@ export class CodexDriver implements AgentDriver {
|
|
|
107
107
|
|
|
108
108
|
async sessionTitle(id: string): Promise<string | undefined> {
|
|
109
109
|
const res = await appServer.call<{ thread: Thread }>("thread/read", { threadId: id, includeTurns: false });
|
|
110
|
-
|
|
110
|
+
const name = res.thread.name?.replace(/\s+/g, " ").trim();
|
|
111
|
+
if (name) return name;
|
|
112
|
+
// app-server 不会自动起名(Codex App / TUI 是在客户端自己生成的),开了设置就由这边生成一次
|
|
113
|
+
const c = config().agents.codex;
|
|
114
|
+
if (!c.autoTitle || this.titled.has(id)) return undefined;
|
|
115
|
+
this.titled.add(id);
|
|
116
|
+
return this.generateTitle(id, c.titleModel).catch((err) => {
|
|
117
|
+
console.error("[codex] 生成会话名称失败:", err instanceof Error ? err.message : err);
|
|
118
|
+
return undefined;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 本进程里已经生成过(或试过)名称的线程:失败了也不反复重试,每轮结束都会来问 */
|
|
123
|
+
private titled = new Set<string>();
|
|
124
|
+
|
|
125
|
+
/** 按第一轮的问答起个短标题,写回线程(thread/name/set),Codex App 里也能看到 */
|
|
126
|
+
private async generateTitle(id: string, model: string): Promise<string | undefined> {
|
|
127
|
+
const res = await appServer.call<{ thread: { turns?: { items?: HistoryItem[] }[] } }>("thread/read", { threadId: id, includeTurns: true });
|
|
128
|
+
const items = res.thread.turns?.[0]?.items ?? [];
|
|
129
|
+
const user = items
|
|
130
|
+
.filter((i) => i.type === "userMessage")
|
|
131
|
+
.flatMap((i) => (i.content ?? []).map((c) => (c.type === "text" ? (c.text ?? "") : "")))
|
|
132
|
+
.join("\n");
|
|
133
|
+
const question = splitAttachmentNote(stripContext(user)).text.trim();
|
|
134
|
+
if (!question) return undefined;
|
|
135
|
+
const answer = items
|
|
136
|
+
.filter((i) => i.type === "agentMessage" && i.phase !== "commentary" && i.text)
|
|
137
|
+
.map((i) => i.text)
|
|
138
|
+
.join("\n\n");
|
|
139
|
+
const out = (await this.complete({
|
|
140
|
+
system: "你给对话起标题。根据用户的第一条消息(和助手的回复)概括这次对话在做什么,输出一个简短的标题:和用户用同一种语言,中文不超过 15 个字,不加引号、句号和表情。",
|
|
141
|
+
prompt: `用户:\n${question.slice(0, 2000)}${answer ? `\n\n助手:\n${answer.slice(0, 1500)}` : ""}`,
|
|
142
|
+
schema: { type: "object", properties: { title: { type: "string" } }, required: ["title"], additionalProperties: false },
|
|
143
|
+
...(model ? { model } : {}),
|
|
144
|
+
timeoutMs: 60_000,
|
|
145
|
+
})) as { title?: unknown };
|
|
146
|
+
const title = String(out?.title ?? "")
|
|
147
|
+
.replace(/\s+/g, " ")
|
|
148
|
+
.replace(/^["'“”‘’「」《》]+|["'“”‘’「」《》。.]+$/g, "")
|
|
149
|
+
.trim()
|
|
150
|
+
.slice(0, 80);
|
|
151
|
+
if (!title) return undefined;
|
|
152
|
+
await appServer.call("thread/name/set", { threadId: id, name: title });
|
|
153
|
+
return title;
|
|
111
154
|
}
|
|
112
155
|
|
|
113
156
|
async readHistory(id: string): Promise<HistoryMessage[]> {
|
package/src/core/config.ts
CHANGED
|
@@ -52,6 +52,10 @@ export type AppConfig = {
|
|
|
52
52
|
defaultEffort: string;
|
|
53
53
|
/** 同 claude.models */
|
|
54
54
|
models: string[];
|
|
55
|
+
/** app-server 不会给线程起名(那是 Codex App / TUI 自己做的),开了就由这边在第一轮后生成 */
|
|
56
|
+
autoTitle: boolean;
|
|
57
|
+
/** 生成会话名称用的模型,空 = Codex 默认模型 */
|
|
58
|
+
titleModel: string;
|
|
55
59
|
};
|
|
56
60
|
};
|
|
57
61
|
web: {
|
|
@@ -126,6 +130,8 @@ export function defaultConfig(): AppConfig {
|
|
|
126
130
|
defaultModel: "",
|
|
127
131
|
defaultEffort: "",
|
|
128
132
|
models: [],
|
|
133
|
+
autoTitle: false,
|
|
134
|
+
titleModel: "",
|
|
129
135
|
},
|
|
130
136
|
},
|
|
131
137
|
web: { enabled: true, host: "0.0.0.0", port: 8800, passwordHash: "", trustedProxies: ["127.0.0.1", "::1"], quotaRefreshMin: 10, quotaEnabled: true },
|
package/web/settings/agents.js
CHANGED
|
@@ -149,6 +149,13 @@ export function agentsTab(cfg, page) {
|
|
|
149
149
|
);
|
|
150
150
|
const codexPick = modelPicker("codex", a.codex.defaultModel, a.codex.defaultEffort, "跟随 config.toml");
|
|
151
151
|
const codexModels = modelChecklist("codex", a.codex.models ?? []);
|
|
152
|
+
// 自动生成会话名称:一行,勾上才显示后面的模型选择
|
|
153
|
+
const titleOn = h("input", { type: "checkbox", checked: !!a.codex.autoTitle });
|
|
154
|
+
const titlePick = modelPicker("codex", a.codex.titleModel ?? "", "", "跟随 config.toml");
|
|
155
|
+
const titleModelEl = h("div", { class: "grow" }, titlePick.modelEl);
|
|
156
|
+
const syncTitle = () => (titleModelEl.hidden = !titleOn.checked);
|
|
157
|
+
titleOn.addEventListener("change", syncTitle);
|
|
158
|
+
syncTitle();
|
|
152
159
|
// 一组勾选框不能放进 <label>(点哪都会切到第一个),所以不用 field()
|
|
153
160
|
const checksField = (list) => h("div", { class: "field" }, h("span", {}, "输入框可选模型"), list.el);
|
|
154
161
|
// 两个 agent 一起保存:整组算一张表单
|
|
@@ -174,6 +181,7 @@ export function agentsTab(cfg, page) {
|
|
|
174
181
|
field("默认模型", codexPick.modelEl),
|
|
175
182
|
field("默认思考程度", codexPick.effortEl),
|
|
176
183
|
checksField(codexModels),
|
|
184
|
+
h("div", { class: "row title-row" }, h("label", { class: "check" }, titleOn, "自动生成会话名称"), titleModelEl),
|
|
177
185
|
),
|
|
178
186
|
h(
|
|
179
187
|
"div",
|
|
@@ -201,6 +209,8 @@ export function agentsTab(cfg, page) {
|
|
|
201
209
|
defaultModel: codexPick.model(),
|
|
202
210
|
defaultEffort: codexPick.effort(),
|
|
203
211
|
models: codexList,
|
|
212
|
+
autoTitle: titleOn.checked,
|
|
213
|
+
titleModel: titlePick.model(),
|
|
204
214
|
},
|
|
205
215
|
},
|
|
206
216
|
});
|