@mukae/contract 0.0.0-stage → 0.1.0-beta.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.d.ts +50 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const defaultGatewayPort = 47321;
|
|
2
|
+
export declare const gatewayPortCandidates: readonly number[];
|
|
3
|
+
export declare const launchScheme = "mukae";
|
|
4
|
+
export declare const launchCommand = "connect";
|
|
5
|
+
export declare const statusPath = "/status";
|
|
6
|
+
export declare const acpPath = "/acp";
|
|
7
|
+
export declare const gatewayStatuses: readonly ["waiting", "choosing", "unconfigured", "cancelled"];
|
|
8
|
+
export type GatewayStatus = (typeof gatewayStatuses)[number];
|
|
9
|
+
export declare const launchAgentTypes: readonly ["claude-acp", "codex-acp", "gemini", "opencode"];
|
|
10
|
+
export type LaunchAgentType = (typeof launchAgentTypes)[number];
|
|
11
|
+
export type AgentSlot = {
|
|
12
|
+
name: string;
|
|
13
|
+
agentType: string;
|
|
14
|
+
};
|
|
15
|
+
export type AgentSlotSelection = {
|
|
16
|
+
result: "use";
|
|
17
|
+
name: string;
|
|
18
|
+
} | {
|
|
19
|
+
result: "choose";
|
|
20
|
+
names: readonly string[];
|
|
21
|
+
} | {
|
|
22
|
+
result: "unconfigured";
|
|
23
|
+
};
|
|
24
|
+
export declare function buildLaunchUrl(input: {
|
|
25
|
+
nonce: string;
|
|
26
|
+
origin: string;
|
|
27
|
+
agentType: string;
|
|
28
|
+
port: number;
|
|
29
|
+
}): string;
|
|
30
|
+
export type LaunchRequest = {
|
|
31
|
+
nonce: string;
|
|
32
|
+
origin: string;
|
|
33
|
+
agentType: string;
|
|
34
|
+
port: number;
|
|
35
|
+
};
|
|
36
|
+
export declare function parseLaunchUrl(value: string): LaunchRequest | undefined;
|
|
37
|
+
export declare function isGatewayPort(value: number): boolean;
|
|
38
|
+
export declare function isNonce(value: string): boolean;
|
|
39
|
+
export declare function isAgentType(value: string): boolean;
|
|
40
|
+
export declare function isHttpOrigin(value: string): boolean;
|
|
41
|
+
export declare function selectAgentSlots(input: {
|
|
42
|
+
agentType: string;
|
|
43
|
+
slots: readonly AgentSlot[];
|
|
44
|
+
}): AgentSlotSelection;
|
|
45
|
+
export declare function parseStatusBody(value: unknown): GatewayStatus | undefined;
|
|
46
|
+
export declare function buildStatusUrl(port: number): string;
|
|
47
|
+
export declare function buildWebSocketUrl(input: {
|
|
48
|
+
port: number;
|
|
49
|
+
nonce: string;
|
|
50
|
+
}): string;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export const defaultGatewayPort = 47321;
|
|
2
|
+
// Each connection runs its own gateway process on one port from this list.
|
|
3
|
+
export const gatewayPortCandidates = Array.from({ length: 20 }, (_, index) => defaultGatewayPort + index);
|
|
4
|
+
export const launchScheme = "mukae";
|
|
5
|
+
export const launchCommand = "connect";
|
|
6
|
+
export const statusPath = "/status";
|
|
7
|
+
export const acpPath = "/acp";
|
|
8
|
+
export const gatewayStatuses = ["waiting", "choosing", "unconfigured", "cancelled"];
|
|
9
|
+
export const launchAgentTypes = ["claude-acp", "codex-acp", "gemini", "opencode"];
|
|
10
|
+
const noncePattern = /^[A-Za-z0-9_-]{8,128}$/;
|
|
11
|
+
const agentTypePattern = /^[a-z][a-z0-9-]{0,63}$/;
|
|
12
|
+
export function buildLaunchUrl(input) {
|
|
13
|
+
const url = new URL(`${launchScheme}://${launchCommand}`);
|
|
14
|
+
url.searchParams.set("nonce", input.nonce);
|
|
15
|
+
url.searchParams.set("origin", input.origin);
|
|
16
|
+
url.searchParams.set("agentType", input.agentType);
|
|
17
|
+
url.searchParams.set("port", String(input.port));
|
|
18
|
+
return url.toString();
|
|
19
|
+
}
|
|
20
|
+
export function parseLaunchUrl(value) {
|
|
21
|
+
let url;
|
|
22
|
+
try {
|
|
23
|
+
url = new URL(value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
if (url.protocol !== `${launchScheme}:` || url.hostname !== launchCommand) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const nonce = url.searchParams.get("nonce");
|
|
32
|
+
const origin = url.searchParams.get("origin");
|
|
33
|
+
const agentType = url.searchParams.get("agentType");
|
|
34
|
+
const port = Number(url.searchParams.get("port"));
|
|
35
|
+
if (!nonce ||
|
|
36
|
+
!isNonce(nonce) ||
|
|
37
|
+
!origin ||
|
|
38
|
+
!isHttpOrigin(origin) ||
|
|
39
|
+
!agentType ||
|
|
40
|
+
!isAgentType(agentType) ||
|
|
41
|
+
!isGatewayPort(port)) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return { nonce, origin, agentType, port };
|
|
45
|
+
}
|
|
46
|
+
export function isGatewayPort(value) {
|
|
47
|
+
return gatewayPortCandidates.includes(value);
|
|
48
|
+
}
|
|
49
|
+
export function isNonce(value) {
|
|
50
|
+
return noncePattern.test(value);
|
|
51
|
+
}
|
|
52
|
+
export function isAgentType(value) {
|
|
53
|
+
return agentTypePattern.test(value);
|
|
54
|
+
}
|
|
55
|
+
export function isHttpOrigin(value) {
|
|
56
|
+
try {
|
|
57
|
+
const url = new URL(value);
|
|
58
|
+
return (url.protocol === "http:" || url.protocol === "https:") && url.origin === value;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function selectAgentSlots(input) {
|
|
65
|
+
const names = input.slots.filter((slot) => slot.agentType === input.agentType).map((slot) => slot.name);
|
|
66
|
+
const onlyName = names[0];
|
|
67
|
+
if (names.length === 0 || onlyName === undefined)
|
|
68
|
+
return { result: "unconfigured" };
|
|
69
|
+
if (names.length === 1)
|
|
70
|
+
return { result: "use", name: onlyName };
|
|
71
|
+
return { result: "choose", names };
|
|
72
|
+
}
|
|
73
|
+
export function parseStatusBody(value) {
|
|
74
|
+
if (typeof value !== "object" || value === null || !("status" in value)) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const status = value.status;
|
|
78
|
+
return gatewayStatuses.find((candidate) => candidate === status);
|
|
79
|
+
}
|
|
80
|
+
export function buildStatusUrl(port) {
|
|
81
|
+
return `http://127.0.0.1:${port}${statusPath}`;
|
|
82
|
+
}
|
|
83
|
+
export function buildWebSocketUrl(input) {
|
|
84
|
+
const url = new URL(`ws://127.0.0.1:${input.port}${acpPath}`);
|
|
85
|
+
url.searchParams.set("nonce", input.nonce);
|
|
86
|
+
return url.toString();
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACxC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,qBAAqB,GAAsB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AAC7H,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC;AACpC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AACvC,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AACpC,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC;AAE9B,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,CAAU,CAAC;AAG7F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AAG3F,MAAM,YAAY,GA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|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Launch URL, ports, and status values for mukae.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/lulu0119/mukae.git",
|
|
12
|
+
"directory": "packages/contract"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^24.6.0",
|
|
25
|
+
"typescript": "^5.9.2"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json && printf '%s\n' '*.test.js' '*.test.js.map' '*.test.d.ts' '*.test.d.ts.map' '*.tsbuildinfo' > dist/.npmignore",
|
|
29
|
+
"test": "tsc -p tsconfig.json && node --test dist/contract.test.js"
|
|
30
|
+
}
|
|
6
31
|
}
|
package/README.md
DELETED