dsh-usage-state 0.3.0

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/lib/typert.js ADDED
@@ -0,0 +1,120 @@
1
+ import { z } from "zod";
2
+ //#region src/host/typert.ts
3
+ /**
4
+ * The host half of the Typert RPC contract.
5
+ *
6
+ * Three requirements here are not obvious and are load-bearing:
7
+ * - the module must export a NAMED `TYPERT`, and `package.json` must expose it
8
+ * as `exports["./typert"]` — that is where the loader looks;
9
+ * - `package` must equal the npm package name exactly;
10
+ * - every parameter and result codec must be "strict" and carry a zod **v4**
11
+ * schema (the loader checks `'_zod' in schema`), which is why zod is a runtime
12
+ * dependency rather than a dev one.
13
+ *
14
+ * `model` is mandatory even when empty.
15
+ */
16
+ const TYPERT_PACKAGE = "dsh-usage-state";
17
+ const TYPERT_SERVICE = "usageState";
18
+ const TYPERT_NAMESPACE = "usageState";
19
+ function strictCodec(name, schema) {
20
+ return {
21
+ mode: "strict",
22
+ typeSymbol: `${TYPERT_PACKAGE}#${name}`,
23
+ schema,
24
+ create: () => schema
25
+ };
26
+ }
27
+ const usageModeSchema = z.enum(["api", "coding-plan"]);
28
+ const balanceSchema = z.object({
29
+ amount: z.number(),
30
+ currency: z.string(),
31
+ granted: z.number().optional(),
32
+ toppedUp: z.number().optional()
33
+ });
34
+ const quotaWindowSchema = z.object({
35
+ id: z.string(),
36
+ usedPercent: z.number(),
37
+ resetsAt: z.number().optional()
38
+ });
39
+ const snapshotErrorSchema = z.object({
40
+ kind: z.enum([
41
+ "config",
42
+ "auth",
43
+ "http",
44
+ "network",
45
+ "parse",
46
+ "unknown"
47
+ ]),
48
+ detail: z.string().optional()
49
+ });
50
+ const snapshotSchema = z.object({
51
+ sourceId: z.string(),
52
+ mode: usageModeSchema,
53
+ balances: z.array(balanceSchema),
54
+ windows: z.array(quotaWindowSchema),
55
+ fetchedAt: z.number(),
56
+ stale: z.boolean().optional(),
57
+ error: snapshotErrorSchema.optional()
58
+ });
59
+ const catalogEntrySchema = z.object({
60
+ id: z.string(),
61
+ displayName: z.string(),
62
+ modes: z.array(usageModeSchema),
63
+ requiresBaseUrl: z.boolean(),
64
+ defaultBaseUrl: z.record(z.string(), z.string()),
65
+ credentialRefs: z.record(z.string(), z.array(z.string()))
66
+ });
67
+ const credentialCandidateSchema = z.object({
68
+ ref: z.string(),
69
+ configured: z.boolean(),
70
+ source: z.string().optional(),
71
+ writable: z.boolean().optional()
72
+ });
73
+ const credentialDescriptionSchema = z.object({
74
+ candidates: z.array(credentialCandidateSchema),
75
+ configured: z.boolean(),
76
+ ref: z.string().optional(),
77
+ source: z.string().optional(),
78
+ writable: z.boolean().optional()
79
+ });
80
+ const usageStateViewSchema = z.object({
81
+ sources: z.array(catalogEntrySchema),
82
+ snapshots: z.record(z.string(), snapshotSchema),
83
+ checkedAt: z.number()
84
+ });
85
+ const credentialReportSchema = z.object({ credentials: z.record(z.string(), credentialDescriptionSchema) });
86
+ const TYPERT = {
87
+ package: TYPERT_PACKAGE,
88
+ face: "host",
89
+ schemas: [],
90
+ model: {
91
+ services: [],
92
+ events: [],
93
+ objects: []
94
+ },
95
+ invocations: [{
96
+ id: `${TYPERT_PACKAGE}#${TYPERT_NAMESPACE}/getState`,
97
+ service: TYPERT_SERVICE,
98
+ namespace: TYPERT_NAMESPACE,
99
+ method: "getState",
100
+ invocation: { kind: "direct" },
101
+ parameters: [{
102
+ name: "force",
103
+ wire: "force",
104
+ source: "json",
105
+ acceptsUndefined: true,
106
+ codec: strictCodec("Force", z.boolean().optional())
107
+ }],
108
+ result: strictCodec("UsageStateView", usageStateViewSchema)
109
+ }, {
110
+ id: `${TYPERT_PACKAGE}#${TYPERT_NAMESPACE}/describeCredentials`,
111
+ service: TYPERT_SERVICE,
112
+ namespace: TYPERT_NAMESPACE,
113
+ method: "describeCredentials",
114
+ invocation: { kind: "direct" },
115
+ parameters: [],
116
+ result: strictCodec("CredentialReport", credentialReportSchema)
117
+ }]
118
+ };
119
+ //#endregion
120
+ export { TYPERT, TYPERT_NAMESPACE, TYPERT_PACKAGE, TYPERT_SERVICE, credentialReportSchema, strictCodec, usageStateViewSchema };
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "dsh-usage-state",
3
+ "version": "0.3.0",
4
+ "type": "module",
5
+ "description": "DSH plugin: show account balance (API mode) or coding-plan quota (5h/7d/30d) for the model in use",
6
+ "license": "MIT",
7
+ "engines": {
8
+ "node": ">=20",
9
+ "dsh": ">=0.1.5-rc.1 <0.2.0-0"
10
+ },
11
+ "scripts": {
12
+ "test": "node --import ./tests/support/client-render-hook.mjs --test",
13
+ "test:watch": "node --import ./tests/support/client-render-hook.mjs --test --watch",
14
+ "typecheck": "tsc --noEmit",
15
+ "build": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\" && tsdown",
16
+ "watch": "tsdown --watch"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "default": "./lib/index.js"
21
+ },
22
+ "./client": {
23
+ "default": "./lib/client.js"
24
+ },
25
+ "./typert": {
26
+ "default": "./lib/typert.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "devDependencies": {
31
+ "@deepseek-ai/dsh-client-locale": "^0.1.5-rc.2",
32
+ "@deepseek-ai/dsh-client-store": "^0.1.5-rc.2",
33
+ "@deepseek-ai/dsh-client-ui-conversation": "^0.1.5-rc.2",
34
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.1.5-rc.2",
35
+ "@deepseek-ai/dsh-client-ui-slots": "^0.1.5-rc.2",
36
+ "@deepseek-ai/dsh-typert-loader": "^0.1.5-rc.2",
37
+ "@types/node": "^24.0.0",
38
+ "@types/react": "~18.3.1",
39
+ "@types/react-dom": "~18.3.1",
40
+ "react": "^18.3.1",
41
+ "react-dom": "^18.2.0",
42
+ "tsdown": "^0.22.14",
43
+ "typescript": "^5.9.2",
44
+ "unrun": "^0.2.39"
45
+ },
46
+ "dependencies": {
47
+ "zod": "4.5.1"
48
+ },
49
+ "main": "lib/index.js",
50
+ "dsh": {
51
+ "bundle": {
52
+ "patch": "./cordis.patch.yml"
53
+ },
54
+ "client": {
55
+ "platform": "web",
56
+ "inject": [
57
+ "@deepseek-ai/dsh-client-locale",
58
+ "@deepseek-ai/dsh-client-ui-slots",
59
+ "@deepseek-ai/dsh-client-ui-conversation",
60
+ "@deepseek-ai/dsh-client-ui-settings"
61
+ ]
62
+ }
63
+ },
64
+ "files": [
65
+ "lib",
66
+ "cordis.patch.yml",
67
+ "README.md",
68
+ "README.en.md",
69
+ "LICENSE",
70
+ "docs/adapters.md"
71
+ ],
72
+ "peerDependencies": {
73
+ "react": "^18.2.0"
74
+ },
75
+ "keywords": [
76
+ "deepseek",
77
+ "dsh",
78
+ "dsh-plugin",
79
+ "usage",
80
+ "balance",
81
+ "quota",
82
+ "coding-plan"
83
+ ],
84
+ "repository": {
85
+ "type": "git",
86
+ "url": "git+https://github.com/takboo/dsh-usage-state.git"
87
+ },
88
+ "homepage": "https://github.com/takboo/dsh-usage-state#readme",
89
+ "bugs": {
90
+ "url": "https://github.com/takboo/dsh-usage-state/issues"
91
+ }
92
+ }