@blockrun/clawrouter 0.12.126 → 0.12.128

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/dist/index.js CHANGED
@@ -79995,6 +79995,45 @@ function buildPartnerTools(proxyBaseUrl) {
79995
79995
  return PARTNER_SERVICES.map((service) => buildTool(service, proxyBaseUrl));
79996
79996
  }
79997
79997
 
79998
+ // src/commands/stats.ts
79999
+ function createStatsCommand() {
80000
+ return {
80001
+ name: "stats",
80002
+ description: "Show ClawRouter usage statistics and cost savings",
80003
+ acceptsArgs: true,
80004
+ requireAuth: false,
80005
+ handler: async (ctx) => {
80006
+ const arg = ctx.args?.trim().toLowerCase() || "7";
80007
+ if (arg === "clear" || arg === "reset") {
80008
+ try {
80009
+ const { deletedFiles } = await clearStats();
80010
+ return {
80011
+ text: `Stats cleared \u2014 ${deletedFiles} log file(s) deleted. Fresh start!`
80012
+ };
80013
+ } catch (err) {
80014
+ return {
80015
+ text: `Failed to clear stats: ${err instanceof Error ? err.message : String(err)}`,
80016
+ isError: true
80017
+ };
80018
+ }
80019
+ }
80020
+ const days = parseInt(arg, 10) || 7;
80021
+ try {
80022
+ const stats = await getStats(Math.min(days, 30));
80023
+ const ascii = formatStatsAscii(stats);
80024
+ return {
80025
+ text: ["```", ascii, "```"].join("\n")
80026
+ };
80027
+ } catch (err) {
80028
+ return {
80029
+ text: `Failed to load stats: ${err instanceof Error ? err.message : String(err)}`,
80030
+ isError: true
80031
+ };
80032
+ }
80033
+ }
80034
+ };
80035
+ }
80036
+
79998
80037
  // src/index.ts
79999
80038
  init_solana_balance();
80000
80039
 
@@ -80727,43 +80766,6 @@ async function startProxyInBackground(api) {
80727
80766
  api.logger.info(`Wallet (${network}): ${displayAddress} | Balance: (checking...)`);
80728
80767
  });
80729
80768
  }
