@nevermined-io/openclaw-plugin 1.0.13 → 1.0.15
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 +39 -24
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/config.d.ts +6 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -1
- package/dist/paid-endpoint.d.ts +20 -0
- package/dist/paid-endpoint.d.ts.map +1 -0
- package/dist/paid-endpoint.js +152 -0
- package/dist/paid-endpoint.js.map +1 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +27 -2
- package/dist/tools.js.map +1 -1
- package/docs/commands.md +14 -15
- package/docs/getting-started.md +13 -8
- package/docs/guide.md +247 -0
- package/docs/setup.md +19 -10
- package/openclaw.plugin.json +10 -0
- package/package.json +2 -3
- package/skills/nevermined/SKILL.md +12 -17
- package/docs/links.md +0 -38
package/README.md
CHANGED
|
@@ -12,16 +12,19 @@ openclaw plugin install @nevermined-io/openclaw-plugin
|
|
|
12
12
|
|
|
13
13
|
The plugin supports two ways to provide your Nevermined API key:
|
|
14
14
|
|
|
15
|
-
### Option A:
|
|
15
|
+
### Option A: Slash command (recommended)
|
|
16
16
|
|
|
17
|
-
Use the `/
|
|
17
|
+
Use the `/nvm_login` command from any chat channel. This opens a browser window where you authenticate with Nevermined, and the API key is captured automatically.
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
/
|
|
21
|
-
/
|
|
22
|
-
/
|
|
20
|
+
/nvm_login # Login to sandbox (default)
|
|
21
|
+
/nvm_login live # Login to live environment
|
|
22
|
+
/nvm_login <api-key> # Paste an API key directly
|
|
23
|
+
/nvm_logout # Remove stored API key
|
|
23
24
|
```
|
|
24
25
|
|
|
26
|
+
On headless servers where a browser can't open, the command provides manual instructions with a login URL.
|
|
27
|
+
|
|
25
28
|
### Option B: Manual configuration
|
|
26
29
|
|
|
27
30
|
Add your API key directly to `openclaw.json`:
|
|
@@ -29,12 +32,19 @@ Add your API key directly to `openclaw.json`:
|
|
|
29
32
|
```json
|
|
30
33
|
{
|
|
31
34
|
"plugins": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
"entries": {
|
|
36
|
+
"nevermined": {
|
|
37
|
+
"enabled": true,
|
|
38
|
+
"config": {
|
|
39
|
+
"nvmApiKey": "sandbox:eyJhbG...",
|
|
40
|
+
"environment": "sandbox",
|
|
41
|
+
"planId": "<your-plan-id>",
|
|
42
|
+
"agentId": "<your-agent-id>",
|
|
43
|
+
"creditsPerRequest": 1,
|
|
44
|
+
"enablePaidEndpoint": false,
|
|
45
|
+
"agentEndpointPath": "/nevermined/agent"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
50
|
}
|
|
@@ -44,40 +54,45 @@ Add your API key directly to `openclaw.json`:
|
|
|
44
54
|
|
|
45
55
|
| Field | Required | Default | Description |
|
|
46
56
|
|-------|----------|---------|-------------|
|
|
47
|
-
| `nvmApiKey` | No | — | Your Nevermined API key (or use `/
|
|
57
|
+
| `nvmApiKey` | No | — | Your Nevermined API key (or use `/nvm_login`) |
|
|
48
58
|
| `environment` | No | `sandbox` | `sandbox` or `live` |
|
|
49
59
|
| `planId` | No | — | Default plan ID for subscriber tools |
|
|
50
60
|
| `agentId` | No | — | Default agent ID for multi-agent plans |
|
|
51
61
|
| `creditsPerRequest` | No | `1` | Credits consumed per request |
|
|
62
|
+
| `enablePaidEndpoint` | No | `false` | Enable the x402 paid HTTP endpoint on the gateway |
|
|
63
|
+
| `agentEndpointPath` | No | `/nevermined/agent` | HTTP path for the paid agent endpoint |
|
|
52
64
|
|
|
53
65
|
## Available Tools
|
|
54
66
|
|
|
55
|
-
###
|
|
67
|
+
### Slash Commands
|
|
56
68
|
|
|
57
|
-
|
|
|
58
|
-
|
|
59
|
-
|
|
|
60
|
-
|
|
|
69
|
+
| Command | Description |
|
|
70
|
+
|---------|-------------|
|
|
71
|
+
| `/nvm_login [environment]` | Authenticate via browser login or paste an API key |
|
|
72
|
+
| `/nvm_logout` | Remove stored API key |
|
|
61
73
|
|
|
62
74
|
### Subscriber Tools
|
|
63
75
|
|
|
64
76
|
| Tool | Description | Key Params |
|
|
65
77
|
|------|-------------|------------|
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
78
|
+
| `nevermined_checkBalance` | Check credit balance for a plan | `planId` |
|
|
79
|
+
| `nevermined_getAccessToken` | Get an x402 access token | `planId`, `agentId` |
|
|
80
|
+
| `nevermined_orderPlan` | Purchase a payment plan | `planId` |
|
|
81
|
+
| `nevermined_queryAgent` | Query an agent end-to-end | `agentUrl`, `prompt`, `planId`, `agentId` |
|
|
70
82
|
|
|
71
83
|
### Builder Tools
|
|
72
84
|
|
|
73
85
|
| Tool | Description | Key Params |
|
|
74
86
|
|------|-------------|------------|
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
87
|
+
| `nevermined_registerAgent` | Register an agent with a plan | `name`, `agentUrl`, `planName`, `priceAmounts`, `priceReceivers`, `creditsAmount`, `tokenAddress` |
|
|
88
|
+
| `nevermined_createPlan` | Create a payment plan | `name`, `priceAmounts`, `priceReceivers`, `creditsAmount`, `tokenAddress` |
|
|
89
|
+
| `nevermined_listPlans` | List your plans | — |
|
|
78
90
|
|
|
79
91
|
## Documentation
|
|
80
92
|
|
|
93
|
+
- [User Guide](./docs/guide.md) — step-by-step tutorial building a paid Weather Oracle agent
|
|
94
|
+
- [Commands Reference](./docs/commands.md) — full parameter documentation for all tools
|
|
95
|
+
- [Setup Reference](./docs/setup.md) — detailed configuration options
|
|
81
96
|
- [Nevermined Docs](https://docs.nevermined.app)
|
|
82
97
|
- [Payments SDK](https://github.com/nevermined-io/payments)
|
|
83
98
|
|
package/dist/auth.js
CHANGED
|
@@ -35,7 +35,7 @@ export function getApiKeyUrl(environment) {
|
|
|
35
35
|
* API keys have the format "environment:base64token".
|
|
36
36
|
*/
|
|
37
37
|
export function looksLikeApiKey(value) {
|
|
38
|
-
return /^(sandbox|live
|
|
38
|
+
return /^(sandbox|live):/.test(value.trim());
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Starts a one-shot HTTP server, opens the Nevermined login page in the browser,
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAGtD,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,YAAY;AAEnD,MAAM,YAAY,GAAG;;;;;;;CAOpB,CAAA;AAQD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,WAA4B;IACtD,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;IACzC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,GAAG,OAAO,CAAC,QAAQ,QAAQ,CAAA;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,WAA4B;IACvD,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;IACzC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAA;IAC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,GAAG,WAAW,WAAW;KACpC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QACjC,IAAI,GAAW,CAAA;QACf,IAAI,IAAc,CAAA;QAClB,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC1B,GAAG,GAAG,MAAM,CAAA;YACZ,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QACd,CAAC;aAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;YAChC,GAAG,GAAG,KAAK,CAAA;YACX,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;QACnC,CAAC;aAAM,CAAC;YACN,GAAG,GAAG,UAAU,CAAA;YAChB,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QACd,CAAC;QACD,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;YAC1B,IAAI,GAAG;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAA;;gBACf,OAAO,EAAE,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -6,9 +6,13 @@ export declare const NeverminedPluginConfigSchema: z.ZodObject<{
|
|
|
6
6
|
planId: z.ZodOptional<z.ZodString>;
|
|
7
7
|
agentId: z.ZodOptional<z.ZodString>;
|
|
8
8
|
creditsPerRequest: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
enablePaidEndpoint: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
agentEndpointPath: z.ZodDefault<z.ZodString>;
|
|
9
11
|
}, "strip", z.ZodTypeAny, {
|
|
10
12
|
environment: "sandbox" | "live";
|
|
11
13
|
creditsPerRequest: number;
|
|
14
|
+
enablePaidEndpoint: boolean;
|
|
15
|
+
agentEndpointPath: string;
|
|
12
16
|
nvmApiKey?: string | undefined;
|
|
13
17
|
planId?: string | undefined;
|
|
14
18
|
agentId?: string | undefined;
|
|
@@ -18,6 +22,8 @@ export declare const NeverminedPluginConfigSchema: z.ZodObject<{
|
|
|
18
22
|
planId?: string | undefined;
|
|
19
23
|
agentId?: string | undefined;
|
|
20
24
|
creditsPerRequest?: number | undefined;
|
|
25
|
+
enablePaidEndpoint?: boolean | undefined;
|
|
26
|
+
agentEndpointPath?: string | undefined;
|
|
21
27
|
}>;
|
|
22
28
|
export type NeverminedPluginConfig = z.infer<typeof NeverminedPluginConfigSchema>;
|
|
23
29
|
export declare function validateConfig(raw: unknown): NeverminedPluginConfig;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,eAAO,MAAM,4BAA4B
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;EAQvC,CAAA;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAA;AAEjF,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,sBAAsB,CAEnE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAKpE;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,sBAAsB,GAAG,QAAQ,CAKjF"}
|
package/dist/config.js
CHANGED
|
@@ -6,13 +6,15 @@ export const NeverminedPluginConfigSchema = z.object({
|
|
|
6
6
|
planId: z.string().optional(),
|
|
7
7
|
agentId: z.string().optional(),
|
|
8
8
|
creditsPerRequest: z.number().int().positive().default(1),
|
|
9
|
+
enablePaidEndpoint: z.boolean().default(false),
|
|
10
|
+
agentEndpointPath: z.string().default('/nevermined/agent'),
|
|
9
11
|
});
|
|
10
12
|
export function validateConfig(raw) {
|
|
11
13
|
return NeverminedPluginConfigSchema.parse(raw);
|
|
12
14
|
}
|
|
13
15
|
export function requireApiKey(config) {
|
|
14
16
|
if (!config.nvmApiKey) {
|
|
15
|
-
throw new Error('Not authenticated. Run
|
|
17
|
+
throw new Error('Not authenticated. Run /nvm_login first.');
|
|
16
18
|
}
|
|
17
19
|
return config.nvmApiKey;
|
|
18
20
|
}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAGlD,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC,MAAM,CAAC;IACnD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC3D,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;
|
|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C,WAAW,EAAE,MAAM,CAAC,WAA8B;KACnD,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { validateConfig, createPaymentsFromConfig, requireApiKey } from './config.js';
|
|
2
2
|
import { Payments } from '@nevermined-io/payments';
|
|
3
3
|
import type { NeverminedPluginConfig } from './config.js';
|
|
4
|
+
import type { AgentHandler } from './paid-endpoint.js';
|
|
4
5
|
export type { NeverminedPluginConfig };
|
|
6
|
+
export type { AgentHandler };
|
|
5
7
|
export { validateConfig, createPaymentsFromConfig, requireApiKey };
|
|
6
8
|
export { startLoginFlow, openBrowser } from './auth.js';
|
|
9
|
+
export { registerPaidEndpoint, mockWeatherHandler } from './paid-endpoint.js';
|
|
10
|
+
/**
|
|
11
|
+
* HTTP route handler signature used by OpenClaw's registerHttpRoute.
|
|
12
|
+
*/
|
|
13
|
+
export type HttpRouteHandler = (req: HttpIncomingMessage, res: HttpServerResponse) => void | Promise<void>;
|
|
14
|
+
export interface HttpIncomingMessage {
|
|
15
|
+
headers: Record<string, string | string[] | undefined>;
|
|
16
|
+
on(event: string, cb: (data?: unknown) => void): void;
|
|
17
|
+
}
|
|
18
|
+
export interface HttpServerResponse {
|
|
19
|
+
writeHead(statusCode: number, headers?: Record<string, string>): void;
|
|
20
|
+
end(body?: string): void;
|
|
21
|
+
}
|
|
7
22
|
/**
|
|
8
23
|
* Minimal subset of the OpenClaw Plugin API used by this plugin.
|
|
9
24
|
*/
|
|
@@ -28,6 +43,11 @@ export interface OpenClawPluginAPI {
|
|
|
28
43
|
handler: (ctx: CommandContext) => Promise<CommandResult> | CommandResult;
|
|
29
44
|
}): void;
|
|
30
45
|
registerGatewayMethod(method: string, handler: unknown): void;
|
|
46
|
+
registerHttpRoute?(route: {
|
|
47
|
+
path: string;
|
|
48
|
+
handler: HttpRouteHandler;
|
|
49
|
+
}): void;
|
|
50
|
+
on?(hookName: string, handler: (...args: unknown[]) => unknown): void;
|
|
31
51
|
}
|
|
32
52
|
export interface CommandContext {
|
|
33
53
|
senderId?: string;
|
|
@@ -42,6 +62,7 @@ export interface CommandResult {
|
|
|
42
62
|
}
|
|
43
63
|
export interface RegisterOptions {
|
|
44
64
|
paymentsFactory?: (config: NeverminedPluginConfig) => Payments;
|
|
65
|
+
agentHandler?: AgentHandler;
|
|
45
66
|
}
|
|
46
67
|
export interface ToolContext {
|
|
47
68
|
config?: Record<string, unknown>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIrF,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAElD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,YAAY,EAAE,sBAAsB,EAAE,CAAA;AACtC,YAAY,EAAE,YAAY,EAAE,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,aAAa,EAAE,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAE7E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,mBAAmB,EACxB,GAAG,EAAE,kBAAkB,KACpB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEzB,MAAM,WAAW,mBA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 @@
|
|
|
1
1
|
import { validateConfig, createPaymentsFromConfig, requireApiKey } from './config.js';
|
|
2
2
|
import { createTools } from './tools.js';
|
|
3
3
|
import { startLoginFlow, looksLikeApiKey, getLoginUrl, getApiKeyUrl } from './auth.js';
|
|
4
|
+
import { registerPaidEndpoint } from './paid-endpoint.js';
|
|
4
5
|
export { validateConfig, createPaymentsFromConfig, requireApiKey };
|
|
5
6
|
export { startLoginFlow, openBrowser } from './auth.js';
|
|
7
|
+
export { registerPaidEndpoint, mockWeatherHandler } from './paid-endpoint.js';
|
|
6
8
|
/**
|
|
7
9
|
* OpenClaw plugin definition object.
|
|
8
10
|
* Exports id, name, description, and a register function.
|
|
@@ -37,6 +39,35 @@ const neverminedPlugin = {
|
|
|
37
39
|
];
|
|
38
40
|
api.registerTool((_ctx) => createTools(getPayments, config), { names: toolNames });
|
|
39
41
|
api.logger.info(`Registered ${toolNames.length} Nevermined payment tools`);
|
|
42
|
+
// --- Paid HTTP endpoint ---
|
|
43
|
+
if (config.enablePaidEndpoint && api.registerHttpRoute) {
|
|
44
|
+
registerPaidEndpoint(api, getPayments, config, options?.agentHandler);
|
|
45
|
+
}
|
|
46
|
+
// --- Credit balance injection into agent context ---
|
|
47
|
+
if (api.on) {
|
|
48
|
+
let cachedBalance = null;
|
|
49
|
+
const CACHE_TTL_MS = 60000;
|
|
50
|
+
api.on('before_prompt_build', async () => {
|
|
51
|
+
if (!config.nvmApiKey || !config.planId)
|
|
52
|
+
return undefined;
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
if (cachedBalance && now - cachedBalance.fetchedAt < CACHE_TTL_MS) {
|
|
55
|
+
return { prependContext: formatBalanceContext(cachedBalance.balance, cachedBalance.planName) };
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const result = await getPayments().plans.getPlanBalance(config.planId);
|
|
59
|
+
cachedBalance = {
|
|
60
|
+
balance: result.balance.toString(),
|
|
61
|
+
planName: result.planName ?? config.planId,
|
|
62
|
+
fetchedAt: now,
|
|
63
|
+
};
|
|
64
|
+
return { prependContext: formatBalanceContext(cachedBalance.balance, cachedBalance.planName) };
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
40
71
|
// --- Slash commands for chat channels ---
|
|
41
72
|
api.registerCommand({
|
|
42
73
|
name: 'nvm_login',
|
|
@@ -96,5 +127,10 @@ const neverminedPlugin = {
|
|
|
96
127
|
});
|
|
97
128
|
},
|
|
98
129
|
};
|
|
130
|
+
function formatBalanceContext(balance, planName) {
|
|
131
|
+
const num = Number(balance);
|
|
132
|
+
const warning = num > 0 && num <= 5 ? ' (LOW — consider ordering more credits)' : '';
|
|
133
|
+
return `[Nevermined] Credits remaining: ${balance} (plan: ${planName})${warning}`;
|
|
134
|
+
}
|
|
99
135
|
export default neverminedPlugin;
|
|
100
136
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAQ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C,GAAG,CAAC,CAAA;oBAEnC,OAAO;wBACL,IAAI,EAAE;4BACJ,qFAAqF;4BACrF,EAAE;4BACF,gCAAgC,QAAQ,EAAE;4BAC1C,0CAA0C,SAAS,EAAE;4BACrD,uCAAuC;4BACvC,8BAA8B;4BAC9B,EAAE;4BACF,uBAAuB,GAAG,YAAY;yBACvC,CAAC,IAAI,CAAC,IAAI,CAAC;qBACb,CAAA;gBACH,CAAC;YACH,CAAC;SACF,CAAC,CAAA;QAEF,GAAG,CAAC,eAAe,CAAC;YAClB,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,yBAAyB;YACtC,WAAW,EAAE,IAAI;YACjB,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;gBAC5B,QAAQ,GAAG,IAAI,CAAA;gBACf,OAAO,EAAE,IAAI,EAAE,uDAAuD,EAAE,CAAA;YAC1E,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAED,SAAS,oBAAoB,CAAC,OAAe,EAAE,QAAgB;IAC7D,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC3B,MAAM,OAAO,GAAG,GAAG,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,yCAAyC,CAAC,CAAC,CAAC,EAAE,CAAA;IACpF,OAAO,mCAAmC,OAAO,WAAW,QAAQ,IAAI,OAAO,EAAE,CAAA;AACnF,CAAC;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Payments } from '@nevermined-io/payments';
|
|
2
|
+
import type { NeverminedPluginConfig } from './config.js';
|
|
3
|
+
import type { OpenClawPluginAPI } from './index.js';
|
|
4
|
+
export type AgentHandler = (body: {
|
|
5
|
+
prompt: string;
|
|
6
|
+
}) => Promise<unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* Registers a paid HTTP endpoint on the OpenClaw gateway.
|
|
9
|
+
* The endpoint handles x402 payment verification, processes requests,
|
|
10
|
+
* and settles credits after successful processing.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerPaidEndpoint(api: OpenClawPluginAPI, getPayments: () => Payments, config: NeverminedPluginConfig, agentHandler?: AgentHandler): void;
|
|
13
|
+
/**
|
|
14
|
+
* Mock weather forecast handler for demonstration purposes.
|
|
15
|
+
* Returns simulated weather data based on the prompt.
|
|
16
|
+
*/
|
|
17
|
+
export declare function mockWeatherHandler(body: {
|
|
18
|
+
prompt: string;
|
|
19
|
+
}): Promise<unknown>;
|
|
20
|
+
//# sourceMappingURL=paid-endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paid-endpoint.d.ts","sourceRoot":"","sources":["../src/paid-endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAEvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,YAAY,CAAA;AAErE,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAEzE;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,iBAAiB,EACtB,WAAW,EAAE,MAAM,QAAQ,EAC3B,MAAM,EAAE,sBAAsB,EAC9B,YAAY,CAAC,EAAE,YAAY,GAC1B,IAAI,CA8GN;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAUnF"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { buildPaymentRequired } from '@nevermined-io/payments';
|
|
2
|
+
/**
|
|
3
|
+
* Registers a paid HTTP endpoint on the OpenClaw gateway.
|
|
4
|
+
* The endpoint handles x402 payment verification, processes requests,
|
|
5
|
+
* and settles credits after successful processing.
|
|
6
|
+
*/
|
|
7
|
+
export function registerPaidEndpoint(api, getPayments, config, agentHandler) {
|
|
8
|
+
const path = config.agentEndpointPath ?? '/nevermined/agent';
|
|
9
|
+
const handler = agentHandler ?? mockWeatherHandler;
|
|
10
|
+
const routeHandler = async (req, res) => {
|
|
11
|
+
// 1. Build payment required descriptor
|
|
12
|
+
const planId = config.planId;
|
|
13
|
+
if (!planId) {
|
|
14
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
15
|
+
res.end(JSON.stringify({ error: 'Server misconfigured — planId not set' }));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const paymentRequired = buildPaymentRequired(planId, {
|
|
19
|
+
endpoint: path,
|
|
20
|
+
agentId: config.agentId,
|
|
21
|
+
httpVerb: 'POST',
|
|
22
|
+
});
|
|
23
|
+
const paymentRequiredHeader = Buffer.from(JSON.stringify(paymentRequired)).toString('base64');
|
|
24
|
+
const maxAmount = BigInt(config.creditsPerRequest ?? 1);
|
|
25
|
+
// 2. Extract payment signature
|
|
26
|
+
const accessToken = getHeader(req.headers, 'payment-signature') ??
|
|
27
|
+
getHeader(req.headers, 'PAYMENT-SIGNATURE');
|
|
28
|
+
if (!accessToken) {
|
|
29
|
+
res.writeHead(402, {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
'payment-required': paymentRequiredHeader,
|
|
32
|
+
});
|
|
33
|
+
res.end(JSON.stringify({ error: 'Payment required — missing payment-signature header' }));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// 3. Verify permissions (check credits without burning)
|
|
37
|
+
try {
|
|
38
|
+
const verification = await getPayments().facilitator.verifyPermissions({
|
|
39
|
+
paymentRequired,
|
|
40
|
+
x402AccessToken: accessToken,
|
|
41
|
+
maxAmount,
|
|
42
|
+
});
|
|
43
|
+
if (!verification.isValid) {
|
|
44
|
+
res.writeHead(402, {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
'payment-required': paymentRequiredHeader,
|
|
47
|
+
});
|
|
48
|
+
res.end(JSON.stringify({
|
|
49
|
+
error: 'Insufficient credits — order the plan first',
|
|
50
|
+
details: verification,
|
|
51
|
+
}));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
res.writeHead(402, {
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
'payment-required': paymentRequiredHeader,
|
|
59
|
+
});
|
|
60
|
+
res.end(JSON.stringify({
|
|
61
|
+
error: 'Payment verification failed',
|
|
62
|
+
message: err instanceof Error ? err.message : String(err),
|
|
63
|
+
}));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// 4. Parse request body and process
|
|
67
|
+
const body = await parseBody(req);
|
|
68
|
+
const prompt = typeof body === 'object' && body !== null && 'prompt' in body
|
|
69
|
+
? body.prompt
|
|
70
|
+
: String(body);
|
|
71
|
+
let result;
|
|
72
|
+
try {
|
|
73
|
+
result = await handler({ prompt });
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
77
|
+
res.end(JSON.stringify({
|
|
78
|
+
error: 'Agent processing failed',
|
|
79
|
+
message: err instanceof Error ? err.message : String(err),
|
|
80
|
+
}));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// 5. Settle permissions (burn credits)
|
|
84
|
+
let settlement;
|
|
85
|
+
try {
|
|
86
|
+
settlement = await getPayments().facilitator.settlePermissions({
|
|
87
|
+
paymentRequired,
|
|
88
|
+
x402AccessToken: accessToken,
|
|
89
|
+
maxAmount,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
// Log settlement failure but still return the result — the agent already processed
|
|
94
|
+
api.logger.warn(`Credit settlement failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
95
|
+
settlement = { error: 'settlement_failed' };
|
|
96
|
+
}
|
|
97
|
+
// 6. Return response with payment-response header
|
|
98
|
+
const paymentResponse = Buffer.from(JSON.stringify(settlement)).toString('base64');
|
|
99
|
+
res.writeHead(200, {
|
|
100
|
+
'Content-Type': 'application/json',
|
|
101
|
+
'payment-response': paymentResponse,
|
|
102
|
+
});
|
|
103
|
+
res.end(JSON.stringify(result));
|
|
104
|
+
};
|
|
105
|
+
api.registerHttpRoute({ path, handler: routeHandler });
|
|
106
|
+
api.logger.info(`Registered paid endpoint at ${path}`);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Mock weather forecast handler for demonstration purposes.
|
|
110
|
+
* Returns simulated weather data based on the prompt.
|
|
111
|
+
*/
|
|
112
|
+
export async function mockWeatherHandler(body) {
|
|
113
|
+
const city = extractCity(body.prompt) ?? 'Unknown';
|
|
114
|
+
return {
|
|
115
|
+
city,
|
|
116
|
+
forecast: 'Partly cloudy with a chance of innovation',
|
|
117
|
+
temperature: Math.floor(Math.random() * 30) + 5,
|
|
118
|
+
unit: 'celsius',
|
|
119
|
+
humidity: Math.floor(Math.random() * 60) + 30,
|
|
120
|
+
source: 'Weather Oracle (Nevermined demo)',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function extractCity(prompt) {
|
|
124
|
+
// Simple heuristic: look for "in <City>" or "for <City>" patterns
|
|
125
|
+
// Use word boundary to avoid matching partial words
|
|
126
|
+
// Use a lookbehind for word boundary + space to avoid matching "at" inside "What"
|
|
127
|
+
const match = prompt.match(/(?:^|\s)(?:in|for|at)\s+([A-Z][a-zA-Z\s]{1,30}?)(?:\?|$|\.|\s*,)/);
|
|
128
|
+
return match ? match[1].trim() : undefined;
|
|
129
|
+
}
|
|
130
|
+
function getHeader(headers, name) {
|
|
131
|
+
const value = headers[name] ?? headers[name.toLowerCase()];
|
|
132
|
+
if (Array.isArray(value))
|
|
133
|
+
return value[0];
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
function parseBody(req) {
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
const chunks = [];
|
|
139
|
+
req.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
140
|
+
req.on('end', () => {
|
|
141
|
+
const raw = Buffer.concat(chunks).toString('utf-8');
|
|
142
|
+
try {
|
|
143
|
+
resolve(raw ? JSON.parse(raw) : {});
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
resolve(raw);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
req.on('error', reject);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=paid-endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paid-endpoint.js","sourceRoot":"","sources":["../src/paid-endpoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAM9D;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,GAAsB,EACtB,WAA2B,EAC3B,MAA8B,EAC9B,YAA2B;IAE3B,MAAM,IAAI,GAAG,MAAM,CAAC,iBAAiB,IAAI,mBAAmB,CAAA;IAC5D,MAAM,OAAO,GAAG,YAAY,IAAI,kBAAkB,CAAA;IAElD,MAAM,YAAY,GAAqB,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QACxD,uCAAuC;QACvC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAA;YAC1D,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,uCAAuC,EAAE,CAAC,CAAC,CAAA;YAC3E,OAAM;QACR,CAAC;QAED,MAAM,eAAe,GAAG,oBAAoB,CAAC,MAAM,EAA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AAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;YACrC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,CAAC,GAAG,CAAC,CAAA;YACd,CAAC;QACH,CAAC,CAAC,CAAA;QACF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,MAAM,QAAQ,EAC3B,MAAM,EAAE,sBAAsB,GAC7B,UAAU,EAAE,CAqQd;AAID,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;CAC/E;AAED,UAAU,UAAU;IAClB,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC/C"}
|
package/dist/tools.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
1
2
|
/**
|
|
2
3
|
* Creates all Nevermined payment tools for the OpenClaw plugin.
|
|
3
4
|
* Each tool is an object with { name, description, parameters, execute }
|
|
@@ -130,6 +131,7 @@ export function createTools(getPayments, config) {
|
|
|
130
131
|
priceAmounts: { type: 'string', description: 'Comma-separated price amounts in wei' },
|
|
131
132
|
priceReceivers: { type: 'string', description: 'Comma-separated receiver addresses' },
|
|
132
133
|
creditsAmount: { type: 'number', description: 'Number of credits in the plan' },
|
|
134
|
+
tokenAddress: { type: 'string', description: 'ERC20 token address (e.g. USDC). Omit for native token.' },
|
|
133
135
|
},
|
|
134
136
|
required: ['name', 'agentUrl', 'planName', 'priceAmounts', 'priceReceivers', 'creditsAmount'],
|
|
135
137
|
},
|
|
@@ -145,7 +147,18 @@ export function createTools(getPayments, config) {
|
|
|
145
147
|
.split(',')
|
|
146
148
|
.map((s) => s.trim());
|
|
147
149
|
const creditsAmount = Number(requireStr(params, 'creditsAmount'));
|
|
148
|
-
const
|
|
150
|
+
const tokenAddress = str(params, 'tokenAddress');
|
|
151
|
+
const priceConfig = {
|
|
152
|
+
amounts: priceAmounts,
|
|
153
|
+
receivers: priceReceivers,
|
|
154
|
+
isCrypto: true,
|
|
155
|
+
tokenAddress: tokenAddress ?? ZERO_ADDRESS,
|
|
156
|
+
contractAddress: ZERO_ADDRESS,
|
|
157
|
+
feeController: ZERO_ADDRESS,
|
|
158
|
+
externalPriceAddress: ZERO_ADDRESS,
|
|
159
|
+
templateAddress: ZERO_ADDRESS,
|
|
160
|
+
};
|
|
161
|
+
const res = await getPayments().agents.registerAgentAndPlan({ name, description }, { endpoints: [{ POST: agentUrl }], agentDefinitionUrl: agentUrl }, { name: planName }, priceConfig, {
|
|
149
162
|
isRedemptionAmountFixed: true,
|
|
150
163
|
redemptionType: 4,
|
|
151
164
|
proofRequired: false,
|
|
@@ -170,6 +183,7 @@ export function createTools(getPayments, config) {
|
|
|
170
183
|
priceReceivers: { type: 'string', description: 'Comma-separated receiver addresses' },
|
|
171
184
|
creditsAmount: { type: 'number', description: 'Number of credits in the plan' },
|
|
172
185
|
accessLimit: { type: 'string', description: '"credits" or "time" (default: credits)' },
|
|
186
|
+
tokenAddress: { type: 'string', description: 'ERC20 token address (e.g. USDC). Omit for native token.' },
|
|
173
187
|
},
|
|
174
188
|
required: ['name', 'priceAmounts', 'priceReceivers', 'creditsAmount'],
|
|
175
189
|
},
|
|
@@ -184,7 +198,18 @@ export function createTools(getPayments, config) {
|
|
|
184
198
|
.map((s) => s.trim());
|
|
185
199
|
const creditsAmount = Number(requireStr(params, 'creditsAmount'));
|
|
186
200
|
const accessLimit = (str(params, 'accessLimit') ?? 'credits');
|
|
187
|
-
const
|
|
201
|
+
const tokenAddress = str(params, 'tokenAddress');
|
|
202
|
+
const priceConfig = {
|
|
203
|
+
amounts: priceAmounts,
|
|
204
|
+
receivers: priceReceivers,
|
|
205
|
+
isCrypto: true,
|
|
206
|
+
tokenAddress: tokenAddress ?? ZERO_ADDRESS,
|
|
207
|
+
contractAddress: ZERO_ADDRESS,
|
|
208
|
+
feeController: ZERO_ADDRESS,
|
|
209
|
+
externalPriceAddress: ZERO_ADDRESS,
|
|
210
|
+
templateAddress: ZERO_ADDRESS,
|
|
211
|
+
};
|
|
212
|
+
const res = await getPayments().plans.registerPlan({ name, description, accessLimit }, priceConfig, {
|
|
188
213
|
isRedemptionAmountFixed: true,
|
|
189
214
|
redemptionType: 4,
|
|
190
215
|
proofRequired: false,
|
package/dist/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,WAA2B,EAC3B,MAA8B;IAE9B,OAAO;QACL,2BAA2B;QAC3B;YACE,IAAI,EAAE,yBAAy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OAAgB;IAC9B,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;KACpE,CAAA;AACH,CAAC;AAED,SAAS,GAAG,CAAC,MAA+B,EAAE,GAAW;IACvD,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;IACrB,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,SAAS,CAAA;IAC/D,OAAO,MAAM,CAAC,CAAC,CAAC,CAAA;AAClB,CAAC;AAED,SAAS,UAAU,CAAC,MAA+B,EAAE,GAAW;IAC9D,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1B,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAA;IAC7D,OAAO,CAAC,CAAA;AACV,CAAC"}
|
package/docs/commands.md
CHANGED
|
@@ -10,7 +10,7 @@ The plugin provides slash commands for chat channels and gateway methods for pro
|
|
|
10
10
|
|
|
11
11
|
## Authentication
|
|
12
12
|
|
|
13
|
-
### `/
|
|
13
|
+
### `/nvm_login [environment]`
|
|
14
14
|
|
|
15
15
|
Authenticate with Nevermined via browser login.
|
|
16
16
|
|
|
@@ -18,29 +18,26 @@ Authenticate with Nevermined via browser login.
|
|
|
18
18
|
|-----------|------|----------|---------|-------------|
|
|
19
19
|
| `environment` | string | No | `sandbox` | `sandbox` or `live` |
|
|
20
20
|
|
|
21
|
-
**Gateway method:** `nevermined.login`
|
|
22
|
-
|
|
23
21
|
**Example:**
|
|
24
22
|
```
|
|
25
|
-
/
|
|
26
|
-
/
|
|
23
|
+
/nvm_login
|
|
24
|
+
/nvm_login live
|
|
25
|
+
/nvm_login sandbox:eyJhbG...
|
|
27
26
|
```
|
|
28
27
|
|
|
29
28
|
---
|
|
30
29
|
|
|
31
|
-
### `/
|
|
30
|
+
### `/nvm_logout`
|
|
32
31
|
|
|
33
32
|
Log out from Nevermined and remove the stored API key.
|
|
34
33
|
|
|
35
|
-
**Gateway method:** `nevermined.logout`
|
|
36
|
-
|
|
37
34
|
---
|
|
38
35
|
|
|
39
36
|
## Subscriber Tools
|
|
40
37
|
|
|
41
38
|
These tools are for users who want to subscribe to plans, check balances, and query agents.
|
|
42
39
|
|
|
43
|
-
### `
|
|
40
|
+
### `nevermined_checkBalance`
|
|
44
41
|
|
|
45
42
|
Check the credit balance for a payment plan.
|
|
46
43
|
|
|
@@ -60,7 +57,7 @@ Check the credit balance for a payment plan.
|
|
|
60
57
|
|
|
61
58
|
---
|
|
62
59
|
|
|
63
|
-
### `
|
|
60
|
+
### `nevermined_getAccessToken`
|
|
64
61
|
|
|
65
62
|
Get an x402 access token for authenticating requests to a Nevermined agent.
|
|
66
63
|
|
|
@@ -78,7 +75,7 @@ Get an x402 access token for authenticating requests to a Nevermined agent.
|
|
|
78
75
|
|
|
79
76
|
---
|
|
80
77
|
|
|
81
|
-
### `
|
|
78
|
+
### `nevermined_orderPlan`
|
|
82
79
|
|
|
83
80
|
Purchase (order) a Nevermined payment plan.
|
|
84
81
|
|
|
@@ -90,7 +87,7 @@ Purchase (order) a Nevermined payment plan.
|
|
|
90
87
|
|
|
91
88
|
---
|
|
92
89
|
|
|
93
|
-
### `
|
|
90
|
+
### `nevermined_queryAgent`
|
|
94
91
|
|
|
95
92
|
End-to-end agent query: acquires an x402 access token, sends the prompt to the agent URL with the `PAYMENT-SIGNATURE` header, and returns the response.
|
|
96
93
|
|
|
@@ -110,7 +107,7 @@ If the agent returns a 402 (Payment Required) response, the tool returns an erro
|
|
|
110
107
|
|
|
111
108
|
These tools are for agent builders who want to register agents and create payment plans.
|
|
112
109
|
|
|
113
|
-
### `
|
|
110
|
+
### `nevermined_registerAgent`
|
|
114
111
|
|
|
115
112
|
Register a new AI agent with an associated payment plan.
|
|
116
113
|
|
|
@@ -123,6 +120,7 @@ Register a new AI agent with an associated payment plan.
|
|
|
123
120
|
| `priceAmounts` | string | **Yes** | Comma-separated price amounts in wei |
|
|
124
121
|
| `priceReceivers` | string | **Yes** | Comma-separated receiver addresses |
|
|
125
122
|
| `creditsAmount` | number | **Yes** | Number of credits in the plan |
|
|
123
|
+
| `tokenAddress` | string | No | ERC20 token address (e.g. USDC). Omit for native token. |
|
|
126
124
|
|
|
127
125
|
**Returns:**
|
|
128
126
|
```json
|
|
@@ -135,7 +133,7 @@ Register a new AI agent with an associated payment plan.
|
|
|
135
133
|
|
|
136
134
|
---
|
|
137
135
|
|
|
138
|
-
### `
|
|
136
|
+
### `nevermined_createPlan`
|
|
139
137
|
|
|
140
138
|
Create a standalone payment plan (without an agent).
|
|
141
139
|
|
|
@@ -147,6 +145,7 @@ Create a standalone payment plan (without an agent).
|
|
|
147
145
|
| `priceReceivers` | string | **Yes** | Comma-separated receiver addresses |
|
|
148
146
|
| `creditsAmount` | number | **Yes** | Number of credits in the plan |
|
|
149
147
|
| `accessLimit` | string | No | `"credits"` (default) or `"time"` |
|
|
148
|
+
| `tokenAddress` | string | No | ERC20 token address (e.g. USDC). Omit for native token. |
|
|
150
149
|
|
|
151
150
|
**Returns:**
|
|
152
151
|
```json
|
|
@@ -157,7 +156,7 @@ Create a standalone payment plan (without an agent).
|
|
|
157
156
|
|
|
158
157
|
---
|
|
159
158
|
|
|
160
|
-
### `
|
|
159
|
+
### `nevermined_listPlans`
|
|
161
160
|
|
|
162
161
|
List the builder's payment plans. No parameters required.
|
|
163
162
|
|
package/docs/getting-started.md
CHANGED
|
@@ -26,10 +26,10 @@ openclaw plugin install @nevermined-io/openclaw-plugin
|
|
|
26
26
|
|
|
27
27
|
### Option A: Browser login (recommended)
|
|
28
28
|
|
|
29
|
-
Use the `/
|
|
29
|
+
Use the `/nvm_login` command from any connected chat channel:
|
|
30
30
|
|
|
31
31
|
```
|
|
32
|
-
/
|
|
32
|
+
/nvm_login
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
This opens a browser window where you authenticate with Nevermined. The API key is captured automatically and stored in your gateway config.
|
|
@@ -37,7 +37,7 @@ This opens a browser window where you authenticate with Nevermined. The API key
|
|
|
37
37
|
To target the live environment:
|
|
38
38
|
|
|
39
39
|
```
|
|
40
|
-
/
|
|
40
|
+
/nvm_login live
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
### Option B: Manual configuration
|
|
@@ -47,9 +47,14 @@ Add your API key directly to `openclaw.json`:
|
|
|
47
47
|
```json
|
|
48
48
|
{
|
|
49
49
|
"plugins": {
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
50
|
+
"entries": {
|
|
51
|
+
"nevermined": {
|
|
52
|
+
"enabled": true,
|
|
53
|
+
"config": {
|
|
54
|
+
"nvmApiKey": "sandbox:eyJhbG...",
|
|
55
|
+
"environment": "sandbox"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
}
|
|
@@ -61,9 +66,9 @@ You can obtain an API key from the [Nevermined App](https://nevermined.app) unde
|
|
|
61
66
|
|
|
62
67
|
After authenticating, verify the plugin is working:
|
|
63
68
|
|
|
64
|
-
1. **Check your balance** — from any chat channel, the agent can call `
|
|
69
|
+
1. **Check your balance** — from any chat channel, the agent can call `nevermined_checkBalance` to verify connectivity.
|
|
65
70
|
|
|
66
|
-
2. **List plans** — call `
|
|
71
|
+
2. **List plans** — call `nevermined_listPlans` to see available payment plans.
|
|
67
72
|
|
|
68
73
|
## Next Steps
|
|
69
74
|
|
package/docs/guide.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Building a Paid AI Agent with OpenClaw and Nevermined"
|
|
3
|
+
description: "Step-by-step guide to building, monetizing, and querying a paid AI agent using the Nevermined OpenClaw plugin"
|
|
4
|
+
icon: "book-open"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Building a Paid AI Agent with OpenClaw and Nevermined
|
|
8
|
+
|
|
9
|
+
The Nevermined OpenClaw plugin lets you monetize AI agents directly from chat channels. Subscribers pay per-request using the [x402 payment protocol](https://docs.nevermined.app/docs/api-reference/typescript/x402-protocol), and builders collect revenue automatically through on-chain payment plans.
|
|
10
|
+
|
|
11
|
+
This guide walks through building a **Weather Oracle** — a paid agent that serves weather forecasts and charges 1 credit per request.
|
|
12
|
+
|
|
13
|
+
## What You Get
|
|
14
|
+
|
|
15
|
+
The plugin adds 7 payment tools and 2 slash commands to your OpenClaw gateway:
|
|
16
|
+
|
|
17
|
+
**Subscriber tools** — for users who consume paid services:
|
|
18
|
+
|
|
19
|
+
| Tool | Purpose |
|
|
20
|
+
|------|---------|
|
|
21
|
+
| `nevermined_checkBalance` | Check remaining credits on a plan |
|
|
22
|
+
| `nevermined_getAccessToken` | Get an x402 token for authenticating requests |
|
|
23
|
+
| `nevermined_orderPlan` | Purchase a payment plan |
|
|
24
|
+
| `nevermined_queryAgent` | Send a paid query to an agent (end-to-end) |
|
|
25
|
+
|
|
26
|
+
**Builder tools** — for developers who create paid services:
|
|
27
|
+
|
|
28
|
+
| Tool | Purpose |
|
|
29
|
+
|------|---------|
|
|
30
|
+
| `nevermined_registerAgent` | Register an agent with a payment plan |
|
|
31
|
+
| `nevermined_createPlan` | Create a standalone payment plan |
|
|
32
|
+
| `nevermined_listPlans` | List your payment plans |
|
|
33
|
+
|
|
34
|
+
**Slash commands**: `/nvm_login` and `/nvm_logout` for authentication.
|
|
35
|
+
|
|
36
|
+
**Paid HTTP endpoint**: An x402-compatible endpoint on the gateway that handles payment verification, request processing, and credit settlement automatically.
|
|
37
|
+
|
|
38
|
+
## Prerequisites
|
|
39
|
+
|
|
40
|
+
- An [OpenClaw](https://openclaw.ai) gateway instance (v2026.2+)
|
|
41
|
+
- Node.js >= 18
|
|
42
|
+
- A [Nevermined account](https://nevermined.app) with an API key
|
|
43
|
+
|
|
44
|
+
## Step 1: Install the Plugin
|
|
45
|
+
|
|
46
|
+
From your OpenClaw gateway server:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
openclaw plugin install @nevermined-io/openclaw-plugin
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or install manually by placing the package in `~/.openclaw/extensions/nevermined/`.
|
|
53
|
+
|
|
54
|
+
After installation, restart the gateway:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
openclaw gateway restart
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You should see in the logs:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
Registered 7 Nevermined payment tools
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Step 2: Authenticate
|
|
67
|
+
|
|
68
|
+
Send `/nvm_login` from any connected chat channel (Telegram, Discord, etc.). The plugin supports two flows:
|
|
69
|
+
|
|
70
|
+
**Browser login** (if your server has a display):
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
/nvm_login
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A browser window opens for Nevermined authentication. The API key is captured automatically.
|
|
77
|
+
|
|
78
|
+
**Manual login** (headless servers):
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
/nvm_login sandbox:eyJhbGciOiJFUzI1NksifQ...
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Paste your API key directly. Get one from [Nevermined App](https://nevermined.app) under Settings > API Keys.
|
|
85
|
+
|
|
86
|
+
Use `sandbox` for testing, `live` for production.
|
|
87
|
+
|
|
88
|
+
## Step 3: Register Your Agent and Payment Plan
|
|
89
|
+
|
|
90
|
+
Ask your Claw to register an agent. In any chat channel, send a message like:
|
|
91
|
+
|
|
92
|
+
> Register a Nevermined agent called "Weather Oracle" at URL `https://my-gateway.example.com/nevermined/agent` with a plan named "Weather Forecast" priced at 1000000 (1 USDC) to address `0xYourWalletAddress` with token `0x036CbD53842c5426634e7929541eC2318f3dCF7e` granting 5 credits.
|
|
93
|
+
|
|
94
|
+
The agent will call `nevermined_registerAgent` with these parameters:
|
|
95
|
+
|
|
96
|
+
| Parameter | Value | Description |
|
|
97
|
+
|-----------|-------|-------------|
|
|
98
|
+
| `name` | Weather Oracle | Display name on Nevermined |
|
|
99
|
+
| `agentUrl` | `https://my-gateway.example.com/nevermined/agent` | Public URL of your paid endpoint |
|
|
100
|
+
| `planName` | Weather Forecast | Name for the payment plan |
|
|
101
|
+
| `priceAmounts` | `1000000` | Price in token units (1 USDC = 1,000,000 wei) |
|
|
102
|
+
| `priceReceivers` | `0xYourWalletAddress` | Your wallet that receives payments |
|
|
103
|
+
| `creditsAmount` | `5` | Credits granted per purchase |
|
|
104
|
+
| `tokenAddress` | `0x036CbD53842c5426634e7929541eC2318f3dCF7e` | USDC on Base Sepolia. Omit for native token. |
|
|
105
|
+
|
|
106
|
+
The tool returns the `agentId` and `planId` — save these for the next step.
|
|
107
|
+
|
|
108
|
+
## Step 4: Enable the Paid Endpoint
|
|
109
|
+
|
|
110
|
+
Add the returned IDs and enable the paid endpoint in your gateway config (`~/.openclaw/openclaw.json`):
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"plugins": {
|
|
115
|
+
"entries": {
|
|
116
|
+
"nevermined": {
|
|
117
|
+
"enabled": true,
|
|
118
|
+
"config": {
|
|
119
|
+
"nvmApiKey": "sandbox:eyJhbG...",
|
|
120
|
+
"environment": "sandbox",
|
|
121
|
+
"planId": "<your-plan-id>",
|
|
122
|
+
"agentId": "<your-agent-id>",
|
|
123
|
+
"enablePaidEndpoint": true,
|
|
124
|
+
"agentEndpointPath": "/nevermined/agent",
|
|
125
|
+
"creditsPerRequest": 1
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Restart the gateway. You should see:
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
Registered 7 Nevermined payment tools
|
|
137
|
+
Registered paid endpoint at /nevermined/agent
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The paid endpoint handles the full x402 lifecycle:
|
|
141
|
+
|
|
142
|
+
1. Extracts the `payment-signature` header from incoming requests
|
|
143
|
+
2. Calls `verifyPermissions` to check the subscriber has credits
|
|
144
|
+
3. Processes the request (runs your agent handler)
|
|
145
|
+
4. Calls `settlePermissions` to burn credits
|
|
146
|
+
5. Returns the response with a `payment-response` header
|
|
147
|
+
|
|
148
|
+
### Configuration Reference
|
|
149
|
+
|
|
150
|
+
| Field | Required | Default | Description |
|
|
151
|
+
|-------|----------|---------|-------------|
|
|
152
|
+
| `nvmApiKey` | No | — | API key (set via `/nvm_login` or config) |
|
|
153
|
+
| `environment` | No | `sandbox` | `sandbox` for testing, `live` for production |
|
|
154
|
+
| `planId` | No | — | Default plan ID for tools and the paid endpoint |
|
|
155
|
+
| `agentId` | No | — | Default agent ID |
|
|
156
|
+
| `creditsPerRequest` | No | `1` | Credits burned per request |
|
|
157
|
+
| `enablePaidEndpoint` | No | `false` | Enable the x402 paid HTTP endpoint |
|
|
158
|
+
| `agentEndpointPath` | No | `/nevermined/agent` | Path for the paid endpoint |
|
|
159
|
+
|
|
160
|
+
## Step 5: Test as a Subscriber
|
|
161
|
+
|
|
162
|
+
From the same gateway (or a different one with a subscriber API key), test the full flow:
|
|
163
|
+
|
|
164
|
+
### Order the plan
|
|
165
|
+
|
|
166
|
+
> Order the Weather Oracle plan `<plan-id>`
|
|
167
|
+
|
|
168
|
+
The Claw calls `nevermined_orderPlan`. You receive 5 credits.
|
|
169
|
+
|
|
170
|
+
### Check your balance
|
|
171
|
+
|
|
172
|
+
> Check my Nevermined balance for plan `<plan-id>`
|
|
173
|
+
|
|
174
|
+
Should show 5 credits.
|
|
175
|
+
|
|
176
|
+
### Query the agent
|
|
177
|
+
|
|
178
|
+
> Ask the Weather Oracle at `http://localhost:18789/nevermined/agent` about the weather in Barcelona
|
|
179
|
+
|
|
180
|
+
The Claw calls `nevermined_queryAgent`, which:
|
|
181
|
+
1. Acquires an x402 access token
|
|
182
|
+
2. Sends the prompt with a `PAYMENT-SIGNATURE` header
|
|
183
|
+
3. The paid endpoint verifies, processes, and settles
|
|
184
|
+
4. Returns the weather forecast
|
|
185
|
+
|
|
186
|
+
### Verify credit burn
|
|
187
|
+
|
|
188
|
+
> Check my balance again
|
|
189
|
+
|
|
190
|
+
Should show 4 credits — one was consumed.
|
|
191
|
+
|
|
192
|
+
## Custom Agent Handlers
|
|
193
|
+
|
|
194
|
+
The plugin includes a mock weather handler for demonstration. To use your own logic, pass a custom `agentHandler` when registering the plugin:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import neverminedPlugin from '@nevermined-io/openclaw-plugin'
|
|
198
|
+
|
|
199
|
+
neverminedPlugin.register(api, {
|
|
200
|
+
agentHandler: async (body) => {
|
|
201
|
+
const response = await myAIModel.generate(body.prompt)
|
|
202
|
+
return { result: response }
|
|
203
|
+
},
|
|
204
|
+
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The handler receives `{ prompt: string }` and returns any JSON-serializable object.
|
|
208
|
+
|
|
209
|
+
## Credit Balance Awareness
|
|
210
|
+
|
|
211
|
+
When the plugin is authenticated and a `planId` is configured, it automatically injects the current credit balance into the agent's context before each prompt. This means your Claw can proactively warn users when credits are running low:
|
|
212
|
+
|
|
213
|
+
> "You have 2 credits remaining on the Weather Forecast plan. Consider ordering more credits."
|
|
214
|
+
|
|
215
|
+
The balance is cached for 60 seconds to avoid excessive API calls.
|
|
216
|
+
|
|
217
|
+
## How It Works
|
|
218
|
+
|
|
219
|
+
The plugin implements the [x402 payment protocol](https://docs.nevermined.app/docs/api-reference/typescript/x402-protocol) for agent-to-agent payments:
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
Subscriber Claw Builder Claw (Gateway)
|
|
223
|
+
│ │
|
|
224
|
+
│ 1. getX402AccessToken(planId) │
|
|
225
|
+
│─────────────────────────────────────>│ Nevermined API
|
|
226
|
+
│<─────────────────────────────────────│ returns token
|
|
227
|
+
│ │
|
|
228
|
+
│ 2. POST /nevermined/agent │
|
|
229
|
+
│ Header: payment-signature: token │
|
|
230
|
+
│ Body: { prompt: "..." } │
|
|
231
|
+
│─────────────────────────────────────>│
|
|
232
|
+
│ │ 3. verifyPermissions()
|
|
233
|
+
│ │ 4. Process request
|
|
234
|
+
│ │ 5. settlePermissions()
|
|
235
|
+
│ 6. Response + payment-response hdr │
|
|
236
|
+
│<─────────────────────────────────────│
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Credits are managed on-chain through the Nevermined Protocol. The `verifyPermissions` step checks the subscriber's balance without burning credits, and `settlePermissions` burns them only after successful processing.
|
|
240
|
+
|
|
241
|
+
## Next Steps
|
|
242
|
+
|
|
243
|
+
- [Commands Reference](./commands) — full parameter documentation for all tools
|
|
244
|
+
- [Setup Reference](./setup) — detailed configuration options
|
|
245
|
+
- [Nevermined Docs](https://docs.nevermined.app) — platform documentation
|
|
246
|
+
- [x402 Protocol](https://docs.nevermined.app/docs/api-reference/typescript/x402-protocol) — payment protocol specification
|
|
247
|
+
- [OpenClaw Plugin Development](https://docs.openclaw.ai/tools/plugin) — building OpenClaw plugins
|
package/docs/setup.md
CHANGED
|
@@ -13,12 +13,19 @@ The plugin reads its configuration from the `plugins.nevermined` section of your
|
|
|
13
13
|
```json
|
|
14
14
|
{
|
|
15
15
|
"plugins": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
"entries": {
|
|
17
|
+
"nevermined": {
|
|
18
|
+
"enabled": true,
|
|
19
|
+
"config": {
|
|
20
|
+
"nvmApiKey": "sandbox:eyJhbG...",
|
|
21
|
+
"environment": "sandbox",
|
|
22
|
+
"planId": "did:nv:abc123...",
|
|
23
|
+
"agentId": "did:nv:def456...",
|
|
24
|
+
"creditsPerRequest": 1,
|
|
25
|
+
"enablePaidEndpoint": false,
|
|
26
|
+
"agentEndpointPath": "/nevermined/agent"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
}
|
|
@@ -28,11 +35,13 @@ The plugin reads its configuration from the `plugins.nevermined` section of your
|
|
|
28
35
|
|
|
29
36
|
| Field | Required | Default | Description |
|
|
30
37
|
|-------|----------|---------|-------------|
|
|
31
|
-
| `nvmApiKey` | No | — | Your Nevermined API key. Can be set via `/
|
|
38
|
+
| `nvmApiKey` | No | — | Your Nevermined API key. Can be set via `/nvm_login` instead. |
|
|
32
39
|
| `environment` | No | `sandbox` | Target environment: `sandbox` for testing, `live` for production. |
|
|
33
40
|
| `planId` | No | — | Default payment plan ID. When set, subscriber tools use this plan automatically. |
|
|
34
41
|
| `agentId` | No | — | Default agent ID. Required for plans with multiple agents. |
|
|
35
42
|
| `creditsPerRequest` | No | `1` | Number of credits consumed per request. |
|
|
43
|
+
| `enablePaidEndpoint` | No | `false` | Enable the x402 paid HTTP endpoint on the gateway. |
|
|
44
|
+
| `agentEndpointPath` | No | `/nevermined/agent` | HTTP path for the paid agent endpoint. |
|
|
36
45
|
|
|
37
46
|
### Environment Details
|
|
38
47
|
|
|
@@ -45,17 +54,17 @@ The plugin reads its configuration from the `plugins.nevermined` section of your
|
|
|
45
54
|
|
|
46
55
|
The plugin supports a browser-based login flow identical to the [Nevermined CLI](/docs/api-reference/cli/getting-started):
|
|
47
56
|
|
|
48
|
-
1. User sends `/
|
|
57
|
+
1. User sends `/nvm_login` in any chat channel
|
|
49
58
|
2. The plugin starts a local HTTP server on a random port
|
|
50
59
|
3. A browser window opens to the Nevermined login page
|
|
51
60
|
4. After authentication, Nevermined redirects back with the API key
|
|
52
|
-
5. The key is stored in the
|
|
61
|
+
5. The key is stored in the plugin's in-memory config for the current session
|
|
53
62
|
|
|
54
63
|
The login times out after 5 minutes if no authentication is received.
|
|
55
64
|
|
|
56
65
|
### Logging Out
|
|
57
66
|
|
|
58
|
-
Send `/
|
|
67
|
+
Send `/nvm_logout` or call `nvm_logout` to remove the stored API key. All payment tools will require re-authentication after logout.
|
|
59
68
|
|
|
60
69
|
## Default Values
|
|
61
70
|
|
package/openclaw.plugin.json
CHANGED
|
@@ -28,6 +28,16 @@
|
|
|
28
28
|
"type": "number",
|
|
29
29
|
"default": 1,
|
|
30
30
|
"description": "Number of credits consumed per request"
|
|
31
|
+
},
|
|
32
|
+
"enablePaidEndpoint": {
|
|
33
|
+
"type": "boolean",
|
|
34
|
+
"default": false,
|
|
35
|
+
"description": "Enable the paid HTTP endpoint on the gateway for receiving paid queries"
|
|
36
|
+
},
|
|
37
|
+
"agentEndpointPath": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"default": "/nevermined/agent",
|
|
40
|
+
"description": "HTTP path for the paid agent endpoint"
|
|
31
41
|
}
|
|
32
42
|
}
|
|
33
43
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nevermined-io/openclaw-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "OpenClaw plugin for Nevermined — exposes subscriber and builder tools as gateway methods",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"typescript": "^5.4.0",
|
|
35
35
|
"eslint": "^8.57.0",
|
|
36
36
|
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
37
|
-
"@typescript-eslint/parser": "^7.0.0"
|
|
38
|
-
"zod": "^3.23.0"
|
|
37
|
+
"@typescript-eslint/parser": "^7.0.0"
|
|
39
38
|
},
|
|
40
39
|
"dependencies": {
|
|
41
40
|
"zod": "^3.23.0"
|
|
@@ -11,36 +11,29 @@ This plugin provides gateway tools for interacting with Nevermined AI agent paym
|
|
|
11
11
|
|
|
12
12
|
## Authentication
|
|
13
13
|
|
|
14
|
-
### `/
|
|
15
|
-
Authenticate with Nevermined via browser login. Opens a browser window to obtain an API key.
|
|
14
|
+
### `/nvm_login [environment]`
|
|
15
|
+
Authenticate with Nevermined via browser login. Opens a browser window to obtain an API key. You can also paste an API key directly: `/nvm_login <api-key>`.
|
|
16
16
|
- `environment` (optional) — `sandbox` or `live` (default: from config)
|
|
17
17
|
|
|
18
|
-
### `/
|
|
18
|
+
### `/nvm_logout`
|
|
19
19
|
Log out from Nevermined and remove the stored API key.
|
|
20
20
|
|
|
21
|
-
### `nevermined.login`
|
|
22
|
-
Gateway method equivalent of `/nvm-login`.
|
|
23
|
-
- `environment` (optional)
|
|
24
|
-
|
|
25
|
-
### `nevermined.logout`
|
|
26
|
-
Gateway method equivalent of `/nvm-logout`.
|
|
27
|
-
|
|
28
21
|
## Subscriber Tools
|
|
29
22
|
|
|
30
|
-
### `
|
|
23
|
+
### `nevermined_checkBalance`
|
|
31
24
|
Check credit balance for a payment plan.
|
|
32
25
|
- `planId` (optional if set in config) — the plan to check
|
|
33
26
|
|
|
34
|
-
### `
|
|
27
|
+
### `nevermined_getAccessToken`
|
|
35
28
|
Get an x402 access token for authenticating agent requests.
|
|
36
29
|
- `planId` (optional if set in config)
|
|
37
30
|
- `agentId` (optional if set in config)
|
|
38
31
|
|
|
39
|
-
### `
|
|
32
|
+
### `nevermined_orderPlan`
|
|
40
33
|
Purchase a payment plan.
|
|
41
34
|
- `planId` (optional if set in config)
|
|
42
35
|
|
|
43
|
-
### `
|
|
36
|
+
### `nevermined_queryAgent`
|
|
44
37
|
End-to-end agent query — acquires a token, calls the agent, returns the response.
|
|
45
38
|
- `agentUrl` (required) — the agent endpoint URL
|
|
46
39
|
- `prompt` (required) — the prompt to send
|
|
@@ -50,7 +43,7 @@ End-to-end agent query — acquires a token, calls the agent, returns the respon
|
|
|
50
43
|
|
|
51
44
|
## Builder Tools
|
|
52
45
|
|
|
53
|
-
### `
|
|
46
|
+
### `nevermined_registerAgent`
|
|
54
47
|
Register a new AI agent with a payment plan.
|
|
55
48
|
- `name` (required) — agent name
|
|
56
49
|
- `agentUrl` (required) — agent endpoint
|
|
@@ -58,14 +51,16 @@ Register a new AI agent with a payment plan.
|
|
|
58
51
|
- `priceAmounts` (required) — comma-separated prices in wei
|
|
59
52
|
- `priceReceivers` (required) — comma-separated receiver addresses
|
|
60
53
|
- `creditsAmount` (required) — number of credits
|
|
54
|
+
- `tokenAddress` (optional) — ERC20 token address (e.g. USDC). Omit for native token.
|
|
61
55
|
|
|
62
|
-
### `
|
|
56
|
+
### `nevermined_createPlan`
|
|
63
57
|
Create a standalone payment plan.
|
|
64
58
|
- `name` (required) — plan name
|
|
65
59
|
- `priceAmounts` (required) — comma-separated prices in wei
|
|
66
60
|
- `priceReceivers` (required) — comma-separated receiver addresses
|
|
67
61
|
- `creditsAmount` (required) — number of credits
|
|
68
62
|
- `accessLimit` (optional) — `"credits"` or `"time"`
|
|
63
|
+
- `tokenAddress` (optional) — ERC20 token address (e.g. USDC). Omit for native token.
|
|
69
64
|
|
|
70
|
-
### `
|
|
65
|
+
### `nevermined_listPlans`
|
|
71
66
|
List your payment plans. No parameters.
|
package/docs/links.md
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Resources"
|
|
3
|
-
description: "Links to Nevermined documentation, SDKs, and community resources"
|
|
4
|
-
icon: "book"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Resources
|
|
8
|
-
|
|
9
|
-
## Nevermined Documentation
|
|
10
|
-
|
|
11
|
-
| Resource | Description |
|
|
12
|
-
|----------|-------------|
|
|
13
|
-
| [Nevermined Docs](https://docs.nevermined.app) | Full platform documentation |
|
|
14
|
-
| [Get Your API Key](https://docs.nevermined.app/docs/getting-started/get-your-api-key) | How to create a Nevermined account and obtain an API key |
|
|
15
|
-
| [Payment Plans](https://docs.nevermined.app/docs/api-reference/typescript/payment-plans-and-agents) | Creating and managing payment plans |
|
|
16
|
-
| [Querying Agents](https://docs.nevermined.app/docs/api-reference/typescript/querying-an-agent) | How to query agents using x402 access tokens |
|
|
17
|
-
| [x402 Protocol](https://docs.nevermined.app/docs/api-reference/typescript/x402-protocol) | The HTTP payment protocol specification |
|
|
18
|
-
|
|
19
|
-
## SDKs
|
|
20
|
-
|
|
21
|
-
| SDK | Language | Package |
|
|
22
|
-
|-----|----------|---------|
|
|
23
|
-
| [Payments SDK](https://github.com/nevermined-io/payments) | TypeScript | `@nevermined-io/payments` |
|
|
24
|
-
| [Payments SDK (Python)](https://github.com/nevermined-io/payments-py) | Python | `payments-py` |
|
|
25
|
-
| [Nevermined CLI](https://www.npmjs.com/package/@nevermined-io/cli) | TypeScript | `@nevermined-io/cli` |
|
|
26
|
-
|
|
27
|
-
## OpenClaw
|
|
28
|
-
|
|
29
|
-
| Resource | Description |
|
|
30
|
-
|----------|-------------|
|
|
31
|
-
| [OpenClaw Docs](https://docs.openclaw.ai) | OpenClaw gateway documentation |
|
|
32
|
-
| [Plugin Development](https://docs.openclaw.ai/tools/plugin) | How to build OpenClaw plugins |
|
|
33
|
-
|
|
34
|
-
## Support
|
|
35
|
-
|
|
36
|
-
- [GitHub Issues](https://github.com/nevermined-io/payments/issues) — report bugs or request features
|
|
37
|
-
- [Nevermined Discord](https://discord.gg/nevermined) — community support
|
|
38
|
-
- [Nevermined App](https://nevermined.app) — manage your account, plans, and agents
|