@xi4z/dsh-utils-approval-qq 0.0.0-stage → 0.9.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/LICENSE +21 -0
- package/lib/index.d.ts +217 -0
- package/lib/index.js +485 -0
- package/lib/index.js.map +1 -0
- package/lib/translate.d.ts +40 -0
- package/lib/translate.js +71 -0
- package/lib/translate.js.map +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +54 -3
- package/src/index.ts +641 -0
- package/src/translate.ts +106 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xi4z
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import z from '@deepseek-ai/schemastery';
|
|
3
|
+
import type { ApprovalOutcome } from '@deepseek-ai/dsh-user-approval/types';
|
|
4
|
+
export declare const name = "dsh-approval-qq";
|
|
5
|
+
/** Settings-page schema. Every key is volatile: reads are live on each request. */
|
|
6
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
7
|
+
enabled: z<boolean, boolean, "volatile-defined">;
|
|
8
|
+
relayUrl: z<string, string, "volatile-defined">;
|
|
9
|
+
sharedKey: z<string, string, "volatile-defined">;
|
|
10
|
+
deviceLabel: z<string, string, "volatile-defined">;
|
|
11
|
+
sendDelayMs: z<number, number, "volatile-defined">;
|
|
12
|
+
pollWaitSeconds: z<number, number, "volatile-defined">;
|
|
13
|
+
timeoutMs: z<number, number, "volatile-defined">;
|
|
14
|
+
includeSubagents: z<boolean, boolean, "volatile-defined">;
|
|
15
|
+
dryRun: z<boolean, boolean, "volatile-defined">;
|
|
16
|
+
allowReceipt: z<string, string, "volatile-defined">;
|
|
17
|
+
denyReceipt: z<string, string, "volatile-defined">;
|
|
18
|
+
translateEnglish: z<boolean, boolean, "volatile-defined">;
|
|
19
|
+
translateTimeoutMs: z<number, number, "volatile-defined">;
|
|
20
|
+
translateProvider: z<string, string, "volatile-defined">;
|
|
21
|
+
translateModel: z<string, string, "volatile-defined">;
|
|
22
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
23
|
+
enabled: z<boolean, boolean, "volatile-defined">;
|
|
24
|
+
relayUrl: z<string, string, "volatile-defined">;
|
|
25
|
+
sharedKey: z<string, string, "volatile-defined">;
|
|
26
|
+
deviceLabel: z<string, string, "volatile-defined">;
|
|
27
|
+
sendDelayMs: z<number, number, "volatile-defined">;
|
|
28
|
+
pollWaitSeconds: z<number, number, "volatile-defined">;
|
|
29
|
+
timeoutMs: z<number, number, "volatile-defined">;
|
|
30
|
+
includeSubagents: z<boolean, boolean, "volatile-defined">;
|
|
31
|
+
dryRun: z<boolean, boolean, "volatile-defined">;
|
|
32
|
+
allowReceipt: z<string, string, "volatile-defined">;
|
|
33
|
+
denyReceipt: z<string, string, "volatile-defined">;
|
|
34
|
+
translateEnglish: z<boolean, boolean, "volatile-defined">;
|
|
35
|
+
translateTimeoutMs: z<number, number, "volatile-defined">;
|
|
36
|
+
translateProvider: z<string, string, "volatile-defined">;
|
|
37
|
+
translateModel: z<string, string, "volatile-defined">;
|
|
38
|
+
}>>, "plain">;
|
|
39
|
+
/** Volatile Config fields arrive as live references; .get() snapshots. */
|
|
40
|
+
interface VolatileRef<T> {
|
|
41
|
+
get(): T;
|
|
42
|
+
}
|
|
43
|
+
/** One setting as the Loader supplies it: a live reference, or a plain value in tests. */
|
|
44
|
+
type MaybeRef<T> = T | VolatileRef<T>;
|
|
45
|
+
/** The runtime shape apply receives (every field volatile, every field optional). */
|
|
46
|
+
export interface ApprovalQqConfig {
|
|
47
|
+
readonly enabled?: MaybeRef<boolean>;
|
|
48
|
+
readonly relayUrl?: MaybeRef<string>;
|
|
49
|
+
readonly sharedKey?: MaybeRef<string>;
|
|
50
|
+
readonly deviceLabel?: MaybeRef<string>;
|
|
51
|
+
readonly sendDelayMs?: MaybeRef<number>;
|
|
52
|
+
readonly pollWaitSeconds?: MaybeRef<number>;
|
|
53
|
+
readonly timeoutMs?: MaybeRef<number>;
|
|
54
|
+
readonly includeSubagents?: MaybeRef<boolean>;
|
|
55
|
+
readonly dryRun?: MaybeRef<boolean>;
|
|
56
|
+
readonly allowReceipt?: MaybeRef<string>;
|
|
57
|
+
readonly denyReceipt?: MaybeRef<string>;
|
|
58
|
+
readonly translateEnglish?: MaybeRef<boolean>;
|
|
59
|
+
readonly translateTimeoutMs?: MaybeRef<number>;
|
|
60
|
+
readonly translateProvider?: MaybeRef<string>;
|
|
61
|
+
readonly translateModel?: MaybeRef<string>;
|
|
62
|
+
}
|
|
63
|
+
/** Normalized options with every default applied. */
|
|
64
|
+
export interface ResolvedOptions {
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
relayUrl: string;
|
|
67
|
+
sharedKey: string;
|
|
68
|
+
deviceLabel: string;
|
|
69
|
+
sendDelayMs: number;
|
|
70
|
+
pollWaitSeconds: number;
|
|
71
|
+
timeoutMs: number;
|
|
72
|
+
includeSubagents: boolean;
|
|
73
|
+
dryRun: boolean;
|
|
74
|
+
allowReceipt: string;
|
|
75
|
+
denyReceipt: string;
|
|
76
|
+
translateEnglish: boolean;
|
|
77
|
+
translateTimeoutMs: number;
|
|
78
|
+
translateProvider: string;
|
|
79
|
+
translateModel: string;
|
|
80
|
+
}
|
|
81
|
+
/** Structural logger slice (matches the host logger without importing it). */
|
|
82
|
+
export interface Logger {
|
|
83
|
+
info(format: unknown, ...param: unknown[]): void;
|
|
84
|
+
warn(format: unknown, ...param: unknown[]): void;
|
|
85
|
+
debug?(format: unknown, ...param: unknown[]): void;
|
|
86
|
+
}
|
|
87
|
+
/** The read-only view approval-policy publishes on the cordis context. */
|
|
88
|
+
export interface ApprovalPolicyInfo {
|
|
89
|
+
describe(agent: unknown, sessionId: string): {
|
|
90
|
+
gated: boolean;
|
|
91
|
+
windowMs: number;
|
|
92
|
+
defaultOutcome: 'rejected' | 'unavailable';
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Structural session/agent/request slices, mirroring dsh types without importing them. */
|
|
96
|
+
interface SessionEventLike {
|
|
97
|
+
readonly type?: string;
|
|
98
|
+
readonly data?: {
|
|
99
|
+
readonly callId?: unknown;
|
|
100
|
+
readonly arguments?: unknown;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
interface SessionLike {
|
|
104
|
+
readonly header?: {
|
|
105
|
+
readonly cwd?: string;
|
|
106
|
+
readonly origin?: string;
|
|
107
|
+
};
|
|
108
|
+
readonly events?: readonly SessionEventLike[];
|
|
109
|
+
}
|
|
110
|
+
interface AgentLike {
|
|
111
|
+
readonly id?: unknown;
|
|
112
|
+
readonly session?: SessionLike;
|
|
113
|
+
}
|
|
114
|
+
export interface ApprovalRequestLike {
|
|
115
|
+
readonly agent: AgentLike;
|
|
116
|
+
readonly toolName: string;
|
|
117
|
+
readonly callId?: unknown;
|
|
118
|
+
readonly reason?: string;
|
|
119
|
+
readonly signal?: AbortSignal;
|
|
120
|
+
}
|
|
121
|
+
/** Expand name / name-with-fallback environment references in a setting. */
|
|
122
|
+
export declare function expandEnv(value: unknown): string;
|
|
123
|
+
/** Resolve the live config into one concrete option set. */
|
|
124
|
+
export declare function resolveOptions(config: ApprovalQqConfig | undefined): ResolvedOptions;
|
|
125
|
+
/** Human-readable remaining time for the countdown line. */
|
|
126
|
+
export declare function formatDuration(ms: number): string;
|
|
127
|
+
/** One deadline line: countdown plus the wall-clock deadline. */
|
|
128
|
+
export declare function deadlineLine(input: {
|
|
129
|
+
remainingMs: number;
|
|
130
|
+
defaultOutcome: 'rejected' | 'unavailable';
|
|
131
|
+
now?: number;
|
|
132
|
+
}): string;
|
|
133
|
+
/** Inputs for an approval card. */
|
|
134
|
+
export interface ApprovalCardInput {
|
|
135
|
+
readonly sessionId: string;
|
|
136
|
+
readonly cwd?: string;
|
|
137
|
+
readonly device?: string;
|
|
138
|
+
readonly toolName: string;
|
|
139
|
+
readonly command?: string;
|
|
140
|
+
readonly reason?: string;
|
|
141
|
+
readonly gated: boolean;
|
|
142
|
+
readonly remainingMs?: number;
|
|
143
|
+
readonly defaultOutcome?: 'rejected' | 'unavailable';
|
|
144
|
+
readonly now?: number;
|
|
145
|
+
}
|
|
146
|
+
/** Render the markdown body of an approval card (the relay adds the keyboard). */
|
|
147
|
+
export declare function renderApprovalCard(input: ApprovalCardInput): string;
|
|
148
|
+
/** Find the gated command from the session log by tool-call id. */
|
|
149
|
+
export declare function commandOf(request: ApprovalRequestLike): string | undefined;
|
|
150
|
+
/** One relay long-poll result. */
|
|
151
|
+
export type RelayState = {
|
|
152
|
+
state: 'pending';
|
|
153
|
+
} | {
|
|
154
|
+
state: 'clicked';
|
|
155
|
+
choice: 'allow' | 'deny';
|
|
156
|
+
} | {
|
|
157
|
+
state: 'closed';
|
|
158
|
+
reason?: string;
|
|
159
|
+
outcome?: string;
|
|
160
|
+
};
|
|
161
|
+
/** The relay client slice the answerer needs (injectable for tests). */
|
|
162
|
+
export interface RelayClient {
|
|
163
|
+
create(input: {
|
|
164
|
+
askId: string;
|
|
165
|
+
markdown: string;
|
|
166
|
+
device?: string;
|
|
167
|
+
}): Promise<{
|
|
168
|
+
messageId?: string;
|
|
169
|
+
}>;
|
|
170
|
+
wait(askId: string, waitSeconds: number, signal?: AbortSignal): Promise<RelayState>;
|
|
171
|
+
settle(askId: string, body: {
|
|
172
|
+
outcome: 'allowed-once' | 'rejected' | 'ignored';
|
|
173
|
+
reason?: string;
|
|
174
|
+
receipt?: string;
|
|
175
|
+
}): Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Build the HTTP client for the relay approval endpoints.
|
|
179
|
+
*
|
|
180
|
+
* baseUrl ends in /approval; endpoints are base, base/askId and
|
|
181
|
+
* base/askId/settle.
|
|
182
|
+
*/
|
|
183
|
+
export declare function createRelayClient(options: {
|
|
184
|
+
baseUrl: string;
|
|
185
|
+
key: string;
|
|
186
|
+
timeoutMs: number;
|
|
187
|
+
fetchImpl?: typeof fetch;
|
|
188
|
+
}): RelayClient;
|
|
189
|
+
/** Generate a 128-bit ask id (hex). */
|
|
190
|
+
export declare function randomAskId(): string;
|
|
191
|
+
/** What an answerer needs; everything injectable so the race is unit-testable. */
|
|
192
|
+
export interface AnswererDeps {
|
|
193
|
+
config: () => ResolvedOptions;
|
|
194
|
+
policyInfo?: () => ApprovalPolicyInfo | undefined;
|
|
195
|
+
relay: (cfg: ResolvedOptions) => RelayClient | undefined;
|
|
196
|
+
now?: () => number;
|
|
197
|
+
sleep?: (ms: number) => Promise<void>;
|
|
198
|
+
randomId?: () => string;
|
|
199
|
+
log?: Logger;
|
|
200
|
+
/** Translate an English reason; undefined keeps the source text. */
|
|
201
|
+
translate?: (text: string, budgetMs: number, signal?: AbortSignal) => Promise<string | undefined>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Build the approval/request answerer.
|
|
205
|
+
*
|
|
206
|
+
* Flow: read the gate window -> call next() immediately (the GUI/downstream
|
|
207
|
+
* chain starts and the window clock ticks) -> debounce -> send the card ->
|
|
208
|
+
* race downstream / click / abort -> settle the relay accordingly.
|
|
209
|
+
*/
|
|
210
|
+
export declare function createAnswerer(deps: AnswererDeps): (request: ApprovalRequestLike, next: () => Promise<ApprovalOutcome>) => Promise<ApprovalOutcome>;
|
|
211
|
+
/**
|
|
212
|
+
* Activate the component.
|
|
213
|
+
* @param ctx - host Cordis context.
|
|
214
|
+
* @param config - row config; volatile fields arrive as live references.
|
|
215
|
+
*/
|
|
216
|
+
export declare function apply(ctx: Context, config?: ApprovalQqConfig): void;
|
|
217
|
+
export {};
|