80730
- function createStatsCommand() {
80731
- return {
80732
- name: "stats",
80733
- description: "Show ClawRouter usage statistics and cost savings",
80734
- acceptsArgs: true,
80735
- requireAuth: false,
80736
- handler: async (ctx) => {
80737
- const arg = ctx.args?.trim().toLowerCase() || "7";
80738
- if (arg === "clear" || arg === "reset") {
80739
- try {
80740
- const { deletedFiles } = await clearStats();
80741
- return {
80742
- text: `Stats cleared \u2014 ${deletedFiles} log file(s) deleted. Fresh start!`
80743
- };
80744
- } catch (err) {
80745
- return {
80746
- text: `Failed to clear stats: ${err instanceof Error ? err.message : String(err)}`,
80747
- isError: true
80748
- };
80749
- }
80750
- }
80751
- const days = parseInt(arg, 10) || 7;
80752
- try {
80753
- const stats = await getStats(Math.min(days, 30));
80754
- const ascii = formatStatsAscii(stats);
80755
- return {
80756
- text: ["```", ascii, "```"].join("\n")
80757
- };
80758
- } catch (err) {
80759
- return {
80760
- text: `Failed to load stats: ${err instanceof Error ? err.message : String(err)}`,
80761
- isError: true
80762
- };
80763
- }
80764
- }
80765
- };
80766
- }
80767
80769
  function createExcludeCommand() {
80768
80770
  return {
80769
80771
  name: "exclude",
@@ -81236,69 +81238,71 @@ var plugin = {
81236
81238
  return;
81237
81239
  }
81238
81240
  const proc = process;
81239
- if (proc.__clawrouterRegistered) return;
81241
+ const alreadyRegistered = !!proc.__clawrouterRegistered;
81240
81242
  proc.__clawrouterRegistered = true;
81241
- api.registerProvider(blockrunProvider);
81242
- api.registerImageGenerationProvider(buildImageGenerationProvider());
81243
- api.registerMusicGenerationProvider(buildMusicGenerationProvider());
81244
- injectModelsConfig(api.logger);
81245
- injectAuthProfile(api.logger);
81246
- const runtimePort = getProxyPort();
81247
- if (!api.config.models) {
81248
- api.config.models = { providers: {} };
81249
- }
81250
- if (!api.config.models.providers) {
81251
- api.config.models.providers = {};
81252
- }
81253
- api.config.models.providers.blockrun = {
81254
- baseUrl: `http://127.0.0.1:${runtimePort}/v1`,
81255
- api: "openai-completions",
81256
- // apiKey is required by pi-coding-agent's ModelRegistry for providers with models.
81257
- apiKey: "x402-proxy-handles-auth",
81258
- models: OPENCLAW_MODELS
81259
- };
81260
- api.logger.info("BlockRun provider registered (55+ models via x402)");
81261
- try {
81262
- const proxyBaseUrl = `http://127.0.0.1:${runtimePort}`;
81263
- const partnerTools = buildPartnerTools(proxyBaseUrl);
81264
- for (const tool of partnerTools) {
81265
- api.registerTool(tool);
81266
- }
81267
- if (partnerTools.length > 0) {
81268
- api.logger.info(
81269
- `Registered ${partnerTools.length} partner tool(s): ${partnerTools.map((t) => t.name).join(", ")}`
81243
+ if (!alreadyRegistered) {
81244
+ api.registerProvider(blockrunProvider);
81245
+ api.registerImageGenerationProvider(buildImageGenerationProvider());
81246
+ api.registerMusicGenerationProvider(buildMusicGenerationProvider());
81247
+ injectModelsConfig(api.logger);
81248
+ injectAuthProfile(api.logger);
81249
+ const runtimePort = getProxyPort();
81250
+ if (!api.config.models) {
81251
+ api.config.models = { providers: {} };
81252
+ }
81253
+ if (!api.config.models.providers) {
81254
+ api.config.models.providers = {};
81255
+ }
81256
+ api.config.models.providers.blockrun = {
81257
+ baseUrl: `http://127.0.0.1:${runtimePort}/v1`,
81258
+ api: "openai-completions",
81259
+ // apiKey is required by pi-coding-agent's ModelRegistry for providers with models.
81260
+ apiKey: "x402-proxy-handles-auth",
81261
+ models: OPENCLAW_MODELS
81262
+ };
81263
+ api.logger.info("BlockRun provider registered (55+ models via x402)");
81264
+ try {
81265
+ const proxyBaseUrl = `http://127.0.0.1:${runtimePort}`;
81266
+ const partnerTools = buildPartnerTools(proxyBaseUrl);
81267
+ for (const tool of partnerTools) {
81268
+ api.registerTool(tool);
81269
+ }
81270
+ if (partnerTools.length > 0) {
81271
+ api.logger.info(
81272
+ `Registered ${partnerTools.length} partner tool(s): ${partnerTools.map((t) => t.name).join(", ")}`
81273
+ );
81274
+ }
81275
+ } catch (err) {
81276
+ api.logger.warn(
81277
+ `Failed to register partner tools: ${err instanceof Error ? err.message : String(err)}`
81270
81278
  );
81271
81279
  }
81272
- api.registerCommand({
81273
- name: "partners",
81274
- description: "List available partner APIs and pricing",
81275
- acceptsArgs: false,
81276
- requireAuth: false,
81277
- handler: async () => {
81278
- if (PARTNER_SERVICES.length === 0) {
81279
- return { text: "No partner APIs available." };
81280
- }
81281
- const lines = ["**Partner APIs** (paid via your ClawRouter wallet)", ""];
81282
- for (const svc of PARTNER_SERVICES) {
81283
- lines.push(`**${svc.name}** (${svc.partner})`);
81284
- lines.push(` ${svc.description}`);
81285
- lines.push(` Tool: \`${`blockrun_${svc.id}`}\``);
81286
- lines.push(
81287
- ` Pricing: ${svc.pricing.perUnit} per ${svc.pricing.unit} (min ${svc.pricing.minimum}, max ${svc.pricing.maximum})`
81288
- );
81289
- lines.push(
81290
- ` **How to use:** Ask "Look up Twitter user @elonmusk" or "Get info on these X accounts: @naval, @balajis"`
81291
- );
81292
- lines.push("");
81293
- }
81294
- return { text: lines.join("\n") };
81295
- }
81296
- });
81297
- } catch (err) {
81298
- api.logger.warn(
81299
- `Failed to register partner tools: ${err instanceof Error ? err.message : String(err)}`
81300
- );
81301
81280
  }
81281
+ api.registerCommand({
81282
+ name: "partners",
81283
+ description: "List available partner APIs and pricing",
81284
+ acceptsArgs: false,
81285
+ requireAuth: false,
81286
+ handler: async () => {
81287
+ if (PARTNER_SERVICES.length === 0) {
81288
+ return { text: "No partner APIs available." };
81289
+ }
81290
+ const lines = ["**Partner APIs** (paid via your ClawRouter wallet)", ""];
81291
+ for (const svc of PARTNER_SERVICES) {
81292
+ lines.push(`**${svc.name}** (${svc.partner})`);
81293
+ lines.push(` ${svc.description}`);
81294
+ lines.push(` Tool: \`${`blockrun_${svc.id}`}\``);
81295
+ lines.push(
81296
+ ` Pricing: ${svc.pricing.perUnit} per ${svc.pricing.unit} (min ${svc.pricing.minimum}, max ${svc.pricing.maximum})`
81297
+ );
81298
+ lines.push(
81299
+ ` **How to use:** Ask "Look up Twitter user @elonmusk" or "Get info on these X accounts: @naval, @balajis"`
81300
+ );
81301
+ lines.push("");
81302
+ }
81303
+ return { text: lines.join("\n") };
81304
+ }
81305
+ });
81302
81306
  api.registerCommand(createWalletCommand(api));
81303
81307
  try {
81304
81308
  const blockrunAlias = createWalletCommand(api);
@@ -81309,6 +81313,7 @@ var plugin = {
81309
81313
  api.registerCommand(createStatsCommand());
81310
81314
  api.registerCommand(createExcludeCommand());
81311
81315
  api.logger.info("Commands registered: /wallet, /blockrun, /stats, /exclude");
81316
+ if (alreadyRegistered) return;
81312
81317
  api.registerService({
81313
81318
  id: "clawrouter-proxy",
81314
81319
  start: () => {
@@ -81353,7 +81358,7 @@ var plugin = {
81353
81358
  }
81354
81359
  startProxyInBackground(api).then(async () => {
81355
81360
  const port = getProxyPort();
81356
- const healthy = await waitForProxyHealth(port, 5e3);
81361
+ const healthy = await waitForProxyHealth(port, 15e3);
81357
81362
  if (!healthy) {
81358
81363
  api.logger.warn(`Proxy health check timed out, commands may not work immediately`);
81359
81364
  }