@flop-labs/sdk 0.7.2 → 0.9.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +134 -1
  2. package/README.md +4 -4
  3. package/dist/bundle/index.esm.js +1 -1
  4. package/dist/bundle/index.esm.js.map +1 -1
  5. package/dist/bundle/index.umd.cjs +1 -1
  6. package/dist/bundle/index.umd.cjs.map +1 -1
  7. package/dist/compute-channel/capacity-reservation.d.ts +5 -3
  8. package/dist/compute-channel/capacity-reservation.d.ts.map +1 -1
  9. package/dist/compute-channel/capacity-reservation.js +7 -3
  10. package/dist/compute-channel/capacity-reservation.js.map +1 -1
  11. package/dist/compute-channel/deepseek-v41.d.ts +13 -6
  12. package/dist/compute-channel/deepseek-v41.d.ts.map +1 -1
  13. package/dist/compute-channel/deepseek-v41.js +19 -10
  14. package/dist/compute-channel/deepseek-v41.js.map +1 -1
  15. package/dist/compute-channel/flop-submitter.d.ts +53 -4
  16. package/dist/compute-channel/flop-submitter.d.ts.map +1 -1
  17. package/dist/compute-channel/flop-submitter.js +94 -4
  18. package/dist/compute-channel/flop-submitter.js.map +1 -1
  19. package/dist/compute-channel/forward-holdings.d.ts +32 -0
  20. package/dist/compute-channel/forward-holdings.d.ts.map +1 -0
  21. package/dist/compute-channel/forward-holdings.js +157 -0
  22. package/dist/compute-channel/forward-holdings.js.map +1 -0
  23. package/dist/compute-channel/index.d.ts +7 -0
  24. package/dist/compute-channel/index.d.ts.map +1 -1
  25. package/dist/compute-channel/index.js +7 -0
  26. package/dist/compute-channel/index.js.map +1 -1
  27. package/dist/compute-channel/kimi-k31.d.ts +73 -0
  28. package/dist/compute-channel/kimi-k31.d.ts.map +1 -0
  29. package/dist/compute-channel/kimi-k31.js +265 -0
  30. package/dist/compute-channel/kimi-k31.js.map +1 -0
  31. package/dist/compute-channel/long-session-chain.d.ts +16 -0
  32. package/dist/compute-channel/long-session-chain.d.ts.map +1 -0
  33. package/dist/compute-channel/long-session-chain.js +212 -0
  34. package/dist/compute-channel/long-session-chain.js.map +1 -0
  35. package/dist/compute-channel/long-session.d.ts +261 -0
  36. package/dist/compute-channel/long-session.d.ts.map +1 -0
  37. package/dist/compute-channel/long-session.js +658 -0
  38. package/dist/compute-channel/long-session.js.map +1 -0
  39. package/dist/compute-channel/miner-host.d.ts.map +1 -1
  40. package/dist/compute-channel/miner-host.js +5 -3
  41. package/dist/compute-channel/miner-host.js.map +1 -1
  42. package/dist/compute-channel/model-config.d.ts +18 -3
  43. package/dist/compute-channel/model-config.d.ts.map +1 -1
  44. package/dist/compute-channel/model-config.js +121 -2
  45. package/dist/compute-channel/model-config.js.map +1 -1
  46. package/dist/compute-channel/peer-info.d.ts +37 -2
  47. package/dist/compute-channel/peer-info.d.ts.map +1 -1
  48. package/dist/compute-channel/peer-info.js +25 -5
  49. package/dist/compute-channel/peer-info.js.map +1 -1
  50. package/dist/compute-channel/response-length.d.ts +84 -0
  51. package/dist/compute-channel/response-length.d.ts.map +1 -0
  52. package/dist/compute-channel/response-length.js +85 -0
  53. package/dist/compute-channel/response-length.js.map +1 -0
  54. package/dist/compute-channel/session-estimate.d.ts.map +1 -1
  55. package/dist/compute-channel/session-estimate.js +20 -1
  56. package/dist/compute-channel/session-estimate.js.map +1 -1
  57. package/dist/compute-channel/spend-journal.d.ts +172 -0
  58. package/dist/compute-channel/spend-journal.d.ts.map +1 -0
  59. package/dist/compute-channel/spend-journal.js +429 -0
  60. package/dist/compute-channel/spend-journal.js.map +1 -0
  61. package/dist/compute-channel/transcript.d.ts +3 -1
  62. package/dist/compute-channel/transcript.d.ts.map +1 -1
  63. package/dist/compute-channel/transcript.js +2 -0
  64. package/dist/compute-channel/transcript.js.map +1 -1
  65. package/dist/compute-channel/transport-http.d.ts +43 -1
  66. package/dist/compute-channel/transport-http.d.ts.map +1 -1
  67. package/dist/compute-channel/transport-http.js +70 -4
  68. package/dist/compute-channel/transport-http.js.map +1 -1
  69. package/dist/direct-swap/retained-runtime-releases.d.ts.map +1 -1
  70. package/dist/direct-swap/retained-runtime-releases.js +11 -1
  71. package/dist/direct-swap/retained-runtime-releases.js.map +1 -1
  72. package/dist/discovery/metered-pricing.d.ts.map +1 -1
  73. package/dist/discovery/metered-pricing.js +17 -1
  74. package/dist/discovery/metered-pricing.js.map +1 -1
  75. package/dist/faucet.d.ts +1 -1
  76. package/dist/faucet.js +1 -1
  77. package/dist/miner-admission.d.ts +15 -4
  78. package/dist/miner-admission.d.ts.map +1 -1
  79. package/dist/miner-admission.js +28 -8
  80. package/dist/miner-admission.js.map +1 -1
  81. package/dist/runtime-compatibility.d.ts +1 -1
  82. package/dist/runtime-compatibility.d.ts.map +1 -1
  83. package/dist/runtime-compatibility.js +6 -2
  84. package/dist/runtime-compatibility.js.map +1 -1
  85. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -7,6 +7,140 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.0] - 2026-11-23
