@runic-labs/sdk
askRunic 和 storeResult —— 面向代理的完整契约。
@runic-labs/sdk 是大多数集成唯一需要直接导入的包。它将 @runic-labs/cache 和 @runic-labs/ledger 封装在两个函数之后。
npm install @runic-labs/sdkpnpm add @runic-labs/sdkyarn add @runic-labs/sdkbun add @runic-labs/sdk模块级函数
对于常见场景——一个代理进程、默认的文件支持存储——可直接使用自由函数:
import { askRunic, storeResult } from "@runic-labs/sdk";
askRunic(decision)
检查这个完全相同的决策是否已被处理。
decisionDecision
{ intent: string; params: Record<string, unknown> }
Decision返回 Promise<CachedEntry | null> —— 未命中时为 null,命中时为缓存条目(并将命中记录到分类账中)。
signature?string
The normalized signature this entry is keyed on.
stringartifact?unknown
Whatever was passed to storeResult() originally.
unknowntokensSpent?number
What producing this artifact cost the first time.
numbercreatedAt?number
Epoch ms when this entry was first stored.
numberlastUsedAt?number
Epoch ms of the most recent hit.
numberhitCount?number
Number of times this entry has been reused.
numberstale?boolean
Advisory only — Runic never acts on this itself.
booleanstoreResult(decision, artifact, tokensSpent)
为某个决策记录新生成的产物,并记录其成本,以便未来命中时知道节省了多少。
decisionDecision
Same shape as askRunic's argument.
Decisionartifactunknown
Whatever you want returned on a future cache hit.
unknowntokensSpentnumber
Agent-reported cost of producing this artifact. Runic never measures this itself.
number返回 Promise<void>。
createRunicClient(options?)
当你需要多个独立客户端时,请改用它而非模块级函数——最常见于测试,或明确选择内存存储时:
import { createRunicClient } from "@runic-labs/sdk";
import { createCache, MemoryCacheStore } from "@runic-labs/cache";
import { createLedger, MemoryLedgerStore } from "@runic-labs/ledger";
const runic = createRunicClient({
cache: createCache(new MemoryCacheStore()),
ledger: createLedger(new MemoryLedgerStore()),
});
await runic.askRunic({ intent: "summarize_pr", params: { repo, pr } });
await runic.storeResult({ intent: "summarize_pr", params: { repo, pr } }, artifact, tokensUsed);
cache?Cache
Defaults to a file-backed cache under .runic/ if omitted.
Cacheledger?Ledger
Defaults to a file-backed ledger under .runic/ if omitted.
Ledger返回一个 RunicClient,其 askRunic / storeResult 形式与模块级函数相同,并限定于你传入的 cache/ledger 实例。