Aller au contenu
Runic
Français
Esc
naviguerouvrir⌘Japerçu
Sur cette page

@runic-labs/sdk

askRunic et storeResult — l’intégralité du contrat destiné aux agents.

@runic-labs/sdk est le seul package que la plupart des intégrations doivent importer directement. Il encapsule @runic-labs/cache et @runic-labs/ledger derrière deux fonctions.

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

Fonctions au niveau du module

Pour le cas courant — un processus d’agent, un stockage par défaut basé sur des fichiers — utilisez directement les fonctions libres :

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

askRunic(decision)

Vérifie si cette décision exacte a déjà été résolue.

PropType
decisionDecision

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

TypeDecision

Renvoie Promise<CachedEntry | null>null en cas d’absence, ou l’entrée mise en cache (et consigne un succès dans le registre) en cas de correspondance.

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)

Enregistre un artefact fraîchement généré pour une décision et consigne son coût afin qu’une future correspondance sache combien elle a économisé.

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

Renvoie Promise<void>.

createRunicClient(options?)

Utilisez ceci à la place des fonctions au niveau du module lorsque vous avez besoin de plusieurs clients indépendants — le plus souvent pour les tests, ou lorsque vous choisissez explicitement un stockage en mémoire :

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

Renvoie un RunicClient ayant la même forme askRunic / storeResult que les fonctions au niveau du module, limité aux instances cache/ledger que vous avez fournies.

Suite

  • Cache — créez des implémentations CacheStore personnalisées
  • Ledger — lisez directement les résumés du registre
  • CLI — inspectez l’état depuis la ligne de commande

Cette page vous a-t-elle été utile ?