davidgereb/dsh-lib-context-injection0

dsh-lib-context-injection

适用于 DSH Web 插件的共享智能体上下文注入助手库。提供后续消息注入、模型选择恢复等功能,用于定时发送、简易门禁及崩溃重启恢复。

AI 分析

核心用途是为 DSH 插件开发者提供上下文注入和会话恢复的共享工具函数。适合 DSH 插件开发者,作为 cost-lens 或 watchdog 等插件的底层依赖自动安装,普通用户无需手动安装。

包名
dsh-lib-context-injection
版本
0.1.1
许可证
MIT
最近更新
2026年8月16日

安装

此插件尚未提供可验证的 bundle,或兼容性检查未通过。请先阅读仓库说明。 阅读完整 README ↗

Usage

import { deriveModelSelection, injectUserMessage, ensureModelSelection } from "dsh-lib-context-injection";

// wake an agent with a plugin-tagged follow-up
injectUserMessage(agent, { text: "Continue where you left off.", plugin: "my-plugin" });

// restore the session's model route on a headless/resumed agent
ensureModelSelection(agent, agent.session?.events ?? [], {
  fallbackProvider: "deepseek",
  fallbackModel: "deepseek-v4-flash",
  logger: ctx.logger,
  plugin: "my-plugin"
});

Cordis scoped-context note. The resume setup(agentCtx) callback passes a Cordis scoped-context proxy; reading a non-injected property on it (e.g. agentCtx.ctx) throws cannot get property "ctx" without inject. installModelSelectionOn/ensureModelSelection handle this: they probe target.ctx in a guarded try/catch and fall back to using the raw context itself — the same as the pre-library callers did.