@xenosystem/acp 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,9 @@
1
+ xeno-acp
2
+ Copyright 2026 XENO Corporation
3
+
4
+ This product includes software developed at XENO Corporation.
5
+
6
+ Built on the Agent Client Protocol SDK (@agentclientprotocol/sdk), Apache-2.0.
7
+ Drives external ACP agents (Claude Code, Codex, OpenCode, Gemini CLI) via their
8
+ official ACP adapters / native ACP modes, using the operator's own provider
9
+ credentials.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @xenosystem/acp
2
+
3
+ OpenAI-compatible HTTP gateway over ACP agents, built on
4
+ [`@xenosystem/acp-core`](https://www.npmjs.com/package/@xenosystem/acp-core).
5
+
6
+ ```bash
7
+ npm install --global @xenosystem/acp
8
+ xeno-acp --help
9
+ xeno-acp init
10
+ # Edit xeno-acp.config.jsonc, including the local bearer key and enabled agents.
11
+ xeno-acp --config ./xeno-acp.config.jsonc
12
+ ```
13
+
14
+ ```bash
15
+ curl -N localhost:8787/v1/chat/completions \
16
+ -H "authorization: Bearer dev-key" -H "content-type: application/json" \
17
+ -d '{"model":"claude-code","stream":true,
18
+ "messages":[{"role":"user","content":"Hello!"}]}'
19
+ ```
20
+
21
+ Endpoints: `GET /v1/models`, `POST /v1/chat/completions`, `GET /healthz`.
22
+ Public beta. Each configured provider uses the operator's own local installation and account;
23
+ XENO ACP does not proxy credentials. See the
24
+ [product documentation](https://xenostudio.ai/docs/acp). Apache-2.0.
package/dist/auth.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Bearer-key auth and per-app agent allowlists.
3
+ *
4
+ * Scope is single-owner / many-internal-apps (SPEC §9): every key maps to one of the
5
+ * owner's apps for attribution and an optional agent allowlist. `open` mode disables auth
6
+ * for local development only.
7
+ */
8
+ import type { ResolvedConfig } from "@xenosystem/acp-core";
9
+ export interface Principal {
10
+ app: string;
11
+ /** Agent ids this principal may use, or "*" for all. */
12
+ agents: string[];
13
+ maxConcurrentSessions?: number;
14
+ }
15
+ export declare class Authenticator {
16
+ private readonly open;
17
+ private readonly byKey;
18
+ constructor(config: ResolvedConfig);
19
+ get isOpen(): boolean;
20
+ /** Extract a bearer token from an Authorization header (or `x-api-key`). */
21
+ static extractToken(headers: Record<string, unknown>): string | undefined;
22
+ /** Resolve a token to a principal, or null if rejected. In open mode, always allows. */
23
+ authenticate(token: string | undefined): Principal | null;
24
+ /** Whether a principal may use a given agent id. */
25
+ static canUseAgent(principal: Principal, agentId: string): boolean;
26
+ }
27
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAErE,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,wDAAwD;IACxD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;gBAEzC,MAAM,EAAE,cAAc;IAKlC,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,4EAA4E;IAC5E,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,SAAS;IAYzE,wFAAwF;IACxF,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI;IAgBzD,oDAAoD;IACpD,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;CAGnE"}
package/dist/auth.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Bearer-key auth and per-app agent allowlists.
3
+ *
4
+ * Scope is single-owner / many-internal-apps (SPEC §9): every key maps to one of the
5
+ * owner's apps for attribution and an optional agent allowlist. `open` mode disables auth
6
+ * for local development only.
7
+ */
8
+ export class Authenticator {
9
+ open;
10
+ byKey = new Map();
11
+ constructor(config) {
12
+ this.open = config.server.auth === "open";
13
+ for (const k of config.keys)
14
+ if (k.key)
15
+ this.byKey.set(k.key, k);
16
+ }
17
+ get isOpen() {
18
+ return this.open;
19
+ }
20
+ /** Extract a bearer token from an Authorization header (or `x-api-key`). */
21
+ static extractToken(headers) {
22
+ const auth = headers["authorization"];
23
+ if (typeof auth === "string") {
24
+ const m = /^Bearer\s+(.+)$/i.exec(auth.trim());
25
+ if (m)
26
+ return m[1];
27
+ if (auth.trim())
28
+ return auth.trim();
29
+ }
30
+ const apiKey = headers["x-api-key"];
31
+ if (typeof apiKey === "string" && apiKey.trim())
32
+ return apiKey.trim();
33
+ return undefined;
34
+ }
35
+ /** Resolve a token to a principal, or null if rejected. In open mode, always allows. */
36
+ authenticate(token) {
37
+ if (this.open) {
38
+ return { app: "open", agents: ["*"] };
39
+ }
40
+ if (!token)
41
+ return null;
42
+ const entry = this.byKey.get(token);
43
+ if (!entry)
44
+ return null;
45
+ return {
46
+ app: entry.app,
47
+ agents: entry.agents,
48
+ ...(entry.maxConcurrentSessions !== undefined
49
+ ? { maxConcurrentSessions: entry.maxConcurrentSessions }
50
+ : {}),
51
+ };
52
+ }
53
+ /** Whether a principal may use a given agent id. */
54
+ static canUseAgent(principal, agentId) {
55
+ return principal.agents.includes("*") || principal.agents.includes(agentId);
56
+ }
57
+ }
58
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"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AI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,OAAO;YACL,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,GAAG,CAAC,KAAK,CAAC,qBAAqB,KAAK,SAAS;gBAC3C,CAAC,CAAC,EAAE,qBAAqB,EAAE,KAAK,CAAC,qBAAqB,EAAE;gBACxD,CAAC,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,CAAC;IAED,oDAAoD;IACpD,MAAM,CAAC,WAAW,CAAC,SAAoB,EAAE,OAAe;QACtD,OAAO,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9E,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { AcpManager, ResolvedConfig } from "@xenosystem/acp-core";
2
+ import type { Authenticator } from "./auth.js";
3
+ /** Shared context handed to every route registrar. */
4
+ export interface RouteContext {
5
+ manager: AcpManager;
6
+ auth: Authenticator;
7
+ config: ResolvedConfig;
8
+ }
9
+ export declare function errorBody(message: string, code: string, type?: string): {
10
+ error: {
11
+ message: string;
12
+ type: string;
13
+ code: string;
14
+ };
15
+ };
16
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,sDAAsD;AACtD,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,SAA0B,GAC7B;IAAE,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAE5D"}
@@ -0,0 +1,4 @@
1
+ export function errorBody(message, code, type = "invalid_request_error") {
2
+ return { error: { message, type, code } };
3
+ }
4
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,SAAS,CACvB,OAAe,EACf,IAAY,EACZ,IAAI,GAAG,uBAAuB;IAE9B,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * xeno-acp gateway CLI bootstrap.
4
+ *
5
+ * Usage:
6
+ * xeno-acp [--config <path>] [--host <h>] [--port <n>]
7
+ * xeno-acp --help
8
+ * xeno-acp --version
9
+ * Env overrides: XENO_ACP_CONFIG, HOST, PORT, XENO_ACP_LOG.
10
+ */
11
+ export { buildServer } from "./server.js";
12
+ export declare const VERSION = "0.1.1";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AAUH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,eAAO,MAAM,OAAO,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * xeno-acp gateway CLI bootstrap.
4
+ *
5
+ * Usage:
6
+ * xeno-acp [--config <path>] [--host <h>] [--port <n>]
7
+ * xeno-acp --help
8
+ * xeno-acp --version
9
+ * Env overrides: XENO_ACP_CONFIG, HOST, PORT, XENO_ACP_LOG.
10
+ */
11
+ import { copyFileSync, existsSync } from "node:fs";
12
+ import { resolve } from "node:path";
13
+ import { fileURLToPath, pathToFileURL } from "node:url";
14
+ import { loadConfig, createLogger } from "@xenosystem/acp-core";
15
+ import { buildServer } from "./server.js";
16
+ // Re-export the pure app factory so tests/embedders can build a server without
17
+ // starting one (importing this module must have no side effects).
18
+ export { buildServer } from "./server.js";
19
+ const log = createLogger("server");
20
+ export const VERSION = "0.1.1";
21
+ function usage() {
22
+ return [
23
+ `xeno-acp ${VERSION} — OpenAI-compatible ACP gateway`,
24
+ "",
25
+ "Usage:",
26
+ " xeno-acp [--config <path>] [--host <host>] [--port <port>]",
27
+ " xeno-acp init [--output <path>]",
28
+ " xeno-acp --help",
29
+ " xeno-acp --version",
30
+ "",
31
+ "Environment:",
32
+ " XENO_ACP_CONFIG configuration file path",
33
+ " HOST listen host override",
34
+ " PORT listen port override",
35
+ " XENO_ACP_LOG log level",
36
+ "",
37
+ ].join("\n");
38
+ }
39
+ function flag(args, name) {
40
+ const i = args.indexOf(name);
41
+ return i !== -1 && i + 1 < args.length ? args[i + 1] : undefined;
42
+ }
43
+ async function main() {
44
+ const args = process.argv.slice(2);
45
+ if (args.includes("--version") || args[0] === "version") {
46
+ process.stdout.write(`xeno-acp ${VERSION}\n`);
47
+ return;
48
+ }
49
+ if (args.includes("--help") || args.includes("-h") || args[0] === "help") {
50
+ process.stdout.write(usage());
51
+ return;
52
+ }
53
+ if (args[0] === "init") {
54
+ const output = resolve(flag(args, "--output") ?? "xeno-acp.config.jsonc");
55
+ if (existsSync(output)) {
56
+ throw new Error(`refusing to overwrite existing config: ${output}`);
57
+ }
58
+ const template = fileURLToPath(new URL("../xeno-acp.config.example.jsonc", import.meta.url));
59
+ copyFileSync(template, output);
60
+ process.stdout.write(`created ${output}\n`);
61
+ return;
62
+ }
63
+ const configPath = flag(args, "--config");
64
+ const config = loadConfig(configPath ? { path: configPath } : {});
65
+ // CLI / env overrides for host & port.
66
+ const host = flag(args, "--host") ?? process.env.HOST ?? config.server.host;
67
+ const port = Number(flag(args, "--port") ?? process.env.PORT ?? config.server.port);
68
+ config.server.host = host;
69
+ config.server.port = port;
70
+ const { app, manager } = buildServer(config);
71
+ await app.listen({ host, port });
72
+ log.info(`listening on http://${host}:${port} ` +
73
+ `(auth=${config.server.auth}, agents=[${config.agents.map((a) => a.id).join(", ")}])`);
74
+ if (config.server.auth === "open") {
75
+ log.warn("auth=open — no API key required. Use this for local dev only.");
76
+ }
77
+ const shutdown = async (sig) => {
78
+ log.info(`${sig} → shutting down`);
79
+ try {
80
+ await app.close();
81
+ await manager.dispose();
82
+ }
83
+ finally {
84
+ process.exit(0);
85
+ }
86
+ };
87
+ process.on("SIGINT", () => void shutdown("SIGINT"));
88
+ process.on("SIGTERM", () => void shutdown("SIGTERM"));
89
+ }
90
+ // Only auto-start when invoked as the entry point (e.g. `node dist/index.js` or the bin).
91
+ // Importing this module (tests, embedders) must not start a server.
92
+ const invokedDirectly = process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href;
93
+ if (invokedDirectly) {
94
+ main().catch((err) => {
95
+ log.error("fatal:", err);
96
+ process.exit(1);
97
+ });
98
+ }
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAChE,OA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AAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAE3F,IAAI,eAAe,EAAE,CAAC;IACpB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACnB,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * OpenAI chat-completions request/response shapes and helpers.
3
+ *
4
+ * This is the ONLY place that knows the OpenAI schema — the engine (@xenosystem/acp-core) stays
5
+ * framework- and protocol-neutral. The server translates: OpenAI request → core prompt →
6
+ * flattened core stream → OpenAI response/SSE.
7
+ */
8
+ import type { ChatMessage } from "@xenosystem/acp-core";
9
+ export type OpenAIContent = string | null | Array<{
10
+ type: string;
11
+ text?: string;
12
+ [k: string]: unknown;
13
+ }>;
14
+ export interface OpenAIMessage {
15
+ role: "system" | "user" | "assistant" | "tool" | "developer";
16
+ content: OpenAIContent;
17
+ name?: string;
18
+ }
19
+ export interface XenoExtension {
20
+ session?: string;
21
+ workspace?: string;
22
+ verbose?: boolean;
23
+ mode?: string;
24
+ }
25
+ export interface ChatCompletionRequest {
26
+ model: string;
27
+ messages: OpenAIMessage[];
28
+ stream?: boolean;
29
+ /** XENO-specific options (additive, non-OpenAI). */
30
+ xeno?: XenoExtension;
31
+ temperature?: number;
32
+ top_p?: number;
33
+ max_tokens?: number;
34
+ user?: string;
35
+ }
36
+ export interface Usage {
37
+ prompt_tokens: number;
38
+ completion_tokens: number;
39
+ total_tokens: number;
40
+ }
41
+ export declare function makeCompletionId(): string;
42
+ /** Unix seconds. (Plain Node runtime — Date is available here.) */
43
+ export declare function nowSeconds(): number;
44
+ /** Normalize OpenAI messages into the engine's `ChatMessage[]`. */
45
+ export declare function normalizeMessages(messages: OpenAIMessage[]): ChatMessage[];
46
+ export interface CompletionParts {
47
+ id: string;
48
+ created: number;
49
+ model: string;
50
+ }
51
+ export declare function buildCompletion(parts: CompletionParts, text: string, finishReason: string, usage: Usage): unknown;
52
+ export declare function buildChunk(parts: CompletionParts, delta: Record<string, unknown>, finishReason: string | null): unknown;
53
+ export declare function sse(data: unknown): string;
54
+ export declare const SSE_DONE = "data: [DONE]\n\n";
55
+ /** Best-effort usage object when the agent didn't report token counts. */
56
+ export declare function usageFrom(u: {
57
+ prompt?: number;
58
+ completion?: number;
59
+ total?: number;
60
+ } | undefined): Usage;
61
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,IAAI,GACJ,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC,CAAC;AAEjE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,CAAC;IAC7D,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,OAA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openai.js ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * OpenAI chat-completions request/response shapes and helpers.
3
+ *
4
+ * This is the ONLY place that knows the OpenAI schema — the engine (@xenosystem/acp-core) stays
5
+ * framework- and protocol-neutral. The server translates: OpenAI request → core prompt →
6
+ * flattened core stream → OpenAI response/SSE.
7
+ */
8
+ import { randomUUID } from "node:crypto";
9
+ export function makeCompletionId() {
10
+ return `chatcmpl-${randomUUID().replace(/-/g, "")}`;
11
+ }
12
+ /** Unix seconds. (Plain Node runtime — Date is available here.) */
13
+ export function nowSeconds() {
14
+ return Math.floor(Date.now() / 1000);
15
+ }
16
+ /** Flatten OpenAI message content (string | parts) into a plain string. */
17
+ function contentToText(content) {
18
+ if (content == null)
19
+ return "";
20
+ if (typeof content === "string")
21
+ return content;
22
+ return content
23
+ .map((part) => (typeof part?.text === "string" ? part.text : ""))
24
+ .filter(Boolean)
25
+ .join("");
26
+ }
27
+ /** Normalize OpenAI messages into the engine's `ChatMessage[]`. */
28
+ export function normalizeMessages(messages) {
29
+ return messages.map((m) => {
30
+ const role = m.role === "developer" ? "system" : m.role;
31
+ return {
32
+ role: role,
33
+ content: contentToText(m.content),
34
+ ...(m.name ? { name: m.name } : {}),
35
+ };
36
+ });
37
+ }
38
+ export function buildCompletion(parts, text, finishReason, usage) {
39
+ return {
40
+ id: parts.id,
41
+ object: "chat.completion",
42
+ created: parts.created,
43
+ model: parts.model,
44
+ choices: [
45
+ {
46
+ index: 0,
47
+ message: { role: "assistant", content: text },
48
+ finish_reason: finishReason,
49
+ },
50
+ ],
51
+ usage,
52
+ };
53
+ }
54
+ export function buildChunk(parts, delta, finishReason) {
55
+ return {
56
+ id: parts.id,
57
+ object: "chat.completion.chunk",
58
+ created: parts.created,
59
+ model: parts.model,
60
+ choices: [{ index: 0, delta, finish_reason: finishReason }],
61
+ };
62
+ }
63
+ export function sse(data) {
64
+ return `data: ${JSON.stringify(data)}\n\n`;
65
+ }
66
+ export const SSE_DONE = "data: [DONE]\n\n";
67
+ /** Best-effort usage object when the agent didn't report token counts. */
68
+ export function usageFrom(u) {
69
+ const prompt = u?.prompt ?? 0;
70
+ const completion = u?.completion ?? 0;
71
+ const total = u?.total ?? prompt + completion;
72
+ return { prompt_tokens: prompt, completion_tokens: completion, total_tokens: total };
73
+ }
74
+ //# sourceMappingURL=openai.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.js","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAwCzC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,YAAY,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,UAAU;IACxB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACvC,CAAC;AAED,2EAA2E;AAC3E,SAAS,aAAa,CAAC,OAAsB;IAC3C,IAAI,OAAO,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC/B,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAChE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,iBAAiB,CAAC,QAAyB;IACzD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACxB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,Q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0EAA0E;AAC1E,MAAM,UAAU,SAAS,CACvB,CAAuE;IAEvE,MAAM,MAAM,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;IAC9B,MAAM,UAAU,GAAG,CAAC,EAAE,UAAU,IAAI,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,MAAM,GAAG,UAAU,CAAC;IAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AACvF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ import { type RouteContext } from "../context.js";
3
+ export declare function registerChat(app: FastifyInstance, ctx: RouteContext): void;
4
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAG7E,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAc7D,wBAAgB,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI,CAqG1E"}
@@ -0,0 +1,89 @@
1
+ import { flatten, resolveModel } from "@xenosystem/acp-core";
2
+ import { Authenticator } from "../auth.js";
3
+ import { errorBody } from "../context.js";
4
+ import { buildChunk, buildCompletion, makeCompletionId, normalizeMessages, nowSeconds, sse, SSE_DONE, usageFrom, } from "../openai.js";
5
+ export function registerChat(app, ctx) {
6
+ app.post("/v1/chat/completions", async (req, reply) => {
7
+ const principal = ctx.auth.authenticate(Authenticator.extractToken(req.headers));
8
+ if (!principal) {
9
+ return reply.code(401).send(errorBody("invalid or missing API key", "invalid_api_key"));
10
+ }
11
+ const body = req.body;
12
+ if (!body || typeof body.model !== "string" || !Array.isArray(body.messages)) {
13
+ return reply
14
+ .code(400)
15
+ .send(errorBody("`model` and `messages` are required", "invalid_request_error"));
16
+ }
17
+ const { id: agentId, submodel } = resolveModel(body.model);
18
+ if (!ctx.manager.hasAgent(agentId)) {
19
+ return reply.code(404).send(errorBody(`unknown model/agent: ${agentId}`, "model_not_found"));
20
+ }
21
+ if (!Authenticator.canUseAgent(principal, agentId)) {
22
+ return reply
23
+ .code(403)
24
+ .send(errorBody(`app "${principal.app}" is not permitted to use agent "${agentId}"`, "permission_denied", "permission_error"));
25
+ }
26
+ const verbose = body.xeno?.verbose ?? false;
27
+ const promptOpts = {
28
+ messages: normalizeMessages(body.messages),
29
+ model: submodel ?? null,
30
+ ...(body.xeno?.session ? { session: body.xeno.session } : {}),
31
+ ...(body.xeno?.workspace ? { workspace: body.xeno.workspace } : {}),
32
+ ...(body.xeno?.mode ? { mode: body.xeno.mode } : {}),
33
+ };
34
+ // Abort the turn if the client disconnects.
35
+ const ac = new AbortController();
36
+ reply.raw.on("close", () => ac.abort());
37
+ promptOpts.signal = ac.signal;
38
+ const parts = {
39
+ id: makeCompletionId(),
40
+ created: nowSeconds(),
41
+ model: body.model,
42
+ };
43
+ if (body.stream) {
44
+ reply.hijack();
45
+ reply.raw.writeHead(200, {
46
+ "content-type": "text/event-stream; charset=utf-8",
47
+ "cache-control": "no-cache, no-transform",
48
+ connection: "keep-alive",
49
+ "x-accel-buffering": "no",
50
+ });
51
+ // Initial role chunk.
52
+ reply.raw.write(sse(buildChunk(parts, { role: "assistant" }, null)));
53
+ let finishReason = "stop";
54
+ try {
55
+ for await (const chunk of flatten(ctx.manager.prompt(body.model, promptOpts), {
56
+ verbose,
57
+ })) {
58
+ if (chunk.type === "delta") {
59
+ reply.raw.write(sse(buildChunk(parts, { content: chunk.text }, null)));
60
+ }
61
+ else {
62
+ finishReason = chunk.finishReason;
63
+ }
64
+ }
65
+ }
66
+ catch (err) {
67
+ reply.raw.write(sse(buildChunk(parts, { content: `\n[xeno-acp error] ${err.message}\n` }, null)));
68
+ }
69
+ reply.raw.write(sse(buildChunk(parts, {}, finishReason)));
70
+ reply.raw.write(SSE_DONE);
71
+ reply.raw.end();
72
+ return reply;
73
+ }
74
+ // Non-streaming: collect the whole turn.
75
+ let text = "";
76
+ let finishReason = "stop";
77
+ let usage;
78
+ for await (const chunk of flatten(ctx.manager.prompt(body.model, promptOpts), { verbose })) {
79
+ if (chunk.type === "delta")
80
+ text += chunk.text;
81
+ else {
82
+ finishReason = chunk.finishReason;
83
+ usage = chunk.usage;
84
+ }
85
+ }
86
+ return reply.send(buildCompletion(parts, text, finishReason, usageFrom(usage)));
87
+ });
88
+ }
89
+ //# sourceMappingURL=chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAsB,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAqB,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,GAAG,EACH,QAAQ,EACR,SAAS,GAGV,MAAM,cAAc,CAAC;AAEtB,MAAM,UAAU,YAAY,CAAC,GAAoB,EAAE,GAAiB;IAClE,GAAG,CAAC,IAAI,CACN,sBAAsB,EACtB,KAAK,EAAE,GAAoD,EAAE,KAAmB,EAAE,EAAE;QAClF,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;QACjF,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,4BAA4B,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC1F,CAAC;QAED,MAAM,IAAI,GAAG,GAAG,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C;iBAC1C,CAAC;gBACJ,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;gBAClC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YACtB,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClF,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ import type { RouteContext } from "../context.js";
3
+ export declare function registerHealth(app: FastifyInstance, ctx: RouteContext): void;
4
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI,CAyB5E"}
@@ -0,0 +1,26 @@
1
+ export function registerHealth(app, ctx) {
2
+ app.get("/healthz", async () => ({
3
+ status: "ok",
4
+ service: "xeno-acp",
5
+ config: {
6
+ server: {
7
+ auth: ctx.config.server.auth,
8
+ host: ctx.config.server.host,
9
+ port: ctx.config.server.port,
10
+ },
11
+ defaults: {
12
+ permission: ctx.config.defaults.permission,
13
+ maxConcurrentSessions: ctx.config.defaults.maxConcurrentSessions,
14
+ terminalTimeoutMs: ctx.config.defaults.terminalTimeoutMs,
15
+ initTimeoutMs: ctx.config.defaults.initTimeoutMs,
16
+ },
17
+ },
18
+ agents: ctx.manager.statuses(),
19
+ }));
20
+ app.get("/", async () => ({
21
+ service: "xeno-acp",
22
+ description: "OpenAI-compatible gateway over ACP agents",
23
+ endpoints: ["/v1/models", "/v1/chat/completions", "/healthz"],
24
+ }));
25
+ }
26
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,cAAc,CAAC,GAAoB,EAAE,GAAiB;IACpE,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;QAC/B,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,UAAU;QACnB,MAAM,EAAE;YACN,MAAM,EAAE;gBACN,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI;gBAC5B,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI;gBAC5B,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI;aAC7B;YACD,QAAQ,EAAE;gBACR,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU;gBAC1C,qBAAqB,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB;gBAChE,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB;gBACxD,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa;aACjD;SACF;QACD,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE;KAC/B,CAAC,CAAC,CAAC;IAEJ,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;QACxB,OAAO,EAAE,UAAU;QACnB,WAAW,EAAE,2CAA2C;QACxD,SAAS,EAAE,CAAC,YAAY,EAAE,sBAAsB,EAAE,UAAU,CAAC;KAC9D,CAAC,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ import { type RouteContext } from "../context.js";
3
+ export declare function registerModels(app: FastifyInstance, ctx: RouteContext): void;
4
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/routes/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAE7E,OAAO,EAAa,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7D,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI,CAmB5E"}
@@ -0,0 +1,24 @@
1
+ import { Authenticator } from "../auth.js";
2
+ import { errorBody } from "../context.js";
3
+ import { nowSeconds } from "../openai.js";
4
+ export function registerModels(app, ctx) {
5
+ app.get("/v1/models", async (req, reply) => {
6
+ const principal = ctx.auth.authenticate(Authenticator.extractToken(req.headers));
7
+ if (!principal) {
8
+ return reply.code(401).send(errorBody("invalid or missing API key", "invalid_api_key"));
9
+ }
10
+ const created = nowSeconds();
11
+ const data = ctx.manager
12
+ .listAgents()
13
+ .filter((a) => Authenticator.canUseAgent(principal, a.id))
14
+ .map((a) => ({
15
+ id: a.id,
16
+ object: "model",
17
+ created,
18
+ owned_by: "xeno-acp",
19
+ name: a.name,
20
+ }));
21
+ return { object: "list", data };
22
+ });
23
+ }
24
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/routes/models.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAqB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,UAAU,cAAc,CAAC,GAAoB,EAAE,GAAiB;IACpE,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,EAAE,GAAmB,EAAE,KAAmB,EAAE,EAAE;QACvE,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;QACjF,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,4BAA4B,EAAE,iBAAiB,CAAC,CAAC,CAAC;QAC1F,CAAC;QACD,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO;aACrB,UAAU,EAAE;aACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;aACzD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACX,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,MAAM,EAAE,OAAO;YACf,OAAO;YACP,QAAQ,EAAE,UAAU;YACpB,IAAI,EAAE,CAAC,CAAC,IAAI;SACb,CAAC,CAAC,CAAC;QACN,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Builds the Fastify app and wires a single shared `AcpManager`.
3
+ *
4
+ * The server is a thin translation shell over @xenosystem/acp-core: it owns no agent logic, only
5
+ * the OpenAI request/response mapping and auth.
6
+ */
7
+ import { type FastifyInstance } from "fastify";
8
+ import { AcpManager, type ResolvedConfig } from "@xenosystem/acp-core";
9
+ export interface BuiltServer {
10
+ app: FastifyInstance;
11
+ manager: AcpManager;
12
+ }
13
+ export declare function buildServer(config: ResolvedConfig): BuiltServer;
14
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,UAAU,EAAgB,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAOrF,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,eAAe,CAAC;IACrB,OAAO,EAAE,UAAU,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,WAAW,CAyB/D"}
package/dist/server.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Builds the Fastify app and wires a single shared `AcpManager`.
3
+ *
4
+ * The server is a thin translation shell over @xenosystem/acp-core: it owns no agent logic, only
5
+ * the OpenAI request/response mapping and auth.
6
+ */
7
+ import Fastify from "fastify";
8
+ import { AcpManager, createLogger } from "@xenosystem/acp-core";
9
+ import { Authenticator } from "./auth.js";
10
+ import { registerHealth } from "./routes/health.js";
11
+ import { registerModels } from "./routes/models.js";
12
+ import { registerChat } from "./routes/chat.js";
13
+ export function buildServer(config) {
14
+ const app = Fastify({
15
+ logger: false,
16
+ bodyLimit: 16 * 1024 * 1024, // 16 MB — room for long histories / inline content
17
+ });
18
+ const manager = new AcpManager(config, createLogger("server"));
19
+ const auth = new Authenticator(config);
20
+ const ctx = { manager, auth, config };
21
+ registerHealth(app, ctx);
22
+ registerModels(app, ctx);
23
+ registerChat(app, ctx);
24
+ app.setErrorHandler((err, _req, reply) => {
25
+ reply.code(err.statusCode ?? 500).send({
26
+ error: {
27
+ message: err.message,
28
+ type: "server_error",
29
+ code: "internal_error",
30
+ },
31
+ });
32
+ });
33
+ return { app, manager };
34
+ }
35
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,OAAiC,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAuB,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE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/v1/chat/completions.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "bin": {
10
+ "xeno-acp": "./dist/index.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "README.md",
15
+ "LICENSE",
16
+ "NOTICE",
17
+ "xeno-acp.config.example.jsonc"
18
+ ],
19
+ "engines": {
20
+ "node": ">=20"
21
+ },
22
+ "keywords": [
23
+ "acp",
24
+ "agent-client-protocol",
25
+ "openai-compatible",
26
+ "ai-gateway",
27
+ "xeno"
28
+ ],
29
+ "homepage": "https://xenostudio.ai/product/acp",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/XENO-CORPORATION/xeno-acp.git",
33
+ "directory": "packages/server"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/XENO-CORPORATION/xeno-acp/issues"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "fastify": "^5.1.0",
43
+ "@xenosystem/acp-core": "^0.1.1"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.9.0",
47
+ "tsx": "^4.19.2",
48
+ "typescript": "^5.6.3"
49
+ },
50
+ "scripts": {
51
+ "dev": "tsx watch src/index.ts",
52
+ "start": "node dist/index.js",
53
+ "build": "tsc -p tsconfig.json",
54
+ "typecheck": "tsc -p tsconfig.json --noEmit",
55
+ "clean": "rimraf dist *.tsbuildinfo"
56
+ }
57
+ }
@@ -0,0 +1,99 @@
1
+ {
2
+ // xeno-acp configuration. Copy to `xeno-acp.config.jsonc` (gitignored) and edit.
3
+ // String values support ${ENV_VAR} expansion.
4
+
5
+ "server": {
6
+ "host": "127.0.0.1",
7
+ "port": 8787,
8
+ // Auth mode: "bearer" (require a known key) or "open" (dev only — no auth).
9
+ "auth": "bearer"
10
+ },
11
+
12
+ // Default working-directory root for sandboxed session workspaces.
13
+ // Each session gets `${workspaceRoot}/<agentId>/<sessionId>/`.
14
+ "workspaceRoot": "./.xeno-acp/workspaces",
15
+ // Keep session workspaces after the turn ends (default false → cleaned up).
16
+ "keepWorkspaces": false,
17
+
18
+ // Per-agent defaults (can be overridden inside each agent entry).
19
+ "defaults": {
20
+ "maxConcurrentSessions": 4,
21
+ "permission": "auto", // "auto" | "deny" | "prompt"
22
+ "terminalTimeoutMs": 120000,
23
+ "initTimeoutMs": 60000
24
+ },
25
+
26
+ // Enabled agents. `id` is what consumers pass as the OpenAI `model`.
27
+ // Omit an entry to disable that agent. Built-in defaults exist for these agents;
28
+ // listing them here lets you override cmd/args/env/model.
29
+ "agents": [
30
+ {
31
+ "id": "claude-code",
32
+ "name": "Claude Code",
33
+ // Official Zed ACP adapter for Claude Code (bridges Claude Code's CLI to ACP).
34
+ "cmd": "npx",
35
+ "args": ["-y", "@zed-industries/claude-code-acp"],
36
+ "defaultModel": null
37
+ // Uses your existing Claude / Anthropic login.
38
+ },
39
+ {
40
+ "id": "codex",
41
+ "name": "Codex CLI",
42
+ "cmd": "npx",
43
+ "args": ["-y", "@zed-industries/codex-acp"],
44
+ "defaultModel": null
45
+ // Uses your existing ChatGPT / OpenAI (Codex) login.
46
+ },
47
+ {
48
+ "id": "opencode",
49
+ "name": "OpenCode",
50
+ // OpenCode speaks ACP natively.
51
+ "cmd": "opencode",
52
+ "args": ["acp"],
53
+ "defaultModel": null
54
+ },
55
+ {
56
+ "id": "gemini",
57
+ "name": "Gemini CLI",
58
+ // Gemini CLI speaks ACP natively via --acp.
59
+ "cmd": "gemini",
60
+ "args": ["--acp"],
61
+ "defaultModel": null
62
+ // Uses your Google login or GEMINI_API_KEY.
63
+ },
64
+ {
65
+ "id": "kimi",
66
+ "name": "Kimi CLI",
67
+ // Kimi CLI speaks ACP natively via `kimi acp`.
68
+ "cmd": "kimi",
69
+ "args": ["acp"],
70
+ "defaultModel": null
71
+ // Uses your existing Kimi / Moonshot login.
72
+ },
73
+ {
74
+ "id": "glm",
75
+ "name": "GLM Agent",
76
+ // GLM Agent is an ACP Registry package for Z.AI GLM Coding Plan.
77
+ "cmd": "npx",
78
+ "args": ["-y", "glm-acp-agent@latest"],
79
+ "defaultModel": null
80
+ // Uses your Z.AI Coding Plan auth.
81
+ }
82
+ ],
83
+
84
+ // Per-app API keys. Each consuming XENO app gets its own key for attribution,
85
+ // an optional agent allowlist, and optional limits. All consumers are the owner's apps.
86
+ "keys": [
87
+ {
88
+ "key": "dev-key",
89
+ "app": "local-dev",
90
+ "agents": ["*"], // "*" = all enabled agents, or a list of agent ids
91
+ "maxConcurrentSessions": 8
92
+ }
93
+ // {
94
+ // "key": "${XENO_WORKFLOW_KEY}",
95
+ // "app": "xeno-workflow",
96
+ // "agents": ["claude-code", "codex"]
97
+ // }
98
+ ]
99
+ }