Skip to content

Commit d116ea0

Browse files
committed
add response hint
1 parent 4313ae2 commit d116ea0

5 files changed

Lines changed: 210 additions & 2146 deletions

File tree

examples/web/src/llms-middleware.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
* Usage with Express:
55
* ```ts
66
* import { llmsMiddleware } from './llms-middleware'
7-
* app.use(llmsMiddleware(llmsContent))
8-
* ```
9-
*
10-
* Usage with Hono:
11-
* ```ts
12-
* import { isAIUserAgent } from './llms-middleware'
13-
* app.use('/', async (c, next) => {
14-
* if (isAIUserAgent(c.req.header('user-agent'))) {
15-
* return c.text(llmsContent)
16-
* }
17-
* await next()
18-
* })
7+
* app.use(llmsMiddleware({
8+
* 'llms.txt': llmsIndex,
9+
* 'llms-free.txt': llmsFree,
10+
* 'llms-pro.txt': llmsPro,
11+
* }))
1912
* ```
2013
*/
2114

@@ -48,20 +41,27 @@ export function isAIUserAgent(userAgent: string | undefined): boolean {
4841

4942
export type LlmsMiddleware = (req: any, res: any, next: () => void) => void
5043

51-
export function llmsMiddleware(llmsContent: string): LlmsMiddleware {
44+
export type LlmsFiles = {
45+
'llms.txt': string
46+
'llms-free.txt': string
47+
'llms-pro.txt': string
48+
}
49+
50+
export function llmsMiddleware(files: LlmsFiles): LlmsMiddleware {
5251
return (req, res, next) => {
5352
const userAgent = req.headers['user-agent']
53+
const filename = req.url?.replace(/^\//, '') as keyof LlmsFiles
5454

55-
if (req.url === '/llms.txt') {
55+
if (filename in files) {
5656
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
57-
res.end(llmsContent)
57+
res.end(files[filename])
5858
return
5959
}
6060

6161
if (req.url === '/' && isAIUserAgent(userAgent)) {
6262
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
6363
res.setHeader('X-Served-As', 'llms.txt')
64-
res.end(llmsContent)
64+
res.end(files['llms.txt'])
6565
return
6666
}
6767

llms-free.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,41 @@
99
### GET /protocols
1010
**Base URL:** `https://api.llama.fi`
1111
List all protocols on defillama along with their tvl
12+
Returns: array of {id, name, symbol, category, chains, tvl, chainTvls, change_1d, change_7d}
1213

1314
### GET /protocol/{protocol}
1415
**Base URL:** `https://api.llama.fi`
1516
Get historical TVL of a protocol and breakdowns by token and chain
1617

1718
**Parameters:**
1819
- `protocol` (path, string, required) — protocol slug Example: `aave`
20+
Returns: {id, name, symbol, category, chains, currentChainTvls, chainTvls}
1921

2022
### GET /v2/historicalChainTvl
2123
**Base URL:** `https://api.llama.fi`
2224
Get historical TVL (excludes liquid staking and double counted tvl) of DeFi on all chains
25+
Returns: array of {date, tvl}
2326

2427
### GET /v2/historicalChainTvl/{chain}
2528
**Base URL:** `https://api.llama.fi`
2629
Get historical TVL (excludes liquid staking and double counted tvl) of a chain
2730

2831
**Parameters:**
2932
- `chain` (path, string, required) — chain slug, you can get these from /chains or the chains property on /protocols Example: `Ethereum`
33+
Returns: array of {date, tvl}
3034

3135
### GET /tvl/{protocol}
3236
**Base URL:** `https://api.llama.fi`
3337
Simplified endpoint to get current TVL of a protocol
3438

3539
**Parameters:**
3640
- `protocol` (path, string, required) — protocol slug Example: `uniswap`
41+
Returns: number
3742

3843
### GET /v2/chains
3944
**Base URL:** `https://api.llama.fi`
4045
Get current TVL of all chains
46+
Returns: array of {gecko_id, tvl, tokenSymbol, cmcId, name, chainId}
4147

4248
---
4349

@@ -50,6 +56,7 @@ Get current prices of tokens by contract address
5056
**Parameters:**
5157
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
5258
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 6 hours Example: `4h`
59+
Returns: {coins}
5360

5461
### GET /prices/historical/{timestamp}/{coins}
5562
**Base URL:** `https://api.llama.fi`
@@ -59,6 +66,7 @@ Get historical prices of tokens by contract address
5966
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
6067
- `timestamp` (path, number, required) — UNIX timestamp of time when you want historical prices Example: `1648680149`
6168
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 6 hours Example: `4h`
69+
Returns: {coins}
6270

6371
### GET /batchHistorical
6472
**Base URL:** `https://api.llama.fi`
@@ -68,6 +76,7 @@ Get historical prices for multiple tokens at multiple different timestamps
6876
- `coins` (query, string, required) — object where keys are coins in the form {chain}:{address}, and values are arrays of requested timestamps Example: `{"avax:0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e": [1666876743, 1666862343], "coingecko:ethereum": [1666869543, 1666862343]}
6977
`
7078
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 6 hours Example: `600`
79+
Returns: {coins}
7180

7281
### GET /chart/{coins}
7382
**Base URL:** `https://api.llama.fi`
@@ -80,6 +89,7 @@ Get token prices at regular time intervals
8089
- `span` (query, number, optional) — number of data points returned, defaults to 0 Example: `10`
8190
- `period` (query, string, optional) — duration between data points, defaults to 24 hours Example: `2d`
8291
- `searchWidth` (query, string, optional) — time range on either side to find price data, defaults to 10% of period Example: `600`
92+
Returns: {coins}
8393

8494
### GET /percentage/{coins}
8595
**Base URL:** `https://api.llama.fi`
@@ -90,13 +100,15 @@ Get percentage change in price over time
90100
- `timestamp` (query, number, optional) — timestamp of data point requested, defaults to time now Example: `1664364537`
91101
- `lookForward` (query, boolean, optional) — whether you want the duration after your given timestamp or not, defaults to false (looking back) Example: `false`
92102
- `period` (query, string, optional) — duration between data points, defaults to 24 hours Example: `3w`
103+
Returns: {coins}
93104

94105
### GET /prices/first/{coins}
95106
**Base URL:** `https://api.llama.fi`
96107
Get earliest timestamp price record for coins
97108

98109
**Parameters:**
99110
- `coins` (path, string, required) — set of comma-separated tokens defined as {chain}:{address} Example: `ethereum:0xdF574c24545E5FfEcb9a659c229253D4111d87e1,coingecko:ethereum,bsc:0x762539b45a1dcce3d36d080f74d1aed37844b878,ethereum:0xdB25f211AB05b1c97D595516F45794528a807ad8`
111+
Returns: {coins}
100112

101113
### GET /block/{chain}/{timestamp}
102114
**Base URL:** `https://api.llama.fi`
@@ -105,6 +117,7 @@ Get the closest block to a timestamp
105117
**Parameters:**
106118
- `chain` (path, string, required) — Chain which you want to get the block from Example: `ethereum`
107119
- `timestamp` (path, integer, required) — UNIX timestamp of the block you are searching for Example: `1603964988`
120+
Returns: {height, timestamp}
108121

109122
---
110123

@@ -116,13 +129,15 @@ List all stablecoins along with their circulating amounts
116129

117130
**Parameters:**
118131
- `includePrices` (query, boolean, optional) — set whether to include current stablecoin prices Example: `true`
132+
Returns: {peggedAssets}
119133

120134
### GET /stablecoincharts/all
121135
**Base URL:** `https://api.llama.fi`
122136
Get historical mcap sum of all stablecoins
123137

124138
**Parameters:**
125139
- `stablecoin` (query, integer, optional) — stablecoin ID, you can get these from /stablecoins Example: `1`
140+
Returns: array of {date, totalCirculating}
126141

127142
### GET /stablecoincharts/{chain}
128143
**Base URL:** `https://api.llama.fi`
@@ -131,21 +146,25 @@ Get historical mcap sum of all stablecoins in a chain
131146
**Parameters:**
132147
- `chain` (path, string, required) — chain slug, you can get these from /chains or the chains property on /protocols Example: `Ethereum`
133148
- `stablecoin` (query, integer, optional) — stablecoin ID, you can get these from /stablecoins Example: `1`
149+
Returns: array of {date, totalCirculating}
134150

135151
### GET /stablecoin/{asset}
136152
**Base URL:** `https://api.llama.fi`
137153
Get historical mcap and historical chain distribution of a stablecoin
138154

139155
**Parameters:**
140156
- `asset` (path, integer, required) — stablecoin ID, you can get these from /stablecoins Example: `1`
157+
Returns: {id, name, symbol, totalCirculating, chainCirculating}
141158

142159
### GET /stablecoinchains
143160
**Base URL:** `https://api.llama.fi`
144161
Get current mcap sum of all stablecoins on each chain
162+
Returns: array of {name, totalCirculating}
145163

146164
### GET /stablecoinprices
147165
**Base URL:** `https://api.llama.fi`
148166
Get historical prices of all stablecoins
167+
Returns: array of {date, prices}
149168

150169
---
151170

@@ -154,13 +173,15 @@ Get historical prices of all stablecoins
154173
### GET /pools
155174
**Base URL:** `https://api.llama.fi`
156175
Retrieve the latest data for all pools, including enriched information such as predictions
176+
Returns: {status, data}
157177

158178
### GET /chart/{pool}
159179
**Base URL:** `https://api.llama.fi`
160180
Get historical APY and TVL of a pool
161181

162182
**Parameters:**
163183
- `pool` (path, string, required) — pool id, can be retrieved from /pools (property is called pool) Example: `747c1d2a-c668-4682-b9f9-296708a3dd90`
184+
Returns: {status, data}
164185

165186
---
166187

@@ -173,6 +194,7 @@ List all dexs along with summaries of their volumes and dataType history data
173194
**Parameters:**
174195
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
175196
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
197+
Returns: {protocols, totalDataChart, allChains}
176198

177199
### GET /overview/dexs/{chain}
178200
**Base URL:** `https://api.llama.fi`
@@ -182,6 +204,7 @@ List all dexs along with summaries of their volumes and dataType history data fi
182204
- `chain` (path, string, required) — chain name, list of all supported chains can be found under allChains attribute in /overview/dexs response Example: `ethereum`
183205
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
184206
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
207+
Returns: {protocols, totalDataChart}
185208

186209
### GET /summary/dexs/{protocol}
187210
**Base URL:** `https://api.llama.fi`
@@ -191,6 +214,7 @@ Get summary of dex volume with historical data
191214
- `protocol` (path, string, required) — protocol slug Example: `uniswap`
192215
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
193216
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
217+
Returns: {name, total24h, totalAllTime, totalDataChart, totalDataChartBreakdown, chains}
194218

195219
### GET /overview/options
196220
**Base URL:** `https://api.llama.fi`
@@ -200,6 +224,7 @@ List all options dexs along with summaries of their volumes and dataType history
200224
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
201225
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
202226
- `dataType` (query, string, optional) — Desired data type, dailyNotionalVolume by default. (one of: dailyPremiumVolume, dailyNotionalVolume) Example: `dailyPremiumVolume`
227+
Returns: {protocols, totalDataChart}
203228

204229
### GET /overview/options/{chain}
205230
**Base URL:** `https://api.llama.fi`
@@ -230,6 +255,7 @@ List all open interest dex exchanges along with summaries of their open interest
230255
**Parameters:**
231256
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
232257
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
258+
Returns: {protocols, totalDataChart, allChains}
233259

234260
---
235261

@@ -243,6 +269,7 @@ List all protocols along with summaries of their fees and revenue and dataType h
243269
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
244270
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
245271
- `dataType` (query, string, optional) — Desired data type, dailyFees by default. (one of: dailyFees, dailyRevenue, dailyHoldersRevenue) Example: `dailyFees`
272+
Returns: {protocols, totalDataChart, totalDataChartBreakdown}
246273

247274
### GET /overview/fees/{chain}
248275
**Base URL:** `https://api.llama.fi`
@@ -253,6 +280,7 @@ List all protocols along with summaries of their fees and revenue and dataType h
253280
- `excludeTotalDataChart` (query, boolean, required) — true to exclude aggregated chart from response Example: `true`
254281
- `excludeTotalDataChartBreakdown` (query, boolean, required) — true to exclude broken down chart from response Example: `true`
255282
- `dataType` (query, string, optional) — Desired data type, dailyFees by default. (one of: dailyFees, dailyRevenue, dailyHoldersRevenue) Example: `dailyFees`
283+
Returns: {protocols, totalDataChart, totalDataChartBreakdown}
256284

257285
### GET /summary/fees/{protocol}
258286
**Base URL:** `https://api.llama.fi`
@@ -261,3 +289,4 @@ Get summary of protocol fees and revenue with historical data
261289
**Parameters:**
262290
- `protocol` (path, string, required) — protocol slug Example: `derive`
263291
- `dataType` (query, string, optional) — Desired data type, dailyFees by default. (one of: dailyFees, dailyRevenue, dailyHoldersRevenue) Example: `dailyFees`
292+
Returns: {id, name, url, referralUrl, description, logo, gecko_id, cmcId, chains, twitter, github, symbol, address, childProtocols, linkedProtocols, defillamaId, disabled, displayName, module, category, methodologyURL, methodology, forkedFrom, audits, audit_links, versionKey, governanceID, treasury, parentProtocol, previousNames, latestFetchIsOk, slug, protocolType, total24h, total48hto24h, total7d, totalAllTime, change_1d, totalDataChart, totalDataChartBreakdown}

0 commit comments

Comments
 (0)