@kilocode/sdk 7.2.4 → 7.2.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.
package/dist/client.js CHANGED
@@ -2,6 +2,31 @@ export * from "./gen/types.gen.js";
2
2
  import { createClient } from "./gen/client/client.gen.js";
3
3
  import { KiloClient } from "./gen/sdk.gen.js";
4
4
  export { KiloClient };
5
+ function pick(value, fallback) {
6
+ if (!value)
7
+ return;
8
+ if (!fallback)
9
+ return value;
10
+ if (value === fallback)
11
+ return fallback;
12
+ if (value === encodeURIComponent(fallback))
13
+ return fallback;
14
+ return value;
15
+ }
16
+ function rewrite(request, directory) {
17
+ if (request.method !== "GET" && request.method !== "HEAD")
18
+ return request;
19
+ const value = pick(request.headers.get("x-kilo-directory"), directory);
20
+ if (!value)
21
+ return request;
22
+ const url = new URL(request.url);
23
+ if (!url.searchParams.has("directory")) {
24
+ url.searchParams.set("directory", value);
25
+ }
26
+ const next = new Request(url.href, request); // kilocode_change
27
+ next.headers.delete("x-kilo-directory");
28
+ return next;
29
+ }
5
30
  export function createKiloClient(config) {
6
31
  if (!config?.fetch) {
7
32
  const customFetch = (req) => {
@@ -30,5 +55,6 @@ export function createKiloClient(config) {
30
55
  ;
31
56
  config.duplex = "half";
32
57
  const client = createClient(config);
58
+ client.interceptors.request.use((request) => rewrite(request, config?.directory));
33
59
  return new KiloClient({ client });
34
60
  }
package/dist/v2/client.js CHANGED
@@ -2,6 +2,41 @@ export * from "./gen/types.gen.js";
2
2
  import { createClient } from "./gen/client/client.gen.js";
3
3
  import { KiloClient } from "./gen/sdk.gen.js";
4
4
  export { KiloClient };
5
+ function pick(value, fallback, encode) {
6
+ if (!value)
7
+ return;
8
+ if (!fallback)
9
+ return value;
10
+ if (value === fallback)
11
+ return fallback;
12
+ if (encode && value === encode(fallback))
13
+ return fallback;
14
+ return value;
15
+ }
16
+ function rewrite(request, values) {
17
+ if (request.method !== "GET" && request.method !== "HEAD")
18
+ return request;
19
+ const url = new URL(request.url);
20
+ let changed = false;
21
+ for (const [name, key] of [
22
+ ["x-kilo-directory", "directory"],
23
+ ["x-kilo-workspace", "workspace"],
24
+ ]) {
25
+ const value = pick(request.headers.get(name), key === "directory" ? values.directory : values.workspace, key === "directory" ? encodeURIComponent : undefined);
26
+ if (!value)
27
+ continue;
28
+ if (!url.searchParams.has(key)) {
29
+ url.searchParams.set(key, value);
30
+ }
31
+ changed = true;
32
+ }
33
+ if (!changed)
34
+ return request;
35
+ const next = new Request(url, request);
36
+ next.headers.delete("x-kilo-directory");
37
+ next.headers.delete("x-kilo-workspace");
38
+ return next;
39
+ }
5
40
  export function createKiloClient(config) {
6
41
  if (!config?.fetch) {
7
42
  const customFetch = (req) => {
@@ -19,11 +54,9 @@ export function createKiloClient(config) {
19
54
  };
20
55
  }
21
56
  if (config?.directory) {
22
- const isNonASCII = /[^\x00-\x7F]/.test(config.directory);
23
- const encodedDirectory = isNonASCII ? encodeURIComponent(config.directory) : config.directory;
24
57
  config.headers = {
25
58
  ...config.headers,
26
- "x-kilo-directory": encodedDirectory,
59
+ "x-kilo-directory": encodeURIComponent(config.directory),
27
60
  };
28
61
  }
29
62
  if (config?.experimental_workspaceID) {
@@ -38,5 +71,9 @@ export function createKiloClient(config) {
38
71
  ;
39
72
  config.duplex = "half";
40
73
  const client = createClient(config);
74
+ client.interceptors.request.use((request) => rewrite(request, {
75
+ directory: config?.directory,
76
+ workspace: config?.experimental_workspaceID,
77
+ }));
41
78
  return new KiloClient({ client });
42
79
  }