@nylorun/agents 0.13.0-beta → 0.14.0-beta

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.
@@ -1,30 +0,0 @@
1
- import { RuntimeError } from "./http.js";
2
- const NO_STORE = { "cache-control": "no-store" };
3
- export function createTokenEndpoint(options) {
4
- return async (request) => {
5
- if (request.method !== "POST")
6
- return new Response(null, { status: 405, headers: { allow: "POST", ...NO_STORE } });
7
- const subject = await options.subject(request);
8
- if (!subject)
9
- return Response.json({ error: "Sign in required" }, { status: 401, headers: NO_STORE });
10
- const role = typeof options.role === "string"
11
- ? options.role
12
- : await options.role(request, subject);
13
- try {
14
- const client = await options.client;
15
- const minted = await client.tokens.create({
16
- subject,
17
- role,
18
- ...(options.scopes ? { scopes: options.scopes } : {}),
19
- ...(options.agents ? { agents: options.agents } : {}),
20
- ...(options.ttlSeconds === undefined ? {} : { ttlSeconds: options.ttlSeconds }),
21
- });
22
- return Response.json({ token: minted.token, expiresAt: minted.expiresAt }, { headers: NO_STORE });
23
- }
24
- catch (error) {
25
- // The person sees that a token could not be issued, never the Runtime's details.
26
- const status = error instanceof RuntimeError && error.status === 400 ? 403 : 502;
27
- return Response.json({ error: "Could not issue a token" }, { status, headers: NO_STORE });
28
- }
29
- };
30
- }