@t54-labs/clawcredit-sdk 0.1.1 → 0.1.3

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 CHANGED
@@ -23,6 +23,12 @@ Install the SDK:
23
23
  npm install @t54-labs/clawcredit-sdk
24
24
  ```
25
25
 
26
+ Configure token via CLI (recommended for humans, not agents):
27
+
28
+ ```bash
29
+ clawcredit configure --token YOUR_API_TOKEN --service-url https://api.claw.credit
30
+ ```
31
+
26
32
  Initialize and register:
27
33
 
28
34
  ```javascript
package/SKILL.md CHANGED
@@ -1,11 +1,29 @@
1
+ ---
2
+ name: clawcredit
3
+ description: ClawCredit integration for Open Claw Agents (registration for credit, trace, and payments).
4
+ ---
5
+
1
6
  # ClawCredit Integration Skill
2
7
 
3
8
  ## 1. Overview
4
- This skill allows Open Claw Agents to access **ClawCredit**, a decentralized credit service.
5
- By integrating the `@clawcredit/sdk`, agents can:
6
- 1. **Get a Credit Line**: Prove your worth (code, prompt, environment) and get funded.
7
- 2. **Pay for Services**: Use your credit to pay other agents/merchants via x402.
8
- 3. **Build Credit**: Good repayment and low-risk behavior increases your limit.
9
+ This skill allows Open Claw Agents to access **ClawCredit**, a credit service that
10
+ requires verifiable integration evidence. The goal is to prove real capability
11
+ and real usage, not placeholder functions.
12
+
13
+ **Do NOT call ClawCredit APIs directly.** All registration and payment calls
14
+ must go through the SDK. Direct API calls bypass audit and trace capture and
15
+ will be rejected or scored lower by the risk engine.
16
+
17
+ By integrating the `@t54-labs/clawcredit-sdk`, agents can:
18
+ 1. **Get a Credit Line**: Submit real core logic + audit trace for initial credit.
19
+ 2. **Pay for Services**: Use your credit to pay other agents/merchants via x402.
20
+ 3. **Build Credit**: Good repayment and low-risk behavior increases your limit.
21
+
22
+ **Compliance affects limits**
23
+ - The more complete and truthful your context (core code, trace, reasoning, runtime),
24
+ the higher your credit limit can be.
25
+ - If you provide minimal or fabricated data, you may receive a very low limit
26
+ or no credit at all.
9
27
 
10
28
  ## 2. Prerequisites
11
29
  - **Node.js Environment** (The SDK is a Node.js package).
@@ -22,16 +40,33 @@ npm install @t54-labs/clawcredit-sdk
22
40
 
23
41
  ### Step 1: Initialization & Registration (with Code Audit)
24
42
  You must register to receive your initial Credit Line.
25
- **IMPORTANT**: Use the `audit()` wrapper on your core logic functions. This proves to the Risk Engine that your code is safe.
43
+ **IMPORTANT**: The audited function must be your REAL core logic, not a placeholder.
44
+ The audit materials are used by the risk engine and directly affect approval and credit size.
45
+
46
+ **What is "core logic"?**
47
+ - The function that handles your main task loop or tool orchestration.
48
+ - The function that decides when to call external services or spend credits.
49
+ - The function that processes user input and produces final outputs.
50
+
51
+ **What NOT to do**
52
+ - Do not use `function coreLogic(input) { return input; }`
53
+ - Do not upload a stub or empty function
54
+ - Do not rename a dummy function and pretend it is core logic
55
+
56
+ **What to do**
57
+ - Wrap the real function that contains your main decision flow
58
+ - Pass that audited function's code as `coreCode`
26
59
 
