@mupt-ai/dari-gateway 1.0.313 → 1.0.314
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/README.md +17 -20
- package/dist/http/handler.js +1 -1
- package/dist/ingress/anthropic_messages.js +1 -1
- package/dist/ingress/models.js +1 -1
- package/dist/{link_client.d.ts → link/client.d.ts} +7 -11
- package/dist/{link_client.js → link/client.js} +5 -6
- package/dist/{ingress/link.d.ts → link/endpoints.d.ts} +3 -4
- package/dist/{ingress/link.js → link/endpoints.js} +158 -62
- package/dist/{runtime/link_grant_access.js → link/grant_access.js} +1 -1
- package/dist/link/grants.d.ts +151 -0
- package/dist/link/grants.js +275 -0
- package/dist/link/key_providers.d.ts +6 -0
- package/dist/link/key_providers.js +21 -0
- package/dist/link/self_hosted.d.ts +3 -0
- package/dist/link/self_hosted.js +166 -0
- package/dist/link/service.d.ts +85 -0
- package/dist/link/service.js +187 -0
- package/dist/link/sqlite_store.d.ts +74 -0
- package/dist/link/sqlite_store.js +381 -0
- package/dist/models/canonical_models.json +19 -0
- package/dist/platform/platform.d.ts +42 -47
- package/dist/runtime/explicit_model.js +1 -1
- package/dist/runtime/prepare_routed_completion.js +1 -1
- package/dist/self_host/main.js +2 -2
- package/dist/self_host/platform.js +4 -249
- package/dist/self_host/resolve.d.ts +2 -2
- package/dist/self_host/resolve.js +3 -19
- package/dist/self_host/stub_gateway.js +3 -3
- package/dist/self_host/subscriptions/http.js +2 -2
- package/dist/telemetry/report.js +1 -1
- package/package.json +2 -2
- package/src/http/handler.ts +1 -1
- package/src/ingress/anthropic_messages.ts +1 -1
- package/src/ingress/models.ts +1 -1
- package/src/{link_client.ts → link/client.ts} +11 -14
- package/src/{ingress/link.ts → link/endpoints.ts} +172 -69
- package/src/{runtime/link_grant_access.ts → link/grant_access.ts} +1 -1
- package/src/link/grants.ts +436 -0
- package/src/link/key_providers.ts +25 -0
- package/src/link/self_hosted.ts +186 -0
- package/src/link/service.ts +281 -0
- package/src/link/sqlite_store.ts +512 -0
- package/src/models/canonical_models.json +19 -0
- package/src/platform/platform.ts +39 -45
- package/src/runtime/explicit_model.ts +1 -1
- package/src/runtime/prepare_routed_completion.ts +1 -1
- package/src/self_host/main.ts +2 -2
- package/src/self_host/platform.ts +5 -267
- package/src/self_host/resolve.ts +6 -21
- package/src/self_host/stub_gateway.ts +3 -3
- package/src/self_host/subscriptions/http.ts +2 -2
- package/src/telemetry/report.ts +1 -1
- package/dist/self_host/link_store.d.ts +0 -167
- package/dist/self_host/link_store.js +0 -564
- package/src/self_host/link_store.ts +0 -782
- /package/dist/{ingress/link_assets.d.ts → link/assets.d.ts} +0 -0
- /package/dist/{ingress/link_assets.js → link/assets.js} +0 -0
- /package/dist/{runtime/link_budget.d.ts → link/budget.d.ts} +0 -0
- /package/dist/{runtime/link_budget.js → link/budget.js} +0 -0
- /package/dist/{models/link_errors.d.ts → link/errors.d.ts} +0 -0
- /package/dist/{models/link_errors.js → link/errors.js} +0 -0
- /package/dist/{ingress/link_font.d.ts → link/font.d.ts} +0 -0
- /package/dist/{ingress/link_font.js → link/font.js} +0 -0
- /package/dist/{runtime/link_grant_access.d.ts → link/grant_access.d.ts} +0 -0
- /package/dist/{runtime/link_in_flight.d.ts → link/in_flight.d.ts} +0 -0
- /package/dist/{runtime/link_in_flight.js → link/in_flight.js} +0 -0
- /package/src/{ingress/link_assets.ts → link/assets.ts} +0 -0
- /package/src/{runtime/link_budget.ts → link/budget.ts} +0 -0
- /package/src/{models/link_errors.ts → link/errors.ts} +0 -0
- /package/src/{ingress/link_font.ts → link/font.ts} +0 -0
- /package/src/{runtime/link_in_flight.ts → link/in_flight.ts} +0 -0
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQLite storage for Dari Link: registered apps, the grants users approve for
|
|
3
|
-
* them, and each grant's tokens. A grant names the subscriptions it may use.
|
|
4
|
-
* Every token is its own row holding only the token's SHA-256, so an access
|
|
5
|
-
* token lives until its own expiry whatever is issued after it; revoking the
|
|
6
|
-
* grant stops them all at once.
|
|
7
|
-
*
|
|
8
|
-
* - access tokens last an hour.
|
|
9
|
-
* - refresh tokens do not expire. A public client's rotates on use; a
|
|
10
|
-
* confidential client, which also proves its secret, keeps its own.
|
|
11
|
-
* - child tokens serve one model, for up to twelve hours, and cannot refresh
|
|
12
|
-
* or mint.
|
|
13
|
-
*/
|
|
14
|
-
import type { Database } from "bun:sqlite";
|
|
15
|
-
import { type SecretBox } from "./secret_box.js";
|
|
16
|
-
import type { LinkApp, LinkBudget, LinkChildToken, LinkGrant, LinkTokens, LinkUsage, LinkUsageQuery } from "../platform/platform.js";
|
|
17
|
-
import { type BudgetStanding } from "../runtime/link_budget.js";
|
|
18
|
-
export declare const LINK_ACCESS_TOKEN_TTL_MS: number;
|
|
19
|
-
export declare const LINK_REFRESH_RACE_MS = 60000;
|
|
20
|
-
export type LinkRevoker = "user" | "app" | "reuse_detected";
|
|
21
|
-
export type ActiveLinkGrant = {
|
|
22
|
-
id: string;
|
|
23
|
-
clientId: string;
|
|
24
|
-
credentialIds: ReadonlySet<string>;
|
|
25
|
-
pins?: LinkPin[];
|
|
26
|
-
tags?: Record<string, string>;
|
|
27
|
-
};
|
|
28
|
-
/** What a presented link token is; null when it is not one this store issued. */
|
|
29
|
-
export type LinkPin = {
|
|
30
|
-
model: string;
|
|
31
|
-
thinking: string | null;
|
|
32
|
-
};
|
|
33
|
-
export type LinkTokenAuth = {
|
|
34
|
-
status: "active";
|
|
35
|
-
grant: ActiveLinkGrant;
|
|
36
|
-
} | {
|
|
37
|
-
status: "expired";
|
|
38
|
-
} | {
|
|
39
|
-
status: "revoked";
|
|
40
|
-
revokedBy: string | null;
|
|
41
|
-
revokedAt: string | null;
|
|
42
|
-
};
|
|
43
|
-
/** An API key a user added on the approval page, for one model provider or gateway. */
|
|
44
|
-
export type LinkApiKey = {
|
|
45
|
-
id: string;
|
|
46
|
-
subject: string;
|
|
47
|
-
provider: string;
|
|
48
|
-
apiKey: string;
|
|
49
|
-
};
|
|
50
|
-
export declare class LinkStore {
|
|
51
|
-
private readonly db;
|
|
52
|
-
private readonly box;
|
|
53
|
-
constructor(db: Database, box?: SecretBox | null);
|
|
54
|
-
private encryptStored;
|
|
55
|
-
private seal;
|
|
56
|
-
private key;
|
|
57
|
-
/** Store a user's API key for a provider, replacing their earlier one for it. */
|
|
58
|
-
addKey(subject: string, provider: string, apiKey: string, now?: Date): LinkApiKey;
|
|
59
|
-
/** Delete a user's API key; false when they have none by that id. */
|
|
60
|
-
removeKey(subject: string, id: string): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Take a deleted plan or key out of every live grant; a grant left with
|
|
63
|
-
* nothing is revoked as the user's doing.
|
|
64
|
-
*/
|
|
65
|
-
dropCredential(credentialId: string, now?: Date): void;
|
|
66
|
-
/** The API keys a user added, oldest first. */
|
|
67
|
-
keys(subject: string): LinkApiKey[];
|
|
68
|
-
/** The API keys with these ids, whoever added them. */
|
|
69
|
-
keysWithIds(ids: ReadonlySet<string>): LinkApiKey[];
|
|
70
|
-
/** A grant's budget; empty when it has none or is unknown. */
|
|
71
|
-
budget(grantId: string): LinkBudget[];
|
|
72
|
-
/** Replace a live grant's budget; false when none is live by that id. */
|
|
73
|
-
setBudget(grantId: string, budget: LinkBudget[]): boolean;
|
|
74
|
-
/** Each of a grant's budget windows as it stands now (see runtime/link_budget.ts). */
|
|
75
|
-
budgetStandings(grantId: string, now?: Date): BudgetStanding[];
|
|
76
|
-
/** Record what one of a grant's requests used; a repeated request id is ignored. */
|
|
77
|
-
recordUsage(entry: LinkUsageEntry): void;
|
|
78
|
-
/** What a grant's requests used, filtered by tags and receive time. */
|
|
79
|
-
usage(grantId: string, query: Omit<LinkUsageQuery, "accessToken">): Omit<LinkUsage, "completeThrough">;
|
|
80
|
-
/** Register an app; a confidential one gets a secret, returned this once. */
|
|
81
|
-
registerApp(name: string, redirectUris: string[], confidential?: boolean, now?: Date): LinkApp & {
|
|
82
|
-
clientSecret?: string;
|
|
83
|
-
};
|
|
84
|
-
app(clientId: string): LinkApp | null;
|
|
85
|
-
/**
|
|
86
|
-
* Create a grant awaiting its code exchange and return the code. With
|
|
87
|
-
* `grantId` (update mode), change that live grant of the app's plans and
|
|
88
|
-
* budget in place instead: its tokens keep working, and the code redeems
|
|
89
|
-
* for more tokens of the same grant.
|
|
90
|
-
*/
|
|
91
|
-
approve(request: {
|
|
92
|
-
subject?: string;
|
|
93
|
-
grantId?: string;
|
|
94
|
-
clientId: string;
|
|
95
|
-
redirectUri: string;
|
|
96
|
-
codeChallenge: string;
|
|
97
|
-
credentialIds: string[];
|
|
98
|
-
budget?: LinkBudget[];
|
|
99
|
-
}, now?: Date): string;
|
|
100
|
-
/** Redeem a code once: the grant's first tokens. */
|
|
101
|
-
exchangeCode(request: {
|
|
102
|
-
clientId: string;
|
|
103
|
-
clientSecret?: string;
|
|
104
|
-
code: string;
|
|
105
|
-
redirectUri: string;
|
|
106
|
-
codeChallenge: string;
|
|
107
|
-
}, now?: Date): LinkTokens;
|
|
108
|
-
/**
|
|
109
|
-
* A new access token for a grant. A public client's refresh token rotates;
|
|
110
|
-
* a confidential client keeps the one it presented.
|
|
111
|
-
*/
|
|
112
|
-
refresh(request: {
|
|
113
|
-
clientId: string;
|
|
114
|
-
clientSecret?: string;
|
|
115
|
-
refreshToken: string;
|
|
116
|
-
}, now?: Date): LinkTokens;
|
|
117
|
-
/** Mint a child token from the grant's access token. */
|
|
118
|
-
exchangeToken(request: {
|
|
119
|
-
clientId: string;
|
|
120
|
-
clientSecret?: string;
|
|
121
|
-
subjectToken: string;
|
|
122
|
-
models: Array<{
|
|
123
|
-
model: string;
|
|
124
|
-
thinking?: string;
|
|
125
|
-
}>;
|
|
126
|
-
expiresIn: number;
|
|
127
|
-
tags: Record<string, string>;
|
|
128
|
-
}, now?: Date): LinkChildToken;
|
|
129
|
-
/** What a presented access or child token is, or null when it is neither. */
|
|
130
|
-
authenticate(token: string, now?: Date): LinkTokenAuth | null;
|
|
131
|
-
/** Revoke the grant any of its tokens names, when the client owns it (RFC 7009). */
|
|
132
|
-
revokeToken(request: {
|
|
133
|
-
clientId: string;
|
|
134
|
-
clientSecret?: string;
|
|
135
|
-
token: string;
|
|
136
|
-
}, now?: Date): void;
|
|
137
|
-
/** The subscriptions a grant may use; empty once it is revoked. */
|
|
138
|
-
credentialIds(grantId: string): ReadonlySet<string>;
|
|
139
|
-
/** The user who approved a grant; null when it has none or is unknown. */
|
|
140
|
-
subject(grantId: string): string | null;
|
|
141
|
-
/** Grants that are not revoked, oldest first. */
|
|
142
|
-
grants(): LinkGrant[];
|
|
143
|
-
/**
|
|
144
|
-
* Revoke a grant: its code and refresh tokens go, and its access and child
|
|
145
|
-
* tokens stop working. False when none is active by that id.
|
|
146
|
-
*/
|
|
147
|
-
revoke(grantId: string, by: LinkRevoker, now?: Date): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* The app a client id names, once it has proven its secret when it has one.
|
|
150
|
-
* A confidential client must send its secret; a public one must not.
|
|
151
|
-
*/
|
|
152
|
-
private authenticateClient;
|
|
153
|
-
private issue;
|
|
154
|
-
}
|
|
155
|
-
export type LinkUsageEntry = {
|
|
156
|
-
requestId: string;
|
|
157
|
-
grantId: string;
|
|
158
|
-
receivedAt: Date;
|
|
159
|
-
model: string | null;
|
|
160
|
-
thinking: string | null;
|
|
161
|
-
tags: Record<string, string>;
|
|
162
|
-
inputTokens: number;
|
|
163
|
-
outputTokens: number;
|
|
164
|
-
cacheReadTokens: number;
|
|
165
|
-
cacheWriteTokens: number;
|
|
166
|
-
status: string;
|
|
167
|
-
};
|