@agentknight/sdk 0.9.69 → 0.9.72
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/chunks/{acp-adapter-VJ2OUSBS.js → acp-adapter-PCNN2NAJ.js} +7 -7
- package/dist/chunks/{chunk-LA6A4TUM.js → chunk-23BKGY5J.js} +4 -4
- package/dist/chunks/{chunk-J63A5OLO.js → chunk-2UHBY25U.js} +1 -1
- package/dist/chunks/{chunk-IRYEOV62.js → chunk-36KL4FSH.js} +2 -2
- package/dist/chunks/{chunk-2D34UDII.js → chunk-5BDFZ3AS.js} +4 -4
- package/dist/chunks/{chunk-F5YCEWE4.js → chunk-5FJJZCP6.js} +680 -629
- package/dist/chunks/{chunk-ES2N66EH.js → chunk-DXHAKWGO.js} +2 -2
- package/dist/chunks/{chunk-35OF2ZNS.js → chunk-E5VHBC55.js} +14 -0
- package/dist/chunks/{chunk-Q5NNNSU2.js → chunk-FQ26TSDG.js} +2 -2
- package/dist/chunks/{chunk-MH7FDSTY.js → chunk-GRUDMHEJ.js} +1 -1
- package/dist/chunks/{chunk-5QYL6NKJ.js → chunk-I42IONUU.js} +1 -1
- package/dist/chunks/{chunk-WAPJZKUK.js → chunk-KPHWVNKP.js} +1 -1
- package/dist/chunks/{chunk-LU73CEHE.js → chunk-PAJZL5ST.js} +7 -2
- package/dist/chunks/{chunk-ZAU2MYQI.js → chunk-TFUSRA2B.js} +2 -2
- package/dist/chunks/chunk-VEJLENEQ.js +174 -0
- package/dist/chunks/{chunk-MB34W52S.js → chunk-VOR4AECB.js} +3 -3
- package/dist/chunks/{claude-adapter-FZNLF5XN.js → claude-adapter-A4LPYQ2Z.js} +71 -211
- package/dist/chunks/{codex-adapter-5ZVOAT6O.js → codex-adapter-AFGS7MPX.js} +7 -7
- package/dist/chunks/{copilot-adapter-V6RAQ4WK.js → copilot-adapter-NXJTI2HY.js} +24 -68
- package/dist/chunks/{managed-agent-adapter-THUSTKRW.js → managed-agent-adapter-4C2PWD4V.js} +6 -6
- package/dist/chunks/{pi-adapter-EHCSR5I2.js → pi-adapter-EZOIK5RA.js} +6 -6
- package/dist/configuration.js +4 -4
- package/dist/index.d.ts +138 -0
- package/dist/index.js +163 -50
- package/dist/runtime.js +2 -2
- package/dist/session-analytics-worker.js +6 -6
- package/package.json +4 -5
- package/dist/chunks/chunk-T6226JFS.js +0 -55
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveCopilotSessionDirectory
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-E5VHBC55.js";
|
|
4
4
|
import {
|
|
5
5
|
PromptFileAttachmentSchema,
|
|
6
6
|
PromptImageAttachmentSchema
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5FJJZCP6.js";
|
|
8
8
|
|
|
9
9
|
// src/prompt-attachments.ts
|
|
10
10
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// src/adapters/copilot/runtime/client-options.ts
|
|
2
|
+
function copilotRuntimeOptions() {
|
|
3
|
+
const legacyKeys = Object.keys(process.env).filter((key) => key.toUpperCase() === "COPILOT_CLI_PATH");
|
|
4
|
+
if (!legacyKeys.some((key) => process.env[key])) return {};
|
|
5
|
+
if (process.env["COPILOT_SDK_DEFAULT_CONNECTION"]?.toLowerCase() === "inprocess") {
|
|
6
|
+
throw new Error("Remove COPILOT_CLI_PATH to use the Copilot SDK in-process runtime.");
|
|
7
|
+
}
|
|
8
|
+
const env = { ...process.env };
|
|
9
|
+
for (const key of legacyKeys) delete env[key];
|
|
10
|
+
return { env };
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
// src/copilot-session-compatibility.ts
|
|
2
14
|
import {
|
|
3
15
|
appendFile,
|
|
@@ -147,6 +159,7 @@ var CopilotSessionCompatibilityClient = class {
|
|
|
147
159
|
}
|
|
148
160
|
const client = new CopilotClient({
|
|
149
161
|
mode: "copilot-cli",
|
|
162
|
+
...copilotRuntimeOptions(),
|
|
150
163
|
sessionFs: {
|
|
151
164
|
conventions: process.platform === "win32" ? "windows" : "posix",
|
|
152
165
|
initialCwd: this.#workingDirectory,
|
|
@@ -269,6 +282,7 @@ function isNodeError(error, code) {
|
|
|
269
282
|
}
|
|
270
283
|
|
|
271
284
|
export {
|
|
285
|
+
copilotRuntimeOptions,
|
|
272
286
|
resumeWithCopilotSessionCompatibility,
|
|
273
287
|
CopilotSessionCompatibilityClient,
|
|
274
288
|
resolveCopilotSessionDirectory
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentSessionRenameError,
|
|
3
3
|
validateSessionName
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-36KL4FSH.js";
|
|
5
5
|
import {
|
|
6
6
|
ConversationItemSchema,
|
|
7
7
|
GroupChatInfoSchema,
|
|
8
8
|
GroupChatParticipantSchema,
|
|
9
9
|
SESSION_TIMELINE_PAGE_SIZE,
|
|
10
10
|
SessionSummarySchema
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-5FJJZCP6.js";
|
|
12
12
|
|
|
13
13
|
// src/group-chat.ts
|
|
14
14
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
decodeTimelineImage,
|
|
3
3
|
normalizeImageMimeType,
|
|
4
4
|
splitTimelineImages
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-KPHWVNKP.js";
|
|
6
6
|
import {
|
|
7
7
|
CONVERSATION_SOURCE_ID_LIMIT
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-5FJJZCP6.js";
|
|
9
9
|
|
|
10
10
|
// src/conversation-normalizer.ts
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
@@ -216,6 +216,11 @@ function projectAttachment(attachment) {
|
|
|
216
216
|
kind: "unknown",
|
|
217
217
|
name: attachment.title
|
|
218
218
|
};
|
|
219
|
+
case "session_reference":
|
|
220
|
+
return {
|
|
221
|
+
kind: "unknown",
|
|
222
|
+
name: attachment.displayName ?? "Session reference"
|
|
223
|
+
};
|
|
219
224
|
}
|
|
220
225
|
}
|
|
221
226
|
function projectCitation(source) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CODING_AGENT_IDS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-36KL4FSH.js";
|
|
4
4
|
import {
|
|
5
5
|
BYTES_PER_KIB,
|
|
6
6
|
LEGACY_SECURE_MESSAGE_MAX_CIPHERTEXT_LENGTH
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5FJJZCP6.js";
|
|
8
8
|
|
|
9
9
|
// src/agent-selection.ts
|
|
10
10
|
import { z } from "zod";
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// src/adapters/claude/runtime.ts
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import { access, open, readFile, realpath, stat } from "node:fs/promises";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { delimiter, dirname, extname, isAbsolute, join, relative, sep } from "node:path";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
var packageName = "@anthropic-ai/claude-agent-sdk";
|
|
10
|
+
var require2 = createRequire(import.meta.url);
|
|
11
|
+
var metadataSchema = z.object({ claudeCodeVersion: z.string().regex(/^\d+\.\d+\.\d+$/) });
|
|
12
|
+
var configurationHint = "Set AGENTKNIGHT_CLAUDE_COMMAND (SDK: command / managed claudeCommand) to an absolute native executable.";
|
|
13
|
+
function missing(error) {
|
|
14
|
+
return error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR", "MODULE_NOT_FOUND"].includes(String(error.code));
|
|
15
|
+
}
|
|
16
|
+
function absolute(path) {
|
|
17
|
+
return !path.includes("\0") && isAbsolute(path) && (process.platform !== "win32" || /^(?:[a-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+[\\/])/i.test(path));
|
|
18
|
+
}
|
|
19
|
+
async function executable(path) {
|
|
20
|
+
try {
|
|
21
|
+
await access(path, process.platform === "win32" ? constants.F_OK : constants.X_OK);
|
|
22
|
+
return (await stat(path)).isFile();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (missing(error)) return false;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function nativeExecutable(path) {
|
|
29
|
+
if (process.platform === "win32" && extname(path).toLowerCase() !== ".exe") return false;
|
|
30
|
+
if (!await executable(path)) return false;
|
|
31
|
+
const file = await open(path, "r");
|
|
32
|
+
try {
|
|
33
|
+
const header = Buffer.alloc(4);
|
|
34
|
+
const { bytesRead } = await file.read(header, 0, header.length, 0);
|
|
35
|
+
if (bytesRead !== 4) return false;
|
|
36
|
+
if (process.platform === "win32") return header.subarray(0, 2).toString() === "MZ";
|
|
37
|
+
return [
|
|
38
|
+
"7f454c46",
|
|
39
|
+
"feedface",
|
|
40
|
+
"cefaedfe",
|
|
41
|
+
"feedfacf",
|
|
42
|
+
"cffaedfe",
|
|
43
|
+
"cafebabe",
|
|
44
|
+
"bebafeca",
|
|
45
|
+
"cafebabf",
|
|
46
|
+
"bfbafeca"
|
|
47
|
+
].includes(header.toString("hex"));
|
|
48
|
+
} finally {
|
|
49
|
+
await file.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function inside(directory, path) {
|
|
53
|
+
const child = relative(directory, path);
|
|
54
|
+
return child === "" || !isAbsolute(child) && child !== ".." && !child.startsWith(`..${sep}`);
|
|
55
|
+
}
|
|
56
|
+
async function findExternal(environment) {
|
|
57
|
+
const name = process.platform === "win32" ? "claude.exe" : "claude";
|
|
58
|
+
try {
|
|
59
|
+
const installed = await realpath(join(homedir(), ".local", "bin", name));
|
|
60
|
+
if (await nativeExecutable(installed)) return installed;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (!missing(error)) throw error;
|
|
63
|
+
}
|
|
64
|
+
const cwd = await realpath(process.cwd());
|
|
65
|
+
for (const directory of (environment.PATH ?? "").split(delimiter)) {
|
|
66
|
+
if (!absolute(directory) || inside(cwd, directory)) continue;
|
|
67
|
+
try {
|
|
68
|
+
const path = await realpath(join(directory, name));
|
|
69
|
+
if (!inside(cwd, path) && await nativeExecutable(path)) return path;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (!missing(error)) throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
async function version(path, environment) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const child = execFile(path, ["--version"], {
|
|
79
|
+
env: environment,
|
|
80
|
+
shell: false,
|
|
81
|
+
windowsHide: true,
|
|
82
|
+
timeout: 5e3,
|
|
83
|
+
maxBuffer: 4096,
|
|
84
|
+
killSignal: "SIGKILL"
|
|
85
|
+
}, (error, stdout) => {
|
|
86
|
+
if (error) reject(new Error(`Claude --version failed. ${configurationHint}`, { cause: error }));
|
|
87
|
+
else resolve(stdout.trim());
|
|
88
|
+
});
|
|
89
|
+
child.stdin?.end();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async function findClaudeExecutable(command, environment = process.env) {
|
|
93
|
+
if (command === void 0) return findExternal(environment);
|
|
94
|
+
if (!absolute(command)) throw new Error(configurationHint);
|
|
95
|
+
const path = await realpath(command).catch((error) => {
|
|
96
|
+
throw new Error(`Claude executable is unavailable. ${configurationHint}`, { cause: error });
|
|
97
|
+
});
|
|
98
|
+
if (!await nativeExecutable(path)) throw new Error(`Claude requires a native executable, not a script or shell shim. ${configurationHint}`);
|
|
99
|
+
return path;
|
|
100
|
+
}
|
|
101
|
+
async function resolveClaudeExecutable(command, environment = process.env) {
|
|
102
|
+
let expected;
|
|
103
|
+
try {
|
|
104
|
+
const entry = require2.resolve(packageName);
|
|
105
|
+
const raw = JSON.parse(await readFile(join(dirname(entry), "package.json"), "utf8"));
|
|
106
|
+
expected = metadataSchema.parse(raw).claudeCodeVersion;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
throw new Error("Claude SDK installation is missing or invalid. Reinstall AgentKnight with optional dependencies enabled.", { cause: error });
|
|
109
|
+
}
|
|
110
|
+
const path = await findClaudeExecutable(command, environment);
|
|
111
|
+
if (path === void 0) throw new Error(`Claude Code ${expected} is not installed. ${configurationHint}`);
|
|
112
|
+
const actual = await version(path, environment);
|
|
113
|
+
if (actual !== `${expected} (Claude Code)`) {
|
|
114
|
+
throw new Error(`This SDK requires Claude Code ${expected}; the local CLI is incompatible or unrecognized. ${configurationHint}`);
|
|
115
|
+
}
|
|
116
|
+
return path;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/local-agent-discovery.ts
|
|
120
|
+
import { constants as constants2 } from "node:fs";
|
|
121
|
+
import { access as access2, stat as stat2 } from "node:fs/promises";
|
|
122
|
+
import { homedir as homedir2 } from "node:os";
|
|
123
|
+
import { delimiter as delimiter2, isAbsolute as isAbsolute2, join as join2 } from "node:path";
|
|
124
|
+
import { fileURLToPath } from "node:url";
|
|
125
|
+
async function accessible(path, executable2 = false) {
|
|
126
|
+
try {
|
|
127
|
+
await access2(path, executable2 && process.platform !== "win32" ? constants2.X_OK : constants2.F_OK);
|
|
128
|
+
return (await stat2(path)).isFile();
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) return false;
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function hasLocalExecutable(command, environment = process.env) {
|
|
135
|
+
const extensions = process.platform === "win32" ? ["", ...(environment.PATHEXT ?? ".EXE;.CMD;.BAT").split(";")] : [""];
|
|
136
|
+
const paths = isAbsolute2(command) || command.includes("/") || command.includes("\\") ? [command] : (environment.PATH ?? "").split(delimiter2).filter(Boolean).map((directory) => join2(directory, command));
|
|
137
|
+
for (const path of paths) {
|
|
138
|
+
for (const extension of extensions) {
|
|
139
|
+
if (await accessible(`${path}${extension}`, true)) return true;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
async function hasPackage(name) {
|
|
145
|
+
try {
|
|
146
|
+
return await accessible(fileURLToPath(import.meta.resolve(name)));
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (error instanceof Error && "code" in error && error.code === "ERR_MODULE_NOT_FOUND") return false;
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async function detectCopilot() {
|
|
153
|
+
return hasPackage("@github/copilot-sdk");
|
|
154
|
+
}
|
|
155
|
+
async function detectPi(agentDirectory) {
|
|
156
|
+
if (!await hasPackage("@earendil-works/pi-coding-agent")) return false;
|
|
157
|
+
const directory = agentDirectory ?? (process.env.PI_CODING_AGENT_DIR || join2(homedir2(), ".pi", "agent"));
|
|
158
|
+
return agentDirectory !== void 0 || await accessible(join2(directory, "auth.json")) || await hasLocalExecutable("pi");
|
|
159
|
+
}
|
|
160
|
+
function hasClaudeProviderConfiguration(environment = process.env) {
|
|
161
|
+
return Boolean(environment.ANTHROPIC_API_KEY?.trim()) || ["CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_VERTEX", "CLAUDE_CODE_USE_FOUNDRY"].some((key) => environment[key] === "1");
|
|
162
|
+
}
|
|
163
|
+
async function detectClaude(command) {
|
|
164
|
+
return await hasPackage("@anthropic-ai/claude-agent-sdk") && await findClaudeExecutable(command) !== void 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export {
|
|
168
|
+
resolveClaudeExecutable,
|
|
169
|
+
hasLocalExecutable,
|
|
170
|
+
detectCopilot,
|
|
171
|
+
detectPi,
|
|
172
|
+
hasClaudeProviderConfiguration,
|
|
173
|
+
detectClaude
|
|
174
|
+
};
|
|
@@ -4,14 +4,14 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
stagePromptAttachments,
|
|
6
6
|
validatePromptAttachments
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-DXHAKWGO.js";
|
|
8
8
|
import {
|
|
9
9
|
decodeTimelineImage,
|
|
10
10
|
normalizeImageMimeType
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KPHWVNKP.js";
|
|
12
12
|
import {
|
|
13
13
|
SessionPromptRequestSchema
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5FJJZCP6.js";
|
|
15
15
|
|
|
16
16
|
// src/adapters/prompt-media.ts
|
|
17
17
|
import { join } from "node:path";
|