@genkaku/protocol 0.0.0-stage → 0.1.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 (75) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bridge.d.ts +46 -0
  3. package/dist/bridge.d.ts.map +1 -0
  4. package/dist/bridge.js +542 -0
  5. package/dist/chain.d.ts +496 -0
  6. package/dist/chain.d.ts.map +1 -0
  7. package/dist/chain.js +763 -0
  8. package/dist/credit.d.ts +35 -0
  9. package/dist/credit.d.ts.map +1 -0
  10. package/dist/credit.js +112 -0
  11. package/dist/dial.d.ts +43 -0
  12. package/dist/dial.d.ts.map +1 -0
  13. package/dist/dial.js +266 -0
  14. package/dist/directory.d.ts +39 -0
  15. package/dist/directory.d.ts.map +1 -0
  16. package/dist/directory.js +149 -0
  17. package/dist/discovery.d.ts +20 -0
  18. package/dist/discovery.d.ts.map +1 -0
  19. package/dist/discovery.js +58 -0
  20. package/dist/hello.d.ts +14 -0
  21. package/dist/hello.d.ts.map +1 -0
  22. package/dist/hello.js +42 -0
  23. package/dist/index.d.ts +32 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +32 -0
  26. package/dist/keys.d.ts +30 -0
  27. package/dist/keys.d.ts.map +1 -0
  28. package/dist/keys.js +126 -0
  29. package/dist/llmBridge.d.ts +34 -0
  30. package/dist/llmBridge.d.ts.map +1 -0
  31. package/dist/llmBridge.js +151 -0
  32. package/dist/lp.d.ts +31 -0
  33. package/dist/lp.d.ts.map +1 -0
  34. package/dist/lp.js +116 -0
  35. package/dist/modeManager.d.ts +30 -0
  36. package/dist/modeManager.d.ts.map +1 -0
  37. package/dist/modeManager.js +81 -0
  38. package/dist/netconfig.d.ts +11 -0
  39. package/dist/netconfig.d.ts.map +1 -0
  40. package/dist/netconfig.js +39 -0
  41. package/dist/offer.d.ts +70 -0
  42. package/dist/offer.d.ts.map +1 -0
  43. package/dist/offer.js +84 -0
  44. package/dist/ollama.d.ts +53 -0
  45. package/dist/ollama.d.ts.map +1 -0
  46. package/dist/ollama.js +162 -0
  47. package/dist/p2pNode.d.ts +50 -0
  48. package/dist/p2pNode.d.ts.map +1 -0
  49. package/dist/p2pNode.js +450 -0
  50. package/dist/paywall.d.ts +30 -0
  51. package/dist/paywall.d.ts.map +1 -0
  52. package/dist/paywall.js +84 -0
  53. package/dist/publishOptIn.d.ts +15 -0
  54. package/dist/publishOptIn.d.ts.map +1 -0
  55. package/dist/publishOptIn.js +34 -0
  56. package/dist/receipts.d.ts +61 -0
  57. package/dist/receipts.d.ts.map +1 -0
  58. package/dist/receipts.js +135 -0
  59. package/dist/registry.d.ts +19 -0
  60. package/dist/registry.d.ts.map +1 -0
  61. package/dist/registry.js +50 -0
  62. package/dist/rpc.d.ts +24 -0
  63. package/dist/rpc.d.ts.map +1 -0
  64. package/dist/rpc.js +143 -0
  65. package/dist/status.d.ts +56 -0
  66. package/dist/status.d.ts.map +1 -0
  67. package/dist/status.js +354 -0
  68. package/dist/userSession.d.ts +64 -0
  69. package/dist/userSession.d.ts.map +1 -0
  70. package/dist/userSession.js +125 -0
  71. package/dist/workerSession.d.ts +67 -0
  72. package/dist/workerSession.d.ts.map +1 -0
  73. package/dist/workerSession.js +65 -0
  74. package/package.json +56 -3
  75. package/README.md +0 -3
