---
title: '@runic-labs/sdk'
description: askRunic और storeResult — एजेंट-उन्मुख पूरा अनुबंध।
sidebar:
  order: 3
---
`@runic-labs/sdk` एकमात्र पैकेज है जिसे अधिकांश इंटीग्रेशन को सीधे इंपोर्ट करने की आवश्यकता होती है। यह `@runic-labs/cache` और `@runic-labs/ledger` को दो फ़ंक्शनों के पीछे रैप करता है।

```package-install
npm i @runic-labs/sdk
```

## मॉड्यूल-स्तरीय फ़ंक्शन

सामान्य स्थिति के लिए — एक एजेंट प्रक्रिया, डिफ़ॉल्ट फ़ाइल-समर्थित स्टोरेज — मुक्त फ़ंक्शनों का सीधे उपयोग करें:

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

### `askRunic(decision)`

जांचता है कि क्या यह सटीक निर्णय पहले ही हल किया जा चुका है।

| Prop | Type | Default | Description |
| - | - | - | - |
| `decision` | `Decision` | - | { intent: string; params: Record<string, unknown> } |

`Promise<CachedEntry | null>` लौटाता है — मिस होने पर `null`, या हिट होने पर कैश की गई एंट्री (और लेजर में हिट लॉग करता है)।

| Prop | Type | Default | Description |
| - | - | - | - |
| `signature?` | `string` | - | The normalized signature this entry is keyed on. |
| `artifact?` | `unknown` | - | Whatever was passed to storeResult() originally. |
| `tokensSpent?` | `number` | - | What producing this artifact cost the first time. |
| `createdAt?` | `number` | - | Epoch ms when this entry was first stored. |
| `lastUsedAt?` | `number` | - | Epoch ms of the most recent hit. |
| `hitCount?` | `number` | - | Number of times this entry has been reused. |
| `stale?` | `boolean` | - | Advisory only — Runic never acts on this itself. |

### `storeResult(decision, artifact, tokensSpent)`

किसी निर्णय के लिए नए सिरे से जनरेट किया गया आर्टिफ़ैक्ट रिकॉर्ड करता है, और उसकी लागत लॉग करता है ताकि भविष्य की हिट को पता हो कि उससे कितनी बचत हुई।

| Prop | Type | Default | Description |
| - | - | - | - |
| `decision` | `Decision` | - | Same shape as askRunic's argument. |
| `artifact` | `unknown` | - | Whatever you want returned on a future cache hit. |
| `tokensSpent` | `number` | - | Agent-reported cost of producing this artifact. Runic never measures this itself. |

`Promise<void>` लौटाता है।

## `createRunicClient(options?)`

जब आपको कई स्वतंत्र क्लाइंट चाहिए हों, तब मॉड्यूल-स्तरीय फ़ंक्शनों के बजाय इसका उपयोग करें — आमतौर पर परीक्षणों के लिए, या इन-मेमोरी स्टोरेज को स्पष्ट रूप से चुनते समय:

```ts
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);
```

| Prop | Type | Default | Description |
| - | - | - | - |
| `cache?` | `Cache` | - | Defaults to a file-backed cache under .runic/ if omitted. |
| `ledger?` | `Ledger` | - | Defaults to a file-backed ledger under .runic/ if omitted. |

वही `askRunic` / `storeResult` संरचना वाला एक `RunicClient` लौटाता है जो आपके द्वारा पास किए गए `cache`/`ledger` इंस्टेंसों तक सीमित होता है।

## आगे

- [कैश](/cache) — कस्टम `CacheStore` इंप्लीमेंटेशन बनाएँ
- [लेजर](/ledger) — लेजर सारांश सीधे पढ़ें
- [CLI](/cli) — कमांड लाइन से स्थिति का निरीक्षण करें
