@token2chat/t2c 0.2.0 → 0.2.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.
@@ -6,7 +6,8 @@
6
6
  import fs from "node:fs/promises";
7
7
  import path from "node:path";
8
8
  import os from "node:os";
9
- import { loadOrCreateProxySecret } from "../config.js";
9
+ import { loadOrCreateProxySecret, WALLET_PATH, formatUnits } from "../config.js";
10
+ import { CashuStore } from "../cashu-store.js";
10
11
  /**
11
12
  * Default models when Gate is unreachable.
12
13
  * IDs use dash format (proxy transforms to slash for Gate/OpenRouter).
@@ -72,25 +73,6 @@ async function getConfigPath() {
72
73
  */
73
74
  function mergeToken2ChatConfig(existingConfig, t2cConfig, gateModels, apiKey) {
74
75
  const config = { ...existingConfig };
75
- // Ensure plugins.entries exists
76
- if (!config.plugins || typeof config.plugins !== "object") {
77
- config.plugins = {};
78
- }
79
- const plugins = config.plugins;
80
- if (!plugins.entries || typeof plugins.entries !== "object") {
81
- plugins.entries = {};
82
- }
83
- const entries = plugins.entries;
84
- // Set/overwrite token2chat plugin config
85
- entries.token2chat = {
86
- enabled: true,
87
- config: {
88
- gateUrl: t2cConfig.gateUrl,
89
- mintUrl: t2cConfig.mintUrl,
90
- proxyPort: t2cConfig.proxyPort,
91
- walletPath: t2cConfig.walletPath,
92
- },
93
- };
94
76
  // Ensure models.providers exists
95
77
  if (!config.models || typeof config.models !== "object") {
96
78
  config.models = {};
@@ -101,11 +83,29 @@ function mergeToken2ChatConfig(existingConfig, t2cConfig, gateModels, apiKey) {
101
83
  }
102
84
  const providers = models.providers;
103
85
  // Set/overwrite token2chat provider config
86
+ const activeModels = gateModels.length > 0 ? gateModels : DEFAULT_MODELS;
104
87
  providers.token2chat = {
105
88
  baseUrl: `http://127.0.0.1:${t2cConfig.proxyPort}/v1`,
106
89
  apiKey,
107
90
  api: "openai-completions",
108
- models: gateModels.length > 0 ? gateModels : DEFAULT_MODELS,
91
+ models: activeModels,
92
+ };
93
+ // Set up agents.defaults with token2chat model allowlist and fallbacks
94
+ if (!config.agents || typeof config.agents !== "object") {
95
+ config.agents = {};
96
+ }
97
+ const agents = config.agents;
98
+ if (!agents.defaults || typeof agents.defaults !== "object") {
99
+ agents.defaults = {};
100
+ }
101
+ const defaults = agents.defaults;
102
+ const modelIds = activeModels.map((m) => m.id);
103
+ defaults.models = modelIds;
104
+ defaults.model = {
105
+ ...(typeof defaults.model === "object" && defaults.model !== null
106
+ ? defaults.model
107
+ : {}),
108
+ fallbacks: modelIds,
109
109
  };
110
110
  return config;
111
111
  }
@@ -175,6 +175,16 @@ export const openclawConnector = {
175
175
  if (existingContent) {
176
176
  console.log(` Backup: ${backupPath}`);
177
177
  }
178
+ // Show wallet balance for onboarding
179
+ try {
180
+ const wallet = await CashuStore.load(WALLET_PATH, config.mintUrl);
181
+ console.log(`\nšŸ’° Wallet balance: ${formatUnits(wallet.balance)}`);
182
+ }
183
+ catch {
184
+ console.log("\nšŸ’° Wallet: not funded yet");
185
+ console.log(` Fund your wallet: t2c mint <amount>`);
186
+ console.log(` Mint URL: ${config.mintUrl}`);
187
+ }
178
188
  console.log("\nšŸ“‹ Next steps:\n");
179
189
  console.log(" 1. Restart OpenClaw gateway:");
180
190
  console.log(" openclaw gateway restart\n");
@@ -189,11 +199,9 @@ export const openclawConnector = {
189
199
  const configPath = await getConfigPath();
190
200
  const content = await fs.readFile(configPath, "utf-8");
191
201
  const doc = JSON.parse(content);
192
- const plugins = doc?.plugins;
193
- const entries = plugins?.entries;
194
202
  const models = doc?.models;
195
203
  const providers = models?.providers;
196
- return (entries?.token2chat !== undefined && providers?.token2chat !== undefined);
204
+ return providers?.token2chat !== undefined;
197
205
  }
198
206
  catch {
199
207
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@token2chat/t2c",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "t2c - Pay-per-request LLM access via Cashu ecash",
@@ -27,7 +27,7 @@
27
27
  "cli"
28
28
  ],
29
29
  "bin": {
30
- "t2c": "./dist/index.js"
30
+ "t2c": "dist/index.js"
31
31
  },
32
32
  "main": "./dist/index.js",
33
33
  "types": "./dist/index.d.ts",