@@ -0,0 +1,65 @@
1
+ // GENKAKU: worker session service (mode B/C).
2
+ // One metered worker session: /genkaku/open handshake → stream completion from
3
+ // the local source → token frames out. Settle wiring is P4.4; the receipt side
4
+ // is validated at session end against the receipts the client piped in.
5
+ export function createWorkerSession(envelope, deps) {
6
+ const sessionId = envelope.jobId;
7
+ let tokens = 0;
8
+ let aborted = false;
9
+ return {
10
+ sessionId,
11
+ tokens: () => tokens,
12
+ abort() { aborted = true; },
13
+ async run() {
14
+ const mode = deps.modeManager.current();
15
+ if (!mode.sharingActive) {
16
+ deps.emit({ type: 'session-error', message: 'worker listeners not installed (mode guard)' });
17
+ return;
18
+ }
19
+ deps.emit({ type: 'session-open', sessionId, escrowId: envelope.escrowId, model: envelope.model });
20
+ // Receipts stream IN while the session runs (client pays on a timer in
21
+ // P4.3 time-billing). Each arrival must be strictly increasing — the
22
+ // ledger rejects stale/non-increasing offers (P2 §3).
23
+ let lastSeq = 0;
24
+ const checkReceipts = () => {
25
+ const latest = deps.latestReceipt();
26
+ if (latest == null || latest.seq <= lastSeq) {
27
+ return;
28
+ }
29
+ const verdict = deps.ledger.offer(sessionId, latest.seq, latest.amount);
30
+ if (verdict.accepted) {
31
+ deps.emit({ type: 'receipt-accepted', seq: latest.seq, amount: latest.amount });
32
+ }
33
+ lastSeq = latest.seq;
34
+ };
35
+ checkReceipts();
36
+ const req = {
37
+ model: envelope.model,
38
+ prompt: envelope.prompt,
39
+ system: envelope.system,
40
+ maxTokens: envelope.maxTokens,
41
+ };
42
+ try {
43
+ await deps.source.stream(req, (delta) => {
44
+ if (aborted) {
45
+ return;
46
+ }
47
+ tokens += 1; // one delta ≈ one token frame from the local source
48
+ deps.emit({ type: 'token-count', tokens });
49
+ deps.onDelta(delta);
50
+ checkReceipts();
51
+ }, deps.abortSignal ?? undefined);
52
+ deps.emit({ type: 'session-end', sessionId, tokens });
53
+ }
54
+ catch (err) {
55
+ if (aborted) {
56
+ deps.emit({ type: 'session-end', sessionId, tokens });
57
+ }
58
+ else {
59
+ deps.emit({ type: 'session-error', message: err instanceof Error ? err.message : String(err) });
60
+ }
61
+ }
62
+ },
63
+ };
64
+ }
65
+ //# sourceMappingURL=workerSession.js.map
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@genkaku/protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "GenKaKu protocol core: on-chain worker directory, USDC escrow billing, libp2p transport, Ollama lifecycle",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "dist/**/*.js",
18
+ "dist/**/*.d.ts",
19
+ "dist/**/*.d.ts.map",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "dependencies": {
24
+ "@chainsafe/libp2p-noise": "15.1.2",
25
+ "@chainsafe/libp2p-yamux": "6.0.2",
26
+ "@libp2p/crypto": "4.1.9",
27
+ "@libp2p/identify": "2.1.5",
28
+ "@libp2p/peer-id-factory": "4.2.4",
29
+ "@libp2p/tcp": "9.1.6",
30
+ "@multiformats/multiaddr": "12.5.1",
31
+ "libp2p": "1.9.4",
32
+ "viem": "2.57.16"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/mlaimail77/genkaku-plugin.git",
37
+ "directory": "packages/protocol"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "author": "GenKaKu Labs",
43
+ "homepage": "https://staging.genkaku.app",
44
+ "keywords": [
45
+ "deepseek-harness",
46
+ "dsh",
47
+ "dsh-plugin",
48
+ "p2p",
49
+ "libp2p",
50
+ "ollama",
51
+ "usdc",
52
+ "base"
53
+ ],
54
+ "scripts": {
55
+ "build": "tsc -p tsconfig.json",
56
+ "typecheck": "tsc -p tsconfig.json --noEmit",
57
+ "test": "node --test dist/**/*.test.js"
58
+ }
6
59
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.