Saltar para o conteúdo
Runic
Português
Esc
navegarabrir⌘Jpré-visualizar
Nesta página

@runic-labs/sdk

askRunic e storeResult — todo o contrato voltado para o agente.

@runic-labs/sdk é o único pacote que a maioria das integrações precisa importar diretamente. Ele encapsula @runic-labs/cache e @runic-labs/ledger por trás de duas funções.

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

Funções no nível do módulo

Para o caso comum — um processo de agente, armazenamento padrão baseado em arquivos — use as funções livres diretamente:

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

askRunic(decision)

Verifica se esta decisão exata já foi resolvida.

PropType
decisionDecision

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

TypeDecision

Retorna Promise<CachedEntry | null>null em caso de ausência, ou a entrada em cache (e registra um acerto no ledger) em caso de acerto.

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)

Registra um artefato recém-gerado para uma decisão e registra seu custo para que um acerto futuro saiba quanto ele economizou.

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

Retorna Promise<void>.

createRunicClient(options?)

Use isto em vez das funções no nível do módulo quando precisar de vários clientes independentes — mais comumente para testes ou ao escolher explicitamente o armazenamento em memória:

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

Retorna um RunicClient com a mesma estrutura de askRunic / storeResult das funções no nível do módulo, restrito às instâncias de cache/ledger que você passou.

Próximo

  • Cache — construa implementações personalizadas de CacheStore
  • Ledger — leia resumos do ledger diretamente
  • CLI — inspecione o estado pela linha de comando

Esta página foi útil?