OpenViking
volcengine
Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:davidgereb/dsh-lib-context-injection
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
Shared agent context-injection helpers for dsh web plugins.
Several dsh web host plugins need to push context into a live agent's session with no browser in the loop, and they used to each implement the same two patterns by hand:
agent.followup(createUserMessage(...)):
dsh-plugin-cost-lens fires scheduled off-peak sends, releases deferred
(cheapass) prompts, and wakes interrupted work at the next off-peak start;
dsh-plugin-watchdog wakes a crash-resumed agent with a "continue where you
left off" prompt.request/header +
assistant/message events and installing it via installModelSelection, so
the persona prompt's {{model}} / {{provider}} variables resolve on
headless/resumed agents (which have no browser to install the selection).This package is the single implementation of both patterns.
Host-only ESM library; it runs inside the dsh server process and imports
@deepseek-ai/dsh-llm + @deepseek-ai/dsh-agent (both shipped with dsh web).
This is a dependency package, not a Cordis plugin — there is no loader entry to add to
cordis.patch.yml, anddsh plugin addwill not make anything load it. If you use one of the consuming plugins (cost-lens, watchdog), it is installed automatically as their git dependency — you don't need to install it yourself.
pnpm ≥ 11 note. pnpm 11 blocks git-hosted transitive dependencies (
blockExoticSubdepsdefaults totrue). If you install this into a dsh profile (or any pnpm workspace) as a direct dependency, pass the flag below; as a transitive dependency ofdsh-plugin-cost-lens/dsh-plugin-watchdog, their install commands already include it.
npm install --save github:davidgereb/dsh-lib-context-injection --config.block-exotic-subdeps=false
# or with pnpm:
pnpm add github:davidgereb/dsh-lib-context-injection --config.block-exotic-subdeps=false
npm install /path/to/dsh-lib-context-injection
# or with pnpm:
pnpm add /path/to/dsh-lib-context-injection
| Export | Purpose |
|---|---|
deriveModelSelection(events, opts?) |
Fold session events into the last durable { provider, model, reasoningEffort? } route. opts.fallbackProvider / opts.fallbackModel cover sessions with no recorded route; opts.includeReasoningEffort also carries the effort from request/header config. |
installModelSelectionOn(target, selection, opts?) |
Safe wrapper around @deepseek-ai/dsh-agent's installModelSelection — never throws; logs via opts.logger.warn (tagged with opts.plugin) and returns false on failure. target is an agent (uses agent.ctx) or a raw agent-scoped context. |
ensureModelSelection(target, events, opts?) |
deriveModelSelection + installModelSelectionOn with two guards: per-context dedupe (WeakSet — one install per context per process) and an optional "route already carried" skip (opts.skipIfRouted, default true): when the agent's options.model already carries a route, the {{model}} variable resolves on its own, so nothing is installed. |
injectUserMessage(agent, message) |
agent.followup(createUserMessage(...)). message.text becomes a text block (or pass full message.content); message.plugin becomes the default { kind: "plugin", plugin } source (or pass message.source explicitly). Returns the created message. |
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) throwscannot get property "ctx" without inject.installModelSelectionOn/ensureModelSelectionhandle this: they probetarget.ctxin a guarded try/catch and fall back to using the raw context itself — the same as the pre-library callers did.
dsh-lib-context-injection/
├── index.js # the library (host-only)
├── package.json # dsh-lib-context-injection
└── scripts/
└── smoke-test.mjs # derive/install/inject unit checks
No build step — index.js is the package.
node scripts/smoke-test.mjs
Compatibility. Tested against dsh
0.1.0-rc.6on Node.js v24.19.0 (dsh web profile). Older or newer dsh releases may change the internals this plugin hooks into — check the changelog before upgrading.
⚠️ AI-generated, provided as-is. This project was written with the assistance of an AI. It is provided AS IS without warranty of any kind, express or implied. The author cannot be held responsible for any damage, data loss, or misbehaviour that results from using it. Use at your own risk.
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: context-injection。