27
60
  ```javascript
28
61
  const { ClawCredit, audit } = require('@t54-labs/clawcredit-sdk');
29
62
 
30
- // 1. Audit your core functions (Optional but recommended for higher limit)
31
- function myCoreLogic(input) {
32
- // ... implementation ...
63
+ // 1. Audit your REAL core logic (required for credit approval)
64
+ function runAgentPipeline(task, tools) {
65
+ // Real routing, tool selection, and response generation
66
+ // Example: select tool, validate, call external API, post-process output
67
+ return tools.handle(task);
33
68
  }
34
- const safeLogic = audit(myCoreLogic);
69
+ const safeLogic = audit(runAgentPipeline);
35
70
 
36
71
  // 2. Initialize Client
37
72
  const credit = new ClawCredit({
@@ -41,7 +76,7 @@ const credit = new ClawCredit({
41
76
  // 3. Register
42
77
  await credit.register({
43
78
  inviteCode: "YOUR_INVITE_CODE",
44
- coreCode: "const agent = ...",
79
+ coreCode: safeLogic.toString(), // Must be the audited core logic above
45
80
  systemPrompt: "You are a helpful assistant...",
46
81
  runtimeEnv: "node-v22",
47
82
  model: "gpt-5.2" // Optional
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ const { loadConfig, saveConfig, DEFAULT_SERVICE_URL } = require('../lib/config');
3
+
4
+ function printHelp() {
5
+ console.log(`
6
+ ClawCredit CLI
7
+
8
+ Usage:
9
+ clawcredit configure --token <API_TOKEN> [--service-url <URL>] [--agent <id>]
10
+ clawcredit show [--agent <id>]
11
+
12
+ Notes:
13
+ - Config is stored at: ~/.openclaw/agents/<agent>/agent/clawcredit.json
14
+ - You can override the config path with CLAWCREDIT_CONFIG
15
+ `);
16
+ }
17
+
18
+ function parseArgs(argv) {
19
+ const args = {};
20
+ for (let i = 0; i < argv.length; i += 1) {
21
+ const key = argv[i];
22
+ if (!key.startsWith('--')) continue;
23
+ const value = argv[i + 1];
24
+ args[key.slice(2)] = value;
25
+ i += 1;
26
+ }
27
+ return args;
28
+ }
29
+
30
+ async function main() {
31
+ const [,, command, ...rest] = process.argv;
32
+ const args = parseArgs(rest);
33
+ const agent = args.agent || 'default';
34
+
35
+ if (!command || command === 'help' || command === '--help' || command === '-h') {
36
+ printHelp();
37
+ return;
38
+ }
39
+
40
+ if (command === 'configure' || command === 'set-token') {
41
+ const token = args.token;
42
+ const serviceUrl = args['service-url'] || DEFAULT_SERVICE_URL;
43
+
44
+ if (!token) {
45
+ console.error('Missing --token');
46
+ process.exit(1);
47
+ }
48
+
49
+ const configPath = saveConfig({ agent, token, serviceUrl });
50
+ console.log(`Saved: ${configPath}`);
51
+ return;
52
+ }
53
+
54
+ if (command === 'show') {
55
+ const { configPath, data, error } = loadConfig(agent);
56
+ if (error) {
57
+ console.error(`Failed to read ${configPath}: ${error.message}`);
58
+ process.exit(1);
59
+ }
60
+ if (!data) {
61
+ console.log(`No config found at: ${configPath}`);
62
+ process.exit(0);
63
+ }
64
+ console.log(JSON.stringify(data, null, 2));
65
+ return;
66
+ }
67
+
68
+ console.error(`Unknown command: ${command}`);
69
+ printHelp();
70
+ process.exit(1);
71
+ }
72
+
73
+ main();
74
+
package/index.js CHANGED
@@ -2,12 +2,20 @@ const axios = require('axios');
2
2
  const { v4: uuidv4 } = require('uuid');
3
3
  const { audit, getAuditedSnapshot } = require('./lib/audit');
4
4
  const { wrapOpenAI, withTrace, getTraceContext } = require('./lib/monitor');
5
+ const { loadConfig, DEFAULT_SERVICE_URL } = require('./lib/config');
6
+ const { getSdkMetadata } = require('./lib/sdk_meta');
5
7
 
6
8
  class ClawCredit {
7
9
  constructor(config = {}) {
8
- this.serviceUrl = config.serviceUrl || 'https://api.clawcredit.com'; // Default production URL
10
+ const agent = config.agent || 'default';
11
+ const loaded = loadConfig(agent);
12
+ const loadedData = loaded.data || {};
13
+
14
+ this.serviceUrl = config.serviceUrl
15
+ || loadedData.serviceUrl
16
+ || DEFAULT_SERVICE_URL;
9
17
  this.agentName = config.agentName;
10
- this.apiToken = config.apiToken; // Token stored after registration
18
+ this.apiToken = config.apiToken || loadedData.apiToken; // Token stored after registration
11
19
  this.agentId = config.agentId;
12
20
  }
13
21
 
@@ -20,17 +28,19 @@ class ClawCredit {
20
28
 
21
29
  // Include audited functions if available (via audit decorator)
22
30
  const auditedFunctions = getAuditedSnapshot();
31
+ const resolvedCoreCode = coreCode || (auditedFunctions[0] && auditedFunctions[0].function_code);
23
32
 
24
33
  try {
25
34
  const payload = {
26
35
  agent_name: this.agentName,
27
36
  invite_code: inviteCode,
28
37
  audit_material: {
29
- core_code: coreCode, // Main entry code provided manually
38
+ core_code: resolvedCoreCode, // Prefer audited function source
30
39
  audited_functions: auditedFunctions, // Auto-collected functions
31
40
  system_prompt: systemPrompt,
32
41
  runtime_env: runtimeEnv,
33
- model: model || null
42
+ model: model || null,
43
+ sdk_meta: getSdkMetadata()
34
44
  }
35
45
  };
36
46
 
@@ -42,7 +52,9 @@ class ClawCredit {
42
52
 
43
53
  return {
44
54
  agent_id: this.agentId,
55
+ api_token: res.data.api_token,
45
56
  credit_limit: res.data.credit_limit,
57
+ token_expires_at: res.data.token_expires_at || null,
46
58
  message: "Registration successful. Credit line issued."
47
59
  };
48
60
  } catch (error) {
package/lib/config.js ADDED
@@ -0,0 +1,50 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+
5
+ const DEFAULT_SERVICE_URL = 'https://api.claw.credit';
6
+
7
+ function getDefaultConfigPath(agent = 'default') {
8
+ const home = os.homedir();
9
+ return path.join(home, '.openclaw', 'agents', agent, 'agent', 'clawcredit.json');
10
+ }
11
+
12
+ function loadConfig(agent = 'default') {
13
+ const overridePath = process.env.CLAWCREDIT_CONFIG;
14
+ const configPath = overridePath || getDefaultConfigPath(agent);
15
+
16
+ if (!fs.existsSync(configPath)) {
17
+ return { configPath, data: null };
18
+ }
19
+
20
+ try {
21
+ const raw = fs.readFileSync(configPath, 'utf-8');
22
+ const data = JSON.parse(raw);
23
+ return { configPath, data };
24
+ } catch (err) {
25
+ return { configPath, data: null, error: err };
26
+ }
27
+ }
28
+
29
+ function saveConfig({ agent = 'default', token, serviceUrl }) {
30
+ const configPath = getDefaultConfigPath(agent);
31
+ const dir = path.dirname(configPath);
32
+ fs.mkdirSync(dir, { recursive: true });
33
+
34
+ const payload = {
35
+ apiToken: token,
36
+ serviceUrl: serviceUrl || DEFAULT_SERVICE_URL,
37
+ updatedAt: new Date().toISOString()
38
+ };
39
+
40
+ fs.writeFileSync(configPath, JSON.stringify(payload, null, 2));
41
+ return configPath;
42
+ }
43
+
44
+ module.exports = {
45
+ DEFAULT_SERVICE_URL,
46
+ getDefaultConfigPath,
47
+ loadConfig,
48
+ saveConfig
49
+ };
50
+
@@ -0,0 +1,27 @@
1
+ const os = require('os');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ function getSdkVersion() {
6
+ try {
7
+ const pkgPath = path.join(__dirname, '..', 'package.json');
8
+ const raw = fs.readFileSync(pkgPath, 'utf-8');
9
+ const pkg = JSON.parse(raw);
10
+ return pkg.version || 'unknown';
11
+ } catch (_) {
12
+ return 'unknown';
13
+ }
14
+ }
15
+
16
+ function getSdkMetadata() {
17
+ return {
18
+ sdk_name: '@t54-labs/clawcredit-sdk',
19
+ sdk_version: getSdkVersion(),
20
+ node_version: process.version,
21
+ platform: os.platform(),
22
+ arch: os.arch()
23
+ };
24
+ }
25
+
26
+ module.exports = { getSdkMetadata };
27
+
package/package.json CHANGED
@@ -1,8 +1,18 @@
1
1
  {
2
2
  "name": "@t54-labs/clawcredit-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Integration SDK for Open Claw Agents to access ClawCredit",
5
5
  "main": "index.js",
6
+ "bin": {
7
+ "clawcredit": "bin/clawcredit.js"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "lib",
12
+ "bin",
13
+ "README.md",
14
+ "SKILL.md"
15
+ ],
6
16
  "dependencies": {
7
17
  "axios": "^1.6.0",
8
18
  "uuid": "^9.0.0"
Binary file