lightnode-sdk 0.7.3 → 0.7.5

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NETWORKS, WORKER_REGISTRY, REGISTRY_TOPICS } from "./networks.js";
2
- import { fromWei, resolveJobTransactions } from "./subgraph.js";
2
+ import { fetchWorkerModels, fromWei, resolveJobTransactions } from "./subgraph.js";
3
3
  import { aggregateModelStats, aggregateWorkerStats, networkAnalytics, modelStatsCsv, workerStatsCsv, workerJobsCsv } from "./analytics.js";
4
4
  import { modelId as computeModelId, estimateJobFee, JOB_REGISTRY_CONSUMER_ABI, consumerGatewayUrl, consumerGatewayHost, prepareSession, submitPrompt, decryptResponse, generateEcdhKeyPair, runInference, runInferenceWithKey, runInferenceStream } from "./inference.js";
5
5
  import { Conversation, chat } from "./chat.js";
@@ -13,7 +13,7 @@ import { OnchainModelRegistry, AIVM_MODEL_REGISTRY_ABI, BENCHMARK_REGISTRY_ABI,
13
13
  import { StalledWorkerError, OnChainRevertError, RelayTokenTimeoutError, GatewayAuthError, isStalledWorker } from "./errors.js";
14
14
  import { GatewayClient, GatewayHttpError } from "./gateway.js";
15
15
  import * as crypto from "./crypto.js";
16
- import type { NetworkId, NetworkConfig, Worker, Job, JobTransactions, ModelInfo, NetworkStats, ModelStat, WorkerStat, NetworkAnalytics } from "./types.js";
16
+ import type { NetworkId, NetworkConfig, Worker, Job, JobTransactions, ModelInfo, WorkerModel, ServedModel, NetworkStats, ModelStat, WorkerStat, NetworkAnalytics } from "./types.js";
17
17
  /**
18
18
  * Read-only client for a LightChain AI network. Pure reads from the public indexer
19
19
  * and the chain; no keys, no writes. Independent, community-built.
@@ -33,6 +33,26 @@ export declare class LightNode {
33
33
  getWorker(address: string): Promise<Worker | null>;
34
34
  /** Recent jobs for one worker, newest first. */
35
35
  getWorkerJobs(address: string, first?: number): Promise<Job[]>;
36
+ /**
37
+ * The on-chain model whitelist for one worker (rows from WorkerRegistry
38
+ * events). Use this when you need to answer "what models is this worker
39
+ * offering" - it is the authoritative signal, not derived from past jobs.
40
+ * Rows can be `is_active: false` (operator removed the registration) or
41
+ * outlive deregister: combine with {@link getWorker}.status to decide
42
+ * whether the worker is currently serving them.
43
+ */
44
+ getWorkerModels(address: string): Promise<WorkerModel[]>;
45
+ /**
46
+ * The models a worker is serving, RECONCILED against the chain. getWorkerModels
47
+ * returns the raw subgraph rows, which go stale after a deregister/re-register
48
+ * (the indexer never clears removals). This joins those rows to model names AND
49
+ * to the authoritative on-chain WorkerRegistry.isEligible(worker, modelId), so
50
+ * each `ServedModel` carries both `indexedActive` (subgraph) and
51
+ * `onchainEligible` (chain truth). Use `onchainEligible === true` to decide what
52
+ * the worker ACTUALLY serves right now; it falls back to null (rely on
53
+ * `indexedActive`) if the chain read is unavailable.
54
+ */
55
+ getServedModels(address: string): Promise<ServedModel[]>;
36
56
  /** The network's registered models (name, fee, output limit, whitelist flags). */
37
57
  getModels(): Promise<ModelInfo[]>;
38
58
  /** Registered workers (default top 200). */
@@ -113,8 +133,8 @@ export declare class LightNode {
113
133
  * (especially in registry-proxy environments like StackBlitz where lockfiles
114
134
  * may pin an older minor than the local install command suggests).
115
135
  */
116
- export declare const SDK_VERSION = "0.7.3";
117
- export { NETWORKS, WORKER_REGISTRY, REGISTRY_TOPICS, aggregateModelStats, aggregateWorkerStats, networkAnalytics, modelStatsCsv, workerStatsCsv, workerJobsCsv, fromWei, resolveJobTransactions, computeModelId as modelId, estimateJobFee, JOB_REGISTRY_CONSUMER_ABI, consumerGatewayUrl, consumerGatewayHost, GatewayClient, GatewayHttpError, prepareSession, submitPrompt, decryptResponse, generateEcdhKeyPair, crypto, runInference, runInferenceWithKey, runInferenceStream, Conversation, chat, runInferenceBatch, Agent, parseAgentOutput, workerPreflight, workerWatch, Bridge, BRIDGE_ROUTE, HYPERLANE_ROUTER_ABI, ERC20_ABI, addressToBytes32, quoteBridgeFee, bridgeableBalance, bridgeAllowance, approveBridge, bridgeTransfer, DAO, DAO_ADDRESSES, ProposalState, PROPOSAL_STATE_LABEL, VoteSupport, GOVERNOR_ABI, VOTES_ABI, OnchainModelRegistry, AIVM_MODEL_REGISTRY_ABI, BENCHMARK_REGISTRY_ABI, ModelStatus, MODEL_STATUS_LABEL, StalledWorkerError, OnChainRevertError, RelayTokenTimeoutError, GatewayAuthError, isStalledWorker, WorkerOperator, WORKER_REGISTRY_ABI, JOB_REGISTRY_OPERATOR_ABI, AI_CONFIG_ABI, JOB_STATE, decodeWorkerError, WorkerOpError, isWorkerOpError, };
136
+ export declare const SDK_VERSION = "0.7.5";
137
+ export { NETWORKS, WORKER_REGISTRY, REGISTRY_TOPICS, aggregateModelStats, aggregateWorkerStats, networkAnalytics, modelStatsCsv, workerStatsCsv, workerJobsCsv, fromWei, resolveJobTransactions, fetchWorkerModels, computeModelId as modelId, estimateJobFee, JOB_REGISTRY_CONSUMER_ABI, consumerGatewayUrl, consumerGatewayHost, GatewayClient, GatewayHttpError, prepareSession, submitPrompt, decryptResponse, generateEcdhKeyPair, crypto, runInference, runInferenceWithKey, runInferenceStream, Conversation, chat, runInferenceBatch, Agent, parseAgentOutput, workerPreflight, workerWatch, Bridge, BRIDGE_ROUTE, HYPERLANE_ROUTER_ABI, ERC20_ABI, addressToBytes32, quoteBridgeFee, bridgeableBalance, bridgeAllowance, approveBridge, bridgeTransfer, DAO, DAO_ADDRESSES, ProposalState, PROPOSAL_STATE_LABEL, VoteSupport, GOVERNOR_ABI, VOTES_ABI, OnchainModelRegistry, AIVM_MODEL_REGISTRY_ABI, BENCHMARK_REGISTRY_ABI, ModelStatus, MODEL_STATUS_LABEL, StalledWorkerError, OnChainRevertError, RelayTokenTimeoutError, GatewayAuthError, isStalledWorker, WorkerOperator, WORKER_REGISTRY_ABI, JOB_REGISTRY_OPERATOR_ABI, AI_CONFIG_ABI, JOB_STATE, decodeWorkerError, WorkerOpError, isWorkerOpError, };
118
138
  export type { BearerSource, GatewayClientOptions, SelectSessionResult, PrepareSessionResult, UploadBlobResult, SessionTokenResult } from "./gateway.js";
119
139
  export type { SessionPreparation, RunInferenceArgs, RunInferenceResult, RunInferenceWithKeyArgs, RunInferenceStreamResult } from "./inference.js";
120
140
  export type { ChatRole, ChatMessage, ConversationOptions, ConversationSendResult } from "./chat.js";
@@ -125,4 +145,4 @@ export type { BridgeChain, BridgeEndpoints, BridgeTransferArgs } from "./bridge.
125
145
  export type { DaoChain, DaoAddresses, ProposalSummary, ProposalRow, DaoConfig } from "./dao.js";
126
146
  export type { BaseModel, ModelVariant, AccessTier, AccessPolicy, Benchmark, OnchainModelRegistryOptions } from "./onchain-models.js";
127
147
  export type { MinimalWalletClient, MinimalPublicClient, WorkerOperatorOpts, WorkerProtocolConfig, WorkerStatus, DeregisterReadiness, StuckJob, EarningsBreakdown, OnchainJob, JobState, DecodedWorkerError, } from "./worker-operator.js";
128
- export type { NetworkId, NetworkConfig, Worker, Job, JobTransactions, ModelInfo, NetworkStats, ModelStat, WorkerStat, NetworkAnalytics };
148
+ export type { NetworkId, NetworkConfig, Worker, Job, JobTransactions, ModelInfo, WorkerModel, ServedModel, NetworkStats, ModelStat, WorkerStat, NetworkAnalytics };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NETWORKS, WORKER_REGISTRY, REGISTRY_TOPICS } from "./networks.js";
2
- import { fetchWorker, fetchWorkerJobs, fetchRecentJobs, fetchJob, fetchModels, fetchWorkers, summarize, fromWei, resolveJobTransactions, } from "./subgraph.js";
3
- import { isRegistered } from "./onchain.js";
2
+ import { fetchWorker, fetchWorkerJobs, fetchWorkerModels, fetchRecentJobs, fetchJob, fetchModels, fetchWorkers, summarize, fromWei, resolveJobTransactions, } from "./subgraph.js";
3
+ import { isRegistered, fetchOnchainEligibleModels } from "./onchain.js";
4
4
  import { aggregateModelStats, aggregateWorkerStats, networkAnalytics, modelStatsCsv, workerStatsCsv, workerJobsCsv, } from "./analytics.js";
5
5
  import { modelId as computeModelId, estimateJobFee, JOB_REGISTRY_CONSUMER_ABI, consumerGatewayUrl, consumerGatewayHost, prepareSession, submitPrompt, decryptResponse, generateEcdhKeyPair, runInference, runInferenceWithKey, runInferenceStream, } from "./inference.js";
6
6
  import { Conversation, chat } from "./chat.js";
@@ -40,6 +40,48 @@ export class LightNode {
40
40
  getWorkerJobs(address, first = 20) {
41
41
  return fetchWorkerJobs(this.network, address, first);
42
42
  }
43
+ /**
44
+ * The on-chain model whitelist for one worker (rows from WorkerRegistry
45
+ * events). Use this when you need to answer "what models is this worker
46
+ * offering" - it is the authoritative signal, not derived from past jobs.
47
+ * Rows can be `is_active: false` (operator removed the registration) or
48
+ * outlive deregister: combine with {@link getWorker}.status to decide
49
+ * whether the worker is currently serving them.
50
+ */
51
+ getWorkerModels(address) {
52
+ return fetchWorkerModels(this.network, address);
53
+ }
54
+ /**
55
+ * The models a worker is serving, RECONCILED against the chain. getWorkerModels
56
+ * returns the raw subgraph rows, which go stale after a deregister/re-register
57
+ * (the indexer never clears removals). This joins those rows to model names AND
58
+ * to the authoritative on-chain WorkerRegistry.isEligible(worker, modelId), so
59
+ * each `ServedModel` carries both `indexedActive` (subgraph) and
60
+ * `onchainEligible` (chain truth). Use `onchainEligible === true` to decide what
61
+ * the worker ACTUALLY serves right now; it falls back to null (rely on
62
+ * `indexedActive`) if the chain read is unavailable.
63
+ */
64
+ async getServedModels(address) {
65
+ const [rows, registry] = await Promise.all([
66
+ fetchWorkerModels(this.network, address),
67
+ fetchModels(this.network),
68
+ ]);
69
+ if (rows.length === 0)
70
+ return [];
71
+ const byId = new Map(registry.map((m) => [m.id.toLowerCase(), m]));
72
+ const eligible = await fetchOnchainEligibleModels(this.network, address, rows.map((r) => r.model_id)).catch(() => null);
73
+ return rows.map((r) => {
74
+ const info = byId.get(r.model_id.toLowerCase());
75
+ return {
76
+ modelId: r.model_id,
77
+ name: info?.name ?? null,
78
+ feeWei: info?.fee,
79
+ maxOutputTokens: info?.max_output_tokens,
80
+ indexedActive: r.is_active,
81
+ onchainEligible: eligible ? (eligible.get(r.model_id.toLowerCase()) ?? null) : null,
82
+ };
83
+ });
84
+ }
43
85
  /** The network's registered models (name, fee, output limit, whitelist flags). */
44
86
  getModels() {
45
87
  return fetchModels(this.network);
@@ -170,11 +212,14 @@ export class LightNode {
170
212
  * (especially in registry-proxy environments like StackBlitz where lockfiles
171
213
  * may pin an older minor than the local install command suggests).
172
214
  */
173
- export const SDK_VERSION = "0.7.3";
215
+ export const SDK_VERSION = "0.7.5";
174
216
  export { NETWORKS, WORKER_REGISTRY, REGISTRY_TOPICS, aggregateModelStats, aggregateWorkerStats, networkAnalytics, modelStatsCsv, workerStatsCsv, workerJobsCsv, fromWei,
175
217
  // v0.7.3 per-job transaction-hash resolver (lifts the upstream
176
218
  // subgraph's "block-only" Job entity to a deep-linkable Job + tx pair).
177
- resolveJobTransactions, computeModelId as modelId, estimateJobFee, JOB_REGISTRY_CONSUMER_ABI, consumerGatewayUrl, consumerGatewayHost,
219
+ resolveJobTransactions,
220
+ // v0.7.4 per-worker model-registration list (the authoritative "what is
221
+ // this worker offering to serve" signal, not derived from past jobs).
222
+ fetchWorkerModels, computeModelId as modelId, estimateJobFee, JOB_REGISTRY_CONSUMER_ABI, consumerGatewayUrl, consumerGatewayHost,
178
223
  // v0.3 inference-submit surface (BETA - see README "Submitting inference").
179
224
  GatewayClient, GatewayHttpError, prepareSession, submitPrompt, decryptResponse, generateEcdhKeyPair, crypto,
180
225
  // v0.4 high-level orchestrator: one call, full flow.
package/dist/onchain.d.ts CHANGED
@@ -6,3 +6,13 @@ import type { NetworkConfig } from "./types.js";
6
6
  * event, or null when the chain can't answer (RPC error, or no events for it).
7
7
  */
8
8
  export declare function isRegistered(cfg: NetworkConfig, address: string): Promise<boolean | null>;
9
+ /**
10
+ * On-chain truth for which of `modelIds` a worker currently serves, via
11
+ * WorkerRegistry.isEligible(worker, modelId). Stronger than the subgraph's
12
+ * WorkerModel.is_active: the indexer lists a worker's models from its LAST
13
+ * registration and never indexes removals, so it goes stale after a
14
+ * deregister/re-register (it can show a model the worker no longer serves, or
15
+ * miss the current one). Returns a Map keyed by lowercased modelId; null on any
16
+ * RPC failure so callers can fall back to the index. One eth_call per model.
17
+ */
18
+ export declare function fetchOnchainEligibleModels(cfg: NetworkConfig, address: string, modelIds: string[]): Promise<Map<string, boolean> | null>;
package/dist/onchain.js CHANGED
@@ -55,3 +55,54 @@ export async function isRegistered(cfg, address) {
55
55
  clearTimeout(timer);
56
56
  }
57
57
  }
58
+ // WorkerRegistry.isEligible(address,bytes32) selector. This view does NOT revert
59
+ // on the deployed predeploy (unlike most of its getters), so it's a reliable
60
+ // on-chain read of whether a worker currently serves a given model.
61
+ const IS_ELIGIBLE_SELECTOR = "0xdb3ebef1";
62
+ /**
63
+ * On-chain truth for which of `modelIds` a worker currently serves, via
64
+ * WorkerRegistry.isEligible(worker, modelId). Stronger than the subgraph's
65
+ * WorkerModel.is_active: the indexer lists a worker's models from its LAST
66
+ * registration and never indexes removals, so it goes stale after a
67
+ * deregister/re-register (it can show a model the worker no longer serves, or
68
+ * miss the current one). Returns a Map keyed by lowercased modelId; null on any
69
+ * RPC failure so callers can fall back to the index. One eth_call per model.
70
+ */
71
+ export async function fetchOnchainEligibleModels(cfg, address, modelIds) {
72
+ if (!/^0x[a-fA-F0-9]{40}$/.test(address) || modelIds.length === 0)
73
+ return null;
74
+ const addrArg = address.toLowerCase().replace(/^0x/, "").padStart(64, "0");
75
+ const ctrl = new AbortController();
76
+ const timer = setTimeout(() => ctrl.abort(), 8000);
77
+ try {
78
+ const entries = await Promise.all(modelIds.map(async (id) => {
79
+ const idArg = id.toLowerCase().replace(/^0x/, "").padStart(64, "0");
80
+ const res = await fetch(cfg.rpc, {
81
+ method: "POST",
82
+ headers: { "content-type": "application/json" },
83
+ body: JSON.stringify({
84
+ jsonrpc: "2.0",
85
+ id: 1,
86
+ method: "eth_call",
87
+ params: [{ to: cfg.workerRegistry, data: `${IS_ELIGIBLE_SELECTOR}${addrArg}${idArg}` }, "latest"],
88
+ }),
89
+ signal: ctrl.signal,
90
+ });
91
+ if (!res.ok)
92
+ throw new Error(`rpc ${res.status}`);
93
+ const json = (await res.json());
94
+ if (json.error || typeof json.result !== "string")
95
+ throw new Error("eth_call failed");
96
+ // bool return: true iff the 32-byte word ends in 1.
97
+ const eligible = /0*1$/.test(json.result.replace(/^0x/, ""));
98
+ return [id.toLowerCase(), eligible];
99
+ }));
100
+ return new Map(entries);
101
+ }
102
+ catch {
103
+ return null;
104
+ }
105
+ finally {
106
+ clearTimeout(timer);
107
+ }
108
+ }
@@ -1,5 +1,5 @@
1
1
  import type { PublicClient } from "viem";
2
- import type { NetworkConfig, Worker, Job, JobTransactions, ModelInfo, NetworkStats } from "./types.js";
2
+ import type { NetworkConfig, Worker, Job, JobTransactions, ModelInfo, NetworkStats, WorkerModel } from "./types.js";
3
3
  /** Convert a wei string to a number of whole tokens (18 decimals). */
4
4
  export declare function fromWei(wei?: string): number;
5
5
  export declare function fetchWorker(cfg: NetworkConfig, address: string): Promise<Worker | null>;
@@ -28,6 +28,13 @@ export declare function resolveJobTransactions(cfg: NetworkConfig, jobId: string
28
28
  publicClient?: PublicClient;
29
29
  job?: Job | null;
30
30
  }): Promise<JobTransactions>;
31
+ /**
32
+ * The on-chain model registrations for one worker. The Graph entity name is
33
+ * `workermodels` (lowercase), and `is_active` flips when the operator
34
+ * removes a registration. Independent of `Worker.status`: a deregistered
35
+ * worker can still have rows here from when it was live.
36
+ */
37
+ export declare function fetchWorkerModels(cfg: NetworkConfig, address: string): Promise<WorkerModel[]>;
31
38
  export declare function fetchModels(cfg: NetworkConfig): Promise<ModelInfo[]>;
32
39
  export declare function fetchWorkers(cfg: NetworkConfig, first?: number): Promise<Worker[]>;
33
40
  export declare function summarize(workers: Worker[], models: ModelInfo[]): NetworkStats;
package/dist/subgraph.js CHANGED
@@ -142,6 +142,16 @@ async function fetchTxHashForJobEvent(client, address, eventTopic, jobTopic, blo
142
142
  return null;
143
143
  }
144
144
  }
145
+ /**
146
+ * The on-chain model registrations for one worker. The Graph entity name is
147
+ * `workermodels` (lowercase), and `is_active` flips when the operator
148
+ * removes a registration. Independent of `Worker.status`: a deregistered
149
+ * worker can still have rows here from when it was live.
150
+ */
151
+ export async function fetchWorkerModels(cfg, address) {
152
+ const data = await gql(cfg.subgraph, `{ workermodels(where:{worker:"${checksum(address)}"}) { id worker model_id is_active created_at updated_at } }`);
153
+ return data.workermodels ?? [];
154
+ }
145
155
  export async function fetchModels(cfg) {
146
156
  const data = await gql(cfg.subgraph, `{ modelinfos { id name fee max_output_tokens is_whitelisted is_enabled } }`);
147
157
  return data.modelinfos ?? [];
package/dist/types.d.ts CHANGED
@@ -63,6 +63,40 @@ export interface ModelInfo {
63
63
  is_whitelisted: boolean;
64
64
  is_enabled: boolean;
65
65
  }
66
+ /**
67
+ * Per-worker model registration row. The on-chain truth for "which models has
68
+ * this worker offered to serve" - indexed from WorkerRegistry events.
69
+ * `is_active` flips to false when the operator removes the registration; it
70
+ * is independent of whether the worker itself is currently registered in the
71
+ * protocol.
72
+ */
73
+ export interface WorkerModel {
74
+ id: string;
75
+ worker: string;
76
+ model_id: string;
77
+ is_active: boolean;
78
+ created_at?: number;
79
+ updated_at?: number;
80
+ }
81
+ /**
82
+ * A worker's served model, reconciled against the chain. Combines the subgraph
83
+ * WorkerModel row (name, is_active) with the authoritative on-chain
84
+ * WorkerRegistry.isEligible read, so you can tell a model the worker ACTUALLY
85
+ * serves now from a stale index row left over after a deregister/re-register.
86
+ */
87
+ export interface ServedModel {
88
+ modelId: string;
89
+ name: string | null;
90
+ feeWei?: string;
91
+ maxOutputTokens?: number;
92
+ /** Subgraph WorkerModel.is_active (can be stale after deregister/re-register). */
93
+ indexedActive: boolean;
94
+ /**
95
+ * On-chain WorkerRegistry.isEligible(worker, modelId) - the authoritative
96
+ * "is it serving this right now". null when the chain read was unavailable.
97
+ */
98
+ onchainEligible: boolean | null;
99
+ }
66
100
  export interface NetworkStats {
67
101
  total: number;
68
102
  active: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightnode-sdk",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "Read-only TypeScript client for LightChain AI: workers, jobs, models, on-chain registration, and per-model network analytics. Independent, community-built (not an official LightChain package).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",