@whiteplusms/dsh-redis 0.0.0-stage → 0.1.3

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.
Files changed (146) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -2
  3. package/README.zh.md +185 -0
  4. package/cordis.patch.yml +4 -0
  5. package/icon.svg +1 -0
  6. package/lib/client/index.d.ts +4 -0
  7. package/lib/client.js +7684 -0
  8. package/lib/connection-errors.d.ts +66 -0
  9. package/lib/connection-errors.js +21 -0
  10. package/lib/domain.d.ts +451 -0
  11. package/lib/domain.js +20 -0
  12. package/lib/host/ai-answer.d.ts +7 -0
  13. package/lib/host/ai-answer.js +132 -0
  14. package/lib/host/ai-budget.d.ts +43 -0
  15. package/lib/host/ai-budget.js +78 -0
  16. package/lib/host/ai-connection-tools.d.ts +8 -0
  17. package/lib/host/ai-connection-tools.js +49 -0
  18. package/lib/host/ai-hash-filter.d.ts +13 -0
  19. package/lib/host/ai-hash-filter.js +97 -0
  20. package/lib/host/ai-hash-pages.d.ts +15 -0
  21. package/lib/host/ai-hash-pages.js +42 -0
  22. package/lib/host/ai-key-pages.d.ts +14 -0
  23. package/lib/host/ai-key-pages.js +27 -0
  24. package/lib/host/ai-locate-tool.d.ts +6 -0
  25. package/lib/host/ai-locate-tool.js +234 -0
  26. package/lib/host/ai-match-tools.d.ts +7 -0
  27. package/lib/host/ai-match-tools.js +112 -0
  28. package/lib/host/ai-page-coordinator.d.ts +21 -0
  29. package/lib/host/ai-page-coordinator.js +81 -0
  30. package/lib/host/ai-page-store.d.ts +40 -0
  31. package/lib/host/ai-page-store.js +104 -0
  32. package/lib/host/ai-profile-tools.d.ts +7 -0
  33. package/lib/host/ai-profile-tools.js +44 -0
  34. package/lib/host/ai-query-scope.d.ts +42 -0
  35. package/lib/host/ai-query-scope.js +104 -0
  36. package/lib/host/ai-reader.d.ts +219 -0
  37. package/lib/host/ai-reader.js +1221 -0
  38. package/lib/host/ai-report-samples.d.ts +26 -0
  39. package/lib/host/ai-report-samples.js +77 -0
  40. package/lib/host/ai-report-tools.d.ts +11 -0
  41. package/lib/host/ai-report-tools.js +70 -0
  42. package/lib/host/ai-set-pages.d.ts +15 -0
  43. package/lib/host/ai-set-pages.js +40 -0
  44. package/lib/host/ai-stream-pages.d.ts +15 -0
  45. package/lib/host/ai-stream-pages.js +42 -0
  46. package/lib/host/ai-tools.d.ts +4 -0
  47. package/lib/host/ai-tools.js +106 -0
  48. package/lib/host/ai-ui-tools.d.ts +10 -0
  49. package/lib/host/ai-ui-tools.js +72 -0
  50. package/lib/host/ai-value.d.ts +12 -0
  51. package/lib/host/ai-value.js +15 -0
  52. package/lib/host/ai-write-tools.d.ts +5 -0
  53. package/lib/host/ai-write-tools.js +101 -0
  54. package/lib/host/ai-writer.d.ts +25 -0
  55. package/lib/host/ai-writer.js +77 -0
  56. package/lib/host/ai-zset-pages.d.ts +15 -0
  57. package/lib/host/ai-zset-pages.js +40 -0
  58. package/lib/host/byte-identity.d.ts +3 -0
  59. package/lib/host/byte-identity.js +12 -0
  60. package/lib/host/client-list.d.ts +13 -0
  61. package/lib/host/client-list.js +35 -0
  62. package/lib/host/connection-service.d.ts +71 -0
  63. package/lib/host/connection-service.js +468 -0
  64. package/lib/host/database-reader.d.ts +10 -0
  65. package/lib/host/database-reader.js +62 -0
  66. package/lib/host/hash-reader.d.ts +12 -0
  67. package/lib/host/hash-reader.js +91 -0
  68. package/lib/host/key-reader.d.ts +20 -0
  69. package/lib/host/key-reader.js +65 -0
  70. package/lib/host/list-reader.d.ts +8 -0
  71. package/lib/host/list-reader.js +61 -0
  72. package/lib/host/match-preset-store.d.ts +36 -0
  73. package/lib/host/match-preset-store.js +201 -0
  74. package/lib/host/profile-snapshots.d.ts +32 -0
  75. package/lib/host/profile-snapshots.js +187 -0
  76. package/lib/host/profile-store.d.ts +15 -0
  77. package/lib/host/profile-store.js +120 -0
  78. package/lib/host/read-context.d.ts +23 -0
  79. package/lib/host/read-context.js +41 -0
  80. package/lib/host/redis-transport.d.ts +34 -0
  81. package/lib/host/redis-transport.js +262 -0
  82. package/lib/host/redis-write-transaction.d.ts +28 -0
  83. package/lib/host/redis-write-transaction.js +180 -0
  84. package/lib/host/resp.d.ts +38 -0
  85. package/lib/host/resp.js +174 -0
  86. package/lib/host/scan-cursors.d.ts +25 -0
  87. package/lib/host/scan-cursors.js +59 -0
  88. package/lib/host/selected-reader.d.ts +22 -0
  89. package/lib/host/selected-reader.js +84 -0
  90. package/lib/host/set-reader.d.ts +12 -0
  91. package/lib/host/set-reader.js +85 -0
  92. package/lib/host/stream-groups.d.ts +17 -0
  93. package/lib/host/stream-groups.js +42 -0
  94. package/lib/host/stream-reader.d.ts +12 -0
  95. package/lib/host/stream-reader.js +105 -0
  96. package/lib/host/string-reader.d.ts +9 -0
  97. package/lib/host/string-reader.js +81 -0
  98. package/lib/host/ui-action-channel.d.ts +4 -0
  99. package/lib/host/ui-action-channel.js +182 -0
  100. package/lib/host/ui-action-coordinator.d.ts +28 -0
  101. package/lib/host/ui-action-coordinator.js +188 -0
  102. package/lib/host/value-prefix.d.ts +5 -0
  103. package/lib/host/value-prefix.js +11 -0
  104. package/lib/host/write-bytes.d.ts +3 -0
  105. package/lib/host/write-bytes.js +9 -0
  106. package/lib/host/write-history.d.ts +18 -0
  107. package/lib/host/write-history.js +79 -0
  108. package/lib/host/write-proposals.d.ts +46 -0
  109. package/lib/host/write-proposals.js +132 -0
  110. package/lib/host/zset-reader.d.ts +12 -0
  111. package/lib/host/zset-reader.js +103 -0
  112. package/lib/host/zset-values.d.ts +6 -0
  113. package/lib/host/zset-values.js +26 -0
  114. package/lib/index.d.ts +6 -0
  115. package/lib/index.js +5 -0
  116. package/lib/redis-answer.d.ts +32 -0
  117. package/lib/redis-answer.js +215 -0
  118. package/lib/redis-databases.d.ts +3 -0
  119. package/lib/redis-databases.js +21 -0
  120. package/lib/redis-read-tools.d.ts +2 -0
  121. package/lib/redis-read-tools.js +7 -0
  122. package/lib/redis-result.d.ts +4 -0
  123. package/lib/redis-result.js +18 -0
  124. package/lib/redis-score.d.ts +2 -0
  125. package/lib/redis-score.js +6 -0
  126. package/lib/remote-service.d.ts +69 -0
  127. package/lib/remote-service.js +187 -0
  128. package/lib/runtime.d.ts +3 -0
  129. package/lib/runtime.js +29 -0
  130. package/lib/stream-id.d.ts +7 -0
  131. package/lib/stream-id.js +19 -0
  132. package/lib/typert.host.d.ts +13 -0
  133. package/lib/typert.host.js +7 -0
  134. package/lib/typert.remote-client.d.ts +98 -0
  135. package/lib/typert.remote-client.js +3 -0
  136. package/lib/typert.shared.d.ts +62 -0
  137. package/lib/typert.shared.js +735 -0
  138. package/lib/ui-action-selection.d.ts +3 -0
  139. package/lib/ui-action-selection.js +12 -0
  140. package/licenses/THIRD_PARTY_NOTICES.txt +9 -0
  141. package/licenses/deepseek-harness-MIT.txt +21 -0
  142. package/licenses/dsh-database-MIT.txt +21 -0
  143. package/licenses/dsh-git-graph-MIT.txt +21 -0
  144. package/licenses/lucide-react-LICENSE.txt +43 -0
  145. package/licenses/phosphor-icons-MIT.txt +21 -0
  146. package/package.json +132 -3
