@mupt-ai/dari-gateway 1.0.320 → 1.0.321
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 +1 -1
- package/dist/protocol/input/router_model.js +1 -1
- package/dist/providers/pi_options.js +5 -0
- package/dist/self_host/subscriptions/http.js +53 -7
- package/package.json +2 -2
- package/src/protocol/input/router_model.ts +1 -1
- package/src/providers/pi_options.ts +4 -0
- package/src/self_host/subscriptions/http.ts +55 -7
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ Model ids are `provider/model`. Clients send `model: "dari/routing"` to let the
|
|
|
112
112
|
export DARI_GATEWAY_URL=http://localhost:8080
|
|
113
113
|
export DARI_GATEWAY_KEY=<one of DARI_GATEWAY_KEYS>
|
|
114
114
|
|
|
115
|
-
dari
|
|
115
|
+
dari accounts subscription connect claude-code # or codex or muse-code; repeat to pool plans
|
|
116
116
|
dari claude
|
|
117
117
|
```
|
|
118
118
|
|
|
@@ -18,7 +18,7 @@ const ANTHROPIC_ROUTER_MODELS = new Set([CANONICAL_ROUTER_MODEL, ...ANTHROPIC_RO
|
|
|
18
18
|
request leaves the client (wire-captured live: Task spawns emit
|
|
19
19
|
`claude-opus-5` even when the session model is dari/routing), so concrete
|
|
20
20
|
Claude-family ids are synonyms too — both bare (`claude-opus-5`) and
|
|
21
|
-
provider-prefixed (`anthropic/claude-opus-5`) forms. `dari claude --setup`
|
|
21
|
+
provider-prefixed (`anthropic/claude-opus-5`) forms. `dari claude --setup-desktop`
|
|
22
22
|
relies on this: the Claude app lists routing as `claude-dari-routing`. */
|
|
23
23
|
const ANTHROPIC_MODEL_ID_PATTERN = /^(anthropic\/)?claude-[a-z0-9][a-z0-9.-]*$/i;
|
|
24
24
|
export function isAnthropicRouterModel(model) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isReasoningEffort, isRecord } from "@mupt-ai/dari-router/policy-engine";
|
|
2
|
+
import { isBackgroundRequest } from "../interaction/types.js";
|
|
2
3
|
import { requiredCapabilitiesFor } from "../interaction/capabilities.js";
|
|
3
4
|
import { toolWireName, toolsByWireName } from "../interaction/tool_identity.js";
|
|
4
5
|
import { gatewayFor, payloadWithGatewayFields } from "../models/gateways.js";
|
|
@@ -95,6 +96,10 @@ export function buildOptions(request, auth, selectedModel, model, pi, sessionId,
|
|
|
95
96
|
const webSearch = anthropicWebSearchFor(request, model);
|
|
96
97
|
if (webSearch !== undefined) {
|
|
97
98
|
patches.push((payload) => payloadWithWebSearchTool(payload, webSearch));
|
|
99
|
+
// A background search is one request whose results are read once. Like
|
|
100
|
+
// Claude Code against Anthropic directly, send it without prompt caching.
|
|
101
|
+
if (isBackgroundRequest(request))
|
|
102
|
+
options.cacheRetention = "none";
|
|
98
103
|
}
|
|
99
104
|
// Pi keeps only the content it models, so native compaction output reaches
|
|
100
105
|
// the client from the provider's own output items.
|
|
@@ -151,13 +151,59 @@ async function completeSession(deps, body, now) {
|
|
|
151
151
|
function summary(store, credential, now) {
|
|
152
152
|
return credentialBody(credential, store.activeCredential(credential.provider, now)?.id === credential.id, now);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
const FIVE_HOURS = 5 * 60;
|
|
155
|
+
const ONE_WEEK = 7 * 24 * 60;
|
|
156
|
+
const ONE_MONTH = 30 * 24 * 60;
|
|
157
|
+
// A model family's own window is named for the family's catalog models.
|
|
158
|
+
const MODEL_FAMILY_NAMES = { fable: "Claude Fable" };
|
|
159
|
+
/** What to call a window: 5 Hour, Weekly, Monthly, Claude Fable Weekly. */
|
|
160
|
+
function usageWindowLabel(window) {
|
|
161
|
+
const minutes = window.minutes;
|
|
162
|
+
const length = minutes === ONE_WEEK ? "Weekly"
|
|
163
|
+
: minutes === ONE_MONTH ? "Monthly"
|
|
164
|
+
: minutes % (24 * 60) === 0 ? `${minutes / (24 * 60)} Day`
|
|
165
|
+
: minutes % 60 === 0 ? `${minutes / 60} Hour`
|
|
166
|
+
: `${minutes} Minute`;
|
|
167
|
+
return window.modelFamily === undefined ? length : `${MODEL_FAMILY_NAMES[window.modelFamily]} ${length}`;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The usage to show, as the hosted API shows it: every running window, a
|
|
171
|
+
* held plan's window full. A hold ends when the window that ran out resets,
|
|
172
|
+
* so the shared window resetting with it shows full. Usage reported without
|
|
173
|
+
* per-window detail, and holds without a matching window, are named by how
|
|
174
|
+
* far off their reset is: only a weekly or monthly window resets more than
|
|
175
|
+
* five hours out, and only OpenCode Go's monthly one more than a week.
|
|
176
|
+
*/
|
|
155
177
|
function usageBody(credential, now) {
|
|
178
|
+
const inferred = (resetsAt) => {
|
|
179
|
+
const left = resetsAt.getTime() - now.getTime();
|
|
180
|
+
if (left > ONE_WEEK * 60_000)
|
|
181
|
+
return ONE_MONTH;
|
|
182
|
+
return left > FIVE_HOURS * 60_000 ? ONE_WEEK : FIVE_HOURS;
|
|
183
|
+
};
|
|
156
184
|
const usage = currentUsage(credential, now);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
185
|
+
let windows = usage === null ? []
|
|
186
|
+
: usage.windows.length > 0 ? usage.windows
|
|
187
|
+
: [{ minutes: inferred(usage.resetsAt), utilization: usage.utilization, resetsAt: usage.resetsAt }];
|
|
188
|
+
if (isHeld(credential, now)) {
|
|
189
|
+
const held = credential.unavailableUntil;
|
|
190
|
+
const gap = (window) => Math.abs(window.resetsAt.getTime() - held.getTime());
|
|
191
|
+
// The hold is the plan's; it never fills a model family's window.
|
|
192
|
+
const closest = windows.filter((window) => window.modelFamily === undefined)
|
|
193
|
+
.reduce((best, window) => best === null || gap(window) < gap(best) ? window : best, null);
|
|
194
|
+
const minutes = closest !== null && gap(closest) < 15 * 60_000 ? closest.minutes : inferred(held);
|
|
195
|
+
windows = [
|
|
196
|
+
...windows.filter((window) => window.modelFamily !== undefined || window.minutes !== minutes),
|
|
197
|
+
{ minutes, utilization: 1, resetsAt: held },
|
|
198
|
+
].sort((a, b) => a.minutes - b.minutes || (a.modelFamily ?? "").localeCompare(b.modelFamily ?? ""));
|
|
199
|
+
}
|
|
200
|
+
if (windows.length === 0)
|
|
201
|
+
return null;
|
|
202
|
+
return {
|
|
203
|
+
utilization: usage?.utilization ?? 1,
|
|
204
|
+
resets_at: (usage?.resetsAt ?? windows[0].resetsAt).toISOString(),
|
|
205
|
+
windows: windows.map((window) => ({
|
|
206
|
+
label: usageWindowLabel(window),
|
|
161
207
|
...(window.modelFamily === undefined ? {} : { model_family: window.modelFamily }),
|
|
162
208
|
minutes: window.minutes,
|
|
163
209
|
utilization: window.utilization,
|
|
@@ -188,8 +234,8 @@ function credentialBody(credential, active, now) {
|
|
|
188
234
|
reason: hold.reason,
|
|
189
235
|
})),
|
|
190
236
|
subscription_active: active,
|
|
191
|
-
// The share of its tightest window the plan last reported used,
|
|
192
|
-
//
|
|
237
|
+
// The share of its tightest window the plan last reported used, and
|
|
238
|
+
// every window as shown; null when it reports none and is not held.
|
|
193
239
|
usage: usageBody(credential, now),
|
|
194
240
|
// Spending banked limit resets is hosted-only.
|
|
195
241
|
auto_redeem_resets: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mupt-ai/dari-gateway",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.321",
|
|
4
4
|
"description": "Self-hostable LLM gateway for coding agents and APIs: one endpoint for Anthropic Messages, OpenAI Chat Completions, and OpenAI Responses, with subscription pooling, failover, and prompt-cache-aware routing.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@aws-sdk/client-sts": "3.1063.0",
|
|
55
|
-
"@mupt-ai/dari-router": "1.0.
|
|
55
|
+
"@mupt-ai/dari-router": "1.0.321",
|
|
56
56
|
"@mupt-ai/pi-ai": "1.5.2-mupt.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
@@ -22,7 +22,7 @@ const ANTHROPIC_ROUTER_MODELS = new Set<string>([CANONICAL_ROUTER_MODEL, ...ANTH
|
|
|
22
22
|
request leaves the client (wire-captured live: Task spawns emit
|
|
23
23
|
`claude-opus-5` even when the session model is dari/routing), so concrete
|
|
24
24
|
Claude-family ids are synonyms too — both bare (`claude-opus-5`) and
|
|
25
|
-
provider-prefixed (`anthropic/claude-opus-5`) forms. `dari claude --setup`
|
|
25
|
+
provider-prefixed (`anthropic/claude-opus-5`) forms. `dari claude --setup-desktop`
|
|
26
26
|
relies on this: the Claude app lists routing as `claude-dari-routing`. */
|
|
27
27
|
const ANTHROPIC_MODEL_ID_PATTERN = /^(anthropic\/)?claude-[a-z0-9][a-z0-9.-]*$/i;
|
|
28
28
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BedrockOptions } from "@mupt-ai/pi-ai/api/bedrock-converse-stream";
|
|
2
2
|
import { isReasoningEffort, isRecord, type ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
|
|
3
|
+
import { isBackgroundRequest } from "../interaction/types.js";
|
|
3
4
|
import type { InteractionRequest, InteractionResponseFormat, InteractionToolChoice } from "../interaction/types.js";
|
|
4
5
|
import { requiredCapabilitiesFor } from "../interaction/capabilities.js";
|
|
5
6
|
import { toolWireName, toolsByWireName } from "../interaction/tool_identity.js";
|
|
@@ -127,6 +128,9 @@ export function buildOptions(
|
|
|
127
128
|
const webSearch = anthropicWebSearchFor(request, model);
|
|
128
129
|
if (webSearch !== undefined) {
|
|
129
130
|
patches.push((payload) => payloadWithWebSearchTool(payload, webSearch));
|
|
131
|
+
// A background search is one request whose results are read once. Like
|
|
132
|
+
// Claude Code against Anthropic directly, send it without prompt caching.
|
|
133
|
+
if (isBackgroundRequest(request)) options.cacheRetention = "none";
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
// Pi keeps only the content it models, so native compaction output reaches
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type SubscriptionProvider,
|
|
15
15
|
} from "./oauth.js";
|
|
16
16
|
import { canonicalModelName } from "../../models/canonical.js";
|
|
17
|
+
import type { SubscriptionUsageWindow } from "../../providers/subscription_limits.js";
|
|
17
18
|
import {
|
|
18
19
|
activeModelHolds,
|
|
19
20
|
currentUsage,
|
|
@@ -174,13 +175,60 @@ function summary(store: SubscriptionStore, credential: SubscriptionCredential, n
|
|
|
174
175
|
return credentialBody(credential, store.activeCredential(credential.provider, now)?.id === credential.id, now);
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
|
|
178
|
+
const FIVE_HOURS = 5 * 60;
|
|
179
|
+
const ONE_WEEK = 7 * 24 * 60;
|
|
180
|
+
const ONE_MONTH = 30 * 24 * 60;
|
|
181
|
+
|
|
182
|
+
// A model family's own window is named for the family's catalog models.
|
|
183
|
+
const MODEL_FAMILY_NAMES = { fable: "Claude Fable" } as const;
|
|
184
|
+
|
|
185
|
+
/** What to call a window: 5 Hour, Weekly, Monthly, Claude Fable Weekly. */
|
|
186
|
+
function usageWindowLabel(window: SubscriptionUsageWindow): string {
|
|
187
|
+
const minutes = window.minutes;
|
|
188
|
+
const length = minutes === ONE_WEEK ? "Weekly"
|
|
189
|
+
: minutes === ONE_MONTH ? "Monthly"
|
|
190
|
+
: minutes % (24 * 60) === 0 ? `${minutes / (24 * 60)} Day`
|
|
191
|
+
: minutes % 60 === 0 ? `${minutes / 60} Hour`
|
|
192
|
+
: `${minutes} Minute`;
|
|
193
|
+
return window.modelFamily === undefined ? length : `${MODEL_FAMILY_NAMES[window.modelFamily]} ${length}`;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The usage to show, as the hosted API shows it: every running window, a
|
|
198
|
+
* held plan's window full. A hold ends when the window that ran out resets,
|
|
199
|
+
* so the shared window resetting with it shows full. Usage reported without
|
|
200
|
+
* per-window detail, and holds without a matching window, are named by how
|
|
201
|
+
* far off their reset is: only a weekly or monthly window resets more than
|
|
202
|
+
* five hours out, and only OpenCode Go's monthly one more than a week.
|
|
203
|
+
*/
|
|
178
204
|
function usageBody(credential: SubscriptionCredential, now: Date) {
|
|
205
|
+
const inferred = (resetsAt: Date) => {
|
|
206
|
+
const left = resetsAt.getTime() - now.getTime();
|
|
207
|
+
if (left > ONE_WEEK * 60_000) return ONE_MONTH;
|
|
208
|
+
return left > FIVE_HOURS * 60_000 ? ONE_WEEK : FIVE_HOURS;
|
|
209
|
+
};
|
|
179
210
|
const usage = currentUsage(credential, now);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
211
|
+
let windows: SubscriptionUsageWindow[] = usage === null ? []
|
|
212
|
+
: usage.windows.length > 0 ? usage.windows
|
|
213
|
+
: [{ minutes: inferred(usage.resetsAt), utilization: usage.utilization, resetsAt: usage.resetsAt }];
|
|
214
|
+
if (isHeld(credential, now)) {
|
|
215
|
+
const held = credential.unavailableUntil!;
|
|
216
|
+
const gap = (window: SubscriptionUsageWindow) => Math.abs(window.resetsAt.getTime() - held.getTime());
|
|
217
|
+
// The hold is the plan's; it never fills a model family's window.
|
|
218
|
+
const closest = windows.filter((window) => window.modelFamily === undefined)
|
|
219
|
+
.reduce<SubscriptionUsageWindow | null>((best, window) => best === null || gap(window) < gap(best) ? window : best, null);
|
|
220
|
+
const minutes = closest !== null && gap(closest) < 15 * 60_000 ? closest.minutes : inferred(held);
|
|
221
|
+
windows = [
|
|
222
|
+
...windows.filter((window) => window.modelFamily !== undefined || window.minutes !== minutes),
|
|
223
|
+
{ minutes, utilization: 1, resetsAt: held },
|
|
224
|
+
].sort((a, b) => a.minutes - b.minutes || (a.modelFamily ?? "").localeCompare(b.modelFamily ?? ""));
|
|
225
|
+
}
|
|
226
|
+
if (windows.length === 0) return null;
|
|
227
|
+
return {
|
|
228
|
+
utilization: usage?.utilization ?? 1,
|
|
229
|
+
resets_at: (usage?.resetsAt ?? windows[0]!.resetsAt).toISOString(),
|
|
230
|
+
windows: windows.map((window) => ({
|
|
231
|
+
label: usageWindowLabel(window),
|
|
184
232
|
...(window.modelFamily === undefined ? {} : { model_family: window.modelFamily }),
|
|
185
233
|
minutes: window.minutes,
|
|
186
234
|
utilization: window.utilization,
|
|
@@ -212,8 +260,8 @@ function credentialBody(credential: SubscriptionCredential, active: boolean, now
|
|
|
212
260
|
reason: hold.reason,
|
|
213
261
|
})),
|
|
214
262
|
subscription_active: active,
|
|
215
|
-
// The share of its tightest window the plan last reported used,
|
|
216
|
-
//
|
|
263
|
+
// The share of its tightest window the plan last reported used, and
|
|
264
|
+
// every window as shown; null when it reports none and is not held.
|
|
217
265
|
usage: usageBody(credential, now),
|
|
218
266
|
// Spending banked limit resets is hosted-only.
|
|
219
267
|
auto_redeem_resets: false,
|