glm-acp-agent 1.0.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/README.md +365 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/credentials.d.ts +15 -0
- package/dist/llm/credentials.d.ts.map +1 -0
- package/dist/llm/credentials.js +54 -0
- package/dist/llm/credentials.js.map +1 -0
- package/dist/llm/glm-client.d.ts +63 -0
- package/dist/llm/glm-client.d.ts.map +1 -0
- package/dist/llm/glm-client.js +217 -0
- package/dist/llm/glm-client.js.map +1 -0
- package/dist/llm/logger.d.ts +19 -0
- package/dist/llm/logger.d.ts.map +1 -0
- package/dist/llm/logger.js +44 -0
- package/dist/llm/logger.js.map +1 -0
- package/dist/protocol/agent.d.ts +77 -0
- package/dist/protocol/agent.d.ts.map +1 -0
- package/dist/protocol/agent.js +732 -0
- package/dist/protocol/agent.js.map +1 -0
- package/dist/protocol/connection.d.ts +9 -0
- package/dist/protocol/connection.d.ts.map +1 -0
- package/dist/protocol/connection.js +18 -0
- package/dist/protocol/connection.js.map +1 -0
- package/dist/protocol/image-preprocessor.d.ts +32 -0
- package/dist/protocol/image-preprocessor.d.ts.map +1 -0
- package/dist/protocol/image-preprocessor.js +149 -0
- package/dist/protocol/image-preprocessor.js.map +1 -0
- package/dist/protocol/session-store.d.ts +54 -0
- package/dist/protocol/session-store.d.ts.map +1 -0
- package/dist/protocol/session-store.js +109 -0
- package/dist/protocol/session-store.js.map +1 -0
- package/dist/protocol/system-prompt.d.ts +29 -0
- package/dist/protocol/system-prompt.d.ts.map +1 -0
- package/dist/protocol/system-prompt.js +103 -0
- package/dist/protocol/system-prompt.js.map +1 -0
- package/dist/setup.d.ts +8 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +95 -0
- package/dist/setup.js.map +1 -0
- package/dist/tests/agent.test.d.ts +2 -0
- package/dist/tests/agent.test.d.ts.map +1 -0
- package/dist/tests/agent.test.js +1118 -0
- package/dist/tests/agent.test.js.map +1 -0
- package/dist/tests/credentials.test.d.ts +2 -0
- package/dist/tests/credentials.test.d.ts.map +1 -0
- package/dist/tests/credentials.test.js +112 -0
- package/dist/tests/credentials.test.js.map +1 -0
- package/dist/tests/executor.test.d.ts +2 -0
- package/dist/tests/executor.test.d.ts.map +1 -0
- package/dist/tests/executor.test.js +497 -0
- package/dist/tests/executor.test.js.map +1 -0
- package/dist/tests/glm-client.test.d.ts +2 -0
- package/dist/tests/glm-client.test.d.ts.map +1 -0
- package/dist/tests/glm-client.test.js +205 -0
- package/dist/tests/glm-client.test.js.map +1 -0
- package/dist/tests/image-preprocessor.test.d.ts +2 -0
- package/dist/tests/image-preprocessor.test.d.ts.map +1 -0
- package/dist/tests/image-preprocessor.test.js +133 -0
- package/dist/tests/image-preprocessor.test.js.map +1 -0
- package/dist/tests/integration.test.d.ts +2 -0
- package/dist/tests/integration.test.d.ts.map +1 -0
- package/dist/tests/integration.test.js +192 -0
- package/dist/tests/integration.test.js.map +1 -0
- package/dist/tests/logger.test.d.ts +2 -0
- package/dist/tests/logger.test.d.ts.map +1 -0
- package/dist/tests/logger.test.js +14 -0
- package/dist/tests/logger.test.js.map +1 -0
- package/dist/tests/mcp-arg-remap.test.d.ts +2 -0
- package/dist/tests/mcp-arg-remap.test.d.ts.map +1 -0
- package/dist/tests/mcp-arg-remap.test.js +65 -0
- package/dist/tests/mcp-arg-remap.test.js.map +1 -0
- package/dist/tests/vision-mcp-client.test.d.ts +2 -0
- package/dist/tests/vision-mcp-client.test.d.ts.map +1 -0
- package/dist/tests/vision-mcp-client.test.js +129 -0
- package/dist/tests/vision-mcp-client.test.js.map +1 -0
- package/dist/tests/zai-mcp-client.test.d.ts +2 -0
- package/dist/tests/zai-mcp-client.test.d.ts.map +1 -0
- package/dist/tests/zai-mcp-client.test.js +386 -0
- package/dist/tests/zai-mcp-client.test.js.map +1 -0
- package/dist/tools/definitions.d.ts +18 -0
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/definitions.js +149 -0
- package/dist/tools/definitions.js.map +1 -0
- package/dist/tools/executor.d.ts +48 -0
- package/dist/tools/executor.d.ts.map +1 -0
- package/dist/tools/executor.js +670 -0
- package/dist/tools/executor.js.map +1 -0
- package/dist/tools/mcp-arg-remap.d.ts +21 -0
- package/dist/tools/mcp-arg-remap.d.ts.map +1 -0
- package/dist/tools/mcp-arg-remap.js +70 -0
- package/dist/tools/mcp-arg-remap.js.map +1 -0
- package/dist/tools/vision-mcp-client.d.ts +38 -0
- package/dist/tools/vision-mcp-client.d.ts.map +1 -0
- package/dist/tools/vision-mcp-client.js +191 -0
- package/dist/tools/vision-mcp-client.js.map +1 -0
- package/dist/tools/zai-mcp-client.d.ts +24 -0
- package/dist/tools/zai-mcp-client.d.ts.map +1 -0
- package/dist/tools/zai-mcp-client.js +189 -0
- package/dist/tools/zai-mcp-client.js.map +1 -0
- package/package.json +37 -0
package/dist/setup.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createInterface } from "node:readline/promises";
|
|
2
|
+
import { credentialsPath, writeCredentials } from "./llm/credentials.js";
|
|
3
|
+
/**
|
|
4
|
+
* Interactive setup flow that prompts the user for a Z.AI API key on stdin and
|
|
5
|
+
* persists it to the credentials file. Invoked when the binary is run with
|
|
6
|
+
* `--setup` so users can configure the agent without leaking the key into
|
|
7
|
+
* their shell history.
|
|
8
|
+
*/
|
|
9
|
+
export async function runSetup(input = process.stdin, output = process.stdout) {
|
|
10
|
+
const path = credentialsPath();
|
|
11
|
+
output.write("GLM ACP agent setup\n");
|
|
12
|
+
output.write("===================\n\n");
|
|
13
|
+
output.write("Get a Z.AI API key from https://z.ai/manage-apikey/apikey-list\n\n");
|
|
14
|
+
const apiKey = (await readSecret(input, output, "Z_AI_API_KEY: ")).trim();
|
|
15
|
+
if (apiKey.length === 0) {
|
|
16
|
+
throw new Error("No API key entered; aborting setup.");
|
|
17
|
+
}
|
|
18
|
+
writeCredentials(apiKey);
|
|
19
|
+
output.write(`\nAPI key saved to ${path}\n`);
|
|
20
|
+
output.write("You can now run `glm-acp-agent` from your ACP client.\n");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read a single line from `input`, masking each character with `*` when stdin
|
|
24
|
+
* is a TTY so the typed key doesn't appear in scrollback. When stdin is piped
|
|
25
|
+
* (the common test/CI case) we fall back to a plain readline read — the key
|
|
26
|
+
* isn't on a screen anyway.
|
|
27
|
+
*/
|
|
28
|
+
async function readSecret(input, output, prompt) {
|
|
29
|
+
const stream = input;
|
|
30
|
+
const isTTY = stream.isTTY === true && typeof stream.setRawMode === "function";
|
|
31
|
+
if (!isTTY) {
|
|
32
|
+
const rl = createInterface({ input, output, terminal: false });
|
|
33
|
+
try {
|
|
34
|
+
return await rl.question(prompt);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
rl.close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
output.write(prompt);
|
|
41
|
+
stream.setRawMode(true);
|
|
42
|
+
stream.resume();
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
let buf = "";
|
|
45
|
+
const cleanup = () => {
|
|
46
|
+
stream.off("data", onData);
|
|
47
|
+
stream.off("close", onClose);
|
|
48
|
+
stream.off("error", onError);
|
|
49
|
+
stream.setRawMode(false);
|
|
50
|
+
stream.pause();
|
|
51
|
+
};
|
|
52
|
+
const onClose = () => {
|
|
53
|
+
cleanup();
|
|
54
|
+
reject(new Error("Input stream closed before a key was entered."));
|
|
55
|
+
};
|
|
56
|
+
const onError = (err) => {
|
|
57
|
+
cleanup();
|
|
58
|
+
reject(err);
|
|
59
|
+
};
|
|
60
|
+
const onData = (data) => {
|
|
61
|
+
const chunk = typeof data === "string" ? data : data.toString("utf8");
|
|
62
|
+
for (const ch of chunk) {
|
|
63
|
+
if (ch === "\n" || ch === "\r") {
|
|
64
|
+
output.write("\n");
|
|
65
|
+
cleanup();
|
|
66
|
+
resolve(buf);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (ch === "") {
|
|
70
|
+
// Ctrl-C
|
|
71
|
+
cleanup();
|
|
72
|
+
reject(new Error("Setup cancelled by user."));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (ch === "" || ch === "\b") {
|
|
76
|
+
// Backspace / DEL
|
|
77
|
+
if (buf.length > 0) {
|
|
78
|
+
buf = buf.slice(0, -1);
|
|
79
|
+
output.write("\b \b");
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
// Ignore other non-printable control characters silently.
|
|
84
|
+
if (ch.charCodeAt(0) < 0x20)
|
|
85
|
+
continue;
|
|
86
|
+
buf += ch;
|
|
87
|
+
output.write("*");
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
stream.on("data", onData);
|
|
91
|
+
stream.on("close", onClose);
|
|
92
|
+
stream.on("error", onError);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,QAA+B,OAAO,CAAC,KAAK,EAC5C,SAAgC,OAAO,CAAC,MAAM;IAE9C,MAAM,IAAI,GAAG,eAAe,EAAE,CAAC;IAE/B,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACxC,MAAM,CAAC,KAAK,CAAC,oEAAoE,CAAC,CAAC;IAEnF,MAAM,MAAM,GAAG,C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