跳到内容
Runic
中文
Esc
导航打开⌘J预览
本页内容

@runic-labs/sdk

askRunic 和 storeResult —— 面向代理的完整契约。

@runic-labs/sdk 是大多数集成唯一需要直接导入的包。它将 @runic-labs/cache@runic-labs/ledger 封装在两个函数之后。

npm install @runic-labs/sdk
pnpm add @runic-labs/sdk
yarn add @runic-labs/sdk
bun add @runic-labs/sdk

模块级函数

对于常见场景——一个代理进程、默认的文件支持存储——可直接使用自由函数:

import { askRunic, storeResult } from "@runic-labs/sdk";

askRunic(decision)

检查这个完全相同的决策是否已被处理。

PropType
decisionDecision

{ intent: string; params: Record<string, unknown> }

TypeDecision

返回 Promise<CachedEntry | null> —— 未命中时为 null,命中时为缓存条目(并将命中记录到分类账中)。

PropType
signature?string

The normalized signature this entry is keyed on.

Typestring
artifact?unknown

Whatever was passed to storeResult() originally.

Typeunknown
tokensSpent?number

What producing this artifact cost the first time.

Typenumber
createdAt?number

Epoch ms when this entry was first stored.

Typenumber
lastUsedAt?number

Epoch ms of the most recent hit.

Typenumber
hitCount?number

Number of times this entry has been reused.

Typenumber
stale?boolean

Advisory only — Runic never acts on this itself.

Typeboolean

storeResult(decision, artifact, tokensSpent)

为某个决策记录新生成的产物,并记录其成本,以便未来命中时知道节省了多少。

PropType
decisionDecision

Same shape as askRunic's argument.

TypeDecision
artifactunknown

Whatever you want returned on a future cache hit.

Typeunknown
tokensSpentnumber

Agent-reported cost of producing this artifact. Runic never measures this itself.

Typenumber

返回 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);
PropType
cache?Cache

Defaults to a file-backed cache under .runic/ if omitted.

TypeCache
ledger?Ledger

Defaults to a file-backed ledger under .runic/ if omitted.

TypeLedger

返回一个 RunicClient,其 askRunic / storeResult 形式与模块级函数相同,并限定于你传入的 cache/ledger 实例。

下一步

  • 缓存 —— 构建自定义 CacheStore 实现
  • 分类账 —— 直接读取分类账摘要
  • CLI —— 从命令行检查状态

这个页面有帮助吗?