@towns-labs/app-framework 4.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 +147 -0
- package/dist/app.d.ts +680 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +2324 -0
- package/dist/app.js.map +1 -0
- package/dist/app.test.d.ts +2 -0
- package/dist/app.test.d.ts.map +1 -0
- package/dist/app.test.js +2070 -0
- package/dist/app.test.js.map +1 -0
- package/dist/identity-types.d.ts +43 -0
- package/dist/identity-types.d.ts.map +1 -0
- package/dist/identity-types.js +2 -0
- package/dist/identity-types.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/eventDedup.d.ts +73 -0
- package/dist/modules/eventDedup.d.ts.map +1 -0
- package/dist/modules/eventDedup.js +105 -0
- package/dist/modules/eventDedup.js.map +1 -0
- package/dist/modules/eventDedup.test.d.ts +2 -0
- package/dist/modules/eventDedup.test.d.ts.map +1 -0
- package/dist/modules/eventDedup.test.js +222 -0
- package/dist/modules/eventDedup.test.js.map +1 -0
- package/dist/modules/interaction-api.d.ts +101 -0
- package/dist/modules/interaction-api.d.ts.map +1 -0
- package/dist/modules/interaction-api.js +213 -0
- package/dist/modules/interaction-api.js.map +1 -0
- package/dist/modules/payments.d.ts +89 -0
- package/dist/modules/payments.d.ts.map +1 -0
- package/dist/modules/payments.js +139 -0
- package/dist/modules/payments.js.map +1 -0
- package/dist/modules/user.d.ts +17 -0
- package/dist/modules/user.d.ts.map +1 -0
- package/dist/modules/user.js +54 -0
- package/dist/modules/user.js.map +1 -0
- package/dist/snapshot-getter.d.ts +21 -0
- package/dist/snapshot-getter.d.ts.map +1 -0
- package/dist/snapshot-getter.js +27 -0
- package/dist/snapshot-getter.js.map +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# @towns-labs/app-framework
|
|
2
|
+
|
|
3
|
+
An agent framework for Towns.
|
|
4
|
+
|
|
5
|
+
## Installing
|
|
6
|
+
|
|
7
|
+
We suggest users to quickstart a project using our cli.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ bunx towns-agent init
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If you prefer to install manually:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ bun add @towns-labs/app-framework viem hono
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
With Node:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { makeTownsApp } from "@towns-labs/app-framework";
|
|
25
|
+
import { serve } from "@hono/node-server";
|
|
26
|
+
|
|
27
|
+
const app = new Hono();
|
|
28
|
+
const agent = await makeTownsApp("<app-private-data-base64>");
|
|
29
|
+
|
|
30
|
+
agent.onMessage((handler, { channelId, isMentioned }) => {
|
|
31
|
+
if (isMentioned) {
|
|
32
|
+
handler.sendMessage(channelId, "Hello, world!");
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const { jwtMiddleware, handler } = agent.start();
|
|
37
|
+
app.post("/webhook", jwtMiddleware, handler);
|
|
38
|
+
|
|
39
|
+
serve({ fetch: app.fetch });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
With Bun:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { makeTownsApp } from "@towns-labs/app-framework";
|
|
46
|
+
|
|
47
|
+
const app = new Hono();
|
|
48
|
+
const agent = await makeTownsApp("<app-private-data-base64>");
|
|
49
|
+
|
|
50
|
+
agent.onMessage((handler, { channelId, isMentioned }) => {
|
|
51
|
+
if (isMentioned) {
|
|
52
|
+
handler.sendMessage(channelId, "Hello, world!");
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const { jwtMiddleware, handler } = agent.start();
|
|
57
|
+
app.post("/webhook", jwtMiddleware, handler);
|
|
58
|
+
|
|
59
|
+
export default app;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Identity Metadata (ERC-8004)
|
|
63
|
+
|
|
64
|
+
Agents can optionally define ERC-8004 compliant identity metadata for agent discovery and trust.
|
|
65
|
+
|
|
66
|
+
### Minimal Example
|
|
67
|
+
|
|
68
|
+
Create `identity.ts`:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import type { AgentAgentIdentityConfig } from "@towns-labs/app-framework";
|
|
72
|
+
|
|
73
|
+
const identity = {
|
|
74
|
+
name: "My Agent",
|
|
75
|
+
description: "A helpful agent for Towns",
|
|
76
|
+
image: "https://example.com/agent-logo.png",
|
|
77
|
+
domain: "myAgent.example.com",
|
|
78
|
+
} as const satisfies AgentIdentityConfig;
|
|
79
|
+
|
|
80
|
+
export default identity;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use in agent setup:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import identity from "./identity";
|
|
87
|
+
|
|
88
|
+
const agent = await makeTownsApp(process.env.APP_PRIVATE_DATA!, {
|
|
89
|
+
commands,
|
|
90
|
+
identity,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Get metadata for hosting at /.well-known/agent-metadata.json
|
|
94
|
+
const metadata = agent.getIdentityMetadata();
|
|
95
|
+
app.get("/.well-known/agent-metadata.json", metadata);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Advanced Example
|
|
99
|
+
|
|
100
|
+
For full ERC-8004 compliance with endpoints and trust models:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import type { AgentIdentityConfig } from "@towns-labs/app-framework";
|
|
104
|
+
|
|
105
|
+
const identity = {
|
|
106
|
+
name: "Advanced Agent",
|
|
107
|
+
description: "AI-powered agent with multi-protocol support",
|
|
108
|
+
image: "https://example.com/agent-logo.png",
|
|
109
|
+
motto: "Building the future of agent economies",
|
|
110
|
+
domain: "agent.example.com",
|
|
111
|
+
|
|
112
|
+
endpoints: [
|
|
113
|
+
{
|
|
114
|
+
name: "A2A",
|
|
115
|
+
endpoint: "https://agent.example.com/.well-known/agent-card.json",
|
|
116
|
+
version: "0.3.0",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "MCP",
|
|
120
|
+
endpoint: "https://mcp.agent.example.com/",
|
|
121
|
+
version: "2025-06-18",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
|
|
125
|
+
registrations: [],
|
|
126
|
+
|
|
127
|
+
supportedTrust: ["reputation", "crypto-economic"],
|
|
128
|
+
|
|
129
|
+
attributes: [
|
|
130
|
+
{ trait_type: "Category", value: "Gateway" },
|
|
131
|
+
{ trait_type: "Model", value: "GPT-4" },
|
|
132
|
+
],
|
|
133
|
+
} as const satisfies AgentIdentityConfig;
|
|
134
|
+
|
|
135
|
+
export default identity;
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The agent automatically adds `agentWallet` endpoint using the agent's app address and `A2A` endpoint if domain is configured.
|
|
139
|
+
|
|
140
|
+
## Debug Logging
|
|
141
|
+
|
|
142
|
+
Agent framework uses `debug` package for logging.
|
|
143
|
+
You can enable by setting the `DEBUG` environment variable to `csb:agent`.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
DEBUG=csb:agent node dist/agent.cjs
|
|
147
|
+
```
|