@openllmsh/sdk 2.10.12-alpha.2 → 2.10.13

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 CHANGED
@@ -67,7 +67,7 @@ The git tags here carry the TypeScript source instead, which Bun runs as is.
67
67
  import { createClient } from "@openllmsh/sdk/client";
68
68
 
69
69
  const ollm = createClient({
70
- origin: "https://openllm.sh",
70
+ origin: "https://www.openllm.sh",
71
71
  apiKey, // sk-llm-…
72
72
  transport: { fetch, websocket: WebSocket },
73
73
  });
@@ -3,6 +3,7 @@
3
3
  * plus an authenticated raw `request` for streaming / non-operation URLs.
4
4
  */
5
5
  import { API_OPERATIONS, callOperation } from "@openllmsh/sdk/openapi";
6
+ import { canonicalApiOrigin } from "@openllmsh/sdk/protocol/canonical-origin";
6
7
  const resolveOp = (op) => {
7
8
  if (typeof op !== "string")
8
9
  return op;
@@ -13,7 +14,7 @@ const resolveOp = (op) => {
13
14
  return found;
14
15
  };
15
16
  export const createClientHttp = (options) => {
16
- const baseUrl = options.origin.replace(/\/+$/, "");
17
+ const baseUrl = canonicalApiOrigin(options.origin);
17
18
  const config = { baseUrl, apiKey: options.apiKey };
18
19
  return {
19
20
  call: async (op, args = {}, callOptions = {}) => callOperation(config, resolveOp(op), args, {
@@ -2,6 +2,7 @@
2
2
  * `@openllmsh/sdk/client` — thin, I/O-injected composition facade over the SDK
3
3
  * layers. Vault session, HTTP, and device tunnel (mux ladder + relay-mux).
4
4
  */
5
+ import { canonicalApiOrigin } from "@openllmsh/sdk/protocol/canonical-origin";
5
6
  import { createClientChat } from "./chat.js";
6
7
  import { createClientDevices, createRelayMux } from "./devices.js";
7
8
  import { createClientHttp } from "./http.js";
@@ -10,7 +11,6 @@ export { createClientChat, DEFAULT_CHAT_TIMEOUT_MS } from "./chat.js";
10
11
  export { createClientDevices, createRelayMux, isTransportFailure, openOverMuxLadder, RTC_SESSION_OPEN_TIMEOUT_MS, SESSION_OPEN_TIMEOUT_MS, } from "./devices.js";
11
12
  export { createClientHttp } from "./http.js";
12
13
  export { createClientVault } from "./vault.js";
13
- const normalizeOrigin = (origin) => origin.replace(/\/+$/, "");
14
14
  /** Shared placeholder for clients that never bind devices (`open` always throws). */
15
15
  const unboundRelayMux = createRelayMux();
16
16
  const unboundDevices = {
@@ -26,7 +26,7 @@ const unboundDevices = {
26
26
  * `WebSocket`, an optional RTC factory, and optional device-tunnel host deps.
27
27
  */
28
28
  export const createClient = (options) => {
29
- const origin = normalizeOrigin(options.origin);
29
+ const origin = canonicalApiOrigin(options.origin);
30
30
  const vault = createClientVault({
31
31
  apiKey: options.apiKey,
32
32
  ...(options.dek !== undefined ? { dek: options.dek } : {}),
@@ -25,7 +25,9 @@ export type TClientTransport = {
25
25
  readonly rtc?: TRtcFactory;
26
26
  };
27
27
  export type TCreateClientOptions = {
28
- /** Cloud origin, e.g. `https://openllm.sh`. Trailing slashes are stripped. */
28
+ /** Cloud origin, e.g. `https://www.openllm.sh`. Trailing slashes are
29
+ * stripped, and the apex `https://openllm.sh` is sent to `www` (the apex
30
+ * redirects, and `fetch` drops the API key on that redirect). */
29
31
  readonly origin: string;
30
32
  /**
31
33
  * `sk-llm-…` API key. May be empty while a CLI-auth claim is still opening
@@ -1,3 +1,4 @@
1
+ import { canonicalApiOrigin } from "@openllmsh/sdk/protocol/canonical-origin";
1
2
  export const DEFAULT_CONNECT_RESOURCE = "https://openllm.sh/v1";
2
3
  const processEnv = () => globalThis.process?.env ?? {};
3
4
  /** Read the config from the `OPENLLM_*` variables in the .env block. */
@@ -14,7 +15,8 @@ export const connectConfigFromEnv = (env = processEnv()) => {
14
15
  privateKey: need("OPENLLM_PRIVATE_KEY"),
15
16
  issuer: need("OPENLLM_ISSUER").replace(/\/+$/, ""),
16
17
  resource: env.OPENLLM_RESOURCE?.trim() || DEFAULT_CONNECT_RESOURCE,
17
- apiOrigin: need("OPENLLM_API_ORIGIN").replace(/\/+$/, ""),
18
+ // The apex redirects to www and fetch drops auth on that hop.
19
+ apiOrigin: canonicalApiOrigin(need("OPENLLM_API_ORIGIN")),
18
20
  redirectUri: need("OPENLLM_REDIRECT_URI"),
19
21
  };
20
22
  };
@@ -22265,6 +22265,136 @@
22265
22265
  "additionalProperties": false
22266
22266
  }
22267
22267
  },
22268
+ "client_popularity": {
22269
+ "anyOf": [
22270
+ {
22271
+ "type": "array",
22272
+ "items": {
22273
+ "type": "object",
22274
+ "properties": {
22275
+ "client": {
22276
+ "type": "string",
22277
+ "enum": [
22278
+ "claude_code",
22279
+ "codex",
22280
+ "opencode",
22281
+ "openllm_cli",
22282
+ "openllm_desktop",
22283
+ "openllm_web",
22284
+ "website",
22285
+ "other"
22286
+ ]
22287
+ },
22288
+ "host": {
22289
+ "anyOf": [
22290
+ {
22291
+ "type": "string"
22292
+ },
22293
+ {
22294
+ "type": "null"
22295
+ }
22296
+ ]
22297
+ },
22298
+ "label": {
22299
+ "type": "string"
22300
+ },
22301
+ "users": {
22302
+ "anyOf": [
22303
+ {
22304
+ "type": "number"
22305
+ },
22306
+ {
22307
+ "type": "string",
22308
+ "enum": [
22309
+ "Infinity",
22310
+ "-Infinity",
22311
+ "NaN"
22312
+ ]
22313
+ }
22314
+ ]
22315
+ },
22316
+ "user_days": {
22317
+ "anyOf": [
22318
+ {
22319
+ "type": "number"
22320
+ },
22321
+ {
22322
+ "type": "string",
22323
+ "enum": [
22324
+ "Infinity",
22325
+ "-Infinity",
22326
+ "NaN"
22327
+ ]
22328
+ }
22329
+ ]
22330
+ },
22331
+ "requests": {
22332
+ "anyOf": [
22333
+ {
22334
+ "type": "number"
22335
+ },
22336
+ {
22337
+ "type": "string",
22338
+ "enum": [
22339
+ "Infinity",
22340
+ "-Infinity",
22341
+ "NaN"
22342
+ ]
22343
+ }
22344
+ ]
22345
+ },
22346
+ "pct_change": {
22347
+ "anyOf": [
22348
+ {
22349
+ "type": "number"
22350
+ },
22351
+ {
22352
+ "type": "string",
22353
+ "enum": [
22354
+ "Infinity",
22355
+ "-Infinity",
22356
+ "NaN"
22357
+ ]
22358
+ },
22359
+ {
22360
+ "type": "null"
22361
+ }
22362
+ ]
22363
+ },
22364
+ "is_new": {
22365
+ "anyOf": [
22366
+ {
22367
+ "type": "boolean"
22368
+ },
22369
+ {
22370
+ "type": "null"
22371
+ },
22372
+ {
22373
+ "type": "null"
22374
+ }
22375
+ ]
22376
+ }
22377
+ },
22378
+ "required": [
22379
+ "client",
22380
+ "host",
22381
+ "label",
22382
+ "users",
22383
+ "user_days",
22384
+ "requests",
22385
+ "pct_change"
22386
+ ],
22387
+ "additionalProperties": false
22388
+ }
22389
+ },
22390
+ {
22391
+ "type": "null"
22392
+ },
22393
+ {
22394
+ "type": "null"
22395
+ }
22396
+ ]
22397
+ },
22268
22398
  "value_by_tier": {
22269
22399
  "type": "array",
22270
22400
  "items": {
@@ -66904,6 +67034,113 @@
66904
67034
  "additionalProperties": false
66905
67035
  }
66906
67036
  },
67037
+ "by_client": {
67038
+ "type": "array",
67039
+ "items": {
67040
+ "type": "object",
67041
+ "properties": {
67042
+ "client": {
67043
+ "anyOf": [
67044
+ {
67045
+ "type": "string",
67046
+ "enum": [
67047
+ "claude_code",
67048
+ "codex",
67049
+ "opencode",
67050
+ "openllm_cli",
67051
+ "openllm_desktop",
67052
+ "openllm_web",
67053
+ "website",
67054
+ "other"
67055
+ ]
67056
+ },
67057
+ {
67058
+ "type": "null"
67059
+ }
67060
+ ]
67061
+ },
67062
+ "host": {
67063
+ "anyOf": [
67064
+ {
67065
+ "type": "string"
67066
+ },
67067
+ {
67068
+ "type": "null"
67069
+ }
67070
+ ]
67071
+ },
67072
+ "requests": {
67073
+ "anyOf": [
67074
+ {
67075
+ "type": "number"
67076
+ },
67077
+ {
67078
+ "type": "string",
67079
+ "enum": [
67080
+ "Infinity",
67081
+ "-Infinity",
67082
+ "NaN"
67083
+ ]
67084
+ }
67085
+ ]
67086
+ },
67087
+ "tokens_in": {
67088
+ "anyOf": [
67089
+ {
67090
+ "type": "number"
67091
+ },
67092
+ {
67093
+ "type": "string",
67094
+ "enum": [
67095
+ "Infinity",
67096
+ "-Infinity",
67097
+ "NaN"
67098
+ ]
67099
+ }
67100
+ ]
67101
+ },
67102
+ "tokens_out": {
67103
+ "anyOf": [
67104
+ {
67105
+ "type": "number"
67106
+ },
67107
+ {
67108
+ "type": "string",
67109
+ "enum": [
67110
+ "Infinity",
67111
+ "-Infinity",
67112
+ "NaN"
67113
+ ]
67114
+ }
67115
+ ]
67116
+ },
67117
+ "cost_usd": {
67118
+ "anyOf": [
67119
+ {
67120
+ "type": "number"
67121
+ },
67122
+ {
67123
+ "type": "string",
67124
+ "enum": [
67125
+ "Infinity",
67126
+ "-Infinity",
67127
+ "NaN"
67128
+ ]
67129
+ }
67130
+ ]
67131
+ }
67132
+ },
67133
+ "required": [
67134
+ "client",
67135
+ "host",
67136
+ "requests",
67137
+ "tokens_in",
67138
+ "tokens_out",
67139
+ "cost_usd"
67140
+ ],
67141
+ "additionalProperties": false
67142
+ }
67143
+ },
66907
67144
  "daily": {
66908
67145
  "type": "array",
66909
67146
  "items": {
@@ -66993,6 +67230,7 @@
66993
67230
  "total_cost_usd",
66994
67231
  "total_api_equivalent_cost_usd",
66995
67232
  "by_model",
67233
+ "by_client",
66996
67234
  "daily"
66997
67235
  ],
66998
67236
  "additionalProperties": false
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The origin the SDK actually sends requests to.
3
+ *
4
+ * The production apex `https://openllm.sh` answers every request with a
5
+ * redirect to `https://www.openllm.sh`. `fetch` follows it but, per the Fetch
6
+ * spec, drops the `Authorization` header on a cross-origin redirect — so a
7
+ * call made against the apex reaches `www` with no credentials and fails as
8
+ * `401 Not authenticated`, indistinguishable from a bad key. Every origin the
9
+ * SDK fetches from goes through here.
10
+ *
11
+ * Only the exact production apex host is rewritten; localhost, preview
12
+ * deployments and self-hosted origins pass through unchanged. Identifiers that
13
+ * are compared exactly rather than fetched (the OAuth `resource` audience, the
14
+ * issuer) must NOT go through here.
15
+ *
16
+ * Dependency-free on purpose: `connect` imports this file alone, never the
17
+ * protocol barrel.
18
+ */
19
+ /** The apex host that redirects, and the host it redirects to. */
20
+ export declare const OPENLLM_APEX_HOST = "openllm.sh";
21
+ export declare const OPENLLM_WWW_HOST = "www.openllm.sh";
22
+ /** Strip trailing slashes and rewrite the production apex host to `www`. */
23
+ export declare const canonicalApiOrigin: (origin: string) => string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The origin the SDK actually sends requests to.
3
+ *
4
+ * The production apex `https://openllm.sh` answers every request with a
5
+ * redirect to `https://www.openllm.sh`. `fetch` follows it but, per the Fetch
6
+ * spec, drops the `Authorization` header on a cross-origin redirect — so a
7
+ * call made against the apex reaches `www` with no credentials and fails as
8
+ * `401 Not authenticated`, indistinguishable from a bad key. Every origin the
9
+ * SDK fetches from goes through here.
10
+ *
11
+ * Only the exact production apex host is rewritten; localhost, preview
12
+ * deployments and self-hosted origins pass through unchanged. Identifiers that
13
+ * are compared exactly rather than fetched (the OAuth `resource` audience, the
14
+ * issuer) must NOT go through here.
15
+ *
16
+ * Dependency-free on purpose: `connect` imports this file alone, never the
17
+ * protocol barrel.
18
+ */
19
+ /** The apex host that redirects, and the host it redirects to. */
20
+ export const OPENLLM_APEX_HOST = "openllm.sh";
21
+ export const OPENLLM_WWW_HOST = "www.openllm.sh";
22
+ /** Strip trailing slashes and rewrite the production apex host to `www`. */
23
+ export const canonicalApiOrigin = (origin) => {
24
+ const trimmed = origin.trim().replace(/\/+$/, "");
25
+ let url;
26
+ try {
27
+ url = new URL(trimmed);
28
+ }
29
+ catch {
30
+ return trimmed;
31
+ }
32
+ if (url.hostname !== OPENLLM_APEX_HOST)
33
+ return trimmed;
34
+ url.hostname = OPENLLM_WWW_HOST;
35
+ return url.toString().replace(/\/+$/, "");
36
+ };
@@ -0,0 +1,60 @@
1
+ import { Schema as S } from "effect";
2
+ /**
3
+ * Which client a gateway request came from — recorded on every
4
+ * `public.requests` row (`client_kind` + `client_host`) so usage can be split
5
+ * by Claude Code vs Codex vs the desktop app vs a website, and which site.
6
+ *
7
+ * Derived from headers the caller already sends, in this order:
8
+ *
9
+ * 1. a browser `Origin` (or `Referer`) of ANOTHER website → that website and
10
+ * its host. First, because a page cannot forge its `Origin` but can set
11
+ * any header CORS lets through — so a site can't count itself as Claude
12
+ * Code by sending the header below;
13
+ * 2. an explicit `x-openllm-client` header naming one of these kinds (clients
14
+ * we control can say who they are instead of being guessed from a UA);
15
+ * 3. a user agent we recognise (`claude-cli/…`, `codex_cli_rs/…`, the desktop
16
+ * shell's `OpenLLMNative/…` suffix, our own CLI's `OpenLLM/…`);
17
+ * 4. a browser `Origin` / `Referer` of our own site → our website;
18
+ * 5. otherwise `other`.
19
+ *
20
+ * Pure and dependency-light: the cloud derives it for requests it serves, and
21
+ * the daemon derives it for hops it walks locally and reports it on the usage
22
+ * record (`DaemonRecordRequest.client_kind` / `client_host`), where the cloud
23
+ * re-checks it with {@link normalizeClientOrigin}.
24
+ */
25
+ export declare const CLIENT_KINDS: readonly ["claude_code", "codex", "opencode", "openllm_cli", "openllm_desktop", "openllm_web", "website", "other"];
26
+ export type TClientKind = (typeof CLIENT_KINDS)[number];
27
+ export declare const ClientKind: S.Literals<readonly ["claude_code", "codex", "opencode", "openllm_cli", "openllm_desktop", "openllm_web", "website", "other"]>;
28
+ /** The header a client we control sets to name itself. */
29
+ export declare const CLIENT_KIND_HEADER = "x-openllm-client";
30
+ /** Longest DNS name; a reported host above it is not a host. */
31
+ export declare const CLIENT_HOST_MAX_LENGTH = 253;
32
+ export type TClientOrigin = {
33
+ readonly kind: TClientKind;
34
+ /** The website's hostname — set only when `kind` is `website`. */
35
+ readonly host: string | null;
36
+ };
37
+ /** Human labels, shared by the overview and the public usage index. */
38
+ export declare const CLIENT_KIND_LABELS: Readonly<Record<TClientKind, string>>;
39
+ /** A bare, lower-case hostname, or null when the value is not one. */
40
+ export declare const normalizeClientHost: (value: string) => string | null;
41
+ export type TClientOriginHints = {
42
+ readonly userAgent: string | null;
43
+ readonly origin: string | null;
44
+ readonly referer: string | null;
45
+ /** The value of {@link CLIENT_KIND_HEADER}, when sent. */
46
+ readonly clientKind: string | null;
47
+ /** The host the request was addressed to: a same-origin page is our site. */
48
+ readonly selfHost: string | null;
49
+ };
50
+ /** Classify one request from its client-identifying headers. */
51
+ export declare const deriveClientOrigin: (hints: TClientOriginHints) => TClientOrigin;
52
+ /** {@link deriveClientOrigin} over a request's headers and URL. */
53
+ export declare const clientOriginOfRequest: (request: Request) => TClientOrigin;
54
+ /**
55
+ * Re-check a client origin someone else reported (a daemon's usage record).
56
+ * An unknown kind is dropped (null), and a host survives only on a `website`
57
+ * row and only as a valid hostname — a website with no usable host stays a
58
+ * website, just unnamed, and one of our own hosts is our website.
59
+ */
60
+ export declare const normalizeClientOrigin: (kind: string | null | undefined, host: string | null | undefined) => TClientOrigin | null;
@@ -0,0 +1,163 @@
1
+ import { Schema as S } from "effect";
2
+ /**
3
+ * Which client a gateway request came from — recorded on every
4
+ * `public.requests` row (`client_kind` + `client_host`) so usage can be split
5
+ * by Claude Code vs Codex vs the desktop app vs a website, and which site.
6
+ *
7
+ * Derived from headers the caller already sends, in this order:
8
+ *
9
+ * 1. a browser `Origin` (or `Referer`) of ANOTHER website → that website and
10
+ * its host. First, because a page cannot forge its `Origin` but can set
11
+ * any header CORS lets through — so a site can't count itself as Claude
12
+ * Code by sending the header below;
13
+ * 2. an explicit `x-openllm-client` header naming one of these kinds (clients
14
+ * we control can say who they are instead of being guessed from a UA);
15
+ * 3. a user agent we recognise (`claude-cli/…`, `codex_cli_rs/…`, the desktop
16
+ * shell's `OpenLLMNative/…` suffix, our own CLI's `OpenLLM/…`);
17
+ * 4. a browser `Origin` / `Referer` of our own site → our website;
18
+ * 5. otherwise `other`.
19
+ *
20
+ * Pure and dependency-light: the cloud derives it for requests it serves, and
21
+ * the daemon derives it for hops it walks locally and reports it on the usage
22
+ * record (`DaemonRecordRequest.client_kind` / `client_host`), where the cloud
23
+ * re-checks it with {@link normalizeClientOrigin}.
24
+ */
25
+ export const CLIENT_KINDS = [
26
+ "claude_code",
27
+ "codex",
28
+ "opencode",
29
+ "openllm_cli",
30
+ "openllm_desktop",
31
+ "openllm_web",
32
+ "website",
33
+ "other",
34
+ ];
35
+ export const ClientKind = S.Literals(CLIENT_KINDS);
36
+ /** The header a client we control sets to name itself. */
37
+ export const CLIENT_KIND_HEADER = "x-openllm-client";
38
+ /** Longest DNS name; a reported host above it is not a host. */
39
+ export const CLIENT_HOST_MAX_LENGTH = 253;
40
+ /** Human labels, shared by the overview and the public usage index. */
41
+ export const CLIENT_KIND_LABELS = {
42
+ claude_code: "Claude Code",
43
+ codex: "Codex",
44
+ opencode: "OpenCode",
45
+ openllm_cli: "OpenLLM CLI",
46
+ openllm_desktop: "OpenLLM desktop app",
47
+ openllm_web: "OpenLLM website",
48
+ website: "Other websites",
49
+ other: "Other clients",
50
+ };
51
+ const isClientKind = (value) => CLIENT_KINDS.includes(value);
52
+ /**
53
+ * Kinds a caller may claim through {@link CLIENT_KIND_HEADER}. `website` is
54
+ * not one of them: a website is identified by its browser-set `Origin`, which
55
+ * a page cannot forge, never by a header it chooses.
56
+ */
57
+ const isClaimableKind = (value) => isClientKind(value) && value !== "website";
58
+ /** Our own site: `openllm.sh` and every subdomain of it. */
59
+ const OWN_ROOT_DOMAIN = "openllm.sh";
60
+ const HOSTNAME_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/;
61
+ /** A bare, lower-case hostname, or null when the value is not one. */
62
+ export const normalizeClientHost = (value) => {
63
+ const host = value.trim().toLowerCase().replace(/\.$/, "");
64
+ return HOSTNAME_PATTERN.test(host) ? host : null;
65
+ };
66
+ /** Hostname of an http(s) URL; null for any other scheme or a bad value. */
67
+ const webHostOf = (value) => {
68
+ if (value === null || value.length === 0 || value === "null")
69
+ return null;
70
+ try {
71
+ const url = new URL(value);
72
+ if (url.protocol !== "http:" && url.protocol !== "https:")
73
+ return null;
74
+ return normalizeClientHost(url.hostname);
75
+ }
76
+ catch {
77
+ return null;
78
+ }
79
+ };
80
+ /**
81
+ * A loopback name is never evidence of being our site: on the daemon (and on a
82
+ * local dev cloud) the request's own host is `127.0.0.1` / `localhost`, and a
83
+ * developer's page on `localhost:5173` would otherwise match it.
84
+ */
85
+ const isLoopbackHost = (host) => host === "localhost" ||
86
+ host.endsWith(".localhost") ||
87
+ /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(host) ||
88
+ host === "0.0.0.0";
89
+ const isOwnHost = (host, selfHost) => (selfHost !== null && host === selfHost && !isLoopbackHost(selfHost)) ||
90
+ host === OWN_ROOT_DOMAIN ||
91
+ host.endsWith(`.${OWN_ROOT_DOMAIN}`);
92
+ const kindFromUserAgent = (userAgent) => {
93
+ const ua = userAgent.trim().toLowerCase();
94
+ if (ua.length === 0)
95
+ return null;
96
+ // The desktop shell appends `OpenLLMNative/<version>` to WKWebView's UA
97
+ // (`packages/native/src-tauri/src/lib.rs`), so this test comes before the
98
+ // browser Origin check: the app loads our own site.
99
+ if (ua.includes("openllmnative/"))
100
+ return "openllm_desktop";
101
+ if (ua.startsWith("claude-cli/") || ua.startsWith("claude-code/"))
102
+ return "claude_code";
103
+ if (ua.startsWith("codex_") ||
104
+ ua.startsWith("codex-") ||
105
+ ua.startsWith("codex/"))
106
+ return "codex";
107
+ if (ua.startsWith("opencode/") || ua.startsWith("opencode "))
108
+ return "opencode";
109
+ if (ua.startsWith("openllm/"))
110
+ return "openllm_cli";
111
+ return null;
112
+ };
113
+ /** Classify one request from its client-identifying headers. */
114
+ export const deriveClientOrigin = (hints) => {
115
+ const host = webHostOf(hints.origin) ?? webHostOf(hints.referer);
116
+ const selfHost = hints.selfHost === null ? null : normalizeClientHost(hints.selfHost);
117
+ const ownSite = host !== null && isOwnHost(host, selfHost);
118
+ if (host !== null && !ownSite)
119
+ return { kind: "website", host };
120
+ const claimed = hints.clientKind?.trim().toLowerCase() ?? "";
121
+ if (isClaimableKind(claimed))
122
+ return { kind: claimed, host: null };
123
+ const fromAgent = hints.userAgent === null ? null : kindFromUserAgent(hints.userAgent);
124
+ if (fromAgent !== null)
125
+ return { kind: fromAgent, host: null };
126
+ if (ownSite)
127
+ return { kind: "openllm_web", host: null };
128
+ return { kind: "other", host: null };
129
+ };
130
+ /** {@link deriveClientOrigin} over a request's headers and URL. */
131
+ export const clientOriginOfRequest = (request) => {
132
+ let selfHost = null;
133
+ try {
134
+ selfHost = new URL(request.url).hostname;
135
+ }
136
+ catch {
137
+ selfHost = null;
138
+ }
139
+ const headers = request.headers;
140
+ return deriveClientOrigin({
141
+ userAgent: headers.get("user-agent"),
142
+ origin: headers.get("origin"),
143
+ referer: headers.get("referer"),
144
+ clientKind: headers.get(CLIENT_KIND_HEADER),
145
+ selfHost,
146
+ });
147
+ };
148
+ /**
149
+ * Re-check a client origin someone else reported (a daemon's usage record).
150
+ * An unknown kind is dropped (null), and a host survives only on a `website`
151
+ * row and only as a valid hostname — a website with no usable host stays a
152
+ * website, just unnamed, and one of our own hosts is our website.
153
+ */
154
+ export const normalizeClientOrigin = (kind, host) => {
155
+ if (kind === null || kind === undefined || !isClientKind(kind))
156
+ return null;
157
+ if (kind !== "website")
158
+ return { kind, host: null };
159
+ const normalized = host === null || host === undefined ? null : normalizeClientHost(host);
160
+ if (normalized !== null && isOwnHost(normalized, null))
161
+ return { kind: "openllm_web", host: null };
162
+ return { kind, host: normalized };
163
+ };
@@ -479,6 +479,14 @@ export declare const DaemonRecordRequest: S.Struct<{
479
479
  * Optional so daemons predating the field still record (the cloud
480
480
  * stores null → the estimator's conservative null pool). */
481
481
  readonly account_hash: S.optional<S.String>;
482
+ /**
483
+ * Which client sent the request the daemon walked (`deriveClientOrigin`
484
+ * over the inbound headers), and a website's hostname. The cloud re-checks
485
+ * both (`normalizeClientOrigin`) before storing them on the row. Optional:
486
+ * daemons predating the fields record a NULL client.
487
+ */
488
+ readonly client_kind: S.optional<S.String>;
489
+ readonly client_host: S.optional<S.String>;
482
490
  /**
483
491
  * Origin-signed team grant echoed on team hops so the cloud attributes
484
492
  * the row to the consumer and settles `team_usage_counters`. Same-user
@@ -1,5 +1,6 @@
1
1
  import { Schema as S } from "effect";
2
2
  import { AuthSessionLostDiagnosticCode } from "./auth.js";
3
+ import { CLIENT_HOST_MAX_LENGTH } from "./client-origin.js";
3
4
  import { ContextOverflowStrategy, FallbackGroup, ModelFallbackBinding, } from "./config.js";
4
5
  import { CooldownReason } from "./cooldown-reason.js";
5
6
  import { DaemonReportingPolicy } from "./doctor-report-policy.js";
@@ -264,6 +265,14 @@ export const DaemonRecordRequest = S.Struct({
264
265
  * Optional so daemons predating the field still record (the cloud
265
266
  * stores null → the estimator's conservative null pool). */
266
267
  account_hash: S.optional(S.String),
268
+ /**
269
+ * Which client sent the request the daemon walked (`deriveClientOrigin`
270
+ * over the inbound headers), and a website's hostname. The cloud re-checks
271
+ * both (`normalizeClientOrigin`) before storing them on the row. Optional:
272
+ * daemons predating the fields record a NULL client.
273
+ */
274
+ client_kind: S.optional(S.String.check(S.isMaxLength(64))),
275
+ client_host: S.optional(S.String.check(S.isMaxLength(CLIENT_HOST_MAX_LENGTH))),
267
276
  /**
268
277
  * Origin-signed team grant echoed on team hops so the cloud attributes
269
278
  * the row to the consumer and settles `team_usage_counters`. Same-user
@@ -4,8 +4,10 @@ export * from "./agent-prompt-text.js";
4
4
  export * from "./api-key-syntax.js";
5
5
  export * from "./audio.js";
6
6
  export * from "./auth.js";
7
+ export * from "./canonical-origin.js";
7
8
  export * from "./changelog.js";
8
9
  export * from "./chat.js";
10
+ export * from "./client-origin.js";
9
11
  export * from "./client-registry.js";
10
12
  export * from "./config.js";
11
13
  export * from "./control-channel.js";
@@ -4,8 +4,10 @@ export * from "./agent-prompt-text.js";
4
4
  export * from "./api-key-syntax.js";
5
5
  export * from "./audio.js";
6
6
  export * from "./auth.js";
7
+ export * from "./canonical-origin.js";
7
8
  export * from "./changelog.js";
8
9
  export * from "./chat.js";
10
+ export * from "./client-origin.js";
9
11
  export * from "./client-registry.js";
10
12
  export * from "./config.js";
11
13
  export * from "./control-channel.js";
@@ -41,6 +41,17 @@ export declare const SEEDGATE_CAP = "seedgate1";
41
41
  export declare const TEAM_SERVE_CAP = "team_serve";
42
42
  /** Returns whether an open-vocabulary capability list advertises seedgate. */
43
43
  export declare const hasSeedgateCap: (caps: readonly string[] | undefined) => boolean;
44
+ /**
45
+ * The serving daemon accepts `client_kind` / `client_host` on a tunnel OPEN's
46
+ * forward headers: the client origin already derived the request came from
47
+ * (a browser on our site or another website loses its `Origin` in the
48
+ * tunnel, so the daemon could not tell on its own). Daemons predating it
49
+ * refuse unknown header keys, so a consumer MUST check this before sending
50
+ * them and otherwise leave them off — the daemon then records what it can
51
+ * see (the forwarded user agent).
52
+ */
53
+ export declare const CLIENT_ORIGIN_CAP = "client1";
54
+ export declare const hasClientOriginCap: (caps: Iterable<string> | undefined | null) => boolean;
44
55
  /**
45
56
  * HTTP media over the existing mux `kind:"tunnel"` stream (STT / TTS / image
46
57
  * generations / image edits). Old peers omit this; consumers MUST fail closed
@@ -163,6 +174,14 @@ export declare const TunnelForwardHeaders: S.Struct<{
163
174
  readonly anthropic_version: S.optional<S.String>;
164
175
  readonly anthropic_beta: S.optional<S.String>;
165
176
  readonly user_agent: S.optional<S.String>;
177
+ /**
178
+ * The client the consumer derived for this request (`TClientKind`) and a
179
+ * website's host. Sent only to a daemon advertising
180
+ * {@link CLIENT_ORIGIN_CAP}; a plain bounded string so a kind this daemon
181
+ * doesn't know yet never fails the OPEN — it is normalized at use.
182
+ */
183
+ readonly client_kind: S.optional<S.String>;
184
+ readonly client_host: S.optional<S.String>;
166
185
  /** Opaque video job id for GET retrieve/content mux follow-up. */
167
186
  readonly video_id: S.optional<S.String>;
168
187
  /**
@@ -222,6 +241,14 @@ export declare const TunnelStreamOpenPayload: S.Struct<{
222
241
  readonly anthropic_version: S.optional<S.String>;
223
242
  readonly anthropic_beta: S.optional<S.String>;
224
243
  readonly user_agent: S.optional<S.String>;
244
+ /**
245
+ * The client the consumer derived for this request (`TClientKind`) and a
246
+ * website's host. Sent only to a daemon advertising
247
+ * {@link CLIENT_ORIGIN_CAP}; a plain bounded string so a kind this daemon
248
+ * doesn't know yet never fails the OPEN — it is normalized at use.
249
+ */
250
+ readonly client_kind: S.optional<S.String>;
251
+ readonly client_host: S.optional<S.String>;
225
252
  /** Opaque video job id for GET retrieve/content mux follow-up. */
226
253
  readonly video_id: S.optional<S.String>;
227
254
  /**
@@ -253,6 +280,14 @@ export declare const StreamOpenPayload: S.Union<readonly [S.Struct<{
253
280
  readonly anthropic_version: S.optional<S.String>;
254
281
  readonly anthropic_beta: S.optional<S.String>;
255
282
  readonly user_agent: S.optional<S.String>;
283
+ /**
284
+ * The client the consumer derived for this request (`TClientKind`) and a
285
+ * website's host. Sent only to a daemon advertising
286
+ * {@link CLIENT_ORIGIN_CAP}; a plain bounded string so a kind this daemon
287
+ * doesn't know yet never fails the OPEN — it is normalized at use.
288
+ */
289
+ readonly client_kind: S.optional<S.String>;
290
+ readonly client_host: S.optional<S.String>;
256
291
  /** Opaque video job id for GET retrieve/content mux follow-up. */
257
292
  readonly video_id: S.optional<S.String>;
258
293
  /**
@@ -9,6 +9,7 @@
9
9
  import { Schema as S } from "effect";
10
10
  import * as Result from "effect/Result";
11
11
  import { AgentStreamOpenPayload } from "./agent.js";
12
+ import { CLIENT_HOST_MAX_LENGTH } from "./client-origin.js";
12
13
  import { HOP_GRANT_B64_MAX } from "./hop-grant.js";
13
14
  import { OPENLLM_CHAIN_HEADER, OPENLLM_RESOLVED_MODEL_HEADER, } from "./inference-headers.js";
14
15
  import { RealtimeStreamOpenPayload } from "./realtime.js";
@@ -47,6 +48,24 @@ export const SEEDGATE_CAP = "seedgate1";
47
48
  export const TEAM_SERVE_CAP = "team_serve";
48
49
  /** Returns whether an open-vocabulary capability list advertises seedgate. */
49
50
  export const hasSeedgateCap = (caps) => caps?.includes(SEEDGATE_CAP) ?? false;
51
+ /**
52
+ * The serving daemon accepts `client_kind` / `client_host` on a tunnel OPEN's
53
+ * forward headers: the client origin already derived the request came from
54
+ * (a browser on our site or another website loses its `Origin` in the
55
+ * tunnel, so the daemon could not tell on its own). Daemons predating it
56
+ * refuse unknown header keys, so a consumer MUST check this before sending
57
+ * them and otherwise leave them off — the daemon then records what it can
58
+ * see (the forwarded user agent).
59
+ */
60
+ export const CLIENT_ORIGIN_CAP = "client1";
61
+ export const hasClientOriginCap = (caps) => {
62
+ if (caps === undefined || caps === null)
63
+ return false;
64
+ for (const cap of caps)
65
+ if (cap === CLIENT_ORIGIN_CAP)
66
+ return true;
67
+ return false;
68
+ };
50
69
  /**
51
70
  * HTTP media over the existing mux `kind:"tunnel"` stream (STT / TTS / image
52
71
  * generations / image edits). Old peers omit this; consumers MUST fail closed
@@ -319,6 +338,14 @@ export const TunnelForwardHeaders = S.Struct({
319
338
  // Preserve whole flags; the mux codec bounds the complete OPEN payload.
320
339
  anthropic_beta: S.optional(S.String),
321
340
  user_agent: S.optional(S.String.check(S.isMaxLength(512))),
341
+ /**
342
+ * The client the consumer derived for this request (`TClientKind`) and a
343
+ * website's host. Sent only to a daemon advertising
344
+ * {@link CLIENT_ORIGIN_CAP}; a plain bounded string so a kind this daemon
345
+ * doesn't know yet never fails the OPEN — it is normalized at use.
346
+ */
347
+ client_kind: S.optional(S.String.check(S.isMaxLength(64))),
348
+ client_host: S.optional(S.String.check(S.isMaxLength(CLIENT_HOST_MAX_LENGTH))),
322
349
  /** Opaque video job id for GET retrieve/content mux follow-up. */
323
350
  video_id: S.optional(S.String.check(S.isMaxLength(256), S.isPattern(/^[A-Za-z0-9._-]+$/))),
324
351
  /**
@@ -580,6 +607,8 @@ export const parseStreamOpenPayload = (value) => {
580
607
  "anthropic_version",
581
608
  "anthropic_beta",
582
609
  "user_agent",
610
+ "client_kind",
611
+ "client_host",
583
612
  "media_persistence",
584
613
  "video_id",
585
614
  "team_grant",
@@ -13,7 +13,7 @@ import { Schema as S } from "effect";
13
13
  * that omits it to the local current version.
14
14
  */
15
15
  export declare const PUBLIC_USAGE_VALUE_METHODOLOGY_VERSION = "account-owned-v2";
16
- export declare const PublicUsageMetric: S.Literals<readonly ["model_popularity", "provider_popularity", "value"]>;
16
+ export declare const PublicUsageMetric: S.Literals<readonly ["model_popularity", "provider_popularity", "client_popularity", "value"]>;
17
17
  export type TPublicUsageMetric = S.Schema.Type<typeof PublicUsageMetric>;
18
18
  export declare const PublicUsagePopularityMetrics: S.Struct<{
19
19
  readonly users: S.Number;
@@ -84,6 +84,15 @@ export declare const PublicUsageIndexStoredMetric: S.Union<readonly [S.Struct<{
84
84
  readonly requests: S.Number;
85
85
  readonly prev_users: S.NullOr<S.Number>;
86
86
  }>;
87
+ }>, S.Struct<{
88
+ readonly metric: S.Literals<readonly ["client_popularity"]>;
89
+ readonly subject: S.String;
90
+ readonly metrics: S.Struct<{
91
+ readonly users: S.Number;
92
+ readonly user_days: S.Number;
93
+ readonly requests: S.Number;
94
+ readonly prev_users: S.NullOr<S.Number>;
95
+ }>;
87
96
  }>, S.Struct<{
88
97
  readonly metric: S.Literals<readonly ["value"]>;
89
98
  readonly subject: S.String;
@@ -97,7 +106,7 @@ export declare const PublicUsageIndexStoredMetric: S.Union<readonly [S.Struct<{
97
106
  readonly prev_value_usd_30d: S.NullOr<S.Number>;
98
107
  }>;
99
108
  }>, S.Struct<{
100
- readonly metric: S.Literals<readonly ["model_popularity", "provider_popularity", "value"]>;
109
+ readonly metric: S.Literals<readonly ["model_popularity", "provider_popularity", "client_popularity", "value"]>;
101
110
  readonly subject: S.Literals<readonly ["__bucket__"]>;
102
111
  readonly metrics: S.Struct<{
103
112
  readonly tier_set_fingerprint: S.optional<S.String>;
@@ -136,6 +145,21 @@ export declare const PublicUsageIndexRow: S.Union<readonly [S.Struct<{
136
145
  readonly requests: S.Number;
137
146
  readonly prev_users: S.NullOr<S.Number>;
138
147
  }>;
148
+ }>, S.Struct<{
149
+ readonly metric_version: S.String;
150
+ readonly provider: S.String;
151
+ readonly label: S.String;
152
+ readonly period_start: S.String;
153
+ readonly period_end: S.String;
154
+ readonly updated_at: S.String;
155
+ readonly metric: S.Literals<readonly ["client_popularity"]>;
156
+ readonly subject: S.String;
157
+ readonly metrics: S.Struct<{
158
+ readonly users: S.Number;
159
+ readonly user_days: S.Number;
160
+ readonly requests: S.Number;
161
+ readonly prev_users: S.NullOr<S.Number>;
162
+ }>;
139
163
  }>, S.Struct<{
140
164
  readonly metric_version: S.String;
141
165
  readonly provider: S.String;
@@ -161,7 +185,7 @@ export declare const PublicUsageIndexRow: S.Union<readonly [S.Struct<{
161
185
  readonly period_start: S.String;
162
186
  readonly period_end: S.String;
163
187
  readonly updated_at: S.String;
164
- readonly metric: S.Literals<readonly ["model_popularity", "provider_popularity", "value"]>;
188
+ readonly metric: S.Literals<readonly ["model_popularity", "provider_popularity", "client_popularity", "value"]>;
165
189
  readonly subject: S.Literals<readonly ["__bucket__"]>;
166
190
  readonly metrics: S.Struct<{
167
191
  readonly tier_set_fingerprint: S.optional<S.String>;
@@ -225,6 +249,34 @@ export declare const PublicProviderPopularity: S.Struct<{
225
249
  readonly is_new: S.withDecodingDefault<S.optional<S.Boolean>, never>;
226
250
  }>;
227
251
  export type TPublicProviderPopularity = S.Schema.Type<typeof PublicProviderPopularity>;
252
+ /**
253
+ * Fewest distinct users a website needs before its hostname is published on
254
+ * the index. Below it the site's traffic still counts, folded into the
255
+ * unnamed "Other websites" row, so a single developer's own site is never
256
+ * named next to their usage.
257
+ */
258
+ export declare const PUBLIC_CLIENT_HOST_MIN_USERS = 3;
259
+ /**
260
+ * Where requests come from: one row per client kind (Claude Code, Codex, the
261
+ * desktop app, our website, …), plus one row per website host that clears
262
+ * {@link PUBLIC_CLIENT_HOST_MIN_USERS}. Measured over the model-popularity
263
+ * window (`windows.model`), the same successful-request ledger.
264
+ */
265
+ export declare const PublicClientPopularity: S.Struct<{
266
+ readonly client: S.Literals<readonly ["claude_code", "codex", "opencode", "openllm_cli", "openllm_desktop", "openllm_web", "website", "other"]>;
267
+ /** A website's hostname; null on every non-website row and on the folded
268
+ * "Other websites" row. */
269
+ readonly host: S.NullOr<S.String>;
270
+ /** Display name: the client's label, or the host. */
271
+ readonly label: S.String;
272
+ readonly users: S.Number;
273
+ readonly user_days: S.Number;
274
+ readonly requests: S.Number;
275
+ readonly pct_change: S.NullOr<S.Number>;
276
+ /** See `PublicModelPopularity.is_new`. */
277
+ readonly is_new: S.withDecodingDefault<S.optional<S.Boolean>, never>;
278
+ }>;
279
+ export type TPublicClientPopularity = S.Schema.Type<typeof PublicClientPopularity>;
228
280
  /**
229
281
  * One period's reading for a tier, for the value trend series.
230
282
  *
@@ -394,6 +446,24 @@ export declare const PublicUsageIndexResponse: S.Struct<{
394
446
  /** See `PublicModelPopularity.is_new`. */
395
447
  readonly is_new: S.withDecodingDefault<S.optional<S.Boolean>, never>;
396
448
  }>>;
449
+ /**
450
+ * Decoded with a default so a peer deployment that predates the field
451
+ * still merges — see the note on `PublicValueByTier`.
452
+ */
453
+ readonly client_popularity: S.withDecodingDefault<S.optional<S.$Array<S.Struct<{
454
+ readonly client: S.Literals<readonly ["claude_code", "codex", "opencode", "openllm_cli", "openllm_desktop", "openllm_web", "website", "other"]>;
455
+ /** A website's hostname; null on every non-website row and on the folded
456
+ * "Other websites" row. */
457
+ readonly host: S.NullOr<S.String>;
458
+ /** Display name: the client's label, or the host. */
459
+ readonly label: S.String;
460
+ readonly users: S.Number;
461
+ readonly user_days: S.Number;
462
+ readonly requests: S.Number;
463
+ readonly pct_change: S.NullOr<S.Number>;
464
+ /** See `PublicModelPopularity.is_new`. */
465
+ readonly is_new: S.withDecodingDefault<S.optional<S.Boolean>, never>;
466
+ }>>>, never>;
397
467
  readonly value_by_tier: S.$Array<S.Struct<{
398
468
  /**
399
469
  * The provider's registry `displayName` — a sign-in-flow label ("Claude
@@ -1,4 +1,5 @@
1
1
  import { Effect, Schema as S } from "effect";
2
+ import { ClientKind } from "./client-origin.js";
2
3
  import { PROVIDER_TIER_METHODOLOGY_VERSION } from "./provider-tier.js";
3
4
  /**
4
5
  * Public usage index — OpenLLM's own aggregate projection of gateway activity,
@@ -17,6 +18,7 @@ export const PUBLIC_USAGE_VALUE_METHODOLOGY_VERSION = PROVIDER_TIER_METHODOLOGY_
17
18
  export const PublicUsageMetric = S.Literals([
18
19
  "model_popularity",
19
20
  "provider_popularity",
21
+ "client_popularity",
20
22
  "value",
21
23
  ]);
22
24
  export const PublicUsagePopularityMetrics = S.Struct({
@@ -67,6 +69,11 @@ export const PublicUsageIndexStoredMetric = S.Union([
67
69
  subject: S.String,
68
70
  metrics: PublicUsagePopularityMetrics,
69
71
  }),
72
+ S.Struct({
73
+ metric: S.Literals(["client_popularity"]),
74
+ subject: S.String,
75
+ metrics: PublicUsagePopularityMetrics,
76
+ }),
70
77
  S.Struct({
71
78
  metric: S.Literals(["value"]),
72
79
  subject: S.String,
@@ -100,6 +107,12 @@ export const PublicUsageIndexRow = S.Union([
100
107
  subject: S.String,
101
108
  metrics: PublicUsagePopularityMetrics,
102
109
  }),
110
+ S.Struct({
111
+ ...PublicUsageIndexRowBase.fields,
112
+ metric: S.Literals(["client_popularity"]),
113
+ subject: S.String,
114
+ metrics: PublicUsagePopularityMetrics,
115
+ }),
103
116
  S.Struct({
104
117
  ...PublicUsageIndexRowBase.fields,
105
118
  metric: S.Literals(["value"]),
@@ -167,6 +180,33 @@ export const PublicProviderPopularity = S.Struct({
167
180
  /** See `PublicModelPopularity.is_new`. */
168
181
  is_new: S.Boolean.pipe(S.optional, S.withDecodingDefault(Effect.succeed(false))),
169
182
  });
183
+ /**
184
+ * Fewest distinct users a website needs before its hostname is published on
185
+ * the index. Below it the site's traffic still counts, folded into the
186
+ * unnamed "Other websites" row, so a single developer's own site is never
187
+ * named next to their usage.
188
+ */
189
+ export const PUBLIC_CLIENT_HOST_MIN_USERS = 3;
190
+ /**
191
+ * Where requests come from: one row per client kind (Claude Code, Codex, the
192
+ * desktop app, our website, …), plus one row per website host that clears
193
+ * {@link PUBLIC_CLIENT_HOST_MIN_USERS}. Measured over the model-popularity
194
+ * window (`windows.model`), the same successful-request ledger.
195
+ */
196
+ export const PublicClientPopularity = S.Struct({
197
+ client: ClientKind,
198
+ /** A website's hostname; null on every non-website row and on the folded
199
+ * "Other websites" row. */
200
+ host: S.NullOr(S.String),
201
+ /** Display name: the client's label, or the host. */
202
+ label: S.String,
203
+ users: S.Number,
204
+ user_days: S.Number,
205
+ requests: S.Number,
206
+ pct_change: S.NullOr(S.Number),
207
+ /** See `PublicModelPopularity.is_new`. */
208
+ is_new: S.Boolean.pipe(S.optional, S.withDecodingDefault(Effect.succeed(false))),
209
+ });
170
210
  /**
171
211
  * One period's reading for a tier, for the value trend series.
172
212
  *
@@ -270,10 +310,16 @@ export const PublicUsageIndexResponse = S.Struct({
270
310
  value_methodology_version: S.String,
271
311
  model_popularity: S.Array(PublicModelPopularity),
272
312
  provider_popularity: S.Array(PublicProviderPopularity),
313
+ /**
314
+ * Decoded with a default so a peer deployment that predates the field
315
+ * still merges — see the note on `PublicValueByTier`.
316
+ */
317
+ client_popularity: S.Array(PublicClientPopularity).pipe(S.optional, S.withDecodingDefault(Effect.succeed([]))),
273
318
  value_by_tier: S.Array(PublicValueByTier),
274
319
  });
275
320
  export function hasPublicUsageIndexData(response) {
276
321
  return (response.model_popularity.length > 0 ||
277
322
  response.provider_popularity.length > 0 ||
323
+ (response.client_popularity?.length ?? 0) > 0 ||
278
324
  response.value_by_tier.length > 0);
279
325
  }
@@ -42,6 +42,20 @@ export declare const ModelBreakdown: S.Struct<{
42
42
  readonly cost_usd: S.Number;
43
43
  }>;
44
44
  export type TModelBreakdown = S.Schema.Type<typeof ModelBreakdown>;
45
+ /**
46
+ * One row of "where my requests came from": a client kind and, for a
47
+ * website, its host (`requests.client_kind` / `client_host`). `client` is
48
+ * null for rows recorded before the client was stored.
49
+ */
50
+ export declare const ClientBreakdown: S.Struct<{
51
+ readonly client: S.NullOr<S.Literals<readonly ["claude_code", "codex", "opencode", "openllm_cli", "openllm_desktop", "openllm_web", "website", "other"]>>;
52
+ readonly host: S.NullOr<S.String>;
53
+ readonly requests: S.Number;
54
+ readonly tokens_in: S.Number;
55
+ readonly tokens_out: S.Number;
56
+ readonly cost_usd: S.Number;
57
+ }>;
58
+ export type TClientBreakdown = S.Schema.Type<typeof ClientBreakdown>;
45
59
  export declare const DailyBucket: S.Struct<{
46
60
  readonly day: S.String;
47
61
  readonly requests: S.Number;
@@ -459,6 +473,16 @@ export declare const UserStats: S.Struct<{
459
473
  readonly tokens_out: S.Number;
460
474
  readonly cost_usd: S.Number;
461
475
  }>>;
476
+ /** The window's requests by the client that sent them (overview Clients
477
+ * tab), busiest first. */
478
+ readonly by_client: S.$Array<S.Struct<{
479
+ readonly client: S.NullOr<S.Literals<readonly ["claude_code", "codex", "opencode", "openllm_cli", "openllm_desktop", "openllm_web", "website", "other"]>>;
480
+ readonly host: S.NullOr<S.String>;
481
+ readonly requests: S.Number;
482
+ readonly tokens_in: S.Number;
483
+ readonly tokens_out: S.Number;
484
+ readonly cost_usd: S.Number;
485
+ }>>;
462
486
  readonly daily: S.$Array<S.Struct<{
463
487
  readonly day: S.String;
464
488
  readonly requests: S.Number;
@@ -1,4 +1,5 @@
1
1
  import { Schema as S } from "effect";
2
+ import { ClientKind } from "./client-origin.js";
2
3
  export const RequestStatus = S.Literals([
3
4
  "success",
4
5
  "error",
@@ -44,6 +45,19 @@ export const ModelBreakdown = S.Struct({
44
45
  tokens_out: S.Number,
45
46
  cost_usd: S.Number,
46
47
  });
48
+ /**
49
+ * One row of "where my requests came from": a client kind and, for a
50
+ * website, its host (`requests.client_kind` / `client_host`). `client` is
51
+ * null for rows recorded before the client was stored.
52
+ */
53
+ export const ClientBreakdown = S.Struct({
54
+ client: S.NullOr(ClientKind),
55
+ host: S.NullOr(S.String),
56
+ requests: S.Number,
57
+ tokens_in: S.Number,
58
+ tokens_out: S.Number,
59
+ cost_usd: S.Number,
60
+ });
47
61
  export const DailyBucket = S.Struct({
48
62
  day: S.String,
49
63
  requests: S.Number,
@@ -215,6 +229,9 @@ export const UserStats = S.Struct({
215
229
  */
216
230
  inferred_subscription_usage: S.optional(S.Array(InferredProviderUsage)),
217
231
  by_model: S.Array(ModelBreakdown),
232
+ /** The window's requests by the client that sent them (overview Clients
233
+ * tab), busiest first. */
234
+ by_client: S.Array(ClientBreakdown),
218
235
  daily: S.Array(DailyBucket),
219
236
  });
220
237
  export const KeyStats = S.Struct({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openllmsh/sdk",
3
- "version": "2.10.12-alpha.2",
3
+ "version": "2.10.13",
4
4
  "private": false,
5
5
  "description": "The OpenLLM SDK: typed API contracts, wire-format adapters, the device tunnel, client-side vault crypto, the OpenAPI spec and MCP tools.",
6
6
  "keywords": [