@@ -0,0 +1,735 @@
1
+ import { MAX_REDIS_WRITE_BYTES, MAX_DATABASE_ENTRIES } from "./domain.js";
2
+ import { DSH_BASELINE, PROTOCOL_VERSION } from "./domain.js";
3
+ import { MAX_PROFILES } from "./domain.js";
4
+ import { MAX_KEY_BYTES, MAX_SCAN_KEYS, MAX_SCAN_JSON_BYTES } from "./domain.js";
5
+ import { MAX_VALUE_BYTES } from "./domain.js";
6
+ import { MAX_LIST_ITEMS } from "./domain.js";
7
+ import { isRedisScore } from "./redis-score.js";
8
+ import { MAX_STREAM_MESSAGES } from "./domain.js";
9
+ import { compareStreamIds, isStreamId, isStreamRange, withinStreamRange } from "./stream-id.js";
10
+ export const TYPERT_PACKAGE = '@whiteplusms/dsh-redis';
11
+ function objectAt(value, keys) {
12
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
13
+ throw new TypeError('Redis RPC: expected object');
14
+ const object = value;
15
+ if (Object.keys(object).some(key => !keys.includes(key)))
16
+ throw new TypeError('Redis RPC: unexpected field');
17
+ return object;
18
+ }
19
+ export const emptyRequestSchema = { parse(value) {
20
+ objectAt(value, []);
21
+ return {};
22
+ } };
23
+ export const statusSchema = { parse(value) {
24
+ const object = objectAt(value, ['state', 'sidebarReadOnly', 'aiWriteAvailable', 'dshBaseline', 'protocolVersion']);
25
+ if (object.state !== 'ready' || object.sidebarReadOnly !== true || object.aiWriteAvailable !== true || object.dshBaseline !== DSH_BASELINE || object.protocolVersion !== PROTOCOL_VERSION)
26
+ throw new TypeError('Redis RPC: invalid Host status');
27
+ return { state: 'ready', sidebarReadOnly: true, aiWriteAvailable: true, dshBaseline: DSH_BASELINE, protocolVersion: PROTOCOL_VERSION };
28
+ } };
29
+ const sessionIdSchema = { parse(value) {
30
+ if (typeof value !== 'string' || value.length === 0)
31
+ throw new TypeError('Redis RPC: invalid session');
32
+ return value;
33
+ } };
34
+ /** Adapted from Git Graph: strict, Agent-scoped direct invocation with cancellation. */
35
+ function createRedisInvocation(method, inputSymbol, resultSymbol, input, result, session) {
36
+ return {
37
+ id: `${TYPERT_PACKAGE}#redisViewer/${method}`, service: 'redisViewer', namespace: 'redisViewer', method,
38
+ invocation: { kind: 'direct' }, cancellation: { parameter: 'signal' },
39
+ scope: { context: 'agent', wire: 'agentId' },
40
+ parameters: [
41
+ { name: 'agent', wire: 'agentId', source: 'lookup', lookup: 'agent', codec: { mode: 'strict', typeSymbol: '@deepseek-ai/dsh-session/types#SessionId', create: () => session } },
42
+ { name: 'request', wire: 'request', source: 'json', codec: { mode: 'strict', typeSymbol: `${TYPERT_PACKAGE}#${inputSymbol}`, create: () => input } },
43
+ ],
44
+ // The Gateway encodes the Host result and the Client Remote decodes it.
45
+ result: { mode: 'strict', typeSymbol: `${TYPERT_PACKAGE}#${resultSymbol}`, create: () => result, encode: value => result.parse(value), decode: value => result.parse(value) },
46
+ };
47
+ }
48
+ function stringAt(value, max) {
49
+ if (typeof value !== 'string' || value.length > max)
50
+ throw new TypeError('Redis RPC: invalid string');
51
+ return value;
52
+ }
53
+ function integerAt(value, min, max) {
54
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < min || value > max)
55
+ throw new TypeError('Redis RPC: invalid integer');
56
+ return value;
57
+ }
58
+ function errorAt(value) {
59
+ if (value === null || value === 'auth' || value === 'network' || value === 'timeout' || value === 'cancelled' || value === 'stale' || value === 'tls-certificate' || value === 'tls-hostname' || value === 'permission' || value === 'oversize' || value === 'protocol' || value === 'busy' || value === 'database' || value === 'type-changed')
60
+ return value;
61
+ throw new TypeError('Redis RPC: invalid connection error');
62
+ }
63
+ function address(value) {
64
+ const object = objectAt(value, ['host', 'port', 'username']);
65
+ const host = stringAt(object.host, 253);
66
+ if (host.length === 0 || /[\s/\\@?#\0]/u.test(host))
67
+ throw new TypeError('Redis RPC: invalid host');
68
+ return { host, port: integerAt(object.port, 1, 65535), username: stringAt(object.username, 256) };
69
+ }
70
+ function environmentAt(value) {
71
+ if (value === undefined)
72
+ return undefined;
73
+ const environment = stringAt(value, 80);
74
+ if (environment.length === 0 || environment.trim() !== environment || /[\u0000-\u001f\u007f]/u.test(environment))
75
+ throw new TypeError('Redis RPC: invalid environment');
76
+ return environment;
77
+ }
78
+ function publicTarget(value) {
79
+ const object = objectAt(value, ['host', 'port', 'username', 'environment', 'tls']);
80
+ if (typeof object.tls !== 'boolean')
81
+ throw new TypeError('Redis RPC: invalid TLS status');
82
+ const environment = environmentAt(object.environment);
83
+ return { ...address({ host: object.host, port: object.port, username: object.username }), ...(environment === undefined ? {} : { environment }), tls: object.tls };
84
+ }
85
+ export const connectionRequestSchema = { parse(value) {
86
+ const object = objectAt(value, ['host', 'port', 'username', 'password', 'environment', 'tls']);
87
+ const tls = object.tls === null ? null : { caPem: stringAt(objectAt(object.tls, ['caPem']).caPem, 65536) };
88
+ const environment = environmentAt(object.environment);
89
+ return { ...address({ host: object.host, port: object.port, username: object.username }), password: stringAt(object.password, 4096), ...(environment === undefined ? {} : { environment }), tls };
90
+ } };
91
+ export const connectionTargetSchema = { parse(value) {
92
+ const object = objectAt(value, ['id', 'generation']);
93
+ const id = stringAt(object.id, 128);
94
+ if (id.length === 0)
95
+ throw new TypeError('Redis RPC: missing connection identity');
96
+ return { id, generation: integerAt(object.generation, 1, Number.MAX_SAFE_INTEGER) };
97
+ } };
98
+ export const connectionViewSchema = { parse(value) {
99
+ const object = objectAt(value, ['id', 'generation', 'db', 'state', 'error', 'target']);
100
+ const state = object.state;
101
+ if (state !== 'connecting' && state !== 'connected' && state !== 'disconnected' && state !== 'error')
102
+ throw new TypeError('Redis RPC: invalid state');
103
+ const id = object.id === null ? null : stringAt(object.id, 128);
104
+ const generation = integerAt(object.generation, 0, Number.MAX_SAFE_INTEGER), db = integerAt(object.db, 0, 65535);
105
+ const error = errorAt(object.error), target = object.target === null ? null : publicTarget(object.target);
106
+ // An untouched session has no target. A closed socket can retain the last
107
+ // target, and SELECT refusals can leave the original DB connected.
108
+ if (id === null ? target !== null || generation !== 0 || db !== 0 || state !== 'disconnected' : id.length === 0 || target === null || generation === 0) {
109
+ throw new TypeError('Redis RPC: inconsistent connection identity');
110
+ }
111
+ // Stale and cancelled invocations can overlay the current connection view.
112
+ if (state === 'error' ? error === null : error !== null && error !== 'stale' && error !== 'cancelled' && !(state === 'connected' && (error === 'database' || error === 'permission'))) {
113
+ throw new TypeError('Redis RPC: inconsistent connection error');
114
+ }
115
+ return { id, generation, db, state, error, target };
116
+ } };
117
+ function profileIdentity(value) {
118
+ const id = stringAt(value, 128);
119
+ if (id.length === 0)
120
+ throw new TypeError('Redis RPC: missing profile identity');
121
+ return id;
122
+ }
123
+ function profileName(value) {
124
+ const name = stringAt(value, 80);
125
+ if (name.length === 0 || name.trim() !== name)
126
+ throw new TypeError('Redis RPC: invalid profile name');
127
+ return name;
128
+ }
129
+ export const connectionSettingsSchema = { parse(value) {
130
+ const object = objectAt(value, ['host', 'port', 'username', 'environment', 'tls']);
131
+ const { password: _password, ...settings } = connectionRequestSchema.parse({ ...object, password: '' });
132
+ return settings;
133
+ } };
134
+ export const saveProfileSchema = { parse(value) {
135
+ const object = objectAt(value, ['id', 'name', 'group', 'settings']);
136
+ return { id: object.id === null ? null : profileIdentity(object.id), name: profileName(object.name), ...(object.group === undefined ? {} : { group: profileName(object.group) }), settings: connectionSettingsSchema.parse(object.settings) };
137
+ } };
138
+ export const profileIdSchema = { parse(value) {
139
+ return { id: profileIdentity(objectAt(value, ['id']).id) };
140
+ } };
141
+ export const profileCollectionSchema = { parse(value) {
142
+ const object = objectAt(value, ['profiles', 'selectedId']);
143
+ if (!Array.isArray(object.profiles) || object.profiles.length > MAX_PROFILES)
144
+ throw new TypeError('Redis RPC: invalid profile list');
145
+ const profiles = object.profiles.map((value) => {
146
+ const item = objectAt(value, ['id', 'name', 'group', 'settings']);
147
+ return { id: profileIdentity(item.id), name: profileName(item.name), ...(item.group === undefined ? {} : { group: profileName(item.group) }), settings: connectionSettingsSchema.parse(item.settings) };
148
+ });
149
+ const selectedId = object.selectedId === null ? null : profileIdentity(object.selectedId);
150
+ if (new Set(profiles.map(value => value.id)).size !== profiles.length || (selectedId !== null && !profiles.some(value => value.id === selectedId)))
151
+ throw new TypeError('Redis RPC: invalid profile identities');
152
+ return { profiles, selectedId };
153
+ } };
154
+ export const databaseTargetSchema = { parse(value) {
155
+ const object = objectAt(value, ['id', 'generation', 'db']);
156
+ return { ...connectionTargetSchema.parse({ id: object.id, generation: object.generation }), db: integerAt(object.db, 0, 65535) };
157
+ } };
158
+ export const writeModeRequestSchema = { parse(value) {
159
+ const object = objectAt(value, ['target', 'enabled']);
160
+ if (typeof object.enabled !== 'boolean')
161
+ throw new TypeError('Redis RPC: invalid write mode');
162
+ return { target: databaseTargetSchema.parse(object.target), enabled: object.enabled };
163
+ } };
164
+ export const writeModeStatusSchema = { parse(value) {
165
+ const object = objectAt(value, ['connection', 'enabled']);
166
+ if (typeof object.enabled !== 'boolean')
167
+ throw new TypeError('Redis RPC: invalid write mode');
168
+ const connection = connectionViewSchema.parse(object.connection);
169
+ if (object.enabled && (connection.state !== 'connected' || connection.id === null))
170
+ throw new TypeError('Redis RPC: invalid enabled connection');
171
+ return { connection, enabled: object.enabled };
172
+ } };
173
+ export const writeLookupRequestSchema = { parse(value) {
174
+ return { id: uiRequestId(objectAt(value, ['id']).id) };
175
+ } };
176
+ export const writeLookupResultSchema = { parse(value) {
177
+ const record = objectAt(value, ['record']).record;
178
+ if (record === null)
179
+ return { record: null };
180
+ const raw = objectAt(record, ['id', 'target', 'identity', 'state', 'startedAt', 'updatedAt', 'readbackAt']);
181
+ const identity = objectAt(raw.identity, ['type', 'keyBase64', 'fieldBase64']);
182
+ if (identity.type !== 'string' && identity.type !== 'hash')
183
+ throw new TypeError('Redis RPC: invalid write identity');
184
+ const keyBase64 = byteStringAt(identity.keyBase64, MAX_REDIS_WRITE_BYTES), fieldBase64 = identity.fieldBase64 === null ? null : byteStringAt(identity.fieldBase64, MAX_REDIS_WRITE_BYTES);
185
+ if ((identity.type === 'string') !== (fieldBase64 === null))
186
+ throw new TypeError('Redis RPC: invalid write field');
187
+ const states = ['pending', 'submitting', 'not-executed', 'conflict', 'rejected', 'written-verified', 'written-unverified', 'written-mismatch', 'unknown'];
188
+ if (typeof raw.state !== 'string' || !states.includes(raw.state))
189
+ throw new TypeError('Redis RPC: invalid write state');
190
+ const timestamp = (input) => { const text = stringAt(input, 24); if (!Number.isFinite(Date.parse(text)) || new Date(text).toISOString() !== text)
191
+ throw new TypeError('Redis RPC: invalid timestamp'); return text; };
192
+ return { record: { id: uiRequestId(raw.id), target: databaseTargetSchema.parse(raw.target), identity: { type: identity.type, keyBase64, fieldBase64 }, state: raw.state, startedAt: timestamp(raw.startedAt), updatedAt: timestamp(raw.updatedAt), readbackAt: raw.readbackAt === null ? null : timestamp(raw.readbackAt) } };
193
+ } };
194
+ /** Stream frames are parsed on the client too: rc.2 does not decode stream items. */
195
+ function uiRequestId(value) {
196
+ const id = stringAt(value, 36);
197
+ if (!/^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/u.test(id))
198
+ throw new TypeError('Redis RPC: invalid UI request identity');
199
+ return id;
200
+ }
201
+ export const actionPointReadRequestSchema = { parse(value) {
202
+ return { requestId: uiRequestId(objectAt(value, ['requestId']).requestId) };
203
+ } };
204
+ export const uiActionAckSchema = { parse(value) {
205
+ const raw = objectAt(value, ['requestId', 'target', 'selectionRevision', 'outcome']);
206
+ if (raw.outcome !== 'applied' && raw.outcome !== 'unsupported' && raw.outcome !== 'failed' && raw.outcome !== 'stale' && raw.outcome !== 'ambiguous')
207
+ throw new TypeError('Redis RPC: invalid UI outcome');
208
+ return { requestId: uiRequestId(raw.requestId), target: raw.target === null ? null : databaseTargetSchema.parse(raw.target), selectionRevision: integerAt(raw.selectionRevision, 0, Number.MAX_SAFE_INTEGER), outcome: raw.outcome };
209
+ } };
210
+ export const uiChannelInputSchema = { parse(value) {
211
+ if (typeof value === 'object' && value !== null && 'kind' in value) {
212
+ const kind = objectAt(value, ['kind', 'revision', 'synchronized', 'requestId', 'request', 'nextRevision', 'actionRequestId']).kind;
213
+ if (kind === 'commitSelection') {
214
+ const raw = objectAt(value, ['kind', 'requestId', 'revision', 'nextRevision']);
215
+ return { kind, requestId: uiRequestId(raw.requestId), revision: integerAt(raw.revision, 0, Number.MAX_SAFE_INTEGER), nextRevision: integerAt(raw.nextRevision, 0, Number.MAX_SAFE_INTEGER) };
216
+ }
217
+ if (kind === 'publishSelection') {
218
+ const raw = objectAt(value, ['kind', 'requestId', 'revision', 'request', 'actionRequestId']);
219
+ return { kind, requestId: uiRequestId(raw.requestId), revision: integerAt(raw.revision, 0, Number.MAX_SAFE_INTEGER), request: setSelectionRequestSchema.parse(raw.request), ...(raw.actionRequestId === undefined ? {} : { actionRequestId: uiRequestId(raw.actionRequestId) }) };
220
+ }
221
+ const raw = objectAt(value, ['kind', 'revision', 'synchronized']);
222
+ if (raw.kind !== 'selection' || typeof raw.synchronized !== 'boolean')
223
+ throw new TypeError('Redis RPC: invalid selection state');
224
+ return { kind: 'selection', revision: integerAt(raw.revision, 0, Number.MAX_SAFE_INTEGER), synchronized: raw.synchronized };
225
+ }
226
+ return uiActionAckSchema.parse(value);
227
+ } };
228
+ export const uiChannelMessageSchema = { parse(value) {
229
+ const kind = objectAt(value, ['kind', 'request', 'requestId', 'accepted']).kind;
230
+ if (kind === 'selectionResult') {
231
+ const raw = objectAt(value, ['kind', 'requestId', 'accepted']);
232
+ if (typeof raw.accepted !== 'boolean')
233
+ throw new TypeError('Redis RPC: invalid selection result');
234
+ return { kind, requestId: uiRequestId(raw.requestId), accepted: raw.accepted };
235
+ }
236
+ if (kind === 'cancel') {
237
+ const raw = objectAt(value, ['kind', 'requestId']);
238
+ return { kind, requestId: uiRequestId(raw.requestId) };
239
+ }
240
+ if (kind !== 'action')
241
+ throw new TypeError('Redis RPC: invalid UI message');
242
+ const raw = objectAt(value, ['kind', 'request']), request = objectAt(raw.request, ['requestId', 'action', 'target', 'selectionRevision', 'expiresAt']);
243
+ const action = objectAt(request.action, ['kind', 'target', 'pattern', 'key', 'keyBase64', 'format', 'field', 'index', 'member', 'id', 'fieldIndex', 'fieldBase64']);
244
+ if (action.kind !== 'show' && action.kind !== 'confirmSelection' && action.kind !== 'refresh' && action.kind !== 'applyMatch' && action.kind !== 'setFormat' && action.kind !== 'selectKey' && action.kind !== 'selectHashField' && action.kind !== 'selectListIndex' && action.kind !== 'selectSetMember' && action.kind !== 'selectZSetMember' && action.kind !== 'selectStreamField')
245
+ throw new TypeError('Redis RPC: unsupported UI action');
246
+ let parsedAction;
247
+ if (action.kind === 'refresh') {
248
+ const raw = objectAt(request.action, ['kind', 'target', 'keyBase64']);
249
+ parsedAction = { kind: action.kind, target: databaseTargetSchema.parse(raw.target), keyBase64: byteStringAt(raw.keyBase64, MAX_KEY_BYTES) };
250
+ }
251
+ else if (action.kind === 'applyMatch') {
252
+ const raw = objectAt(request.action, ['kind', 'target', 'pattern']);
253
+ parsedAction = { kind: action.kind, target: databaseTargetSchema.parse(raw.target), pattern: stringAt(raw.pattern, 256) };
254
+ }
255
+ else if (action.kind === 'setFormat') {
256
+ const raw = objectAt(request.action, ['kind', 'keyBase64', 'format']);
257
+ if (raw.format !== 'text' && raw.format !== 'json' && raw.format !== 'hex' && raw.format !== 'base64')
258
+ throw new TypeError('Redis RPC: invalid preview format');
259
+ parsedAction = { kind: action.kind, keyBase64: byteStringAt(raw.keyBase64, MAX_KEY_BYTES), format: raw.format };
260
+ }
261
+ else if (action.kind === 'selectKey')
262
+ parsedAction = { kind: action.kind, key: identityAt(objectAt(request.action, ['kind', 'key']).key) };
263
+ else if (action.kind === 'selectHashField') {
264
+ const raw = objectAt(request.action, ['kind', 'keyBase64', 'field']);
265
+ parsedAction = { kind: action.kind, keyBase64: byteStringAt(raw.keyBase64, MAX_KEY_BYTES), field: identityAt(raw.field) };
266
+ }
267
+ else if (action.kind === 'selectListIndex') {
268
+ const raw = objectAt(request.action, ['kind', 'keyBase64', 'index']);
269
+ parsedAction = { kind: action.kind, keyBase64: byteStringAt(raw.keyBase64, MAX_KEY_BYTES), index: unsignedIntegerAt(raw.index) };
270
+ }
271
+ else if (action.kind === 'selectSetMember' || action.kind === 'selectZSetMember') {
272
+ const raw = objectAt(request.action, ['kind', 'keyBase64', 'member']);
273
+ parsedAction = { kind: action.kind, keyBase64: byteStringAt(raw.keyBase64, MAX_KEY_BYTES), member: identityAt(raw.member) };
274
+ }
275
+ else if (action.kind === 'selectStreamField') {
276
+ const raw = objectAt(request.action, ['kind', 'keyBase64', 'id', 'fieldIndex', 'fieldBase64']), id = stringAt(raw.id, 41);
277
+ if (!isStreamId(id) || id === '0-0')
278
+ throw new TypeError('Redis RPC: invalid Stream ID');
279
+ parsedAction = { kind: action.kind, keyBase64: byteStringAt(raw.keyBase64, MAX_KEY_BYTES), id, fieldIndex: integerAt(raw.fieldIndex, 0, MAX_SCAN_KEYS - 1), fieldBase64: byteStringAt(raw.fieldBase64, MAX_KEY_BYTES) };
280
+ }
281
+ else {
282
+ objectAt(request.action, ['kind']);
283
+ parsedAction = { kind: action.kind };
284
+ }
285
+ if ((action.kind === 'show' || action.kind === 'refresh' || action.kind === 'applyMatch') !== (request.target === null))
286
+ throw new TypeError('Redis RPC: invalid UI action target');
287
+ return { kind, request: { requestId: uiRequestId(request.requestId), action: parsedAction, target: request.target === null ? null : databaseTargetSchema.parse(request.target), selectionRevision: integerAt(request.selectionRevision, 0, Number.MAX_SAFE_INTEGER), expiresAt: integerAt(request.expiresAt, 1, Number.MAX_SAFE_INTEGER) } };
288
+ } };
289
+ /** One scoped stream carries Host actions down and their acknowledgements up. */
290
+ function createRedisUiStreamInvocation(input, output, ack, session) {
291
+ return { ...createRedisInvocation('openUiChannel', 'EmptyRequest', 'UiChannelMessage', input, output, session), mode: 'stream',
292
+ uplink: { codec: { mode: 'strict', typeSymbol: `${TYPERT_PACKAGE}#UiChannelInput`, create: () => ack } } };
293
+ }
294
+ function scanToken(value) {
295
+ const cursor = value === null ? null : stringAt(value, 36);
296
+ if (cursor !== null && !/^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/u.test(cursor))
297
+ throw new TypeError('Redis RPC: invalid scan token');
298
+ return cursor;
299
+ }
300
+ function byteStringAt(value, maxBytes) {
301
+ const base64 = stringAt(value, Math.ceil(maxBytes / 3) * 4);
302
+ let decoded;
303
+ try {
304
+ decoded = atob(base64);
305
+ }
306
+ catch {
307
+ throw new TypeError('Redis RPC: invalid bytes');
308
+ }
309
+ if (decoded.length > maxBytes || btoa(decoded) !== base64)
310
+ throw new TypeError('Redis RPC: invalid bytes');
311
+ return base64;
312
+ }
313
+ function unsignedIntegerAt(value) {
314
+ const text = stringAt(value, 19);
315
+ if (!/^(?:0|[1-9]\d{0,18})$/u.test(text) || BigInt(text) > (1n << 63n) - 1n)
316
+ throw new TypeError('Redis RPC: invalid integer text');
317
+ return text;
318
+ }
319
+ function sampleTimeAt(value) {
320
+ const text = stringAt(value, 24);
321
+ if (!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/u.test(text) || !Number.isFinite(Date.parse(text)) || new Date(text).toISOString() !== text)
322
+ throw new TypeError('Redis RPC: invalid sample time');
323
+ return text;
324
+ }
325
+ function metadataAt(value) {
326
+ if (value === null)
327
+ return null;
328
+ const item = objectAt(value, ['type', 'ttlMs', 'length']);
329
+ const type = stringAt(item.type, 128);
330
+ if (!/^[\w-]{1,128}$/u.test(type))
331
+ throw new TypeError('Redis RPC: invalid Redis type');
332
+ return { type, ttlMs: item.ttlMs === '-1' ? '-1' : unsignedIntegerAt(item.ttlMs), length: item.length === null ? null : unsignedIntegerAt(item.length) };
333
+ }
334
+ function identityAt(value) {
335
+ const item = objectAt(value, ['base64', 'byteLength', 'label']);
336
+ const base64 = byteStringAt(item.base64, MAX_KEY_BYTES), byteLength = integerAt(item.byteLength, 0, MAX_KEY_BYTES);
337
+ if (atob(base64).length !== byteLength)
338
+ throw new TypeError('Redis RPC: invalid byte identity');
339
+ return { base64, byteLength, label: stringAt(item.label, 1024) };
340
+ }
341
+ export const scanKeysRequestSchema = { parse(value) {
342
+ const object = objectAt(value, ['target', 'pattern', 'cursor']);
343
+ const cursor = scanToken(object.cursor);
344
+ return { target: databaseTargetSchema.parse(object.target), pattern: stringAt(object.pattern, 256), cursor };
345
+ } };
346
+ export const scanKeysResultSchema = { parse(value) {
347
+ const object = objectAt(value, ['state', 'error', 'keys', 'cursor', 'sampledAt']);
348
+ const error = errorAt(object.error);
349
+ if ((object.state !== 'page' && object.state !== 'failed') || (object.state === 'page') !== (error === null))
350
+ throw new TypeError('Redis RPC: invalid scan state');
351
+ if (!Array.isArray(object.keys) || object.keys.length > MAX_SCAN_KEYS)
352
+ throw new TypeError('Redis RPC: invalid key list');
353
+ const keys = object.keys.map((value) => identityAt(value));
354
+ const cursor = scanToken(object.cursor);
355
+ const sampledAt = sampleTimeAt(object.sampledAt);
356
+ if (object.state === 'failed' && (keys.length !== 0 || cursor !== null))
357
+ throw new TypeError('Redis RPC: failed scan contains data');
358
+ const result = { state: object.state, error, keys, cursor, sampledAt };
359
+ if (new TextEncoder().encode(JSON.stringify(result)).length > MAX_SCAN_JSON_BYTES)
360
+ throw new TypeError('Redis RPC: scan budget exceeded');
361
+ return result;
362
+ } };
363
+ export const stringReadRequestSchema = { parse(value) {
364
+ const object = objectAt(value, ['target', 'keyBase64', 'offset', 'count']);
365
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), offset: unsignedIntegerAt(object.offset), count: integerAt(object.count, 1, MAX_VALUE_BYTES) };
366
+ } };
367
+ export const stringReadResultSchema = { parse(value) {
368
+ const object = objectAt(value, ['state', 'error', 'metadata', 'offset', 'base64', 'byteLength', 'prefix', 'suffix', 'complete', 'nextOffset', 'sampledAt']);
369
+ const state = object.state, error = errorAt(object.error);
370
+ if (state !== 'value' && state !== 'missing' && state !== 'unsupported' && state !== 'changed' && state !== 'failed')
371
+ throw new TypeError('Redis RPC: invalid value state');
372
+ if ((state === 'failed') !== (error !== null))
373
+ throw new TypeError('Redis RPC: invalid read error');
374
+ const metadata = metadataAt(object.metadata);
375
+ const offset = unsignedIntegerAt(object.offset), base64 = byteStringAt(object.base64, MAX_VALUE_BYTES);
376
+ const byteLength = integerAt(object.byteLength, 0, MAX_VALUE_BYTES), prefix = byteStringAt(object.prefix, 3), suffix = byteStringAt(object.suffix, 3);
377
+ if (atob(base64).length !== byteLength || typeof object.complete !== 'boolean')
378
+ throw new TypeError('Redis RPC: invalid byte window');
379
+ const nextOffset = object.nextOffset === null ? null : unsignedIntegerAt(object.nextOffset);
380
+ if (state === 'value') {
381
+ if (metadata?.type !== 'string' || metadata.length === null)
382
+ throw new TypeError('Redis RPC: missing String metadata');
383
+ const end = BigInt(offset) + BigInt(byteLength), length = BigInt(metadata.length);
384
+ if (byteLength > 0 && end > length)
385
+ throw new TypeError('Redis RPC: window past EOF');
386
+ if (BigInt(atob(prefix).length) > (BigInt(offset) < 3n ? BigInt(offset) : 3n) || BigInt(atob(suffix).length) > (length > end ? length - end : 0n))
387
+ throw new TypeError('Redis RPC: context past value boundary');
388
+ if (object.complete !== (offset === '0' && BigInt(byteLength) === length) || nextOffset !== (byteLength > 0 && end < length ? String(end) : null))
389
+ throw new TypeError('Redis RPC: invalid completeness');
390
+ }
391
+ else {
392
+ if (base64 !== '' || byteLength !== 0 || prefix !== '' || suffix !== '' || object.complete || nextOffset !== null)
393
+ throw new TypeError('Redis RPC: non-value response contains bytes');
394
+ if (state === 'unsupported' ? metadata === null || metadata.type === 'string' || metadata.type === 'none' || metadata.length !== null : metadata !== null)
395
+ throw new TypeError('Redis RPC: invalid non-value metadata');
396
+ }
397
+ return { state, error, metadata, offset, base64, byteLength, prefix, suffix, complete: object.complete, nextOffset, sampledAt: sampleTimeAt(object.sampledAt) };
398
+ } };
399
+ export const scanHashRequestSchema = { parse(value) {
400
+ const object = objectAt(value, ['target', 'keyBase64', 'pattern', 'cursor']);
401
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), pattern: stringAt(object.pattern, 256), cursor: scanToken(object.cursor) };
402
+ } };
403
+ function bytePrefixAt(value) {
404
+ const object = objectAt(value, ['base64', 'byteLength', 'fullByteLength', 'suffix']);
405
+ const base64 = byteStringAt(object.base64, MAX_VALUE_BYTES), suffix = byteStringAt(object.suffix, 3);
406
+ const byteLength = integerAt(object.byteLength, 0, MAX_VALUE_BYTES), fullByteLength = integerAt(object.fullByteLength, 0, MAX_SCAN_JSON_BYTES);
407
+ if (atob(base64).length !== byteLength || byteLength !== Math.min(fullByteLength, MAX_VALUE_BYTES) || atob(suffix).length !== Math.min(3, fullByteLength - byteLength))
408
+ throw new TypeError('Redis RPC: invalid Hash value prefix');
409
+ return { base64, byteLength, fullByteLength, suffix };
410
+ }
411
+ export const hashFieldReadRequestSchema = { parse(value) {
412
+ const object = objectAt(value, ['target', 'keyBase64', 'fieldBase64']);
413
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), fieldBase64: byteStringAt(object.fieldBase64, MAX_KEY_BYTES) };
414
+ } };
415
+ export const actionPointReadResultSchema = { parse(value) {
416
+ const object = objectAt(value, ['state', 'error', 'cell', 'score', 'streamMessage', 'sampledAt']);
417
+ const state = object.state, error = errorAt(object.error);
418
+ if (state !== 'value' && state !== 'selection-missing' && state !== 'missing' && state !== 'changed' && state !== 'failed')
419
+ throw new TypeError('Redis RPC: invalid action point state');
420
+ if ((state === 'failed') !== (error !== null) || (state === 'value') !== (object.cell !== null))
421
+ throw new TypeError('Redis RPC: invalid action point result');
422
+ const cell = object.cell === null ? null : bytePrefixAt(object.cell);
423
+ const score = object.score === null ? null : stringAt(object.score, 128);
424
+ if (score !== null && (state !== 'value' || !isRedisScore(score)))
425
+ throw new TypeError('Redis RPC: invalid action point score');
426
+ const streamMessage = object.streamMessage === null ? null : (() => {
427
+ const raw = objectAt(object.streamMessage, ['id', 'fields']), id = stringAt(raw.id, 41);
428
+ if (!isStreamId(id) || id === '0-0' || !Array.isArray(raw.fields) || raw.fields.length === 0 || raw.fields.length > MAX_SCAN_KEYS)
429
+ throw new TypeError('Redis RPC: invalid point Stream message');
430
+ return { id, fields: raw.fields.map((value) => { const pair = objectAt(value, ['field', 'value']); return { field: identityAt(pair.field), value: bytePrefixAt(pair.value) }; }) };
431
+ })();
432
+ if (streamMessage !== null && (state !== 'value' || score !== null))
433
+ throw new TypeError('Redis RPC: invalid point Stream state');
434
+ const result = { state, error, cell, score, streamMessage, sampledAt: sampleTimeAt(object.sampledAt) };
435
+ if (new TextEncoder().encode(JSON.stringify(result)).length > MAX_SCAN_JSON_BYTES)
436
+ throw new TypeError('Redis RPC: point result budget exceeded');
437
+ return result;
438
+ } };
439
+ export const scanHashResultSchema = { parse(value) {
440
+ const object = objectAt(value, ['state', 'error', 'metadata', 'entries', 'cursor', 'sampledAt']);
441
+ const state = object.state, error = errorAt(object.error), metadata = metadataAt(object.metadata);
442
+ if (state !== 'page' && state !== 'missing' && state !== 'unsupported' && state !== 'changed' && state !== 'failed')
443
+ throw new TypeError('Redis RPC: invalid Hash state');
444
+ if ((state === 'failed') !== (error !== null) || !Array.isArray(object.entries) || object.entries.length > MAX_SCAN_KEYS)
445
+ throw new TypeError('Redis RPC: invalid Hash result');
446
+ const entries = object.entries.map((value) => {
447
+ const item = objectAt(value, ['field', 'value']);
448
+ return { field: identityAt(item.field), value: bytePrefixAt(item.value) };
449
+ });
450
+ const cursor = scanToken(object.cursor), sampledAt = sampleTimeAt(object.sampledAt);
451
+ if (state === 'page') {
452
+ if (metadata?.type !== 'hash' || metadata.length === null || BigInt(entries.length) > BigInt(metadata.length) || new Set(entries.map(entry => entry.field.base64)).size !== entries.length)
453
+ throw new TypeError('Redis RPC: invalid Hash page');
454
+ }
455
+ else {
456
+ if (entries.length !== 0 || cursor !== null)
457
+ throw new TypeError('Redis RPC: non-page contains Hash data');
458
+ if (state === 'unsupported' ? metadata === null || metadata.type === 'hash' || metadata.type === 'none' || metadata.length !== null : metadata !== null)
459
+ throw new TypeError('Redis RPC: invalid Hash metadata');
460
+ }
461
+ const result = { state, error, metadata, entries, cursor, sampledAt };
462
+ if (new TextEncoder().encode(JSON.stringify(result)).length > MAX_SCAN_JSON_BYTES)
463
+ throw new TypeError('Redis RPC: Hash result budget exceeded');
464
+ return result;
465
+ } };
466
+ export const listReadRequestSchema = { parse(value) {
467
+ const object = objectAt(value, ['target', 'keyBase64', 'offset', 'count']);
468
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), offset: unsignedIntegerAt(object.offset), count: integerAt(object.count, 1, MAX_LIST_ITEMS) };
469
+ } };
470
+ export const listReadResultSchema = { parse(value) {
471
+ const object = objectAt(value, ['state', 'error', 'metadata', 'entries', 'offset', 'nextOffset', 'sampledAt']);
472
+ const state = object.state, error = errorAt(object.error), metadata = metadataAt(object.metadata);
473
+ if (state !== 'page' && state !== 'missing' && state !== 'unsupported' && state !== 'changed' && state !== 'failed')
474
+ throw new TypeError('Redis RPC: invalid List state');
475
+ if ((state === 'failed') !== (error !== null) || !Array.isArray(object.entries) || object.entries.length > MAX_LIST_ITEMS)
476
+ throw new TypeError('Redis RPC: invalid List result');
477
+ const offset = unsignedIntegerAt(object.offset), nextOffset = object.nextOffset === null ? null : unsignedIntegerAt(object.nextOffset);
478
+ const entries = object.entries.map((value) => {
479
+ const item = objectAt(value, ['index', 'value']);
480
+ return { index: unsignedIntegerAt(item.index), value: bytePrefixAt(item.value) };
481
+ });
482
+ if (state === 'page') {
483
+ if (metadata?.type !== 'list' || metadata.length === null || entries.some((entry, index) => BigInt(entry.index) !== BigInt(offset) + BigInt(index)))
484
+ throw new TypeError('Redis RPC: invalid List positions');
485
+ const end = BigInt(offset) + BigInt(entries.length), length = BigInt(metadata.length);
486
+ if ((entries.length > 0 && end > length) || (entries.length === 0 && BigInt(offset) < length) || nextOffset !== (entries.length > 0 && end < length ? String(end) : null))
487
+ throw new TypeError('Redis RPC: invalid List continuation');
488
+ }
489
+ else {
490
+ if (entries.length !== 0 || nextOffset !== null)
491
+ throw new TypeError('Redis RPC: non-page contains List rows');
492
+ if (state === 'unsupported' ? metadata === null || metadata.type === 'list' || metadata.type === 'none' || metadata.length !== null : metadata !== null)
493
+ throw new TypeError('Redis RPC: invalid List metadata');
494
+ }
495
+ const result = { state, error, metadata, entries, offset, nextOffset, sampledAt: sampleTimeAt(object.sampledAt) };
496
+ if (new TextEncoder().encode(JSON.stringify(result)).length > MAX_SCAN_JSON_BYTES)
497
+ throw new TypeError('Redis RPC: List result budget exceeded');
498
+ return result;
499
+ } };
500
+ export const scanSetRequestSchema = { parse(value) {
501
+ const object = objectAt(value, ['target', 'keyBase64', 'pattern', 'cursor']);
502
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), pattern: stringAt(object.pattern, 256), cursor: scanToken(object.cursor) };
503
+ } };
504
+ export const setMemberReadRequestSchema = { parse(value) {
505
+ const object = objectAt(value, ['target', 'keyBase64', 'memberBase64']);
506
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), memberBase64: byteStringAt(object.memberBase64, MAX_KEY_BYTES) };
507
+ } };
508
+ export const scanSetResultSchema = { parse(value) {
509
+ const object = objectAt(value, ['state', 'error', 'metadata', 'members', 'cursor', 'sampledAt']);
510
+ const state = object.state, error = errorAt(object.error), metadata = metadataAt(object.metadata);
511
+ if (state !== 'page' && state !== 'missing' && state !== 'unsupported' && state !== 'changed' && state !== 'failed')
512
+ throw new TypeError('Redis RPC: invalid Set state');
513
+ if ((state === 'failed') !== (error !== null) || !Array.isArray(object.members) || object.members.length > MAX_SCAN_KEYS)
514
+ throw new TypeError('Redis RPC: invalid Set result');
515
+ const members = object.members.map((value) => identityAt(value)), cursor = scanToken(object.cursor);
516
+ if (state === 'page') {
517
+ if (metadata?.type !== 'set' || metadata.length === null || BigInt(members.length) > BigInt(metadata.length) || new Set(members.map(member => member.base64)).size !== members.length)
518
+ throw new TypeError('Redis RPC: invalid Set page');
519
+ }
520
+ else {
521
+ if (members.length !== 0 || cursor !== null)
522
+ throw new TypeError('Redis RPC: non-page contains Set members');
523
+ if (state === 'unsupported' ? metadata === null || metadata.type === 'set' || metadata.type === 'none' || metadata.length !== null : metadata !== null)
524
+ throw new TypeError('Redis RPC: invalid Set metadata');
525
+ }
526
+ const result = { state, error, metadata, members, cursor, sampledAt: sampleTimeAt(object.sampledAt) };
527
+ if (new TextEncoder().encode(JSON.stringify(result)).length > MAX_SCAN_JSON_BYTES)
528
+ throw new TypeError('Redis RPC: Set result budget exceeded');
529
+ return result;
530
+ } };
531
+ export const zsetReadRequestSchema = { parse(value) {
532
+ const mode = objectAt(value, ['target', 'keyBase64', 'mode', 'offset', 'count', 'pattern', 'cursor']).mode;
533
+ if (mode === 'range') {
534
+ const object = objectAt(value, ['target', 'keyBase64', 'mode', 'offset', 'count']);
535
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), mode, offset: unsignedIntegerAt(object.offset), count: integerAt(object.count, 1, MAX_LIST_ITEMS) };
536
+ }
537
+ if (mode !== 'scan')
538
+ throw new TypeError('Redis RPC: invalid ZSet mode');
539
+ const object = objectAt(value, ['target', 'keyBase64', 'mode', 'pattern', 'cursor']);
540
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), mode, pattern: stringAt(object.pattern, 256), cursor: scanToken(object.cursor) };
541
+ } };
542
+ export const zsetReadResultSchema = { parse(value) {
543
+ const object = objectAt(value, ['state', 'error', 'metadata', 'mode', 'entries', 'offset', 'nextOffset', 'cursor', 'sampledAt']);
544
+ const state = object.state, mode = object.mode, error = errorAt(object.error), metadata = metadataAt(object.metadata);
545
+ if (state !== 'page' && state !== 'missing' && state !== 'unsupported' && state !== 'changed' && state !== 'failed')
546
+ throw new TypeError('Redis RPC: invalid ZSet state');
547
+ if (mode !== 'range' && mode !== 'scan')
548
+ throw new TypeError('Redis RPC: invalid ZSet mode');
549
+ if ((state === 'failed') !== (error !== null) || !Array.isArray(object.entries) || object.entries.length > (mode === 'range' ? MAX_LIST_ITEMS : MAX_SCAN_KEYS))
550
+ throw new TypeError('Redis RPC: invalid ZSet rows');
551
+ const entries = object.entries.map((value) => {
552
+ const item = objectAt(value, ['member', 'score', 'rank']), score = stringAt(item.score, 128);
553
+ if (!isRedisScore(score))
554
+ throw new TypeError('Redis RPC: invalid score');
555
+ return { member: identityAt(item.member), score, rank: item.rank === null ? null : unsignedIntegerAt(item.rank) };
556
+ });
557
+ const offset = object.offset === null ? null : unsignedIntegerAt(object.offset), nextOffset = object.nextOffset === null ? null : unsignedIntegerAt(object.nextOffset), cursor = scanToken(object.cursor);
558
+ if (mode === 'range' ? offset === null || cursor !== null || entries.some((entry, index) => entry.rank !== String(BigInt(offset) + BigInt(index))) : offset !== null || nextOffset !== null || entries.some(entry => entry.rank !== null))
559
+ throw new TypeError('Redis RPC: mixed ZSet paging modes');
560
+ if (state === 'page') {
561
+ if (metadata?.type !== 'zset' || metadata.length === null || BigInt(entries.length) > BigInt(metadata.length) || new Set(entries.map(entry => entry.member.base64)).size !== entries.length)
562
+ throw new TypeError('Redis RPC: invalid ZSet metadata');
563
+ if (mode === 'range' && offset !== null) {
564
+ const end = BigInt(offset) + BigInt(entries.length), length = BigInt(metadata.length);
565
+ if ((entries.length > 0 && end > length) || (entries.length === 0 && BigInt(offset) < length) || nextOffset !== (entries.length > 0 && end < length ? String(end) : null))
566
+ throw new TypeError('Redis RPC: invalid ZSet range');
567
+ }
568
+ }
569
+ else {
570
+ if (entries.length !== 0 || nextOffset !== null || cursor !== null)
571
+ throw new TypeError('Redis RPC: non-page contains ZSet rows');
572
+ if (state === 'unsupported' ? metadata === null || metadata.type === 'zset' || metadata.type === 'none' || metadata.length !== null : metadata !== null)
573
+ throw new TypeError('Redis RPC: invalid ZSet metadata');
574
+ }
575
+ const result = { state, error, metadata, mode, entries, offset, nextOffset, cursor, sampledAt: sampleTimeAt(object.sampledAt) };
576
+ if (new TextEncoder().encode(JSON.stringify(result)).length > MAX_SCAN_JSON_BYTES)
577
+ throw new TypeError('Redis RPC: ZSet result budget exceeded');
578
+ return result;
579
+ } };
580
+ function streamRangeAt(object) {
581
+ const direction = object.direction, start = stringAt(object.start, 41), end = stringAt(object.end, 41);
582
+ if ((direction !== 'forward' && direction !== 'reverse') || !isStreamRange(start, end))
583
+ throw new TypeError('Redis RPC: invalid Stream range');
584
+ return { direction, start, end };
585
+ }
586
+ export const streamReadRequestSchema = { parse(value) {
587
+ const object = objectAt(value, ['target', 'keyBase64', 'direction', 'start', 'end', 'count', 'cursor']);
588
+ return { target: databaseTargetSchema.parse(object.target), keyBase64: byteStringAt(object.keyBase64, MAX_KEY_BYTES), ...streamRangeAt(object), count: integerAt(object.count, 1, MAX_STREAM_MESSAGES), cursor: scanToken(object.cursor) };
589
+ } };
590
+ export const streamReadResultSchema = { parse(value) {
591
+ const object = objectAt(value, ['state', 'error', 'metadata', 'direction', 'start', 'end', 'messages', 'cursor', 'sampledAt']);
592
+ const state = object.state, error = errorAt(object.error), metadata = metadataAt(object.metadata), range = streamRangeAt(object);
593
+ if (state !== 'page' && state !== 'missing' && state !== 'unsupported' && state !== 'changed' && state !== 'failed')
594
+ throw new TypeError('Redis RPC: invalid Stream state');
595
+ if ((state === 'failed') !== (error !== null) || !Array.isArray(object.messages) || object.messages.length > MAX_STREAM_MESSAGES)
596
+ throw new TypeError('Redis RPC: invalid Stream result');
597
+ let previous = null, fields = 0;
598
+ const messages = object.messages.map((value) => {
599
+ const item = objectAt(value, ['id', 'fields']), id = stringAt(item.id, 41);
600
+ if (!isStreamId(id) || id === '0-0' || !withinStreamRange(id, range.start, range.end) || (previous !== null && (range.direction === 'forward' ? compareStreamIds(id, previous) <= 0 : compareStreamIds(id, previous) >= 0)) || !Array.isArray(item.fields) || item.fields.length === 0)
601
+ throw new TypeError('Redis RPC: invalid Stream message');
602
+ previous = id;
603
+ fields += item.fields.length;
604
+ if (fields > MAX_SCAN_KEYS)
605
+ throw new TypeError('Redis RPC: Stream fields exceeded');
606
+ return { id, fields: item.fields.map((value) => { const pair = objectAt(value, ['field', 'value']); return { field: identityAt(pair.field), value: bytePrefixAt(pair.value) }; }) };
607
+ });
608
+ const cursor = scanToken(object.cursor);
609
+ if (state === 'page') {
610
+ if (metadata?.type !== 'stream' || metadata.length === null || BigInt(messages.length) > BigInt(metadata.length) || (messages.length === 0 && cursor !== null))
611
+ throw new TypeError('Redis RPC: invalid Stream metadata');
612
+ }
613
+ else {
614
+ if (messages.length !== 0 || cursor !== null)
615
+ throw new TypeError('Redis RPC: non-page contains Stream data');
616
+ if (state === 'unsupported' ? metadata === null || metadata.type === 'stream' || metadata.type === 'none' || metadata.length !== null : metadata !== null)
617
+ throw new TypeError('Redis RPC: invalid Stream metadata');
618
+ }
619
+ const result = { state, error, metadata, ...range, messages, cursor, sampledAt: sampleTimeAt(object.sampledAt) };
620
+ if (new TextEncoder().encode(JSON.stringify(result)).length > MAX_SCAN_JSON_BYTES)
621
+ throw new TypeError('Redis RPC: Stream result budget exceeded');
622
+ return result;
623
+ } };
624
+ export const databasesReadRequestSchema = { parse(value) {
625
+ const object = objectAt(value, ['target']);
626
+ return { target: databaseTargetSchema.parse(object.target) };
627
+ } };
628
+ export const databasesReadResultSchema = { parse(value) {
629
+ const object = objectAt(value, ['state', 'error', 'catalog', 'sampledAt']), state = object.state, error = errorAt(object.error);
630
+ if ((state !== 'value' && state !== 'failed') || (state === 'value') !== (error === null) || (state === 'value') !== (object.catalog !== null))
631
+ throw new TypeError('Redis RPC: invalid database state');
632
+ const catalog = object.catalog === null ? null : (() => {
633
+ const raw = objectAt(object.catalog, ['databaseCount', 'keyspace', 'currentKeys']);
634
+ const databaseCount = raw.databaseCount === null ? null : integerAt(raw.databaseCount, 1, 65536);
635
+ if (raw.keyspace !== null && (!Array.isArray(raw.keyspace) || raw.keyspace.length > MAX_DATABASE_ENTRIES))
636
+ throw new TypeError('Redis RPC: invalid database counts');
637
+ const seen = new Set();
638
+ const keyspace = raw.keyspace === null ? null : raw.keyspace.map(value => {
639
+ const row = objectAt(value, ['db', 'keys']), db = integerAt(row.db, 0, databaseCount === null ? 65535 : databaseCount - 1);
640
+ if (seen.has(db))
641
+ throw new TypeError('Redis RPC: duplicate database');
642
+ seen.add(db);
643
+ return { db, keys: unsignedIntegerAt(row.keys) };
644
+ });
645
+ return { databaseCount, keyspace, currentKeys: raw.currentKeys === null ? null : unsignedIntegerAt(raw.currentKeys) };
646
+ })();
647
+ return { state, error, catalog, sampledAt: sampleTimeAt(object.sampledAt) };
648
+ } };
649
+ function selectionAt(value) {
650
+ if (value === null)
651
+ return null;
652
+ const record = objectAt(value, ['keyBase64', 'item']);
653
+ let item = null;
654
+ if (record.item !== null) {
655
+ if (record.item === null || typeof record.item !== 'object' || Array.isArray(record.item))
656
+ throw new TypeError('Redis RPC: invalid selection');
657
+ const kind = Reflect.get(record.item, 'kind');
658
+ if (kind === 'hash') {
659
+ const raw = objectAt(record.item, ['kind', 'fieldBase64']);
660
+ item = { kind, fieldBase64: byteStringAt(raw.fieldBase64, MAX_KEY_BYTES) };
661
+ }
662
+ else if (kind === 'list') {
663
+ const raw = objectAt(record.item, ['kind', 'index']);
664
+ item = { kind, index: unsignedIntegerAt(raw.index) };
665
+ }
666
+ else if (kind === 'set' || kind === 'zset') {
667
+ const raw = objectAt(record.item, ['kind', 'memberBase64']);
668
+ item = { kind, memberBase64: byteStringAt(raw.memberBase64, MAX_KEY_BYTES) };
669
+ }
670
+ else if (kind === 'stream') {
671
+ const raw = objectAt(record.item, ['kind', 'id', 'fieldIndex', 'fieldBase64']), id = stringAt(raw.id, 41);
672
+ if (!isStreamId(id) || id === '0-0')
673
+ throw new TypeError('Redis RPC: invalid selected message');
674
+ item = { kind, id, fieldIndex: integerAt(raw.fieldIndex, 0, MAX_SCAN_KEYS - 1), fieldBase64: byteStringAt(raw.fieldBase64, MAX_KEY_BYTES) };
675
+ }
676
+ else
677
+ throw new TypeError('Redis RPC: invalid selected type');
678
+ }
679
+ return { keyBase64: byteStringAt(record.keyBase64, MAX_KEY_BYTES), item };
680
+ }
681
+ export const setSelectionRequestSchema = { parse(value) {
682
+ const raw = objectAt(value, ['target', 'selection']);
683
+ return { target: databaseTargetSchema.parse(raw.target), selection: selectionAt(raw.selection) };
684
+ } };
685
+ export const selectionAckSchema = { parse(value) {
686
+ const raw = objectAt(value, ['accepted']);
687
+ if (typeof raw.accepted !== 'boolean')
688
+ throw new TypeError('Redis RPC: invalid selection acknowledgement');
689
+ return { accepted: raw.accepted };
690
+ } };
691
+ export const aiBudgetStatusSchema = { parse(value) {
692
+ const raw = objectAt(value, ['callsUsed', 'maxCalls', 'bytesUsed', 'maxBytes', 'inFlight', 'stopped']);
693
+ const maxCalls = integerAt(raw.maxCalls, 1, Number.MAX_SAFE_INTEGER), maxBytes = integerAt(raw.maxBytes, 1, Number.MAX_SAFE_INTEGER);
694
+ const callsUsed = integerAt(raw.callsUsed, 0, maxCalls), bytesUsed = integerAt(raw.bytesUsed, 0, maxBytes), inFlight = integerAt(raw.inFlight, 0, callsUsed);
695
+ if (typeof raw.stopped !== 'boolean')
696
+ throw new TypeError('Redis RPC: invalid AI budget');
697
+ return { callsUsed, maxCalls, bytesUsed, maxBytes, inFlight, stopped: raw.stopped };
698
+ } };
699
+ export const aiBudgetResumeSchema = { parse(value) {
700
+ const raw = objectAt(value, ['accepted', 'status']);
701
+ if (typeof raw.accepted !== 'boolean')
702
+ throw new TypeError('Redis RPC: invalid AI budget acknowledgement');
703
+ return { accepted: raw.accepted, status: aiBudgetStatusSchema.parse(raw.status) };
704
+ } };
705
+ /** The Client uses the parsers directly; the Host adapts them to the registry's Zod codecs. */
706
+ export function createRedisDescriptors(adapt) {
707
+ const session = adapt(sessionIdSchema);
708
+ const direct = (method, inputSymbol, resultSymbol, input, result) => createRedisInvocation(method, inputSymbol, resultSymbol, adapt(input), adapt(result), session);
709
+ return [
710
+ direct('status', 'EmptyRequest', 'RedisHostStatus', emptyRequestSchema, statusSchema),
711
+ direct('connect', 'ConnectionRequest', 'ConnectionView', connectionRequestSchema, connectionViewSchema),
712
+ direct('disconnect', 'ConnectionTarget', 'ConnectionView', connectionTargetSchema, connectionViewSchema),
713
+ direct('connectionStatus', 'EmptyRequest', 'ConnectionView', emptyRequestSchema, connectionViewSchema),
714
+ direct('writeModeStatus', 'EmptyRequest', 'RedisWriteModeStatus', emptyRequestSchema, writeModeStatusSchema),
715
+ direct('setWriteMode', 'RedisWriteModeRequest', 'RedisWriteModeStatus', writeModeRequestSchema, writeModeStatusSchema),
716
+ direct('writeLookup', 'RedisWriteLookupRequest', 'RedisWriteLookupResult', writeLookupRequestSchema, writeLookupResultSchema),
717
+ direct('listProfiles', 'EmptyRequest', 'ProfileCollection', emptyRequestSchema, profileCollectionSchema),
718
+ direct('saveProfile', 'SaveProfileRequest', 'ProfileCollection', saveProfileSchema, profileCollectionSchema),
719
+ direct('removeProfile', 'ProfileId', 'ProfileCollection', profileIdSchema, profileCollectionSchema),
720
+ direct('selectDatabase', 'DatabaseTarget', 'ConnectionView', databaseTargetSchema, connectionViewSchema),
721
+ direct('scanKeys', 'ScanKeysRequest', 'ScanKeysResult', scanKeysRequestSchema, scanKeysResultSchema),
722
+ direct('readString', 'StringReadRequest', 'StringReadResult', stringReadRequestSchema, stringReadResultSchema),
723
+ direct('scanHash', 'ScanHashRequest', 'ScanHashResult', scanHashRequestSchema, scanHashResultSchema),
724
+ direct('readActionPoint', 'ActionPointReadRequest', 'ActionPointReadResult', actionPointReadRequestSchema, actionPointReadResultSchema),
725
+ direct('readList', 'ListReadRequest', 'ListReadResult', listReadRequestSchema, listReadResultSchema),
726
+ direct('scanSet', 'ScanSetRequest', 'ScanSetResult', scanSetRequestSchema, scanSetResultSchema),
727
+ direct('readZSet', 'ZSetReadRequest', 'ZSetReadResult', zsetReadRequestSchema, zsetReadResultSchema),
728
+ direct('readStream', 'StreamReadRequest', 'StreamReadResult', streamReadRequestSchema, streamReadResultSchema),
729
+ direct('readDatabases', 'DatabasesReadRequest', 'DatabasesReadResult', databasesReadRequestSchema, databasesReadResultSchema),
730
+ direct('aiBudgetStatus', 'EmptyRequest', 'AiBudgetStatus', emptyRequestSchema, aiBudgetStatusSchema),
731
+ direct('resumeAiBudget', 'EmptyRequest', 'AiBudgetResume', emptyRequestSchema, aiBudgetResumeSchema),
732
+ createRedisUiStreamInvocation(adapt(emptyRequestSchema), adapt(uiChannelMessageSchema), adapt(uiChannelInputSchema), session),
733
+ ];
734
+ }
735
+ export const redisDescriptors = createRedisDescriptors(schema => schema);