lightnode-sdk 0.3.1 → 0.4.0
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 +38 -0
- package/dist/add.d.ts +51 -0
- package/dist/add.js +935 -0
- package/dist/cli.js +87 -8
- package/dist/errors.d.ts +55 -0
- package/dist/errors.js +64 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +5 -2
- package/dist/inference.d.ts +130 -0
- package/dist/inference.js +293 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,10 +80,48 @@ npx lightnode registered 0x6781…6e0f # true | false | null
|
|
|
80
80
|
npx lightnode fee llama3-8b # on-chain job fee
|
|
81
81
|
npx lightnode analytics --csv # per-model performance (CSV)
|
|
82
82
|
npx lightnode reliability --csv # per-worker reliability (CSV)
|
|
83
|
+
|
|
84
|
+
# Patch an existing project (auto-detects Next.js, Hono, or Node):
|
|
85
|
+
npx lightnode add inference # encrypted inference route/script
|
|
86
|
+
npx lightnode add chat # chat-style UI with conversation history
|
|
87
|
+
npx lightnode add analytics-dashboard # read-only network + worker analytics page
|
|
88
|
+
npx lightnode add nft-mint-with-inference # AI-generated NFT metadata with on-chain provenance
|
|
89
|
+
# All `add` commands accept [--template auto|nextjs-api|hono|node] [--net testnet|mainnet] [--force]
|
|
90
|
+
|
|
91
|
+
# Or scaffold a brand-new project:
|
|
92
|
+
npm create lightnode-app my-app
|
|
83
93
|
```
|
|
84
94
|
|
|
85
95
|
## Submitting inference
|
|
86
96
|
|
|
97
|
+
**Easy mode (`runInference` — v0.4+):** one async call drives the whole protocol —
|
|
98
|
+
SIWE → prepareSession → on-chain createSession → relay WS → encrypt + upload prompt
|
|
99
|
+
→ on-chain submitJob → decrypt streamed chunks → wait for `JobCompleted` →
|
|
100
|
+
return the assembled answer + three tx hashes. Built-in retry on `StalledWorkerError`.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { LightNode, GatewayClient, runInference } from "lightnode-sdk";
|
|
104
|
+
import WS from "ws"; // omit in the browser
|
|
105
|
+
|
|
106
|
+
const ln = new LightNode("testnet");
|
|
107
|
+
const gateway = new GatewayClient({ network: "testnet", bearer: await getJwt() });
|
|
108
|
+
const { answer, txs } = await runInference({
|
|
109
|
+
prompt: "Reply with a one-sentence fun fact about the ocean.",
|
|
110
|
+
gateway, wallet, publicClient, network: ln.network,
|
|
111
|
+
WebSocket: WS,
|
|
112
|
+
onChunk: (chunk) => process.stdout.write(chunk), // live streaming
|
|
113
|
+
maxRetries: 2, // auto-retry on stall
|
|
114
|
+
});
|
|
115
|
+
console.log("\n", txs); // { createSession, submitJob, jobCompleted }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The lower-level helpers (`prepareSession`, `submitPrompt`, `decryptResponse`,
|
|
119
|
+
the typed errors `StalledWorkerError` / `OnChainRevertError` / `GatewayAuthError`
|
|
120
|
+
/ `RelayTokenTimeoutError`) stay exported for builders who want a different
|
|
121
|
+
retry policy or to reuse a session across prompts.
|
|
122
|
+
|
|
123
|
+
### Manual mode (the full surface)
|
|
124
|
+
|
|
87
125
|
`v0.3+` ships the encrypted inference-submit flow end to end. Wire-compatible with
|
|
88
126
|
the reference client [`lcai-chat-v2`](https://github.com/lightchain-protocol/lcai-chat-v2)
|
|
89
127
|
(same ECDH-P256 + AES-256-GCM, same gateway endpoints, same `JobRegistry` calls).
|
package/dist/add.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `lightnode add inference` - patch an EXISTING project to do encrypted
|
|
3
|
+
* LightChain AI inference. Detects the framework from package.json (Next.js,
|
|
4
|
+
* Hono, or plain Node) and writes the appropriate route/script + a .env.example
|
|
5
|
+
* if one isn't already there. Idempotent: existing files are not overwritten
|
|
6
|
+
* unless --force is passed.
|
|
7
|
+
*
|
|
8
|
+
* No runtime dependencies; templates are inlined as string literals.
|
|
9
|
+
*/
|
|
10
|
+
type Template = "nextjs-api" | "hono" | "node";
|
|
11
|
+
type Network = "testnet" | "mainnet";
|
|
12
|
+
interface AddOpts {
|
|
13
|
+
template?: Template | "auto";
|
|
14
|
+
network?: Network;
|
|
15
|
+
force?: boolean;
|
|
16
|
+
cwd?: string;
|
|
17
|
+
}
|
|
18
|
+
interface WrittenFile {
|
|
19
|
+
path: string;
|
|
20
|
+
skipped?: boolean;
|
|
21
|
+
reason?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Implementation called by `lightnode add inference [...]`.
|
|
25
|
+
* Returns the list of files written + the install command the user should run.
|
|
26
|
+
*/
|
|
27
|
+
export declare function addInference(opts?: AddOpts): {
|
|
28
|
+
written: WrittenFile[];
|
|
29
|
+
install: string;
|
|
30
|
+
template: Template;
|
|
31
|
+
network: Network;
|
|
32
|
+
};
|
|
33
|
+
export declare function addAnalyticsDashboard(opts?: AddOpts): {
|
|
34
|
+
written: WrittenFile[];
|
|
35
|
+
install: string;
|
|
36
|
+
template: Template;
|
|
37
|
+
network: Network;
|
|
38
|
+
};
|
|
39
|
+
export declare function addChat(opts?: AddOpts): {
|
|
40
|
+
written: WrittenFile[];
|
|
41
|
+
install: string;
|
|
42
|
+
template: Template;
|
|
43
|
+
network: Network;
|
|
44
|
+
};
|
|
45
|
+
export declare function addNftMint(opts?: AddOpts): {
|
|
46
|
+
written: WrittenFile[];
|
|
47
|
+
install: string;
|
|
48
|
+
template: Template;
|
|
49
|
+
network: Network;
|
|
50
|
+
};
|
|
51
|
+
export {};
|