amp-acp 0.6.2 → 0.7.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/dist/index.js +110 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,6 +10,12 @@ var __export = (target, all) => {
|
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
// src/index.ts
|
|
14
|
+
import fs2 from "node:fs";
|
|
15
|
+
import path3 from "node:path";
|
|
16
|
+
import os2 from "node:os";
|
|
17
|
+
import readline from "node:readline";
|
|
18
|
+
|
|
13
19
|
// node_modules/zod/v3/external.js
|
|
14
20
|
var exports_external = {};
|
|
15
21
|
__export(exports_external, {
|
|
@@ -9641,10 +9647,13 @@ function safeJson(x) {
|
|
|
9641
9647
|
return;
|
|
9642
9648
|
}
|
|
9643
9649
|
}
|
|
9650
|
+
|
|
9651
|
+
// src/server.ts
|
|
9652
|
+
import path2 from "node:path";
|
|
9644
9653
|
// package.json
|
|
9645
9654
|
var package_default = {
|
|
9646
9655
|
name: "amp-acp",
|
|
9647
|
-
version: "0.
|
|
9656
|
+
version: "0.7.0",
|
|
9648
9657
|
private: false,
|
|
9649
9658
|
type: "module",
|
|
9650
9659
|
main: "dist/index.js",
|
|
@@ -9695,12 +9704,29 @@ class AmpAcpAgent {
|
|
|
9695
9704
|
console.info(`[acp] amp-acp v${PACKAGE_VERSION} initialized`);
|
|
9696
9705
|
return {
|
|
9697
9706
|
protocolVersion: 1,
|
|
9698
|
-
|
|
9707
|
+
agentInfo: {
|
|
9708
|
+
name: "amp-acp",
|
|
9709
|
+
title: "Amp ACP Agent",
|
|
9710
|
+
version: PACKAGE_VERSION
|
|
9711
|
+
},
|
|
9699
9712
|
agentCapabilities: {
|
|
9700
9713
|
promptCapabilities: { image: true, embeddedContext: true },
|
|
9701
9714
|
mcpCapabilities: { http: true, sse: true }
|
|
9702
9715
|
},
|
|
9703
|
-
authMethods: [
|
|
9716
|
+
authMethods: [
|
|
9717
|
+
{
|
|
9718
|
+
id: "setup",
|
|
9719
|
+
name: "Amp API Key Setup",
|
|
9720
|
+
description: "Run interactive setup to configure your Amp API key",
|
|
9721
|
+
_meta: {
|
|
9722
|
+
"terminal-auth": {
|
|
9723
|
+
command: getTerminalAuthCommand(),
|
|
9724
|
+
args: ["--setup"],
|
|
9725
|
+
label: "Amp API Key Setup"
|
|
9726
|
+
}
|
|
9727
|
+
}
|
|
9728
|
+
}
|
|
9729
|
+
]
|
|
9704
9730
|
};
|
|
9705
9731
|
}
|
|
9706
9732
|
async newSession(params) {
|
|
@@ -9746,6 +9772,9 @@ class AmpAcpAgent {
|
|
|
9746
9772
|
return result;
|
|
9747
9773
|
}
|
|
9748
9774
|
async authenticate(_params) {
|
|
9775
|
+
if (process.env.AMP_API_KEY) {
|
|
9776
|
+
return {};
|
|
9777
|
+
}
|
|
9749
9778
|
throw RequestError.authRequired();
|
|
9750
9779
|
}
|
|
9751
9780
|
async prompt(params) {
|
|
@@ -9821,6 +9850,10 @@ ${chunk.resource.text}
|
|
|
9821
9850
|
}
|
|
9822
9851
|
}
|
|
9823
9852
|
if (message.type === "result" && message.is_error) {
|
|
9853
|
+
if (typeof message.error === "string" && isAuthError(message.error)) {
|
|
9854
|
+
console.error("[amp] Auth error in result, requesting authentication:", message.error);
|
|
9855
|
+
throw RequestError.authRequired();
|
|
9856
|
+
}
|
|
9824
9857
|
await this.client.sessionUpdate({
|
|
9825
9858
|
sessionId: params.sessionId,
|
|
9826
9859
|
update: { sessionUpdate: "agent_message_chunk", content: { type: "text", text: `Error: ${message.error}` } }
|
|
@@ -9832,6 +9865,10 @@ ${chunk.resource.text}
|
|
|
9832
9865
|
if (s.cancelled || err instanceof Error && (err.name === "AbortError" || err.message.includes("aborted"))) {
|
|
9833
9866
|
return { stopReason: "cancelled" };
|
|
9834
9867
|
}
|
|
9868
|
+
if (err instanceof Error && isAuthError(err.message)) {
|
|
9869
|
+
console.error("[amp] Auth error, requesting authentication:", err.message);
|
|
9870
|
+
throw RequestError.authRequired();
|
|
9871
|
+
}
|
|
9835
9872
|
console.error("[amp] Execution error:", err);
|
|
9836
9873
|
throw err;
|
|
9837
9874
|
} finally {
|
|
@@ -9866,6 +9903,17 @@ ${chunk.resource.text}
|
|
|
9866
9903
|
return this.client.writeTextFile(params);
|
|
9867
9904
|
}
|
|
9868
9905
|
}
|
|
9906
|
+
function isAuthError(message) {
|
|
9907
|
+
const lower = message.toLowerCase();
|
|
9908
|
+
return lower.includes("invalid or missing api key") || lower.includes("run 'amp login'") || lower.includes("authentication") || lower.includes("unauthorized") || lower.includes("no api key found") || lower.includes("api key") && lower.includes("login flow") || lower.includes("api key") && (lower.includes("missing") || lower.includes("invalid"));
|
|
9909
|
+
}
|
|
9910
|
+
function getTerminalAuthCommand(argv1 = process.argv[1], execPath = process.execPath) {
|
|
9911
|
+
const resolvedArgv1 = argv1 ? path2.resolve(argv1) : "";
|
|
9912
|
+
if (!resolvedArgv1 || resolvedArgv1.startsWith("/$bunfs/")) {
|
|
9913
|
+
return execPath;
|
|
9914
|
+
}
|
|
9915
|
+
return resolvedArgv1;
|
|
9916
|
+
}
|
|
9869
9917
|
|
|
9870
9918
|
// src/run-acp.ts
|
|
9871
9919
|
function runAcp() {
|
|
@@ -9880,5 +9928,62 @@ console.log = console.error;
|
|
|
9880
9928
|
console.info = console.error;
|
|
9881
9929
|
console.warn = console.error;
|
|
9882
9930
|
console.debug = console.error;
|
|
9883
|
-
|
|
9884
|
-
process.
|
|
9931
|
+
function getConfigDir() {
|
|
9932
|
+
if (process.platform === "win32") {
|
|
9933
|
+
return path3.join(process.env.APPDATA ?? path3.join(os2.homedir(), "AppData", "Roaming"), "amp-acp");
|
|
9934
|
+
}
|
|
9935
|
+
return path3.join(process.env.XDG_CONFIG_HOME ?? path3.join(os2.homedir(), ".config"), "amp-acp");
|
|
9936
|
+
}
|
|
9937
|
+
function getCredentialsPath() {
|
|
9938
|
+
return path3.join(getConfigDir(), "credentials.json");
|
|
9939
|
+
}
|
|
9940
|
+
function loadStoredApiKey() {
|
|
9941
|
+
const credPath = getCredentialsPath();
|
|
9942
|
+
try {
|
|
9943
|
+
const data = JSON.parse(fs2.readFileSync(credPath, "utf-8"));
|
|
9944
|
+
return data.apiKey || undefined;
|
|
9945
|
+
} catch {
|
|
9946
|
+
return;
|
|
9947
|
+
}
|
|
9948
|
+
}
|
|
9949
|
+
function prompt(question) {
|
|
9950
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
9951
|
+
return new Promise((resolve) => {
|
|
9952
|
+
rl.question(question, (answer) => {
|
|
9953
|
+
rl.close();
|
|
9954
|
+
resolve(answer.trim());
|
|
9955
|
+
});
|
|
9956
|
+
});
|
|
9957
|
+
}
|
|
9958
|
+
async function setup() {
|
|
9959
|
+
const existing = process.env.AMP_API_KEY || loadStoredApiKey();
|
|
9960
|
+
if (existing) {
|
|
9961
|
+
console.error("AMP API key is already configured.");
|
|
9962
|
+
process.exit(0);
|
|
9963
|
+
}
|
|
9964
|
+
console.error("You can get your API key from: https://ampcode.com/settings");
|
|
9965
|
+
const apiKey = await prompt("Paste your AMP API key: ");
|
|
9966
|
+
if (!apiKey) {
|
|
9967
|
+
console.error("No API key provided. Aborting.");
|
|
9968
|
+
process.exit(1);
|
|
9969
|
+
}
|
|
9970
|
+
const configDir = getConfigDir();
|
|
9971
|
+
fs2.mkdirSync(configDir, { recursive: true });
|
|
9972
|
+
const credPath = getCredentialsPath();
|
|
9973
|
+
fs2.writeFileSync(credPath, JSON.stringify({ apiKey }, null, 2) + `
|
|
9974
|
+
`, { mode: 384 });
|
|
9975
|
+
console.error(`API key saved to ${credPath}`);
|
|
9976
|
+
process.exit(0);
|
|
9977
|
+
}
|
|
9978
|
+
if (process.argv.includes("--setup")) {
|
|
9979
|
+
await setup();
|
|
9980
|
+
} else {
|
|
9981
|
+
if (!process.env.AMP_API_KEY) {
|
|
9982
|
+
const stored = loadStoredApiKey();
|
|
9983
|
+
if (stored) {
|
|
9984
|
+
process.env.AMP_API_KEY = stored;
|
|
9985
|
+
}
|
|
9986
|
+
}
|
|
9987
|
+
runAcp();
|
|
9988
|
+
process.stdin.resume();
|
|
9989
|
+
}
|