@kilocode/sdk 7.7.4 → 7.7.5
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.
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { KiloClient } from "../v2/client.js";
|
|
2
|
+
type Decision = {
|
|
3
|
+
requestID: string;
|
|
4
|
+
directory: string;
|
|
5
|
+
reply: "once" | "always" | "reject";
|
|
6
|
+
approvedAlways: string[];
|
|
7
|
+
deniedAlways: string[];
|
|
8
|
+
message?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Send a permission decision with one bounded wait across both requests.
|
|
12
|
+
* A timeout aborts only the client wait, so callers must reconcile an aborted
|
|
13
|
+
* rule save because the server may still persist the rules.
|
|
14
|
+
* Rules are saved first so a failed save never continues to the reply.
|
|
15
|
+
*/
|
|
16
|
+
export declare function respondToPermission(client: KiloClient, input: Decision, timeout?: number): Promise<{
|
|
17
|
+
error?: unknown;
|
|
18
|
+
saved?: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* An aborted rule save can still complete on the server. A request that is no
|
|
22
|
+
* longer pending was applied, so the caller must not offer a retry that could
|
|
23
|
+
* persist a conflicting rule. Returns false when the outcome stays unknown.
|
|
24
|
+
*/
|
|
25
|
+
export declare function permissionSettled(client: KiloClient, directory: string, requestID: string, timeout?: number): Promise<boolean>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send a permission decision with one bounded wait across both requests.
|
|
3
|
+
* A timeout aborts only the client wait, so callers must reconcile an aborted
|
|
4
|
+
* rule save because the server may still persist the rules.
|
|
5
|
+
* Rules are saved first so a failed save never continues to the reply.
|
|
6
|
+
*/
|
|
7
|
+
export async function respondToPermission(client, input, timeout = 15_000) {
|
|
8
|
+
const deadline = Date.now() + timeout;
|
|
9
|
+
const budget = () => Math.max(0, deadline - Date.now());
|
|
10
|
+
const saved = input.approvedAlways.length > 0 || input.deniedAlways.length > 0;
|
|
11
|
+
try {
|
|
12
|
+
if (saved) {
|
|
13
|
+
await client.permission.saveAlwaysRules({
|
|
14
|
+
requestID: input.requestID,
|
|
15
|
+
directory: input.directory,
|
|
16
|
+
approvedAlways: input.approvedAlways,
|
|
17
|
+
deniedAlways: input.deniedAlways,
|
|
18
|
+
}, { throwOnError: true, signal: AbortSignal.timeout(budget()) });
|
|
19
|
+
}
|
|
20
|
+
await client.permission.reply({
|
|
21
|
+
requestID: input.requestID,
|
|
22
|
+
directory: input.directory,
|
|
23
|
+
reply: input.reply,
|
|
24
|
+
interactive: true,
|
|
25
|
+
...(input.message ? { message: input.message } : {}),
|
|
26
|
+
}, { throwOnError: true, signal: AbortSignal.timeout(budget()) });
|
|
27
|
+
return { saved };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return { error, saved };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An aborted rule save can still complete on the server. A request that is no
|
|
35
|
+
* longer pending was applied, so the caller must not offer a retry that could
|
|
36
|
+
* persist a conflicting rule. Returns false when the outcome stays unknown.
|
|
37
|
+
*/
|
|
38
|
+
export async function permissionSettled(client, directory, requestID, timeout = 5_000) {
|
|
39
|
+
const { data, error } = await client.permission.list({ directory }, { signal: AbortSignal.timeout(timeout) });
|
|
40
|
+
if (error || !data)
|
|
41
|
+
return false;
|
|
42
|
+
return !data.some((permission) => permission.id === requestID);
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@kilocode/sdk",
|
|
4
|
-
"version": "7.7.
|
|
4
|
+
"version": "7.7.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"./v2/types": {
|
|
42
42
|
"import": "./dist/v2/gen/types.gen.js",
|
|
43
43
|
"types": "./dist/v2/gen/types.gen.d.ts"
|
|
44
|
+
},
|
|
45
|
+
"./permission": {
|
|
46
|
+
"import": "./dist/kilocode/permission.js",
|
|
47
|
+
"types": "./dist/kilocode/permission.d.ts"
|
|
44
48
|
}
|
|
45
49
|
},
|
|
46
50
|
"files": [
|