@slopus/happy-agent-client 0.0.99 → 0.0.100

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.
@@ -5,5 +5,85 @@
5
5
  * is always by provider and then by model; a client wanting a rollup computes
6
6
  * its own.
7
7
  */
8
- export {};
8
+ import { Type } from "@sinclair/typebox";
9
+ import { Nullable } from "./common.js";
10
+ import { providerModelReferenceSchema } from "./daemon.js";
11
+ /** One normalized account-usage window reported by a provider. */
12
+ export const providerAccountUsageWindowSchema = Type.Object({
13
+ usedPercent: Type.Number(),
14
+ resetsAt: Nullable(Type.Number()),
15
+ startsAt: Nullable(Type.Number()),
16
+ durationMs: Nullable(Type.Number()),
17
+ /** When this window itself was last measured, protocol 29 or newer. */
18
+ capturedAt: Type.Optional(Type.Number()),
19
+ });
20
+ /** Spendable balance reported alongside a provider's account limits. */
21
+ export const providerAccountUsageCreditsSchema = Type.Object({
22
+ available: Type.Boolean(),
23
+ remainingCents: Nullable(Type.Number()),
24
+ unlimited: Type.Boolean(),
25
+ usedPercent: Nullable(Type.Number()),
26
+ });
27
+ /** The complete latest normalized account-usage reading from one vendor. */
28
+ export const providerAccountUsageSchema = Type.Object({
29
+ providerId: Type.String(),
30
+ vendor: Type.Union([Type.Literal("claude"), Type.Literal("codex"), Type.Literal("grok")]),
31
+ capturedAt: Type.Number(),
32
+ planName: Nullable(Type.String()),
33
+ exhausted: Type.Boolean(),
34
+ windows: Type.Object({
35
+ fiveHour: Nullable(providerAccountUsageWindowSchema),
36
+ weekly: Nullable(providerAccountUsageWindowSchema),
37
+ monthly: Nullable(providerAccountUsageWindowSchema),
38
+ /** Claude's separate weekly Fable allowance. Omitted or null when unreported. */
39
+ fableWeekly: Type.Optional(Nullable(providerAccountUsageWindowSchema)),
40
+ }),
41
+ credits: Nullable(providerAccountUsageCreditsSchema),
42
+ });
43
+ /**
44
+ * Everything the daemon knows about reading one provider account, without its configuration.
45
+ *
46
+ * The refresh fields are optional only for compatibility with older daemons: a protocol-29 daemon
47
+ * always sends them, so an entry without `refreshedAt` comes from a daemon that neither publishes
48
+ * `provider.usage.updated` nor serves `POST /v0/usage/refresh`.
49
+ */
50
+ export const providerAccountUsageStateSchema = Type.Object({
51
+ providerId: Type.String(),
52
+ /** The latest successful normalized reading, or `null` when none is available. */
53
+ usage: Nullable(providerAccountUsageSchema),
54
+ /** When the daemon last finished asking, successfully or not. */
55
+ checkedAt: Nullable(Type.Number()),
56
+ /** Why no reading is available at all. */
57
+ error: Nullable(Type.String()),
58
+ /** When the last successful reading arrived, from a poll or from inference. */
59
+ refreshedAt: Type.Optional(Nullable(Type.Number())),
60
+ /** Why the latest read failed, kept even while an older reading is shown. */
61
+ refreshError: Type.Optional(Nullable(Type.String())),
62
+ /** The instant before which the vendor asked not to be asked again. */
63
+ retryAt: Type.Optional(Nullable(Type.Number())),
64
+ /** Whether a read of this account is in flight. */
65
+ refreshing: Type.Optional(Type.Boolean()),
66
+ });
67
+ /** One configured provider, its complete model catalog, and its latest account limits. */
68
+ export const providerUsageEntrySchema = Type.Composite([
69
+ providerAccountUsageStateSchema,
70
+ Type.Object({
71
+ /** The canonical provider key from the effective configuration. */
72
+ type: Type.String(),
73
+ enabled: Type.Boolean(),
74
+ /** The same complete model-reference list returned for this provider by `GET /v0/config`. */
75
+ models: Type.Array(providerModelReferenceSchema),
76
+ }),
77
+ ]);
78
+ /** `POST /v0/usage/refresh` request body, protocol 29 or newer. */
79
+ export const providerUsageRefreshRequestSchema = Type.Object({
80
+ /** The accounts to consider; every enabled account when omitted. */
81
+ providerIds: Type.Optional(Type.Array(Type.String())),
82
+ /** Read only accounts older than this; defaults to 300000 and is at least 60000. */
83
+ olderThanMs: Type.Optional(Type.Number({ minimum: 0 })),
84
+ }, { additionalProperties: false });
85
+ /** `POST /v0/usage/refresh` — `202`; the results arrive as `provider.usage.updated`. */
86
+ export const providerUsageRefreshResponseSchema = Type.Object({
87
+ started: Type.Array(Type.String()),
88
+ });
9
89
  //# sourceMappingURL=usage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../sources/protocol/usage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../sources/protocol/usage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAa3D,kEAAkE;AAClE,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,CAAC,MAAM,CAAC;IACxD,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE;IAC1B,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACjC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACjC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACnC,uEAAuE;IACvE,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;CAC3C,CAAC,CAAC;AAGH,wEAAwE;AACxE,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,CAAC,MAAM,CAAC;IACzD,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE;IACzB,cAAc,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACvC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE;IACzB,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;CACvC,CAAC,CAAC;AAGH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,MAAM,CAAC;IAClD,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE;IACzB,MAAM,EAAE,IAAI,CAAC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IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/C,mDAAmD;IACnD,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;CAC5C,CAAC,CAAC;AAGH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC,SAAS,CAAC;IACnD,+BAA+B;IAC/B,IAAI,CAAC,MAAM,CAAC;QACR,mEAAmE;QACnE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACvB,6FAA6F;QAC7F,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,4BAA4B,CAAC;KACnD,CAAC;CACL,CAAC,CAAC;AAGH,mEAAmE;AACnE,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,CAAC,MAAM,CACxD;IACI,oEAAoE;IACpE,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACrD,oFAAoF;IACpF,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;CAC1D,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAClC,CAAC;AAGF,wFAAwF;AACxF,MAAM,CAAC,MAAM,kCAAkC,GAAG,IAAI,CAAC,MAAM,CAAC;IAC1D,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;CACrC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slopus/happy-agent-client",
3
- "version": "0.0.99",
3
+ "version": "0.0.100",
4
4
  "description": "Typed client for the Happy agent HTTP API.",
5
5
  "license": "MIT",
6
6
  "repository": {