arc402-cli 0.2.0 → 0.3.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/README.md +2 -0
- package/dist/commands/accept.d.ts.map +1 -1
- package/dist/commands/accept.js +26 -1
- package/dist/commands/accept.js.map +1 -1
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +31 -0
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/arena-handshake.d.ts.map +1 -1
- package/dist/commands/arena-handshake.js +22 -0
- package/dist/commands/arena-handshake.js.map +1 -1
- package/dist/commands/deliver.d.ts.map +1 -1
- package/dist/commands/deliver.js +19 -0
- package/dist/commands/deliver.js.map +1 -1
- package/dist/commands/hire.d.ts.map +1 -1
- package/dist/commands/hire.js +29 -0
- package/dist/commands/hire.js.map +1 -1
- package/dist/commands/workroom.d.ts.map +1 -1
- package/dist/commands/workroom.js +37 -0
- package/dist/commands/workroom.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon/config.d.ts +1 -1
- package/dist/daemon/config.d.ts.map +1 -1
- package/dist/daemon/config.js +2 -2
- package/dist/daemon/config.js.map +1 -1
- package/dist/daemon/index.d.ts.map +1 -1
- package/dist/daemon/index.js +336 -1
- package/dist/daemon/index.js.map +1 -1
- package/dist/endpoint-notify.d.ts +18 -0
- package/dist/endpoint-notify.d.ts.map +1 -0
- package/dist/endpoint-notify.js +43 -0
- package/dist/endpoint-notify.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/accept.ts +31 -1
- package/src/commands/agent.ts +37 -0
- package/src/commands/arena-handshake.ts +33 -0
- package/src/commands/deliver.ts +19 -0
- package/src/commands/hire.ts +31 -1
- package/src/commands/workroom.ts +44 -0
- package/src/config.ts +1 -1
- package/src/daemon/config.ts +2 -2
- package/src/daemon/index.ts +347 -1
- package/src/endpoint-notify.ts +46 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared endpoint-notify helper for CLI commands.
|
|
3
|
+
* Resolves an agent's registered HTTP endpoint from AgentRegistry
|
|
4
|
+
* and POSTs lifecycle events after onchain transactions.
|
|
5
|
+
*/
|
|
6
|
+
import { ethers } from "ethers";
|
|
7
|
+
import { AGENT_REGISTRY_ABI } from "./abis";
|
|
8
|
+
|
|
9
|
+
export const DEFAULT_REGISTRY_ADDRESS = "0xD5c2851B00090c92Ba7F4723FB548bb30C9B6865";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Reads an agent's public HTTP endpoint from AgentRegistry.
|
|
13
|
+
* Returns empty string if not registered or no endpoint.
|
|
14
|
+
*/
|
|
15
|
+
export async function resolveAgentEndpoint(
|
|
16
|
+
address: string,
|
|
17
|
+
provider: ethers.Provider,
|
|
18
|
+
registryAddress = DEFAULT_REGISTRY_ADDRESS
|
|
19
|
+
): Promise<string> {
|
|
20
|
+
const registry = new ethers.Contract(registryAddress, AGENT_REGISTRY_ABI, provider);
|
|
21
|
+
const agentData = await registry.getAgent(address);
|
|
22
|
+
return (agentData.endpoint as string) ?? "";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* POSTs JSON payload to {endpoint}{path}. Returns true on success.
|
|
27
|
+
* Never throws — logs a warning on failure.
|
|
28
|
+
*/
|
|
29
|
+
export async function notifyAgent(
|
|
30
|
+
endpoint: string,
|
|
31
|
+
path: string,
|
|
32
|
+
payload: Record<string, unknown>
|
|
33
|
+
): Promise<boolean> {
|
|
34
|
+
if (!endpoint) return false;
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(`${endpoint}${path}`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: { "Content-Type": "application/json" },
|
|
39
|
+
body: JSON.stringify(payload),
|
|
40
|
+
});
|
|
41
|
+
return res.ok;
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.warn(`Warning: endpoint notify failed (${endpoint}${path}): ${err instanceof Error ? err.message : String(err)}`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|