dsh-feishu-lark-notify 0.26.0 → 0.26.2

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.
Files changed (2) hide show
  1. package/lib/index.js +29 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -37,7 +37,7 @@ import { startWsInbound } from './inbound-ws.js'
37
37
  export const name = 'feishu-notify'
38
38
 
39
39
  /** 版本号(与 package.json 保持一致,单测会校验)。 */
40
- export const VERSION = '0.26.0'
40
+ export const VERSION = '0.26.2'
41
41
 
42
42
  /** 内存日志上限。 */
43
43
  const LOG_LIMIT = 200
@@ -1912,6 +1912,14 @@ export function apply(ctx, rawConfig) {
1912
1912
  return { ok: true, path: filePath, prompt, kindLabel }
1913
1913
  }
1914
1914
 
1915
+ /**
1916
+ * 生成一个不会撞车的会话 id(`session-<uuid>`,与 DSH 自己的命名习惯一致)。
1917
+ * @returns 会话 id。
1918
+ */
1919
+ function newSessionId() {
1920
+ return `session-${crypto.randomUUID()}`
1921
+ }
1922
+
1915
1923
  /**
1916
1924
  * 新建会话时借一个模型配置。
1917
1925
  *
@@ -1955,6 +1963,7 @@ export function apply(ctx, rawConfig) {
1955
1963
  return { ok: false, created: false, reason: 'unsupported' }
1956
1964
  }
1957
1965
  // 借一个「活着的」agent 来取模型配置(liveSessions() 是投影对象,没有 options)
1966
+ // 会话 id 自己生成,避免宿主用 session-1/session-2 这种会撞车的自增 id
1958
1967
  const anchorAgent = (() => {
1959
1968
  try {
1960
1969
  const roots = ctx.get('agents')?.roots?.() ?? []
@@ -1973,16 +1982,22 @@ export function apply(ctx, rawConfig) {
1973
1982
  void replyToChat(message.chatId, `借不到模型配置(${anchor.label || anchor.id.slice(-6)} 没有 modelSelection),先在 DSH 里给它选个模型。`)
1974
1983
  return { ok: false, created: false, reason: 'no-model' }
1975
1984
  }
1985
+ // 目录一定要用**当前会话的项目目录**:用 processPath() 会落进 profile 目录,
1986
+ // 新会话就会跑到「未分组」里去。
1987
+ const cwd = sessionCwd(anchorAgent.session, stateFor(anchorAgent.session))
1976
1988
 
1977
1989
  let handle
1978
1990
  try {
1979
1991
  handle = await agents.create({
1992
+ // 必须自己给一个唯一 id:不给的话宿主会生成 `session-1`、`session-2` 这种,
1993
+ // 一旦上一次那个还活着,第二次建就直接报 `session "session-1" already exists`。
1994
+ sessionId: newSessionId(),
1980
1995
  agentOptions: {
1981
1996
  provider: model.provider,
1982
1997
  model: model.model,
1983
1998
  ...(model.reasoningEffort === undefined ? {} : { reasoningEffort: model.reasoningEffort }),
1984
1999
  },
1985
- meta: { cwd: projectRoot() },
2000
+ meta: { cwd: cwd === '' ? projectRoot() : cwd },
1986
2001
  })
1987
2002
  } catch (error) {
1988
2003
  const detail = String(error?.message ?? error)
@@ -2003,6 +2018,18 @@ export function apply(ctx, rawConfig) {
2003
2018
  if (typeof title === 'string' && title !== '') {
2004
2019
  createdTitles.set(agent.id, title)
2005
2020
  sessionRoster.remember([{ id: agent.id, label: title, status: 'running', live: true }, ...rosterSessions()])
2021
+ // 真的把标题写进会话(否则模型会按第一句自动起名,你看到的就不是「测试」)
2022
+ try {
2023
+ const titles = ctx.get('sessionTitle')
2024
+ if (titles !== undefined && typeof titles.rename === 'function') {
2025
+ await titles.rename(agent.session, title)
2026
+ log(`[${via}] 新会话标题已设为「${title}」`)
2027
+ } else {
2028
+ log(`[${via}] 宿主没有 sessionTitle 服务,标题只在插件内生效`)
2029
+ }
2030
+ } catch (error) {
2031
+ log(`[${via}] 设置标题失败(不影响使用):${error?.message ?? error}`)
2032
+ }
2006
2033
  }
2007
2034
 
2008
2035
  let sent = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-feishu-lark-notify",
3
- "version": "0.26.0",
3
+ "version": "0.26.2",
4
4
  "description": "把 DSH 的任务完成 / 需要你处理的通知推到飞书(Lark):在飞书里点审批、答选择题、按标题把指令交给指定会话,也能收发图片和文件。自带可视化配置页。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",