Saltar al contenido
Runic
Español
Esc
navegarabrir⌘Jvista previa
En esta página

@runic-labs/sdk

askRunic y storeResult — todo el contrato de cara al agente.

@runic-labs/sdk es el único paquete que la mayoría de las integraciones necesitan importar directamente. Envuelve @runic-labs/cache y @runic-labs/ledger mediante dos funciones.

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

Funciones de nivel de módulo

Para el caso habitual — un proceso de agente, almacenamiento predeterminado respaldado por archivos — usa directamente las funciones libres:

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

askRunic(decision)

Comprueba si esta decisión exacta ya se ha resuelto.

PropType
decisionDecision

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

TypeDecision

Devuelve Promise<CachedEntry | null>null si no se encuentra, o la entrada en caché (y registra un acierto en el libro mayor) si se encuentra.

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 un artefacto recién generado para una decisión y anota su coste para que un acierto futuro sepa cuánto ahorró.

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

Devuelve Promise<void>.

createRunicClient(options?)

Usa esto en lugar de las funciones de nivel de módulo cuando necesites varios clientes independientes — normalmente para pruebas o al elegir explícitamente almacenamiento en memoria:

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

Devuelve un RunicClient con la misma forma de askRunic / storeResult que las funciones de nivel de módulo, limitado a las instancias de cache/ledger que proporcionaste.

Siguiente

  • Caché — crea implementaciones personalizadas de CacheStore
  • Libro mayor — lee resúmenes del libro mayor directamente
  • CLI — inspecciona el estado desde la línea de comandos

¿Te ha resultado útil esta página?