@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.
- package/LICENSE +21 -0
- package/README.md +184 -2
- package/README.zh.md +185 -0
- package/cordis.patch.yml +4 -0
- package/icon.svg +1 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client.js +7684 -0
- package/lib/connection-errors.d.ts +66 -0
- package/lib/connection-errors.js +21 -0
- package/lib/domain.d.ts +451 -0
- package/lib/domain.js +20 -0
- package/lib/host/ai-answer.d.ts +7 -0
- package/lib/host/ai-answer.js +132 -0
- package/lib/host/ai-budget.d.ts +43 -0
- package/lib/host/ai-budget.js +78 -0
- package/lib/host/ai-connection-tools.d.ts +8 -0
- package/lib/host/ai-connection-tools.js +49 -0
- package/lib/host/ai-hash-filter.d.ts +13 -0
- package/lib/host/ai-hash-filter.js +97 -0
- package/lib/host/ai-hash-pages.d.ts +15 -0
- package/lib/host/ai-hash-pages.js +42 -0
- package/lib/host/ai-key-pages.d.ts +14 -0
- package/lib/host/ai-key-pages.js +27 -0
- package/lib/host/ai-locate-tool.d.ts +6 -0
- package/lib/host/ai-locate-tool.js +234 -0
- package/lib/host/ai-match-tools.d.ts +7 -0
- package/lib/host/ai-match-tools.js +112 -0
- package/lib/host/ai-page-coordinator.d.ts +21 -0
- package/lib/host/ai-page-coordinator.js +81 -0
- package/lib/host/ai-page-store.d.ts +40 -0
- package/lib/host/ai-page-store.js +104 -0
- package/lib/host/ai-profile-tools.d.ts +7 -0
- package/lib/host/ai-profile-tools.js +44 -0
- package/lib/host/ai-query-scope.d.ts +42 -0
- package/lib/host/ai-query-scope.js +104 -0
- package/lib/host/ai-reader.d.ts +219 -0
- package/lib/host/ai-reader.js +1221 -0
- package/lib/host/ai-report-samples.d.ts +26 -0
- package/lib/host/ai-report-samples.js +77 -0
- package/lib/host/ai-report-tools.d.ts +11 -0
- package/lib/host/ai-report-tools.js +70 -0
- package/lib/host/ai-set-pages.d.ts +15 -0
- package/lib/host/ai-set-pages.js +40 -0
- package/lib/host/ai-stream-pages.d.ts +15 -0
- package/lib/host/ai-stream-pages.js +42 -0
- package/lib/host/ai-tools.d.ts +4 -0
- package/lib/host/ai-tools.js +106 -0
- package/lib/host/ai-ui-tools.d.ts +10 -0
- package/lib/host/ai-ui-tools.js +72 -0
- package/lib/host/ai-value.d.ts +12 -0
- package/lib/host/ai-value.js +15 -0
- package/lib/host/ai-write-tools.d.ts +5 -0
- package/lib/host/ai-write-tools.js +101 -0
- package/lib/host/ai-writer.d.ts +25 -0
- package/lib/host/ai-writer.js +77 -0
- package/lib/host/ai-zset-pages.d.ts +15 -0
- package/lib/host/ai-zset-pages.js +40 -0
- package/lib/host/byte-identity.d.ts +3 -0
- package/lib/host/byte-identity.js +12 -0
- package/lib/host/client-list.d.ts +13 -0
- package/lib/host/client-list.js +35 -0
- package/lib/host/connection-service.d.ts +71 -0
- package/lib/host/connection-service.js +468 -0
- package/lib/host/database-reader.d.ts +10 -0
- package/lib/host/database-reader.js +62 -0
- package/lib/host/hash-reader.d.ts +12 -0
- package/lib/host/hash-reader.js +91 -0
- package/lib/host/key-reader.d.ts +20 -0
- package/lib/host/key-reader.js +65 -0
- package/lib/host/list-reader.d.ts +8 -0
- package/lib/host/list-reader.js +61 -0
- package/lib/host/match-preset-store.d.ts +36 -0
- package/lib/host/match-preset-store.js +201 -0
- package/lib/host/profile-snapshots.d.ts +32 -0
- package/lib/host/profile-snapshots.js +187 -0
- package/lib/host/profile-store.d.ts +15 -0
- package/lib/host/profile-store.js +120 -0
- package/lib/host/read-context.d.ts +23 -0
- package/lib/host/read-context.js +41 -0
- package/lib/host/redis-transport.d.ts +34 -0
- package/lib/host/redis-transport.js +262 -0
- package/lib/host/redis-write-transaction.d.ts +28 -0
- package/lib/host/redis-write-transaction.js +180 -0
- package/lib/host/resp.d.ts +38 -0
- package/lib/host/resp.js +174 -0
- package/lib/host/scan-cursors.d.ts +25 -0
- package/lib/host/scan-cursors.js +59 -0
- package/lib/host/selected-reader.d.ts +22 -0
- package/lib/host/selected-reader.js +84 -0
- package/lib/host/set-reader.d.ts +12 -0
- package/lib/host/set-reader.js +85 -0
- package/lib/host/stream-groups.d.ts +17 -0
- package/lib/host/stream-groups.js +42 -0
- package/lib/host/stream-reader.d.ts +12 -0
- package/lib/host/stream-reader.js +105 -0
- package/lib/host/string-reader.d.ts +9 -0
- package/lib/host/string-reader.js +81 -0
- package/lib/host/ui-action-channel.d.ts +4 -0
- package/lib/host/ui-action-channel.js +182 -0
- package/lib/host/ui-action-coordinator.d.ts +28 -0
- package/lib/host/ui-action-coordinator.js +188 -0
- package/lib/host/value-prefix.d.ts +5 -0
- package/lib/host/value-prefix.js +11 -0
- package/lib/host/write-bytes.d.ts +3 -0
- package/lib/host/write-bytes.js +9 -0
- package/lib/host/write-history.d.ts +18 -0
- package/lib/host/write-history.js +79 -0
- package/lib/host/write-proposals.d.ts +46 -0
- package/lib/host/write-proposals.js +132 -0
- package/lib/host/zset-reader.d.ts +12 -0
- package/lib/host/zset-reader.js +103 -0
- package/lib/host/zset-values.d.ts +6 -0
- package/lib/host/zset-values.js +26 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +5 -0
- package/lib/redis-answer.d.ts +32 -0
- package/lib/redis-answer.js +215 -0
- package/lib/redis-databases.d.ts +3 -0
- package/lib/redis-databases.js +21 -0
- package/lib/redis-read-tools.d.ts +2 -0
- package/lib/redis-read-tools.js +7 -0
- package/lib/redis-result.d.ts +4 -0
- package/lib/redis-result.js +18 -0
- package/lib/redis-score.d.ts +2 -0
- package/lib/redis-score.js +6 -0
- package/lib/remote-service.d.ts +69 -0
- package/lib/remote-service.js +187 -0
- package/lib/runtime.d.ts +3 -0
- package/lib/runtime.js +29 -0
- package/lib/stream-id.d.ts +7 -0
- package/lib/stream-id.js +19 -0
- package/lib/typert.host.d.ts +13 -0
- package/lib/typert.host.js +7 -0
- package/lib/typert.remote-client.d.ts +98 -0
- package/lib/typert.remote-client.js +3 -0
- package/lib/typert.shared.d.ts +62 -0
- package/lib/typert.shared.js +735 -0
- package/lib/ui-action-selection.d.ts +3 -0
- package/lib/ui-action-selection.js +12 -0
- package/licenses/THIRD_PARTY_NOTICES.txt +9 -0
- package/licenses/deepseek-harness-MIT.txt +21 -0
- package/licenses/dsh-database-MIT.txt +21 -0
- package/licenses/dsh-git-graph-MIT.txt +21 -0
- package/licenses/lucide-react-LICENSE.txt +43 -0
- package/licenses/phosphor-icons-MIT.txt +21 -0
- package/package.json +132 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
import { MAX_PROFILES } from "../domain.js";
|
|
3
|
+
const PAGE_SIZE = 10;
|
|
4
|
+
/** Profile names are shared by the DSH profile; connection settings stay local. */
|
|
5
|
+
export function registerRedisProfileTools(ctx, reader, snapshots, list) {
|
|
6
|
+
ctx.effect(() => () => { snapshots.dispose(); }, 'redis profile snapshots');
|
|
7
|
+
ctx.on('session/disposed', session => { snapshots.disposeSession(session.id); });
|
|
8
|
+
ctx.tools.register(defineTool({
|
|
9
|
+
name: 'redis_viewer_profiles',
|
|
10
|
+
description: '仅在用户要求查看已有 Redis 连接资料时列出名称、分组、唯一 ID 和同一对话内有效的短期 snapshotToken。令牌有效期最多五分钟,同一资料重新列出后旧令牌失效;为 null 表示容量不足,稍后重试。每页最多 10 条,不返回连接设置中的地址、用户名、证书或凭据;名称和分组按用户保存的内容返回。不会连接 Redis。每页重新读取资料,翻页期间资料可能变化,不能把各页当作同一时刻的快照。',
|
|
11
|
+
parameters: { offset: { type: 'integer', description: '从 0 开始的资料位置;续页使用上次返回的 nextOffset。' } },
|
|
12
|
+
output: { schema: { type: 'json' }, render: (_args, value) => [{ type: 'text', text: JSON.stringify(value) }] },
|
|
13
|
+
finalizeContent: reader.finalizeDelivery,
|
|
14
|
+
async execute(args, exec) {
|
|
15
|
+
exec.signal.throwIfAborted();
|
|
16
|
+
const agent = exec.agent;
|
|
17
|
+
if (agent === undefined)
|
|
18
|
+
throw new Error('Redis 工具调用缺少有效的 DSH 对话身份。');
|
|
19
|
+
if (Object.keys(args).some(key => key !== 'offset'))
|
|
20
|
+
throw new Error('Redis 工具包含不支持的参数。');
|
|
21
|
+
const offset = args.offset ?? 0;
|
|
22
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || offset > MAX_PROFILES)
|
|
23
|
+
throw new Error('连接资料位置无效。');
|
|
24
|
+
return reader.withBudget(agent.session.id, exec.signal, async (stage) => {
|
|
25
|
+
const { profiles } = await list(agent, exec.signal);
|
|
26
|
+
exec.signal.throwIfAborted();
|
|
27
|
+
const selected = profiles.slice(offset, offset + PAGE_SIZE);
|
|
28
|
+
const prepared = snapshots.prepare(agent.session.id, selected);
|
|
29
|
+
let staged = false;
|
|
30
|
+
try {
|
|
31
|
+
const page = selected.map((profile, index) => ({ id: profile.id, name: profile.name, ...(profile.group === undefined ? {} : { group: profile.group }), snapshotToken: prepared.tokens[index] ?? null }));
|
|
32
|
+
const result = { profiles: page, total: profiles.length, nextOffset: offset + page.length < profiles.length ? offset + page.length : null, sampledAt: new Date().toISOString(), snapshot: false };
|
|
33
|
+
stage({ result, commit: prepared.commit, rollback: prepared.rollback });
|
|
34
|
+
staged = true;
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
if (!staged)
|
|
39
|
+
prepared.rollback();
|
|
40
|
+
}
|
|
41
|
+
}, exec);
|
|
42
|
+
},
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { type InferArgs, type ParameterSchemaSpec, type ToolExecution } from '@deepseek-ai/dsh-tools';
|
|
3
|
+
import type { DatabaseTarget } from '../domain.js';
|
|
4
|
+
import type { RedisAiReader } from './ai-reader.js';
|
|
5
|
+
export declare const keySearchParameters: {
|
|
6
|
+
readonly match: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly required: true;
|
|
9
|
+
};
|
|
10
|
+
readonly cursor: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const hashFilterParameters: {
|
|
15
|
+
readonly field: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
readonly required: true;
|
|
18
|
+
};
|
|
19
|
+
readonly equals: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
readonly required: true;
|
|
22
|
+
};
|
|
23
|
+
readonly match: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
readonly required: true;
|
|
26
|
+
};
|
|
27
|
+
readonly cursor: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Use the tool's own schema before presenting arguments for confirmation. */
|
|
32
|
+
export declare function parseQueryArgs<S extends ParameterSchemaSpec>(schema: S, value: unknown): InferArgs<S>;
|
|
33
|
+
interface QueryScope<T> {
|
|
34
|
+
readonly target: DatabaseTarget;
|
|
35
|
+
readonly conditions: Readonly<Record<string, string>> | null;
|
|
36
|
+
readonly data: T;
|
|
37
|
+
readonly sidebar?: true;
|
|
38
|
+
}
|
|
39
|
+
/** DSH owns policy and presentation; the plugin binds consent to this call and DB. */
|
|
40
|
+
export declare function registerQueryScope<T>(ctx: Context, reader: RedisAiReader, owns: (name: string) => boolean, prepare: (exec: ToolExecution, sessionId: string, signal: AbortSignal) => QueryScope<T> | Promise<QueryScope<T>>): (exec: ToolExecution) => T;
|
|
41
|
+
export declare function registerRedisQueryScope(ctx: Context, reader: RedisAiReader): (exec: ToolExecution) => void;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ToolArgsError, validateArgs } from '@deepseek-ai/dsh-tools';
|
|
2
|
+
import { scanKeysRequestSchema } from "../typert.shared.js";
|
|
3
|
+
import { MAX_AI_VALUE_BYTES } from "./ai-value.js";
|
|
4
|
+
export const keySearchParameters = { match: { type: 'string', required: true }, cursor: { type: 'string' } };
|
|
5
|
+
export const hashFilterParameters = { ...keySearchParameters, field: { type: 'string', required: true }, equals: { type: 'string', required: true } };
|
|
6
|
+
/** Use the tool's own schema before presenting arguments for confirmation. */
|
|
7
|
+
export function parseQueryArgs(schema, value) {
|
|
8
|
+
const errors = validateArgs(schema, value);
|
|
9
|
+
if (errors.length > 0)
|
|
10
|
+
throw new ToolArgsError(errors);
|
|
11
|
+
const args = value;
|
|
12
|
+
if (Object.keys(args).some(key => !Object.hasOwn(schema, key)))
|
|
13
|
+
throw new Error('Redis 工具包含不支持的参数。');
|
|
14
|
+
return args;
|
|
15
|
+
}
|
|
16
|
+
/** DSH owns policy and presentation; the plugin binds consent to this call and DB. */
|
|
17
|
+
export function registerQueryScope(ctx, reader, owns, prepare) {
|
|
18
|
+
const admitted = new Map();
|
|
19
|
+
const lifetime = new AbortController();
|
|
20
|
+
ctx.effect(() => () => { lifetime.abort(); admitted.clear(); }, 'redis query confirmations');
|
|
21
|
+
ctx.on('tools/result', exec => { admitted.delete(exec.token); });
|
|
22
|
+
ctx.on('tools/pre-execute', async (exec, next) => {
|
|
23
|
+
if (!owns(exec.name))
|
|
24
|
+
return next();
|
|
25
|
+
const signal = AbortSignal.any([exec.signal, lifetime.signal]);
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
const agent = exec.agent;
|
|
28
|
+
if (agent === undefined)
|
|
29
|
+
return { kind: 'deny', reason: 'Redis 工具调用缺少有效的 DSH 对话身份。' };
|
|
30
|
+
const before = reader.currentTarget(agent.session.id);
|
|
31
|
+
const decision = await next();
|
|
32
|
+
if (decision.kind === 'deny' || decision.kind === 'cancel')
|
|
33
|
+
return decision;
|
|
34
|
+
signal.throwIfAborted();
|
|
35
|
+
if (!reader.isCurrentTarget(agent.session.id, before))
|
|
36
|
+
return { kind: 'deny', reason: 'Redis 连接或 DB 已变化,请重新确认查询范围。' };
|
|
37
|
+
const scope = await prepare(exec, agent.session.id, signal);
|
|
38
|
+
const { target } = scope;
|
|
39
|
+
if (target.id !== before.id || target.generation !== before.generation || target.db !== before.db)
|
|
40
|
+
return { kind: 'deny', reason: 'Redis 连接或 DB 已变化,请重新确认查询范围。' };
|
|
41
|
+
let gate = decision;
|
|
42
|
+
if (scope.conditions !== null) {
|
|
43
|
+
const approval = ctx.get('approval');
|
|
44
|
+
if (approval === undefined)
|
|
45
|
+
return { kind: 'deny', reason: '无法确认 Redis 查询范围,请在可交互的 DSH 对话中重试。' };
|
|
46
|
+
const address = reader.connectionSnapshot(agent.session.id).target;
|
|
47
|
+
if (!reader.isCurrentTarget(agent.session.id, target) || address === null)
|
|
48
|
+
return { kind: 'deny', reason: 'Redis 连接或 DB 已变化,请重新确认查询范围。' };
|
|
49
|
+
const endpoint = JSON.stringify(address.host) + ':' + address.port + ' / DB ' + target.db;
|
|
50
|
+
const conditions = JSON.stringify(scope.conditions);
|
|
51
|
+
const en = scope.sidebar ? `Confirm Redis sidebar query scope: ${endpoint}\n${conditions}\nApplying this preset starts a sidebar SCAN that may traverse the entire current DB keyspace.` : `Confirm Redis query scope: ${endpoint}\n${conditions}\nSCAN may traverse the entire current DB keyspace. This authorizes this query and its matching continuation pages within the existing read budget; it is not a snapshot.`;
|
|
52
|
+
const zh = scope.sidebar ? `确认 Redis 侧栏查询范围:${endpoint}\n${conditions}\n应用该预设会启动侧栏 SCAN,可能遍历当前 DB 的整个键空间。` : `确认 Redis 查询范围:${endpoint}\n${conditions}\nSCAN 可能遍历当前 DB 的整个键空间。本次确认适用于该查询及条件不变的续页,仍受现有读取预算限制;结果不是快照。`;
|
|
53
|
+
const previous = decision.kind === 'ask' ? decision.displayReason : undefined;
|
|
54
|
+
const fallback = decision.kind === 'ask' ? previous?.en ?? decision.reason : undefined;
|
|
55
|
+
const include = (policy, scope) => policy === undefined ? scope : policy + '\n\n' + scope;
|
|
56
|
+
const displayReason = {
|
|
57
|
+
...Object.fromEntries(Object.entries(previous ?? {}).map(([locale, policy]) => [locale, include(policy, en)])),
|
|
58
|
+
en: include(fallback, en), zh: include(previous?.zh ?? fallback, zh),
|
|
59
|
+
};
|
|
60
|
+
if (decision.kind === 'ask') {
|
|
61
|
+
// Let DSH resolve the final Host decision after all policy wrappers.
|
|
62
|
+
gate = { ...decision, displayReason };
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const outcome = await approval.request({ agent, toolName: exec.name, callId: exec.callId, reason: 'Confirm Redis query scope', displayReason, signal });
|
|
66
|
+
if (outcome === 'cancelled')
|
|
67
|
+
return { kind: 'cancel' };
|
|
68
|
+
if (outcome === 'rejected')
|
|
69
|
+
return { kind: 'deny', reason: 'Redis 查询已被拒绝;未开始扫描。停止本次查询;仅在用户主动重新发起查询时再处理,不要重复请求确认或换工具绕过。' };
|
|
70
|
+
if (outcome !== 'allowed-once')
|
|
71
|
+
return { kind: 'deny', reason: 'Redis 查询确认服务不可用;未开始扫描。请检查 DSH 的交互确认通道,不要自动重试或改用其他工具。' };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
signal.throwIfAborted();
|
|
75
|
+
if (!reader.isCurrentTarget(agent.session.id, target))
|
|
76
|
+
return { kind: 'deny', reason: 'Redis 连接或 DB 已变化,请重新确认查询范围。' };
|
|
77
|
+
admitted.set(exec.token, scope);
|
|
78
|
+
return gate;
|
|
79
|
+
});
|
|
80
|
+
return (exec) => {
|
|
81
|
+
exec.signal.throwIfAborted();
|
|
82
|
+
const scope = admitted.get(exec.token);
|
|
83
|
+
// Run synchronously in the body too: an around-dispatch policy may await
|
|
84
|
+
// after pre-dispatch. A replaced connection must never inherit permission.
|
|
85
|
+
if (lifetime.signal.aborted || exec.agent === undefined || scope === undefined || !reader.isCurrentTarget(exec.agent.session.id, scope.target))
|
|
86
|
+
throw new Error('Redis 查询范围未确认或连接已变化,请重新发起查询。');
|
|
87
|
+
return scope.data;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function registerRedisQueryScope(ctx, reader) {
|
|
91
|
+
return registerQueryScope(ctx, reader, name => name === 'redis_viewer_keys' || name === 'redis_viewer_filter_hash', (exec, sessionId) => {
|
|
92
|
+
const filter = exec.name === 'redis_viewer_filter_hash' ? parseQueryArgs(hashFilterParameters, exec.arguments) : null;
|
|
93
|
+
const args = filter ?? parseQueryArgs(keySearchParameters, exec.arguments);
|
|
94
|
+
const target = reader.currentTarget(sessionId);
|
|
95
|
+
scanKeysRequestSchema.parse({ target, pattern: args.match, cursor: null });
|
|
96
|
+
const texts = filter === null ? [args.match] : [filter.match, filter.field, filter.equals];
|
|
97
|
+
if (texts.some(value => Buffer.from(value, 'utf8').toString('utf8') !== value))
|
|
98
|
+
throw new Error('查询条件包含无法无损编码的字符,请修正条件。');
|
|
99
|
+
if (filter !== null && (Buffer.byteLength(filter.field) > 1024 || Buffer.byteLength(filter.equals) > MAX_AI_VALUE_BYTES))
|
|
100
|
+
throw new Error('筛选字段或目标值超过允许的字节数。');
|
|
101
|
+
const conditions = args.cursor !== undefined ? null : filter === null ? { match: args.match } : { match: filter.match, field: filter.field, equals: filter.equals };
|
|
102
|
+
return { target, conditions, data: undefined };
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ToolExecution, ToolExecutionResult } from '@deepseek-ai/dsh-tools';
|
|
3
|
+
import { type RedisConnections } from './connection-service.js';
|
|
4
|
+
import { type PreparedAiPage, type PreparedAiResult } from './ai-page-store.js';
|
|
5
|
+
import { RedisReportSamples } from './ai-report-samples.js';
|
|
6
|
+
import type { ConnectionErrorCode, ConnectionView, DatabaseTarget, SetSelectionRequest, SelectionAck } from '../domain.js';
|
|
7
|
+
declare const json: z.ZodJSONSchema;
|
|
8
|
+
export type AiJson = z.infer<typeof json>;
|
|
9
|
+
export interface AiValueRequest {
|
|
10
|
+
readonly key?: string;
|
|
11
|
+
readonly keyBase64?: string;
|
|
12
|
+
readonly field?: string;
|
|
13
|
+
readonly fieldBase64?: string;
|
|
14
|
+
readonly member?: string;
|
|
15
|
+
readonly memberBase64?: string;
|
|
16
|
+
readonly cursor?: string;
|
|
17
|
+
readonly offset?: string;
|
|
18
|
+
readonly count?: number;
|
|
19
|
+
readonly bytes?: number;
|
|
20
|
+
readonly match?: string;
|
|
21
|
+
readonly start?: string;
|
|
22
|
+
readonly end?: string;
|
|
23
|
+
readonly direction?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface AiGeoRequest {
|
|
26
|
+
readonly key?: string;
|
|
27
|
+
readonly keyBase64?: string;
|
|
28
|
+
readonly member?: string;
|
|
29
|
+
readonly memberBase64?: string;
|
|
30
|
+
readonly other?: string;
|
|
31
|
+
readonly otherBase64?: string;
|
|
32
|
+
readonly unit?: string;
|
|
33
|
+
}
|
|
34
|
+
/** A separate reader bank shares the real connection, never the UI's cursors. */
|
|
35
|
+
export declare class RedisAiReader {
|
|
36
|
+
private readonly connections;
|
|
37
|
+
private readonly invalidateUiActions;
|
|
38
|
+
private readonly confirmSelection;
|
|
39
|
+
private readonly isSelectionCurrent;
|
|
40
|
+
private readonly onDatabaseChange;
|
|
41
|
+
private readonly budget;
|
|
42
|
+
readonly reportSamples: RedisReportSamples;
|
|
43
|
+
private readonly keyPages;
|
|
44
|
+
private readonly hashFilter;
|
|
45
|
+
private readonly strings;
|
|
46
|
+
private readonly hashes;
|
|
47
|
+
private readonly hashPages;
|
|
48
|
+
private readonly lists;
|
|
49
|
+
private readonly sets;
|
|
50
|
+
private readonly setPages;
|
|
51
|
+
private readonly zsets;
|
|
52
|
+
private readonly zsetRanks;
|
|
53
|
+
private readonly zsetPages;
|
|
54
|
+
private readonly streams;
|
|
55
|
+
private readonly streamPages;
|
|
56
|
+
private readonly timeSeriesPages;
|
|
57
|
+
private readonly selections;
|
|
58
|
+
constructor(connections: RedisConnections, invalidateUiActions: (sessionId: string) => void, confirmSelection: (sessionId: string, target: DatabaseTarget, expected: number | null, signal: AbortSignal) => Promise<number>, isSelectionCurrent: (sessionId: string, revision: number | null) => boolean, onDatabaseChange?: (sessionId: string) => void);
|
|
59
|
+
/** Hold cursor and budget until DSH has applied its final result policy. */
|
|
60
|
+
readonly finalizeDelivery: (exec: Readonly<ToolExecution>, result: Readonly<ToolExecutionResult>) => {
|
|
61
|
+
type: "text";
|
|
62
|
+
text: string;
|
|
63
|
+
}[] | undefined;
|
|
64
|
+
/** All registered tools share a budget tied to the trusted DSH session. */
|
|
65
|
+
withBudget(sessionId: string, signal: AbortSignal, operation: (stage: (page: PreparedAiResult) => void) => AiJson | Promise<AiJson>, execution?: ToolExecution): Promise<AiJson>;
|
|
66
|
+
budgetStatus(sessionId: string): import("../domain.js").AiBudgetStatus;
|
|
67
|
+
resumeBudget(sessionId: string): {
|
|
68
|
+
accepted: boolean;
|
|
69
|
+
status: import("../domain.js").AiBudgetStatus;
|
|
70
|
+
};
|
|
71
|
+
private target;
|
|
72
|
+
currentTarget(sessionId: string): DatabaseTarget;
|
|
73
|
+
isCurrentTarget(sessionId: string, target: DatabaseTarget): boolean;
|
|
74
|
+
/** Bind a UI action to one confirmed selection without reading its value. */
|
|
75
|
+
prepareUiSelection(sessionId: string, signal: AbortSignal): Promise<{
|
|
76
|
+
target: DatabaseTarget;
|
|
77
|
+
keyBase64: string;
|
|
78
|
+
revision: number;
|
|
79
|
+
current: () => boolean;
|
|
80
|
+
sameRevision: () => boolean;
|
|
81
|
+
}>;
|
|
82
|
+
/** Capture the confirmed current Key, and guard every command against intervening selection. */
|
|
83
|
+
prepareHashField(sessionId: string, fieldBase64: string, signal: AbortSignal): Promise<{
|
|
84
|
+
target: DatabaseTarget;
|
|
85
|
+
keyBase64: string;
|
|
86
|
+
revision: number;
|
|
87
|
+
sample: import("./selected-reader.js").SelectedResult;
|
|
88
|
+
currentKey: () => boolean;
|
|
89
|
+
}>;
|
|
90
|
+
prepareListIndex(sessionId: string, index: string, signal: AbortSignal): Promise<{
|
|
91
|
+
target: DatabaseTarget;
|
|
92
|
+
keyBase64: string;
|
|
93
|
+
revision: number;
|
|
94
|
+
sample: import("./selected-reader.js").SelectedResult;
|
|
95
|
+
currentKey: () => boolean;
|
|
96
|
+
}>;
|
|
97
|
+
prepareSetMember(sessionId: string, memberBase64: string, signal: AbortSignal): Promise<{
|
|
98
|
+
target: DatabaseTarget;
|
|
99
|
+
keyBase64: string;
|
|
100
|
+
revision: number;
|
|
101
|
+
sample: import("./selected-reader.js").SelectedResult;
|
|
102
|
+
currentKey: () => boolean;
|
|
103
|
+
}>;
|
|
104
|
+
prepareZSetMember(sessionId: string, memberBase64: string, signal: AbortSignal): Promise<{
|
|
105
|
+
target: DatabaseTarget;
|
|
106
|
+
keyBase64: string;
|
|
107
|
+
revision: number;
|
|
108
|
+
sample: import("./selected-reader.js").SelectedResult;
|
|
109
|
+
currentKey: () => boolean;
|
|
110
|
+
}>;
|
|
111
|
+
prepareStreamField(sessionId: string, id: string, fieldIndex: number, signal: AbortSignal): Promise<{
|
|
112
|
+
target: DatabaseTarget;
|
|
113
|
+
keyBase64: string;
|
|
114
|
+
revision: number;
|
|
115
|
+
sample: {
|
|
116
|
+
message: import("../domain.js").StreamMessage | null;
|
|
117
|
+
state: "value" | "selection-missing" | "selection-changed" | "missing" | "unsupported" | "changed" | "failed";
|
|
118
|
+
error: ConnectionErrorCode | null;
|
|
119
|
+
metadata: import("../domain.js").KeyMetadata | null;
|
|
120
|
+
cell: import("../domain.js").BytePrefix | null;
|
|
121
|
+
score: string | null;
|
|
122
|
+
sampledAt: string;
|
|
123
|
+
};
|
|
124
|
+
currentKey: () => boolean;
|
|
125
|
+
}>;
|
|
126
|
+
private prepareSelectedItem;
|
|
127
|
+
private prepareSelection;
|
|
128
|
+
/** A single TYPE lookup checks existence without scanning or fetching a value. */
|
|
129
|
+
probeKey(sessionId: string, target: DatabaseTarget, keyBase64: string, signal: AbortSignal, validate: () => void): Promise<{
|
|
130
|
+
readonly state: 'found' | 'missing' | 'failed';
|
|
131
|
+
readonly error: ConnectionErrorCode | null;
|
|
132
|
+
readonly sampledAt: string;
|
|
133
|
+
}>;
|
|
134
|
+
private project;
|
|
135
|
+
connectionSnapshot(sessionId: string): ConnectionView;
|
|
136
|
+
status(sessionId: string): AiJson;
|
|
137
|
+
private selection;
|
|
138
|
+
setSelection(sessionId: string, request: SetSelectionRequest): SelectionAck;
|
|
139
|
+
/** Only the checked UI action commit may update selection without cancelling itself. */
|
|
140
|
+
commitSelection(sessionId: string, request: SetSelectionRequest): SelectionAck;
|
|
141
|
+
private saveSelection;
|
|
142
|
+
scan(sessionId: string, args: {
|
|
143
|
+
readonly match: string;
|
|
144
|
+
readonly cursor?: string;
|
|
145
|
+
}, signal: AbortSignal, stage?: (page: PreparedAiResult) => void): Promise<AiJson>;
|
|
146
|
+
/** Filter one bounded batch without returning unrelated Hash values to the model. */
|
|
147
|
+
filterHash(sessionId: string, args: {
|
|
148
|
+
readonly match: string;
|
|
149
|
+
readonly field: string;
|
|
150
|
+
readonly equals: string;
|
|
151
|
+
readonly cursor?: string;
|
|
152
|
+
}, signal: AbortSignal, stage: (page: PreparedAiResult) => void): Promise<AiJson>;
|
|
153
|
+
/** Read only type and expiry for one explicit identity; never fetch its value. */
|
|
154
|
+
keyMetadata(sessionId: string, args: {
|
|
155
|
+
readonly key?: string;
|
|
156
|
+
readonly keyBase64?: string;
|
|
157
|
+
}, signal: AbortSignal): Promise<AiJson>;
|
|
158
|
+
/** Read only the bytes overlapping an explicitly requested bit range. */
|
|
159
|
+
bitmap(sessionId: string, args: {
|
|
160
|
+
readonly key?: string;
|
|
161
|
+
readonly keyBase64?: string;
|
|
162
|
+
readonly offset: string;
|
|
163
|
+
readonly count: number;
|
|
164
|
+
}, signal: AbortSignal): Promise<AiJson>;
|
|
165
|
+
/** Read one bounded forward window of raw time-series samples. */
|
|
166
|
+
private timeSeries;
|
|
167
|
+
/** Opaque continuation binds the original range to the session and connection. */
|
|
168
|
+
prepareTimeSeries(sessionId: string, args: {
|
|
169
|
+
readonly key?: string;
|
|
170
|
+
readonly keyBase64?: string;
|
|
171
|
+
readonly from: string;
|
|
172
|
+
readonly to: string;
|
|
173
|
+
readonly count?: number;
|
|
174
|
+
readonly cursor?: string;
|
|
175
|
+
}, signal: AbortSignal): Promise<PreparedAiPage>;
|
|
176
|
+
/** One explicit JSONPath; preserve the Redis JSON text instead of rounding numbers. */
|
|
177
|
+
jsonPath(sessionId: string, args: {
|
|
178
|
+
readonly key?: string;
|
|
179
|
+
readonly keyBase64?: string;
|
|
180
|
+
readonly path: string;
|
|
181
|
+
}, signal: AbortSignal): Promise<AiJson>;
|
|
182
|
+
/** GEO is explicit: a ZSet alone does not prove that its scores are geographic. */
|
|
183
|
+
geo(sessionId: string, args: AiGeoRequest, signal: AbortSignal): Promise<AiJson>;
|
|
184
|
+
/** MEMORY USAGE is a bounded estimate for one explicit Key, not a value read. */
|
|
185
|
+
memoryUsage(sessionId: string, args: {
|
|
186
|
+
readonly key?: string;
|
|
187
|
+
readonly keyBase64?: string;
|
|
188
|
+
}, signal: AbortSignal): Promise<AiJson>;
|
|
189
|
+
/** Compare at most the first 4096 bytes per String; values never enter the tool result. */
|
|
190
|
+
compareStrings(sessionId: string, args: {
|
|
191
|
+
readonly left?: string;
|
|
192
|
+
readonly leftBase64?: string;
|
|
193
|
+
readonly right?: string;
|
|
194
|
+
readonly rightBase64?: string;
|
|
195
|
+
}, signal: AbortSignal): Promise<AiJson>;
|
|
196
|
+
/** Slow log is server-wide: return only bounded metadata, never argument bytes. */
|
|
197
|
+
slowLog(sessionId: string, count: number, signal: AbortSignal): Promise<AiJson>;
|
|
198
|
+
/** Only a short allowlist of server metrics is returned to the model. */
|
|
199
|
+
overview(sessionId: string, section: string, signal: AbortSignal): Promise<AiJson>;
|
|
200
|
+
/** CLIENT LIST is server-wide and may exceed the bounded RESP frame. */
|
|
201
|
+
clients(sessionId: string, signal: AbortSignal): Promise<AiJson>;
|
|
202
|
+
/** Sample group counters without fetching messages or advancing consumption. */
|
|
203
|
+
streamGroups(sessionId: string, args: {
|
|
204
|
+
readonly key?: string;
|
|
205
|
+
readonly keyBase64?: string;
|
|
206
|
+
}, signal: AbortSignal): Promise<AiJson>;
|
|
207
|
+
selectDatabase(sessionId: string, db: number, signal: AbortSignal): Promise<AiJson>;
|
|
208
|
+
read(sessionId: string, args: AiValueRequest, signal: AbortSignal, stage?: (page: PreparedAiResult) => void): Promise<AiJson>;
|
|
209
|
+
/** A named Hash field is read directly; it must never depend on a sidebar selection. */
|
|
210
|
+
private readExplicitHashField;
|
|
211
|
+
/** Discover Set versus ZSet, then reuse the exact member reader without UI state. */
|
|
212
|
+
private readExplicitMember;
|
|
213
|
+
private readValue;
|
|
214
|
+
clearTarget(sessionId: string): void;
|
|
215
|
+
disposeSession(sessionId: string): void;
|
|
216
|
+
private disposeCursors;
|
|
217
|
+
dispose(): void;
|
|
218
|
+
}
|
|
219
|
+
export {};
|