11
+
12
+ ### Added
13
+
14
+ - `computeChannel.predictResponseLength`: one shared completion-length predictor returning p50/p90
15
+ completion tokens with their source (`heuristic`, `history:<window>` or `model:<id>`), for
16
+ pre-request previews only. `responseLengthHistory` builds a per-model baseline from aggregate
17
+ `(prompt, completion)` token counts by prompt bucket; `estimatePromptTokens` is the shared
18
+ `⌈chars / 4⌉` prompt heuristic. `previewTurn` prices a turn at `max_tokens` (`bound`, what holds
19
+ and caps are sized by) and at the predicted p50/p90 through `estimateSession`, and suggests a
20
+ `max_tokens` no larger than the caller's. Billing and settlement never read a prediction.
21
+ - `computeChannel.fetchSessionInfoEvidence` keeps a miner's v2-asking signed session info as
22
+ evidence (`{ challenge, proof }`), and `computeChannel.verifySessionInfoEvidence` re-verifies it
23
+ later for an exact chain, account, session key and model identity.
24
+ - Session info proof v2: `fetchSessionInfoProof` / `fetchProvenSessionInfo` take an optional
25
+ `version` 2, and `verifySessionInfoProof` accepts a `flop-session-info-v2` proof, which also signs
26
+ the inference backend's build and chat profile (`backend`). v1 proofs verify as before and never
27
+ carry a backend; a v2 proof with its backend stripped or altered does not verify.
28
+ `test-vectors/compute-channel/session-info-proof-v2.json` pins the encoding.
29
+ - `parseMeteringConfig` meters `moonshotai/Kimi-K3.1-Pro` @ `d9e99b07` as the unverified
30
+ `kimi-k31-reference-v1` family (devnet only, text-only), and only for its exact config bytes; any
31
+ other `kimi_k31` config keeps the MLA/KDA refusals. It reports BF16 activations and expert-only
32
+ MXFP4 weights, bills `ceil(F / 10^9)` once per turn with the router, gate products and attention
33
+ residuals counted (arch hash `cee27be3…e7af`). It is priced only when both the model hash and the
34
+ miner's measured root are content root `0xbfe37d42…ca90`.
35
+ The module is exported from `computeChannel`, including `refuseKimiK31Media`.
36
+
37
+ ### Changed
38
+
39
+ - `SUPPORTED_SPEC_VERSIONS` admits devnet runtime `1014034` (candidate 1.14.34, D-0553 / #4575), and `SUPPORTED_SPEC_VERSION_RANGE` now ends at `1014034`. `1014031` stays admitted so clients work before and after `setCode`; `1014032` and `1014033` stay rejected.
40
+
41
+ ### Fixed
42
+
43
+ - `computeChannel.LongSession` keeps waiting when the miner's `/session/close` hand-off times out
44
+ or loses its connection, since the miner answers only after DA publish, TOPLOC and `settle`. It
45
+ polls the finalized channel for up to 600 s on `close()` (capped by the channel window's length),
46
+ or one turn timeout on a rollover while a request waits, and journals the channel `closed` once
47
+ it finalizes `Closed`; `close()` reconciles a rolled-over channel that finalized later. A close
48
+ that never finalizes is still `orphaned` for the timeout refund, and a refusal from the miner
49
+ still orphans at once.
50
+
51
+ ## [0.8.0] - 2026-11-21
52
+
53
+ ### Added
54
+
55
+ - Retained voucher sources accept the deployed devnet `tzkv-runtime` 1014031 release (exact source,
56
+ genesis, code and metadata hashes); any other retained release is still refused.
57
+ - `compute-channel` `assertNoForwardHoldings(api, account)` / `forwardHoldings`: at the finalized
58
+ head, refuses an account that holds forward units (total or active), resale listings, open
59
+ draws, forward channels as agent or miner, funded forward offers, posted bids or bid claims, and
60
+ fails closed when any of that storage cannot be read or a scan is unbounded.
61
+ - `LongSessionConfig.beforeSpend(kind)`: runs before every open and top-up, before anything is
62
+ journaled or signed; a throw refuses that spend.
63
+ - `LongTurnOptions.acceptReceipt(receipt)`: runs on the miner's receipt after the tariff check and
64
+ before the turn is acknowledged; a throw refuses the turn without acking or co-signing it.
65
+ - `compute-channel` long sessions for agent launch lanes: `LongSession.open|turn|recover|close`
66
+ buys a channel from a named miner only when a request needs it (a fitting miner-signed offer,
67
+ else a bare `open_channel` priced from the chain's unconsented floor; never `force_open`),
68
+ verifies the miner's info proof and finalized registration, calibration and model identity
69
+ before funding, tops up and rolls over on demand, checks each turn's tariff against the
70
+ finalized escrow before acknowledging it, and replays a journaled result for a repeated
71
+ request id. `SpendJournal` and the owner-only `FileSpendJournal` record each spend's signed
72
+ transaction hash and debit a lifetime budget before broadcast, freeze purchases while an
73
+ outcome is unknown, and allow one spender per (genesis, payer).
74
+ - `SpendingSubmitter.prepare` on `FlopChainSubmitter` and `SessionChainSubmitter` signs with an
75
+ explicit nonce and a 64-block mortal era before broadcasting; `SessionChainSubmitter` takes a
76
+ `waitForFinality` flag. `computeChannelSpend` exposes the declared-spend table.
77
+ - `parseMeteringConfig` meters `deepseek-ai/DeepSeek-V4.1-Flash-1017` at its pinned config as the
78
+ `deepseek-v41-reference-v1` family, for devnet only. No certificate proves its g_n:
79
+ `meteringIsUnverified` marks it, `UNVERIFIED_METERING` names it, and the miner host reports
80
+ provenance `GnSource.UnverifiedMinerComputed`. The DeepSeek-V4.1 module, including
81
+ `DEEPSEEK_V41_REVISION` and `DEEPSEEK_V41_CONTENT_ROOT`, is now exported from `computeChannel`.
82
+
83
+ ### Changed
84
+
85
+ - `fetchSessionInfoProof` allows the whole exchange 25 s (was 10 s).
86
+ - `SessionChainSubmitter` accepts `openChannelWithOffer` and `openChannelWithProfiledOffer`,
87
+ declaring their escrow as the session spend.
88
+ - `WeightQuantization.bits` can be `null`, for the mixed `fp8+mxfp4` method only.
89
+ - The DeepSeek-V4.1 execution profile pins publisher revision `08c8657f`, so its arch hash is now
90
+ `a242fa26…97e2`.
91
+ - `meteringArchHash`, `meteredReferenceGn` and session estimates throw on an unknown family tag
92
+ instead of metering it as a legacy architecture.
93
+
94
+ ### Fixed
95
+
96
+ - `notifyMinerOpen` retries the miner's `400 channel not found on-chain` for up to 60 s (every 2 s,
97
+ within the caller's abort signal). The opener waits for its own node's finality, but the miner reads
98
+ its own node, which the RPC pool serves while up to ~30 blocks behind, so a just-opened channel was
99
+ refused and its escrow left for the timeout refund (seen on devnet tools probes). Any other refusal
100
+ still fails at once.
101
+ - `LongSession` no longer buys or serves work its channel cannot settle. The pallet settles at most
102
+ `min(pinned reservation rate, current cap) x max_duration` G_n per channel. A turn's worst-case
103
+ G_n is `worstCaseTurnPlanck - BasePerTurn`. Before buying, the session refuses an offer or bare
104
+ window whose allowance at the miner's reservation rate is below one worst-case turn. After
105
+ inclusion it re-checks the pinned snapshot. Before each turn it refuses when the verified G_n plus
106
+ the worst-case turn would pass the live channel's allowance. It rolls over only when a new channel
107
+ could settle that turn; otherwise it throws `CalibratedAllowanceError`
108
+ (`CALIBRATED_ALLOWANCE_TOO_SMALL`), which names the miner's rate, and keeps the channel. Exported
109
+ `settleableAllowance(channel)`.
110
+ - `reservationRateUpdate(cap, sessions, current, owned?)`: a stored rate equal to `owned`, the rate
111
+ the caller's keeper set itself, now follows the cap both ways. Any other stored rate is still only
112
+ lowered.
113
+
114
+ - `LongSession` keeps a channel after a miner refuses a turn before serving it. That is an HTTP
115
+ 400/413 from `/session/turn` with no stream, frame or receipt, now `MinerTurnRejectedError`
116
+ from `HttpSessionTransport`. The miner's turn index and fence are unchanged, so a retry no
117
+ longer buys a new channel. Every other turn failure still retires the channel.
118
+ - `LongSession.turn` refuses a turn whose `/session/turn` body would pass the worker's limit with
119
+ `TurnTooLargeError`, before buying or sending. New exports: `MAX_SESSION_TURN_BODY_BYTES` (1 MiB),
120
+ `sessionTurnBody` and `sessionTurnBodyBytes`.
121
+ - `SpendingSubmitter.prepare` refuses to sign when the finalized head's `timestamp.now` is older
122
+ than a quarter of the spend era in wall time (or that far ahead of the local clock), or when it or `babe.expectedBlockTime` cannot be
123
+ read. A uniformly lagging RPC node had produced a spend whose era expired. New:
124
+ `assertFinalizedHeadFresh`.
125
+ - When finalized evidence resolves an ambiguous spend, `FileSpendJournal.resolve` keeps the
126
+ original send error in `reason`.
127
+ - `FileSpendJournal`'s one-spender lock is per (genesis, payer) again across journal directories:
128
+ it lives in `~/.flop/payers/<sha256(genesis|account)>/` (`payersRoot` option,
129
+ `defaultPayersRoot`), keyed by the decoded account so any SS58 format of it is the same payer.
130
+ That directory registers every journal used for the payer, and an unresolved spend in any of
131
+ them freezes purchases from all of them (`SpendingFrozenError.journalDir` names the journal).
132
+ - Journal recovery no longer depends on the miner or the model: `reconcileSpendJournal(journal,
133
+ reader)` with the journal-only `createJournalChainReader(api)` resolves spends and channel
134
+ states from finalized chain state without miner admission, calibration or model identity, so
135
+ recovery works after the miner went inactive, its lease expired or the model was withdrawn.
136
+ `LongSession` uses the same reconciliation, and purchases keep those checks.
137
+
138
+ ### Security
139
+
140
+ - `meteredPricing` prices DeepSeek-V4.1 only when the model hash and the miner's reported measured
141
+ root are both the pinned checkpoint root. The same config under another hash, or a miner that
142
+ measured other bytes, gets no quote.
143
+
10
144
  ## [0.7.2] - 2026-11-20
11
145
 
12
146
  ### Changed
@@ -501,7 +635,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
501
635
 
502
636
  - `inspectHuggingFace` resolves an immutable inventory and bounded config before weight transfer. `fetchHuggingFaceToDir` supports an external `resumeState` receipt with hashed file reuse and pending-rename crash recovery.
503
637
 
504
-
505
638
  - Opt-in miner turn-evidence persistence before transcript/fence mutation, for
506
639
  private encrypted replay and retirement handoff without changing receipt bytes.
507
640
  - Hash-verified whole-blob retrieval on `HttpValidatorDa` for watchtower DA reads
package/README.md CHANGED
@@ -30,9 +30,9 @@ For the examples, set `FLOP_HTLC_TEE_REQUIREMENTS` to that canonical hex from yo
30
30
 
31
31
  TypeScript SDK for the FLOP Network — HTLC workflows, PoI proofs, and account management.
32
32
 
33
- `SUPPORTED_SPEC_VERSIONS` in this source admits exactly `1013000`, `1014000`, `1014001`, `1014002`, `1014003`, `1014004`, `1014005`, `1014007`, `1014008`, `1014009`, `1014010`, `1014011`, `1014012`, `1014013`, `1014014`, `1014015`, `1014016`, `1014017`, `1014018`, `1014019`, `1014020`, `1014021`, `1014022`, `1014023`, `1014024`, `1014025`, `1014026`, `1014027`, `1014029`, `1014031`.
33
+ `SUPPORTED_SPEC_VERSIONS` in this source admits exactly `1013000`, `1014000`, `1014001`, `1014002`, `1014003`, `1014004`, `1014005`, `1014007`, `1014008`, `1014009`, `1014010`, `1014011`, `1014012`, `1014013`, `1014014`, `1014015`, `1014016`, `1014017`, `1014018`, `1014019`, `1014020`, `1014021`, `1014022`, `1014023`, `1014024`, `1014025`, `1014026`, `1014027`, `1014029`, `1014031`, `1014034`.
34
34
  `SUPPORTED_SPEC_VERSION_RANGE` retains its exported shape as the envelope
35
- `1013000..1014031`; admission requires exact membership (including no `1014006`, `1014028` or `1014030`). The published `0.4.0` executable stops at `1014011` and also excludes `1014006`;
35
+ `1013000..1014034`; admission requires exact membership (including no `1014006`, `1014028`, `1014030`, `1014032` or `1014033`). The published `0.4.0` executable stops at `1014011` and also excludes `1014006`;
36
36
  its bundled README has stale connection and HTLC examples. These source corrections
37
37
  are unreleased: installing `@latest` does not deliver them until a new version is
38
38
  published. The examples below describe this source candidate. Qualification covers
@@ -374,14 +374,14 @@ const response = await x402Fetch('https://api.example.com/inference', {
374
374
  });
375
375
  ```
376
376
 
377
- #### `parsePaymentHeaders(headers)`
377
+ #### `parsePaymentHeaders(response)`
378
378
 
379
379
  Parse x402 payment headers from response.
380
380
 
381
381
  ```typescript
382
382
  import { parsePaymentHeaders } from '@flop-labs/sdk';
383
383
 
384
- const payment = parsePaymentHeaders(response.headers);
384
+ const payment = parsePaymentHeaders(response);
385
385
  ```
386
386
 
387
387
  ### Named-miner sessions