mppx 0.2.6 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/proxy/Proxy.d.ts.map +1 -1
- package/dist/proxy/Proxy.js +71 -5
- package/dist/proxy/Proxy.js.map +1 -1
- package/dist/proxy/Service.d.ts +4 -1
- package/dist/proxy/Service.d.ts.map +1 -1
- package/dist/proxy/Service.js +54 -39
- package/dist/proxy/Service.js.map +1 -1
- package/dist/proxy/services/openai.js +1 -1
- package/dist/proxy/services/openai.js.map +1 -1
- package/package.json +1 -1
- package/src/proxy/Proxy.test.ts +204 -51
- package/src/proxy/Proxy.ts +83 -5
- package/src/proxy/Service.ts +53 -35
- package/src/proxy/services/openai.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../src/proxy/Proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAA;AAKtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,kFAAkF;AAClF,MAAM,MAAM,KAAK,GAAG;IAClB,sFAAsF;IACtF,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC9C,uFAAuF;IACvF,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,KAAK,IAAI,CAAA;CACxE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../src/proxy/Proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAA;AAKtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,kFAAkF;AAClF,MAAM,MAAM,KAAK,GAAG;IAClB,sFAAsF;IACtF,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC9C,uFAAuF;IACvF,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,KAAK,IAAI,CAAA;CACxE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,KAAK,CA6HnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,KAAY,MAAM,GAAG;QACnB,sEAAsE;QACtE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC7B,0DAA0D;QAC1D,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAChC,qEAAqE;QACrE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAAG,SAAS,CAAA;QAC3C,qEAAqE;QACrE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,CAAA;QAC3B,8DAA8D;QAC9D,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAC3B,CAAA;CACF"}
|
package/dist/proxy/Proxy.js
CHANGED
|
@@ -48,17 +48,44 @@ export function create(config) {
|
|
|
48
48
|
return new Response(Service.toLlmsTxt(config.services, {
|
|
49
49
|
title: config.title,
|
|
50
50
|
description: config.description,
|
|
51
|
-
}), {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
}), { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
|
|
52
|
+
if (request.method === 'GET' && pathname === '/discover.md')
|
|
53
|
+
return new Response(Service.toLlmsTxt(config.services, {
|
|
54
|
+
title: config.title,
|
|
55
|
+
description: config.description,
|
|
56
|
+
}), { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
|
|
57
|
+
if (request.method === 'GET' && (pathname === '/discover' || pathname === '/discover/')) {
|
|
58
|
+
if (wantsMarkdown(request))
|
|
59
|
+
return new Response(Service.toLlmsTxt(config.services, {
|
|
60
|
+
title: config.title,
|
|
61
|
+
description: config.description,
|
|
62
|
+
}), { headers: { 'Content-Type': 'text/plain; charset=utf-8' } });
|
|
55
63
|
return Response.json(config.services.map(Service.serialize));
|
|
64
|
+
}
|
|
65
|
+
if (request.method === 'GET' &&
|
|
66
|
+
(pathname === '/discover/all' || pathname === '/discover/all/')) {
|
|
67
|
+
if (wantsMarkdown(request))
|
|
68
|
+
return new Response(Service.toServicesMarkdown(config.services), {
|
|
69
|
+
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
|
|
70
|
+
});
|
|
71
|
+
return Response.json(config.services.map(Service.serialize));
|
|
72
|
+
}
|
|
73
|
+
if (request.method === 'GET' && pathname === '/discover/all.md')
|
|
74
|
+
return new Response(Service.toServicesMarkdown(config.services), {
|
|
75
|
+
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
|
|
76
|
+
});
|
|
56
77
|
{
|
|
57
|
-
|
|
78
|
+
// List service
|
|
79
|
+
const match = pathname.match(/^\/discover\/([^/]+)\.md$/) ?? pathname.match(/^\/discover\/([^/]+)\/?$/);
|
|
58
80
|
if (request.method === 'GET' && match) {
|
|
59
81
|
const service = config.services.find((s) => s.id === match[1]);
|
|
60
82
|
if (!service)
|
|
61
83
|
return new Response('Not Found', { status: 404 });
|
|
84
|
+
const wantsText = pathname.endsWith('.md') || wantsMarkdown(request);
|
|
85
|
+
if (wantsText)
|
|
86
|
+
return new Response(Service.toMarkdown(service), {
|
|
87
|
+
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
|
|
88
|
+
});
|
|
62
89
|
return Response.json(Service.serialize(service));
|
|
63
90
|
}
|
|
64
91
|
}
|
|
@@ -126,4 +153,43 @@ async function proxyUpstream(options) {
|
|
|
126
153
|
upstreamRes = await service.rewriteResponse(upstreamRes, ctx);
|
|
127
154
|
return upstreamRes;
|
|
128
155
|
}
|
|
156
|
+
const aiUserAgents = [
|
|
157
|
+
'GPTBot',
|
|
158
|
+
'OAI-SearchBot',
|
|
159
|
+
'ChatGPT-User',
|
|
160
|
+
'anthropic-ai',
|
|
161
|
+
'ClaudeBot',
|
|
162
|
+
'claude-web',
|
|
163
|
+
'PerplexityBot',
|
|
164
|
+
'Perplexity-User',
|
|
165
|
+
'Google-Extended',
|
|
166
|
+
'Googlebot',
|
|
167
|
+
'Bingbot',
|
|
168
|
+
'Amazonbot',
|
|
169
|
+
'Applebot',
|
|
170
|
+
'Applebot-Extended',
|
|
171
|
+
'FacebookBot',
|
|
172
|
+
'meta-externalagent',
|
|
173
|
+
'Bytespider',
|
|
174
|
+
'DuckAssistBot',
|
|
175
|
+
'cohere-ai',
|
|
176
|
+
'AI2Bot',
|
|
177
|
+
'CCBot',
|
|
178
|
+
'Diffbot',
|
|
179
|
+
'YouBot',
|
|
180
|
+
'MistralAI-User',
|
|
181
|
+
'GoogleAgent-Mariner',
|
|
182
|
+
];
|
|
183
|
+
const terminalUserAgents = ['curl', 'Wget', 'HTTPie', 'httpie-go', 'mppx', 'presto', 'xh'];
|
|
184
|
+
function wantsMarkdown(request) {
|
|
185
|
+
const accept = request.headers.get('accept');
|
|
186
|
+
if (accept && (accept.includes('text/markdown') || accept.includes('text/plain')))
|
|
187
|
+
return true;
|
|
188
|
+
const ua = request.headers.get('user-agent') ?? '';
|
|
189
|
+
if (aiUserAgents.some((agent) => ua.includes(agent)))
|
|
190
|
+
return true;
|
|
191
|
+
if (terminalUserAgents.some((agent) => ua.includes(agent)))
|
|
192
|
+
return true;
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
129
195
|
//# sourceMappingURL=Proxy.js.map
|
package/dist/proxy/Proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Proxy.js","sourceRoot":"","sources":["../../src/proxy/Proxy.ts"],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ChB,qBAAqB;CACtB,CAAA;AAED,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAE1F,SAAS,aAAa,CAAC,OAA2B;IAChD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC5C,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IAC9F,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAA;IAClD,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IACjE,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAA;IACvE,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/dist/proxy/Service.d.ts
CHANGED
|
@@ -100,7 +100,6 @@ export declare namespace from {
|
|
|
100
100
|
export { from as custom };
|
|
101
101
|
/** Serializes a service for discovery responses. */
|
|
102
102
|
export declare function serialize(s: Service): {
|
|
103
|
-
baseUrl: string;
|
|
104
103
|
description: string | undefined;
|
|
105
104
|
id: string;
|
|
106
105
|
docsLlmsUrl: string | undefined;
|
|
@@ -118,6 +117,10 @@ export declare function toLlmsTxt(services: Service[], options?: {
|
|
|
118
117
|
title?: string | undefined;
|
|
119
118
|
description?: string | undefined;
|
|
120
119
|
}): string;
|
|
120
|
+
/** Renders a full markdown listing of all services with their routes. */
|
|
121
|
+
export declare function toServicesMarkdown(services: Service[]): string;
|
|
122
|
+
/** Renders a markdown string for a single service. */
|
|
123
|
+
export declare function toMarkdown(s: Service): string;
|
|
121
124
|
/** Extracts per-endpoint options from an endpoint definition. */
|
|
122
125
|
export declare function getOptions(endpoint: Endpoint): EndpointOptions | undefined;
|
|
123
126
|
//# sourceMappingURL=Service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../src/proxy/Service.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,MAAM,MAAM,OAAO,GAAG;IACpB,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAA;IACf,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,gFAAgF;IAChF,EAAE,EAAE,MAAM,CAAA;IACV,gIAAgI;IAChI,WAAW,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,KAAK,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAC3F,qFAAqF;IACrF,cAAc,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAA;IACzF,2EAA2E;IAC3E,eAAe,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAA;IAC7F,kDAAkD;IAClD,MAAM,EAAE,WAAW,CAAA;IACnB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,aAAa,GAAG;IAAE,GAAG,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,eAA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@@ function resolveRewriteRequest(config) {
|
|
|
66
66
|
/** Serializes a service for discovery responses. */
|
|
67
67
|
export function serialize(s) {
|
|
68
68
|
return {
|
|
69
|
-
baseUrl: s.baseUrl,
|
|
70
69
|
description: s.description,
|
|
71
70
|
id: s.id,
|
|
72
71
|
docsLlmsUrl: s.docsLlmsUrl?.({}),
|
|
73
72
|
routes: Object.entries(s.routes).map(([pattern, endpoint]) => {
|
|
74
73
|
const tokens = pattern.trim().split(/\s+/);
|
|
75
74
|
const hasMethod = tokens.length >= 2;
|
|
75
|
+
const path = hasMethod ? tokens.slice(1).join(' ') : tokens[0];
|
|
76
76
|
return {
|
|
77
77
|
docsLlmsUrl: s.docsLlmsUrl?.({ route: pattern }),
|
|
78
78
|
method: hasMethod ? tokens[0] : undefined,
|
|
79
|
-
path:
|
|
80
|
-
pattern
|
|
79
|
+
path: `/${s.id}${path}`,
|
|
80
|
+
pattern: hasMethod ? `${tokens[0]} /${s.id}${path}` : `/${s.id}${path}`,
|
|
81
81
|
payment: endpoint ? resolvePayment(endpoint) : null,
|
|
82
82
|
};
|
|
83
83
|
}),
|
|
@@ -91,56 +91,71 @@ export function toLlmsTxt(services, options) {
|
|
|
91
91
|
'',
|
|
92
92
|
`> ${options?.description ?? 'Paid API proxy powered by [Machine Payments Protocol](https://mpp.tempo.xyz).'}`,
|
|
93
93
|
'',
|
|
94
|
-
'For machine-readable service data, use `GET /services` (JSON).',
|
|
95
|
-
'',
|
|
96
94
|
];
|
|
97
95
|
if (services.length === 0)
|
|
98
96
|
return lines.join('\n');
|
|
99
97
|
lines.push('## Services', '');
|
|
100
98
|
for (const s of services) {
|
|
101
|
-
const serialized = serialize(s);
|
|
102
|
-
const free = serialized.routes.filter((r) => r.payment === null).length;
|
|
103
|
-
const paid = serialized.routes.length - free;
|
|
104
|
-
const parts = [paid && `${paid} paid`, free && `${free} free`].filter(Boolean).join(', ');
|
|
105
99
|
const label = s.title ?? s.id;
|
|
106
|
-
const desc = s.description ? `: ${s.description}
|
|
107
|
-
lines.push(`- [${label}](
|
|
100
|
+
const desc = s.description ? `: ${s.description}` : '';
|
|
101
|
+
lines.push(`- [${label}](/discover/${s.id}.md)${desc}`);
|
|
108
102
|
}
|
|
103
|
+
lines.push('', '[See all service definitions](/discover/all.md)');
|
|
104
|
+
return lines.join('\n');
|
|
105
|
+
}
|
|
106
|
+
/** Renders a full markdown listing of all services with their routes. */
|
|
107
|
+
export function toServicesMarkdown(services) {
|
|
108
|
+
const lines = ['# Services', ''];
|
|
109
|
+
if (services.length === 0)
|
|
110
|
+
return lines.join('\n');
|
|
109
111
|
for (const s of services) {
|
|
110
|
-
|
|
111
|
-
const docsLlmsUrl = s.docsLlmsUrl?.({});
|
|
112
|
-
lines.push('', `## ${s.title ?? s.id}`, '');
|
|
112
|
+
lines.push(`## [${s.title ?? s.id}](/discover/${s.id}.md)`, '');
|
|
113
113
|
if (s.description)
|
|
114
114
|
lines.push(s.description, '');
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
pushRoutes(lines, s);
|
|
116
|
+
}
|
|
117
|
+
return lines.join('\n');
|
|
118
|
+
}
|
|
119
|
+
/** Renders a markdown string for a single service. */
|
|
120
|
+
export function toMarkdown(s) {
|
|
121
|
+
const docsLlmsUrl = s.docsLlmsUrl?.({});
|
|
122
|
+
const lines = [`# ${s.title ?? s.id}`, ''];
|
|
123
|
+
if (docsLlmsUrl)
|
|
124
|
+
lines.push(`> Documentation: ${docsLlmsUrl}`, '');
|
|
125
|
+
if (s.description)
|
|
126
|
+
lines.push(s.description, '');
|
|
127
|
+
pushRoutes(lines, s, '##');
|
|
128
|
+
return lines.join('\n');
|
|
129
|
+
}
|
|
130
|
+
function pushRoutes(lines, s, heading = '###') {
|
|
131
|
+
lines.push(`${heading} Routes`, '');
|
|
132
|
+
const serialized = serialize(s);
|
|
133
|
+
for (const route of serialized.routes) {
|
|
134
|
+
const p = route.payment;
|
|
135
|
+
const desc = p?.description ? `: ${p.description}` : '';
|
|
136
|
+
lines.push(`- \`${route.pattern}\`${desc}`);
|
|
137
|
+
if (!p) {
|
|
138
|
+
lines.push(' - Type: free');
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
lines.push(` - Type: ${p.intent}`);
|
|
142
|
+
if (p.amount) {
|
|
143
|
+
const perUnit = p.unitType ? `/${p.unitType}` : '';
|
|
144
|
+
if (p.decimals !== undefined) {
|
|
145
|
+
const price = Number(p.amount) / 10 ** Number(p.decimals);
|
|
146
|
+
lines.push(` - Price: ${price}${perUnit} (${p.amount} units, ${p.decimals} decimals)`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
lines.push(` - Units: ${p.amount}${perUnit}`);
|
|
135
150
|
}
|
|
136
|
-
if (p.currency)
|
|
137
|
-
lines.push(` - Currency: ${p.currency}`);
|
|
138
151
|
}
|
|
139
|
-
if (
|
|
140
|
-
lines.push(` -
|
|
152
|
+
if (p.currency)
|
|
153
|
+
lines.push(` - Currency: ${p.currency}`);
|
|
141
154
|
}
|
|
155
|
+
if (route.docsLlmsUrl)
|
|
156
|
+
lines.push(` - Docs: ${route.docsLlmsUrl}`);
|
|
157
|
+
lines.push('');
|
|
142
158
|
}
|
|
143
|
-
return lines.join('\n');
|
|
144
159
|
}
|
|
145
160
|
/** Extracts per-endpoint options from an endpoint definition. */
|
|
146
161
|
export function getOptions(endpoint) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../../src/proxy/Service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAA;AA+D1B;;;;;;;;;;;;;;GAcG;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,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;AACnF,CAAC;AAED,SAAS,cAAc,CACrB,KAA6F;IAE7F,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAC5B,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAO,KAAK,CAAA;IAC7C,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -22,7 +22,7 @@ export function openai(config) {
|
|
|
22
22
|
description: 'Chat completions, embeddings, image generation, and audio transcription.',
|
|
23
23
|
docsLlmsUrl: ({ route }) => route
|
|
24
24
|
? `https://context7.com/websites/platform_openai/llms.txt?topic=${encodeURIComponent(route)}`
|
|
25
|
-
:
|
|
25
|
+
: 'https://context7.com/websites/platform_openai/llms.txt',
|
|
26
26
|
rewriteRequest(request, ctx) {
|
|
27
27
|
const apiKey = ctx.apiKey ?? config.apiKey;
|
|
28
28
|
request.headers.set('Authorization', `Bearer ${apiKey}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/proxy/services/openai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAqB;IAC1C,OAAO,OAAO,CAAC,IAAI,CAAgB,QAAQ,EAAE;QAC3C,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,wBAAwB;QACnD,WAAW,EAAE,0EAA0E;QACvF,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CACzB,KAAK;YACH,CAAC,CAAC,gEAAgE,kBAAkB,CAAC,KAAK,CAAC,EAAE;YAC7F,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/proxy/services/openai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAqB;IAC1C,OAAO,OAAO,CAAC,IAAI,CAAgB,QAAQ,EAAE;QAC3C,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,wBAAwB;QACnD,WAAW,EAAE,0EAA0E;QACvF,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CACzB,KAAK;YACH,CAAC,CAAC,gEAAgE,kBAAkB,CAAC,KAAK,CAAC,EAAE;YAC7F,CAAC,CAAC,wDAAwD;QAC9D,cAAc,CAAC,OAAO,EAAE,GAAG;YACzB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAA;YAC1C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,MAAM,EAAE,CAAC,CAAA;YACxD,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,QAAQ;KAChB,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
package/src/proxy/Proxy.test.ts
CHANGED
|
@@ -61,7 +61,7 @@ function createUpstream(handler: (req: Request) => Response | Promise<Response>)
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
describe('create', () => {
|
|
64
|
-
test('behavior: GET /
|
|
64
|
+
test('behavior: GET /discover/all returns service discovery JSON', async () => {
|
|
65
65
|
const proxy = ApiProxy.create({
|
|
66
66
|
services: [
|
|
67
67
|
Service.from('api', {
|
|
@@ -80,24 +80,23 @@ describe('create', () => {
|
|
|
80
80
|
})
|
|
81
81
|
proxyServer = await Http.createServer(proxy.listener)
|
|
82
82
|
|
|
83
|
-
const res = await fetch(`${proxyServer.url}/
|
|
83
|
+
const res = await fetch(`${proxyServer.url}/discover/all`)
|
|
84
84
|
expect(res.status).toBe(200)
|
|
85
85
|
expect(await res.json()).toMatchInlineSnapshot(`
|
|
86
86
|
[
|
|
87
87
|
{
|
|
88
|
-
"baseUrl": "https://api.example.com",
|
|
89
88
|
"id": "api",
|
|
90
89
|
"routes": [
|
|
91
90
|
{
|
|
92
91
|
"method": "GET",
|
|
93
|
-
"path": "/v1/models",
|
|
94
|
-
"pattern": "GET /v1/models",
|
|
92
|
+
"path": "/api/v1/models",
|
|
93
|
+
"pattern": "GET /api/v1/models",
|
|
95
94
|
"payment": null,
|
|
96
95
|
},
|
|
97
96
|
{
|
|
98
97
|
"method": "POST",
|
|
99
|
-
"path": "/v1/generate",
|
|
100
|
-
"pattern": "POST /v1/generate",
|
|
98
|
+
"path": "/api/v1/generate",
|
|
99
|
+
"pattern": "POST /api/v1/generate",
|
|
101
100
|
"payment": {
|
|
102
101
|
"amount": "1000000",
|
|
103
102
|
"currency": "0x20c0000000000000000000000000000000000001",
|
|
@@ -110,8 +109,8 @@ describe('create', () => {
|
|
|
110
109
|
},
|
|
111
110
|
{
|
|
112
111
|
"method": "POST",
|
|
113
|
-
"path": "/v1/stream",
|
|
114
|
-
"pattern": "POST /v1/stream",
|
|
112
|
+
"path": "/api/v1/stream",
|
|
113
|
+
"pattern": "POST /api/v1/stream",
|
|
115
114
|
"payment": {
|
|
116
115
|
"amount": "1000000",
|
|
117
116
|
"currency": "0x20c0000000000000000000000000000000000001",
|
|
@@ -129,7 +128,25 @@ describe('create', () => {
|
|
|
129
128
|
`)
|
|
130
129
|
})
|
|
131
130
|
|
|
132
|
-
test('behavior: GET /
|
|
131
|
+
test('behavior: GET /discover returns JSON by default', async () => {
|
|
132
|
+
const proxy = ApiProxy.create({
|
|
133
|
+
services: [
|
|
134
|
+
Service.from('api', {
|
|
135
|
+
baseUrl: 'https://api.example.com',
|
|
136
|
+
routes: {
|
|
137
|
+
'GET /v1/models': true,
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
],
|
|
141
|
+
})
|
|
142
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
143
|
+
|
|
144
|
+
const res = await fetch(`${proxyServer.url}/discover`)
|
|
145
|
+
expect(res.status).toBe(200)
|
|
146
|
+
expect(res.headers.get('content-type')).toMatchInlineSnapshot(`"application/json"`)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('behavior: GET /discover returns llms.txt for markdown clients', async () => {
|
|
133
150
|
const proxy = ApiProxy.create({
|
|
134
151
|
title: 'My AI Gateway',
|
|
135
152
|
description: 'A paid proxy for LLM and AI services.',
|
|
@@ -165,7 +182,9 @@ describe('create', () => {
|
|
|
165
182
|
})
|
|
166
183
|
proxyServer = await Http.createServer(proxy.listener)
|
|
167
184
|
|
|
168
|
-
const res = await fetch(`${proxyServer.url}/
|
|
185
|
+
const res = await fetch(`${proxyServer.url}/discover`, {
|
|
186
|
+
headers: { Accept: 'text/plain' },
|
|
187
|
+
})
|
|
169
188
|
expect(res.status).toBe(200)
|
|
170
189
|
expect(res.headers.get('content-type')).toBe('text/plain; charset=utf-8')
|
|
171
190
|
expect(await res.text()).toMatchInlineSnapshot(`
|
|
@@ -173,44 +192,16 @@ describe('create', () => {
|
|
|
173
192
|
|
|
174
193
|
> A paid proxy for LLM and AI services.
|
|
175
194
|
|
|
176
|
-
For machine-readable service data, use \`GET /services\` (JSON).
|
|
177
|
-
|
|
178
195
|
## Services
|
|
179
196
|
|
|
180
|
-
- [OpenAI](
|
|
181
|
-
- [Anthropic](
|
|
182
|
-
|
|
183
|
-
## OpenAI
|
|
184
|
-
|
|
185
|
-
Chat completions, embeddings, image generation, and audio transcription.
|
|
186
|
-
|
|
187
|
-
- \`POST /v1/chat/completions\` - Chat completion
|
|
188
|
-
- Type: charge
|
|
189
|
-
- Price: 0.05 (50000 units, 6 decimals)
|
|
190
|
-
- Currency: 0x20c0000000000000000000000000000000000001
|
|
191
|
-
- Docs: https://context7.com/websites/platform_openai/llms.txt?topic=POST%20%2Fv1%2Fchat%2Fcompletions
|
|
192
|
-
- \`POST /v1/embeddings\` - Generate embeddings
|
|
193
|
-
- Type: charge
|
|
194
|
-
- Price: 0.01 (10000 units, 6 decimals)
|
|
195
|
-
- Currency: 0x20c0000000000000000000000000000000000001
|
|
196
|
-
- Docs: https://context7.com/websites/platform_openai/llms.txt?topic=POST%20%2Fv1%2Fembeddings
|
|
197
|
-
|
|
198
|
-
## Anthropic
|
|
199
|
-
|
|
200
|
-
Claude language models for messages and completions.
|
|
197
|
+
- [OpenAI](/discover/openai.md): Chat completions, embeddings, image generation, and audio transcription.
|
|
198
|
+
- [Anthropic](/discover/anthropic.md): Claude language models for messages and completions.
|
|
201
199
|
|
|
202
|
-
|
|
203
|
-
- Type: charge
|
|
204
|
-
- Price: 0.03 (30000 units, 6 decimals)
|
|
205
|
-
- Currency: 0x20c0000000000000000000000000000000000001
|
|
206
|
-
- \`POST /v1/messages/stream\` - Stream message
|
|
207
|
-
- Type: session
|
|
208
|
-
- Price: 0.01/token (10000 units, 6 decimals)
|
|
209
|
-
- Currency: 0x20c0000000000000000000000000000000000001"
|
|
200
|
+
[See all service definitions](/discover/all.md)"
|
|
210
201
|
`)
|
|
211
202
|
})
|
|
212
203
|
|
|
213
|
-
test('behavior: GET /
|
|
204
|
+
test('behavior: GET /discover/:id returns single service', async () => {
|
|
214
205
|
const proxy = ApiProxy.create({
|
|
215
206
|
services: [
|
|
216
207
|
Service.from('api', {
|
|
@@ -224,23 +215,22 @@ describe('create', () => {
|
|
|
224
215
|
})
|
|
225
216
|
proxyServer = await Http.createServer(proxy.listener)
|
|
226
217
|
|
|
227
|
-
const res = await fetch(`${proxyServer.url}/
|
|
218
|
+
const res = await fetch(`${proxyServer.url}/discover/api`)
|
|
228
219
|
expect(res.status).toBe(200)
|
|
229
220
|
expect(await res.json()).toMatchInlineSnapshot(`
|
|
230
221
|
{
|
|
231
|
-
"baseUrl": "https://api.example.com",
|
|
232
222
|
"id": "api",
|
|
233
223
|
"routes": [
|
|
234
224
|
{
|
|
235
225
|
"method": "GET",
|
|
236
|
-
"path": "/v1/models",
|
|
237
|
-
"pattern": "GET /v1/models",
|
|
226
|
+
"path": "/api/v1/models",
|
|
227
|
+
"pattern": "GET /api/v1/models",
|
|
238
228
|
"payment": null,
|
|
239
229
|
},
|
|
240
230
|
{
|
|
241
231
|
"method": "POST",
|
|
242
|
-
"path": "/v1/generate",
|
|
243
|
-
"pattern": "POST /v1/generate",
|
|
232
|
+
"path": "/api/v1/generate",
|
|
233
|
+
"pattern": "POST /api/v1/generate",
|
|
244
234
|
"payment": {
|
|
245
235
|
"amount": "1000000",
|
|
246
236
|
"currency": "0x20c0000000000000000000000000000000000001",
|
|
@@ -256,10 +246,173 @@ describe('create', () => {
|
|
|
256
246
|
`)
|
|
257
247
|
})
|
|
258
248
|
|
|
259
|
-
test('behavior: GET /
|
|
249
|
+
test('behavior: GET /discover/all.md returns full markdown with routes', async () => {
|
|
250
|
+
const proxy = ApiProxy.create({
|
|
251
|
+
services: [
|
|
252
|
+
openai({
|
|
253
|
+
apiKey: 'sk-test',
|
|
254
|
+
routes: {
|
|
255
|
+
'POST /v1/chat/completions': mppx_server.charge({
|
|
256
|
+
amount: '0.05',
|
|
257
|
+
description: 'Chat completion',
|
|
258
|
+
}),
|
|
259
|
+
'GET /v1/models': true,
|
|
260
|
+
},
|
|
261
|
+
}),
|
|
262
|
+
anthropic({
|
|
263
|
+
apiKey: 'sk-ant-test',
|
|
264
|
+
routes: {
|
|
265
|
+
'POST /v1/messages': mppx_server.charge({
|
|
266
|
+
amount: '0.03',
|
|
267
|
+
description: 'Send message',
|
|
268
|
+
}),
|
|
269
|
+
},
|
|
270
|
+
}),
|
|
271
|
+
],
|
|
272
|
+
})
|
|
273
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
274
|
+
|
|
275
|
+
const res = await fetch(`${proxyServer.url}/discover/all.md`)
|
|
276
|
+
expect(res.status).toBe(200)
|
|
277
|
+
expect(res.headers.get('content-type')).toBe('text/markdown; charset=utf-8')
|
|
278
|
+
expect(await res.text()).toMatchInlineSnapshot(`
|
|
279
|
+
"# Services
|
|
280
|
+
|
|
281
|
+
## [OpenAI](/discover/openai.md)
|
|
282
|
+
|
|
283
|
+
Chat completions, embeddings, image generation, and audio transcription.
|
|
284
|
+
|
|
285
|
+
### Routes
|
|
286
|
+
|
|
287
|
+
- \`POST /openai/v1/chat/completions\`: Chat completion
|
|
288
|
+
- Type: charge
|
|
289
|
+
- Price: 0.05 (50000 units, 6 decimals)
|
|
290
|
+
- Currency: 0x20c0000000000000000000000000000000000001
|
|
291
|
+
- Docs: https://context7.com/websites/platform_openai/llms.txt?topic=POST%20%2Fv1%2Fchat%2Fcompletions
|
|
292
|
+
|
|
293
|
+
- \`GET /openai/v1/models\`
|
|
294
|
+
- Type: free
|
|
295
|
+
- Docs: https://context7.com/websites/platform_openai/llms.txt?topic=GET%20%2Fv1%2Fmodels
|
|
296
|
+
|
|
297
|
+
## [Anthropic](/discover/anthropic.md)
|
|
298
|
+
|
|
299
|
+
Claude language models for messages and completions.
|
|
300
|
+
|
|
301
|
+
### Routes
|
|
302
|
+
|
|
303
|
+
- \`POST /anthropic/v1/messages\`: Send message
|
|
304
|
+
- Type: charge
|
|
305
|
+
- Price: 0.03 (30000 units, 6 decimals)
|
|
306
|
+
- Currency: 0x20c0000000000000000000000000000000000001
|
|
307
|
+
"
|
|
308
|
+
`)
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
test('behavior: GET /discover/:id.md returns markdown', async () => {
|
|
312
|
+
const proxy = ApiProxy.create({
|
|
313
|
+
services: [
|
|
314
|
+
openai({
|
|
315
|
+
apiKey: 'sk-test',
|
|
316
|
+
routes: {
|
|
317
|
+
'POST /v1/chat/completions': mppx_server.charge({
|
|
318
|
+
amount: '0.05',
|
|
319
|
+
description: 'Chat completion',
|
|
320
|
+
}),
|
|
321
|
+
'GET /v1/models': true,
|
|
322
|
+
},
|
|
323
|
+
}),
|
|
324
|
+
anthropic({
|
|
325
|
+
apiKey: 'sk-ant-test',
|
|
326
|
+
routes: {
|
|
327
|
+
'POST /v1/messages': mppx_server.charge({ amount: '0.03' }),
|
|
328
|
+
},
|
|
329
|
+
}),
|
|
330
|
+
],
|
|
331
|
+
})
|
|
332
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
333
|
+
|
|
334
|
+
const res = await fetch(`${proxyServer.url}/discover/openai.md`)
|
|
335
|
+
expect(res.status).toBe(200)
|
|
336
|
+
expect(res.headers.get('content-type')).toBe('text/markdown; charset=utf-8')
|
|
337
|
+
expect(await res.text()).toMatchInlineSnapshot(`
|
|
338
|
+
"# OpenAI
|
|
339
|
+
|
|
340
|
+
> Documentation: https://context7.com/websites/platform_openai/llms.txt
|
|
341
|
+
|
|
342
|
+
Chat completions, embeddings, image generation, and audio transcription.
|
|
343
|
+
|
|
344
|
+
## Routes
|
|
345
|
+
|
|
346
|
+
- \`POST /openai/v1/chat/completions\`: Chat completion
|
|
347
|
+
- Type: charge
|
|
348
|
+
- Price: 0.05 (50000 units, 6 decimals)
|
|
349
|
+
- Currency: 0x20c0000000000000000000000000000000000001
|
|
350
|
+
- Docs: https://context7.com/websites/platform_openai/llms.txt?topic=POST%20%2Fv1%2Fchat%2Fcompletions
|
|
351
|
+
|
|
352
|
+
- \`GET /openai/v1/models\`
|
|
353
|
+
- Type: free
|
|
354
|
+
- Docs: https://context7.com/websites/platform_openai/llms.txt?topic=GET%20%2Fv1%2Fmodels
|
|
355
|
+
"
|
|
356
|
+
`)
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
test('behavior: GET /discover/:id with Accept: text/markdown returns markdown', async () => {
|
|
360
|
+
const proxy = ApiProxy.create({
|
|
361
|
+
services: [
|
|
362
|
+
openai({
|
|
363
|
+
apiKey: 'sk-test',
|
|
364
|
+
routes: { 'GET /v1/models': true },
|
|
365
|
+
}),
|
|
366
|
+
anthropic({
|
|
367
|
+
apiKey: 'sk-ant-test',
|
|
368
|
+
routes: {
|
|
369
|
+
'POST /v1/messages': mppx_server.charge({ amount: '0.03' }),
|
|
370
|
+
},
|
|
371
|
+
}),
|
|
372
|
+
],
|
|
373
|
+
})
|
|
374
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
375
|
+
|
|
376
|
+
const res = await fetch(`${proxyServer.url}/discover/anthropic`, {
|
|
377
|
+
headers: { Accept: 'text/markdown' },
|
|
378
|
+
})
|
|
379
|
+
expect(res.status).toBe(200)
|
|
380
|
+
expect(res.headers.get('content-type')).toBe('text/markdown; charset=utf-8')
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
test('behavior: GET /discover/:id without Accept returns JSON', async () => {
|
|
384
|
+
const proxy = ApiProxy.create({
|
|
385
|
+
services: [
|
|
386
|
+
openai({
|
|
387
|
+
apiKey: 'sk-test',
|
|
388
|
+
routes: { 'GET /v1/models': true },
|
|
389
|
+
}),
|
|
390
|
+
anthropic({
|
|
391
|
+
apiKey: 'sk-ant-test',
|
|
392
|
+
routes: {
|
|
393
|
+
'POST /v1/messages': mppx_server.charge({ amount: '0.03' }),
|
|
394
|
+
},
|
|
395
|
+
}),
|
|
396
|
+
],
|
|
397
|
+
})
|
|
398
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
399
|
+
|
|
400
|
+
const res = await fetch(`${proxyServer.url}/discover/openai`)
|
|
401
|
+
expect(res.status).toBe(200)
|
|
402
|
+
expect(res.headers.get('content-type')).toMatchInlineSnapshot(`"application/json"`)
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
test('behavior: GET /discover/:id.md returns 404 for unknown', async () => {
|
|
406
|
+
const proxy = ApiProxy.create({ services: [] })
|
|
407
|
+
proxyServer = await Http.createServer(proxy.listener)
|
|
408
|
+
const res = await fetch(`${proxyServer.url}/discover/unknown.md`)
|
|
409
|
+
expect(res.status).toBe(404)
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
test('behavior: GET /discover/:id returns 404 for unknown', async () => {
|
|
260
413
|
const proxy = ApiProxy.create({ services: [] })
|
|
261
414
|
proxyServer = await Http.createServer(proxy.listener)
|
|
262
|
-
const res = await fetch(`${proxyServer.url}/
|
|
415
|
+
const res = await fetch(`${proxyServer.url}/discover/unknown`)
|
|
263
416
|
expect(res.status).toBe(404)
|
|
264
417
|
})
|
|
265
418
|
|
package/src/proxy/Proxy.ts
CHANGED
|
@@ -66,19 +66,58 @@ export function create(config: create.Config): Proxy {
|
|
|
66
66
|
title: config.title,
|
|
67
67
|
description: config.description,
|
|
68
68
|
}),
|
|
69
|
-
{
|
|
70
|
-
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
71
|
-
},
|
|
69
|
+
{ headers: { 'Content-Type': 'text/plain; charset=utf-8' } },
|
|
72
70
|
)
|
|
73
71
|
|
|
74
|
-
if (request.method === 'GET' &&
|
|
72
|
+
if (request.method === 'GET' && pathname === '/discover.md')
|
|
73
|
+
return new Response(
|
|
74
|
+
Service.toLlmsTxt(config.services, {
|
|
75
|
+
title: config.title,
|
|
76
|
+
description: config.description,
|
|
77
|
+
}),
|
|
78
|
+
{ headers: { 'Content-Type': 'text/plain; charset=utf-8' } },
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if (request.method === 'GET' && (pathname === '/discover' || pathname === '/discover/')) {
|
|
82
|
+
if (wantsMarkdown(request))
|
|
83
|
+
return new Response(
|
|
84
|
+
Service.toLlmsTxt(config.services, {
|
|
85
|
+
title: config.title,
|
|
86
|
+
description: config.description,
|
|
87
|
+
}),
|
|
88
|
+
{ headers: { 'Content-Type': 'text/plain; charset=utf-8' } },
|
|
89
|
+
)
|
|
75
90
|
return Response.json(config.services.map(Service.serialize))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
request.method === 'GET' &&
|
|
95
|
+
(pathname === '/discover/all' || pathname === '/discover/all/')
|
|
96
|
+
) {
|
|
97
|
+
if (wantsMarkdown(request))
|
|
98
|
+
return new Response(Service.toServicesMarkdown(config.services), {
|
|
99
|
+
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
|
|
100
|
+
})
|
|
101
|
+
return Response.json(config.services.map(Service.serialize))
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (request.method === 'GET' && pathname === '/discover/all.md')
|
|
105
|
+
return new Response(Service.toServicesMarkdown(config.services), {
|
|
106
|
+
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
|
|
107
|
+
})
|
|
76
108
|
|
|
77
109
|
{
|
|
78
|
-
|
|
110
|
+
// List service
|
|
111
|
+
const match =
|
|
112
|
+
pathname.match(/^\/discover\/([^/]+)\.md$/) ?? pathname.match(/^\/discover\/([^/]+)\/?$/)
|
|
79
113
|
if (request.method === 'GET' && match) {
|
|
80
114
|
const service = config.services.find((s) => s.id === match[1])
|
|
81
115
|
if (!service) return new Response('Not Found', { status: 404 })
|
|
116
|
+
const wantsText = pathname.endsWith('.md') || wantsMarkdown(request)
|
|
117
|
+
if (wantsText)
|
|
118
|
+
return new Response(Service.toMarkdown(service), {
|
|
119
|
+
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
|
|
120
|
+
})
|
|
82
121
|
return Response.json(Service.serialize(service))
|
|
83
122
|
}
|
|
84
123
|
}
|
|
@@ -183,3 +222,42 @@ async function proxyUpstream(options: proxyUpstream.Options): Promise<Response>
|
|
|
183
222
|
|
|
184
223
|
return upstreamRes
|
|
185
224
|
}
|
|
225
|
+
|
|
226
|
+
const aiUserAgents = [
|
|
227
|
+
'GPTBot',
|
|
228
|
+
'OAI-SearchBot',
|
|
229
|
+
'ChatGPT-User',
|
|
230
|
+
'anthropic-ai',
|
|
231
|
+
'ClaudeBot',
|
|
232
|
+
'claude-web',
|
|
233
|
+
'PerplexityBot',
|
|
234
|
+
'Perplexity-User',
|
|
235
|
+
'Google-Extended',
|
|
236
|
+
'Googlebot',
|
|
237
|
+
'Bingbot',
|
|
238
|
+
'Amazonbot',
|
|
239
|
+
'Applebot',
|
|
240
|
+
'Applebot-Extended',
|
|
241
|
+
'FacebookBot',
|
|
242
|
+
'meta-externalagent',
|
|
243
|
+
'Bytespider',
|
|
244
|
+
'DuckAssistBot',
|
|
245
|
+
'cohere-ai',
|
|
246
|
+
'AI2Bot',
|
|
247
|
+
'CCBot',
|
|
248
|
+
'Diffbot',
|
|
249
|
+
'YouBot',
|
|
250
|
+
'MistralAI-User',
|
|
251
|
+
'GoogleAgent-Mariner',
|
|
252
|
+
]
|
|
253
|
+
|
|
254
|
+
const terminalUserAgents = ['curl', 'Wget', 'HTTPie', 'httpie-go', 'mppx', 'presto', 'xh']
|
|
255
|
+
|
|
256
|
+
function wantsMarkdown(request: globalThis.Request): boolean {
|
|
257
|
+
const accept = request.headers.get('accept')
|
|
258
|
+
if (accept && (accept.includes('text/markdown') || accept.includes('text/plain'))) return true
|
|
259
|
+
const ua = request.headers.get('user-agent') ?? ''
|
|
260
|
+
if (aiUserAgents.some((agent) => ua.includes(agent))) return true
|
|
261
|
+
if (terminalUserAgents.some((agent) => ua.includes(agent))) return true
|
|
262
|
+
return false
|
|
263
|
+
}
|
package/src/proxy/Service.ts
CHANGED
|
@@ -160,18 +160,18 @@ function resolveRewriteRequest(
|
|
|
160
160
|
/** Serializes a service for discovery responses. */
|
|
161
161
|
export function serialize(s: Service) {
|
|
162
162
|
return {
|
|
163
|
-
baseUrl: s.baseUrl,
|
|
164
163
|
description: s.description,
|
|
165
164
|
id: s.id,
|
|
166
165
|
docsLlmsUrl: s.docsLlmsUrl?.({}),
|
|
167
166
|
routes: Object.entries(s.routes).map(([pattern, endpoint]) => {
|
|
168
167
|
const tokens = pattern.trim().split(/\s+/)
|
|
169
168
|
const hasMethod = tokens.length >= 2
|
|
169
|
+
const path = hasMethod ? tokens.slice(1).join(' ') : tokens[0]
|
|
170
170
|
return {
|
|
171
171
|
docsLlmsUrl: s.docsLlmsUrl?.({ route: pattern }),
|
|
172
172
|
method: hasMethod ? tokens[0] : undefined,
|
|
173
|
-
path:
|
|
174
|
-
pattern
|
|
173
|
+
path: `/${s.id}${path}`,
|
|
174
|
+
pattern: hasMethod ? `${tokens[0]} /${s.id}${path}` : `/${s.id}${path}`,
|
|
175
175
|
payment: endpoint ? resolvePayment(endpoint) : null,
|
|
176
176
|
}
|
|
177
177
|
}),
|
|
@@ -189,53 +189,71 @@ export function toLlmsTxt(
|
|
|
189
189
|
'',
|
|
190
190
|
`> ${options?.description ?? 'Paid API proxy powered by [Machine Payments Protocol](https://mpp.tempo.xyz).'}`,
|
|
191
191
|
'',
|
|
192
|
-
'For machine-readable service data, use `GET /services` (JSON).',
|
|
193
|
-
'',
|
|
194
192
|
]
|
|
195
193
|
|
|
196
194
|
if (services.length === 0) return lines.join('\n')
|
|
197
195
|
|
|
198
196
|
lines.push('## Services', '')
|
|
199
197
|
for (const s of services) {
|
|
200
|
-
const serialized = serialize(s)
|
|
201
|
-
const free = serialized.routes.filter((r) => r.payment === null).length
|
|
202
|
-
const paid = serialized.routes.length - free
|
|
203
|
-
const parts = [paid && `${paid} paid`, free && `${free} free`].filter(Boolean).join(', ')
|
|
204
198
|
const label = s.title ?? s.id
|
|
205
|
-
const desc = s.description ? `: ${s.description}
|
|
206
|
-
lines.push(`- [${label}](
|
|
199
|
+
const desc = s.description ? `: ${s.description}` : ''
|
|
200
|
+
lines.push(`- [${label}](/discover/${s.id}.md)${desc}`)
|
|
207
201
|
}
|
|
202
|
+
lines.push('', '[See all service definitions](/discover/all.md)')
|
|
203
|
+
|
|
204
|
+
return lines.join('\n')
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Renders a full markdown listing of all services with their routes. */
|
|
208
|
+
export function toServicesMarkdown(services: Service[]): string {
|
|
209
|
+
const lines: string[] = ['# Services', '']
|
|
210
|
+
|
|
211
|
+
if (services.length === 0) return lines.join('\n')
|
|
208
212
|
|
|
209
213
|
for (const s of services) {
|
|
210
|
-
|
|
211
|
-
const docsLlmsUrl = s.docsLlmsUrl?.({})
|
|
212
|
-
lines.push('', `## ${s.title ?? s.id}`, '')
|
|
214
|
+
lines.push(`## [${s.title ?? s.id}](/discover/${s.id}.md)`, '')
|
|
213
215
|
if (s.description) lines.push(s.description, '')
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
216
|
+
pushRoutes(lines, s)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return lines.join('\n')
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Renders a markdown string for a single service. */
|
|
223
|
+
export function toMarkdown(s: Service): string {
|
|
224
|
+
const docsLlmsUrl = s.docsLlmsUrl?.({})
|
|
225
|
+
const lines: string[] = [`# ${s.title ?? s.id}`, '']
|
|
226
|
+
if (docsLlmsUrl) lines.push(`> Documentation: ${docsLlmsUrl}`, '')
|
|
227
|
+
if (s.description) lines.push(s.description, '')
|
|
228
|
+
pushRoutes(lines, s, '##')
|
|
229
|
+
return lines.join('\n')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function pushRoutes(lines: string[], s: Service, heading: '##' | '###' = '###') {
|
|
233
|
+
lines.push(`${heading} Routes`, '')
|
|
234
|
+
const serialized = serialize(s)
|
|
235
|
+
for (const route of serialized.routes) {
|
|
236
|
+
const p = route.payment as Record<string, unknown> | null
|
|
237
|
+
const desc = p?.description ? `: ${p.description}` : ''
|
|
238
|
+
lines.push(`- \`${route.pattern}\`${desc}`)
|
|
239
|
+
if (!p) {
|
|
240
|
+
lines.push(' - Type: free')
|
|
241
|
+
} else {
|
|
242
|
+
lines.push(` - Type: ${p.intent}`)
|
|
243
|
+
if (p.amount) {
|
|
244
|
+
const perUnit = p.unitType ? `/${p.unitType}` : ''
|
|
245
|
+
if (p.decimals !== undefined) {
|
|
246
|
+
const price = Number(p.amount) / 10 ** Number(p.decimals)
|
|
247
|
+
lines.push(` - Price: ${price}${perUnit} (${p.amount} units, ${p.decimals} decimals)`)
|
|
248
|
+
} else {
|
|
249
|
+
lines.push(` - Units: ${p.amount}${perUnit}`)
|
|
231
250
|
}
|
|
232
|
-
if (p.currency) lines.push(` - Currency: ${p.currency}`)
|
|
233
251
|
}
|
|
234
|
-
if (
|
|
252
|
+
if (p.currency) lines.push(` - Currency: ${p.currency}`)
|
|
235
253
|
}
|
|
254
|
+
if (route.docsLlmsUrl) lines.push(` - Docs: ${route.docsLlmsUrl}`)
|
|
255
|
+
lines.push('')
|
|
236
256
|
}
|
|
237
|
-
|
|
238
|
-
return lines.join('\n')
|
|
239
257
|
}
|
|
240
258
|
|
|
241
259
|
/** Extracts per-endpoint options from an endpoint definition. */
|
|
@@ -24,7 +24,7 @@ export function openai(config: openai.Config) {
|
|
|
24
24
|
docsLlmsUrl: ({ route }) =>
|
|
25
25
|
route
|
|
26
26
|
? `https://context7.com/websites/platform_openai/llms.txt?topic=${encodeURIComponent(route)}`
|
|
27
|
-
:
|
|
27
|
+
: 'https://context7.com/websites/platform_openai/llms.txt',
|
|
28
28
|
rewriteRequest(request, ctx) {
|
|
29
29
|
const apiKey = ctx.apiKey ?? config.apiKey
|
|
30
30
|
request.headers.set('Authorization', `Bearer ${apiKey}`)
|