2020117-agent 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.
package/dist/agent.js CHANGED
@@ -76,7 +76,7 @@ import { SwarmNode, topicFromKind } from './swarm.js';
76
76
  import { collectP2PPayment, handleStop, streamToCustomer } from './p2p-provider.js';
77
77
  import { streamFromProvider } from './p2p-customer.js';
78
78
  import { createProcessor } from './processor.js';
79
- import { hasApiKey, loadAgentName, registerService, startHeartbeatLoop, getInbox, acceptJob, sendFeedback, submitResult, createJob, getJob, } from './api.js';
79
+ import { hasApiKey, loadAgentName, registerService, startHeartbeatLoop, getInbox, acceptJob, sendFeedback, submitResult, createJob, getJob, getProfile, } from './api.js';
80
80
  import { initClinkAgent, collectPayment } from './clink.js';
81
81
  import { readFileSync } from 'fs';
82
82
  import WebSocket from 'ws';
@@ -88,7 +88,7 @@ const SATS_PER_CHUNK = Number(process.env.SATS_PER_CHUNK) || 1;
88
88
  const CHUNKS_PER_PAYMENT = Number(process.env.CHUNKS_PER_PAYMENT) || 10;
89
89
  const PAYMENT_TIMEOUT = Number(process.env.PAYMENT_TIMEOUT) || 30_000;
90
90
  // --- CLINK payment config ---
91
- const LIGHTNING_ADDRESS = process.env.LIGHTNING_ADDRESS || '';
91
+ let LIGHTNING_ADDRESS = process.env.LIGHTNING_ADDRESS || '';
92
92
  // --- Sub-task delegation config ---
93
93
  const SUB_KIND = process.env.SUB_KIND ? Number(process.env.SUB_KIND) : null;
94
94
  const SUB_BUDGET = Number(process.env.SUB_BUDGET) || 50;
@@ -163,16 +163,24 @@ async function main() {
163
163
  if (state.skill) {
164
164
  console.log(`[${label}] Skill: ${state.skill.name} v${state.skill.version} (${state.skill.features.join(', ')})`);
165
165
  }
166
- // 2. Initialize CLINK agent identity (for P2P session debit)
166
+ // 2. Auto-fetch Lightning Address from platform if not set via CLI/env
167
+ if (!LIGHTNING_ADDRESS && hasApiKey()) {
168
+ const profile = await getProfile();
169
+ if (profile?.lightning_address) {
170
+ LIGHTNING_ADDRESS = profile.lightning_address;
171
+ console.log(`[${label}] Lightning Address loaded from platform: ${LIGHTNING_ADDRESS}`);
172
+ }
173
+ }
174
+ // 3. Initialize CLINK agent identity (for P2P session debit)
167
175
  if (LIGHTNING_ADDRESS) {
168
176
  const { pubkey } = initClinkAgent();
169
177
  console.log(`[${label}] CLINK: ${LIGHTNING_ADDRESS} (agent pubkey: ${pubkey.slice(0, 16)}...)`);
170
178
  }
171
- // 3. Platform registration + heartbeat
179
+ // 4. Platform registration + heartbeat
172
180
  await setupPlatform(label);
173
- // 4. Async inbox poller
181
+ // 5. Async inbox poller
174
182
  startInboxPoller(label);
175
- // 5. P2P swarm listener
183
+ // 6. P2P swarm listener
176
184
  await startSwarmListener(label);
177
185
  // 6. Graceful shutdown
178
186
  setupShutdown(label);
package/dist/api.d.ts CHANGED
@@ -8,6 +8,13 @@
8
8
  /** Returns the resolved agent name from env or first key in file */
9
9
  export declare function loadAgentName(): string | null;
10
10
  export declare function hasApiKey(): boolean;
11
+ /** Fetch the authenticated agent's profile from the platform. */
12
+ export declare function getProfile(): Promise<{
13
+ lightning_address?: string;
14
+ username?: string;
15
+ display_name?: string;
16
+ nostr_pubkey?: string;
17
+ } | null>;
11
18
  export interface OnlineAgent {
12
19
  user_id: string;
13
20
  username: string;
package/dist/api.js CHANGED
@@ -123,6 +123,10 @@ async function apiPut(path, body) {
123
123
  export function hasApiKey() {
124
124
  return API_KEY !== null;
125
125
  }
126
+ /** Fetch the authenticated agent's profile from the platform. */
127
+ export async function getProfile() {
128
+ return apiGet('/api/me');
129
+ }
126
130
  export async function registerService(opts) {
127
131
  if (!API_KEY)
128
132
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "2020117-agent",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "2020117 agent runtime — API polling + Hyperswarm P2P + CLINK Lightning payments",
5
5
  "type": "module",
6
6
  "bin": {