@0gfoundation/0g-agentdna 0.2.3 → 0.5.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 (255) hide show
  1. package/GUIDE.md +190 -40
  2. package/OPERATORS.md +164 -0
  3. package/OPERATORS.zh.md +141 -0
  4. package/PROVIDERS.md +6 -0
  5. package/PROVIDERS.zh.md +3 -1
  6. package/README.md +84 -11
  7. package/dist/AgentClient.d.ts +374 -26
  8. package/dist/AgentClient.d.ts.map +1 -1
  9. package/dist/AgentClient.js +323 -40
  10. package/dist/AgentClient.js.map +1 -1
  11. package/dist/AgenticID.d.ts +170 -80
  12. package/dist/AgenticID.d.ts.map +1 -1
  13. package/dist/AgenticID.js +300 -42
  14. package/dist/AgenticID.js.map +1 -1
  15. package/dist/AttestorClient.d.ts +115 -31
  16. package/dist/AttestorClient.d.ts.map +1 -1
  17. package/dist/AttestorClient.js +276 -56
  18. package/dist/AttestorClient.js.map +1 -1
  19. package/dist/Credentials.d.ts +574 -0
  20. package/dist/Credentials.d.ts.map +1 -0
  21. package/dist/Credentials.js +838 -0
  22. package/dist/Credentials.js.map +1 -0
  23. package/dist/Operators.d.ts +60 -0
  24. package/dist/Operators.d.ts.map +1 -0
  25. package/dist/Operators.js +38 -0
  26. package/dist/Operators.js.map +1 -0
  27. package/dist/Providers.d.ts +13 -0
  28. package/dist/Providers.d.ts.map +1 -1
  29. package/dist/Providers.js +20 -1
  30. package/dist/Providers.js.map +1 -1
  31. package/dist/Releases.d.ts +51 -0
  32. package/dist/Releases.d.ts.map +1 -0
  33. package/dist/Releases.js +72 -0
  34. package/dist/Releases.js.map +1 -0
  35. package/dist/ReputationClient.d.ts +47 -3
  36. package/dist/ReputationClient.d.ts.map +1 -1
  37. package/dist/ReputationClient.js +204 -78
  38. package/dist/ReputationClient.js.map +1 -1
  39. package/dist/ServeProof.d.ts +70 -23
  40. package/dist/ServeProof.d.ts.map +1 -1
  41. package/dist/ServeProof.js +94 -35
  42. package/dist/ServeProof.js.map +1 -1
  43. package/dist/ServeSession.d.ts +17 -2
  44. package/dist/ServeSession.d.ts.map +1 -1
  45. package/dist/ServeSession.js +77 -9
  46. package/dist/ServeSession.js.map +1 -1
  47. package/dist/Settings.d.ts +25 -1
  48. package/dist/Settings.d.ts.map +1 -1
  49. package/dist/Settings.js +53 -1
  50. package/dist/Settings.js.map +1 -1
  51. package/dist/TrustRegistry.d.ts +28 -0
  52. package/dist/TrustRegistry.d.ts.map +1 -0
  53. package/dist/TrustRegistry.js +67 -0
  54. package/dist/TrustRegistry.js.map +1 -0
  55. package/dist/abi.d.ts +346 -34
  56. package/dist/abi.d.ts.map +1 -1
  57. package/dist/abi.js +150 -30
  58. package/dist/abi.js.map +1 -1
  59. package/dist/cli/attach.d.ts +79 -0
  60. package/dist/cli/attach.d.ts.map +1 -0
  61. package/dist/cli/attach.js +253 -0
  62. package/dist/cli/attach.js.map +1 -0
  63. package/dist/cli/commands/cells.d.ts +45 -0
  64. package/dist/cli/commands/cells.d.ts.map +1 -1
  65. package/dist/cli/commands/cells.js +77 -0
  66. package/dist/cli/commands/cells.js.map +1 -1
  67. package/dist/cli/commands/cred.d.ts +12 -0
  68. package/dist/cli/commands/cred.d.ts.map +1 -0
  69. package/dist/cli/commands/cred.js +43 -0
  70. package/dist/cli/commands/cred.js.map +1 -0
  71. package/dist/cli/commands/doctor.d.ts.map +1 -1
  72. package/dist/cli/commands/doctor.js +44 -35
  73. package/dist/cli/commands/doctor.js.map +1 -1
  74. package/dist/cli/commands/interactive.d.ts +597 -21
  75. package/dist/cli/commands/interactive.d.ts.map +1 -1
  76. package/dist/cli/commands/interactive.js +5082 -1323
  77. package/dist/cli/commands/interactive.js.map +1 -1
  78. package/dist/cli/commands/list.d.ts +5 -5
  79. package/dist/cli/commands/list.d.ts.map +1 -1
  80. package/dist/cli/commands/list.js +21 -26
  81. package/dist/cli/commands/list.js.map +1 -1
  82. package/dist/cli/commands/providers.d.ts +4 -0
  83. package/dist/cli/commands/providers.d.ts.map +1 -1
  84. package/dist/cli/commands/providers.js +19 -5
  85. package/dist/cli/commands/providers.js.map +1 -1
  86. package/dist/cli/commands/releases.d.ts +13 -0
  87. package/dist/cli/commands/releases.d.ts.map +1 -0
  88. package/dist/cli/commands/releases.js +65 -0
  89. package/dist/cli/commands/releases.js.map +1 -0
  90. package/dist/cli/commands/settings.d.ts +5 -0
  91. package/dist/cli/commands/settings.d.ts.map +1 -1
  92. package/dist/cli/commands/settings.js +70 -24
  93. package/dist/cli/commands/settings.js.map +1 -1
  94. package/dist/cli/commands/status.d.ts +2 -1
  95. package/dist/cli/commands/status.d.ts.map +1 -1
  96. package/dist/cli/commands/status.js +22 -19
  97. package/dist/cli/commands/status.js.map +1 -1
  98. package/dist/cli/config.d.ts +48 -1
  99. package/dist/cli/config.d.ts.map +1 -1
  100. package/dist/cli/config.js +114 -5
  101. package/dist/cli/config.js.map +1 -1
  102. package/dist/cli/credentials.d.ts +179 -0
  103. package/dist/cli/credentials.d.ts.map +1 -0
  104. package/dist/cli/credentials.js +1443 -0
  105. package/dist/cli/credentials.js.map +1 -0
  106. package/dist/cli/download.d.ts +21 -0
  107. package/dist/cli/download.d.ts.map +1 -0
  108. package/dist/cli/download.js +89 -0
  109. package/dist/cli/download.js.map +1 -0
  110. package/dist/cli/env.d.ts +6 -0
  111. package/dist/cli/env.d.ts.map +1 -1
  112. package/dist/cli/env.js +18 -6
  113. package/dist/cli/env.js.map +1 -1
  114. package/dist/cli/envelope.d.ts +4 -2
  115. package/dist/cli/envelope.d.ts.map +1 -1
  116. package/dist/cli/envelope.js +10 -6
  117. package/dist/cli/envelope.js.map +1 -1
  118. package/dist/cli/errors.d.ts +45 -1
  119. package/dist/cli/errors.d.ts.map +1 -1
  120. package/dist/cli/errors.js +77 -0
  121. package/dist/cli/errors.js.map +1 -1
  122. package/dist/cli/inference.d.ts.map +1 -1
  123. package/dist/cli/inference.js +7 -0
  124. package/dist/cli/inference.js.map +1 -1
  125. package/dist/cli/inkView.d.ts +341 -0
  126. package/dist/cli/inkView.d.ts.map +1 -0
  127. package/dist/cli/inkView.js +1019 -0
  128. package/dist/cli/inkView.js.map +1 -0
  129. package/dist/cli/legacy/modelKey.d.ts +24 -0
  130. package/dist/cli/legacy/modelKey.d.ts.map +1 -0
  131. package/dist/cli/legacy/modelKey.js +32 -0
  132. package/dist/cli/legacy/modelKey.js.map +1 -0
  133. package/dist/cli/livePrompt.d.ts +212 -0
  134. package/dist/cli/livePrompt.d.ts.map +1 -0
  135. package/dist/cli/livePrompt.js +576 -0
  136. package/dist/cli/livePrompt.js.map +1 -0
  137. package/dist/cli/main.js +206 -72
  138. package/dist/cli/main.js.map +1 -1
  139. package/dist/cli/modelkey.d.ts +64 -0
  140. package/dist/cli/modelkey.d.ts.map +1 -0
  141. package/dist/cli/modelkey.js +113 -0
  142. package/dist/cli/modelkey.js.map +1 -0
  143. package/dist/cli/outboxSync.d.ts +51 -0
  144. package/dist/cli/outboxSync.d.ts.map +1 -0
  145. package/dist/cli/outboxSync.js +210 -0
  146. package/dist/cli/outboxSync.js.map +1 -0
  147. package/dist/cli/plain.d.ts +46 -0
  148. package/dist/cli/plain.d.ts.map +1 -0
  149. package/dist/cli/plain.js +260 -0
  150. package/dist/cli/plain.js.map +1 -0
  151. package/dist/cli/proofs.d.ts +5 -0
  152. package/dist/cli/proofs.d.ts.map +1 -1
  153. package/dist/cli/proofs.js +20 -0
  154. package/dist/cli/proofs.js.map +1 -1
  155. package/dist/cli/ref.d.ts.map +1 -1
  156. package/dist/cli/ref.js +3 -2
  157. package/dist/cli/ref.js.map +1 -1
  158. package/dist/cli/releaseNotice.d.ts +64 -0
  159. package/dist/cli/releaseNotice.d.ts.map +1 -0
  160. package/dist/cli/releaseNotice.js +194 -0
  161. package/dist/cli/releaseNotice.js.map +1 -0
  162. package/dist/cli/sdk.d.ts +18 -0
  163. package/dist/cli/sdk.d.ts.map +1 -1
  164. package/dist/cli/sdk.js +99 -1
  165. package/dist/cli/sdk.js.map +1 -1
  166. package/dist/cli/settings.d.ts +90 -9
  167. package/dist/cli/settings.d.ts.map +1 -1
  168. package/dist/cli/settings.js +273 -21
  169. package/dist/cli/settings.js.map +1 -1
  170. package/dist/cli/textfit.d.ts +28 -0
  171. package/dist/cli/textfit.d.ts.map +1 -0
  172. package/dist/cli/textfit.js +111 -0
  173. package/dist/cli/textfit.js.map +1 -0
  174. package/dist/constants.d.ts +1 -1
  175. package/dist/constants.js +1 -1
  176. package/dist/context.d.ts +26 -0
  177. package/dist/context.d.ts.map +1 -1
  178. package/dist/context.js +1 -0
  179. package/dist/context.js.map +1 -1
  180. package/dist/index.d.ts +19 -11
  181. package/dist/index.d.ts.map +1 -1
  182. package/dist/index.js +35 -2
  183. package/dist/index.js.map +1 -1
  184. package/dist/legacy/modelKey.d.ts +67 -0
  185. package/dist/legacy/modelKey.d.ts.map +1 -0
  186. package/dist/legacy/modelKey.js +80 -0
  187. package/dist/legacy/modelKey.js.map +1 -0
  188. package/dist/legacy/serveProofV1.d.ts +56 -0
  189. package/dist/legacy/serveProofV1.d.ts.map +1 -0
  190. package/dist/legacy/serveProofV1.js +91 -0
  191. package/dist/legacy/serveProofV1.js.map +1 -0
  192. package/dist/provider-catalog.json +3 -2
  193. package/dist/secretEnv.d.ts +18 -3
  194. package/dist/secretEnv.d.ts.map +1 -1
  195. package/dist/secretEnv.js +16 -2
  196. package/dist/secretEnv.js.map +1 -1
  197. package/dist/types.d.ts +63 -1
  198. package/dist/types.d.ts.map +1 -1
  199. package/dist/viemErrors.d.ts +30 -0
  200. package/dist/viemErrors.d.ts.map +1 -0
  201. package/dist/viemErrors.js +36 -0
  202. package/dist/viemErrors.js.map +1 -0
  203. package/package.json +5 -1
  204. package/src/AgentClient.ts +622 -68
  205. package/src/AgenticID.ts +345 -56
  206. package/src/AttestorClient.ts +330 -83
  207. package/src/Credentials.ts +1027 -0
  208. package/src/Operators.ts +71 -0
  209. package/src/Providers.ts +20 -0
  210. package/src/Releases.ts +95 -0
  211. package/src/ReputationClient.ts +231 -79
  212. package/src/ServeProof.ts +123 -39
  213. package/src/ServeSession.ts +91 -9
  214. package/src/Settings.ts +61 -1
  215. package/src/TrustRegistry.ts +75 -0
  216. package/src/abi.ts +153 -30
  217. package/src/cli/attach.ts +257 -0
  218. package/src/cli/commands/cells.ts +104 -0
  219. package/src/cli/commands/cred.ts +44 -0
  220. package/src/cli/commands/doctor.ts +45 -37
  221. package/src/cli/commands/interactive.ts +4120 -664
  222. package/src/cli/commands/list.ts +21 -30
  223. package/src/cli/commands/providers.ts +17 -4
  224. package/src/cli/commands/releases.ts +60 -0
  225. package/src/cli/commands/settings.ts +75 -28
  226. package/src/cli/commands/status.ts +24 -21
  227. package/src/cli/config.ts +119 -4
  228. package/src/cli/credentials.ts +1379 -0
  229. package/src/cli/download.ts +80 -0
  230. package/src/cli/env.ts +22 -7
  231. package/src/cli/envelope.ts +10 -6
  232. package/src/cli/errors.ts +92 -0
  233. package/src/cli/inference.ts +8 -1
  234. package/src/cli/inkView.ts +969 -0
  235. package/src/cli/legacy/modelKey.ts +35 -0
  236. package/src/cli/livePrompt.ts +615 -0
  237. package/src/cli/main.ts +206 -76
  238. package/src/cli/modelkey.ts +124 -0
  239. package/src/cli/outboxSync.ts +231 -0
  240. package/src/cli/plain.ts +260 -0
  241. package/src/cli/proofs.ts +27 -0
  242. package/src/cli/ref.ts +5 -4
  243. package/src/cli/releaseNotice.ts +200 -0
  244. package/src/cli/sdk.ts +87 -7
  245. package/src/cli/settings.ts +275 -25
  246. package/src/cli/textfit.ts +95 -0
  247. package/src/constants.ts +1 -1
  248. package/src/context.ts +28 -0
  249. package/src/index.ts +50 -7
  250. package/src/legacy/modelKey.ts +80 -0
  251. package/src/legacy/serveProofV1.ts +124 -0
  252. package/src/provider-catalog.json +3 -2
  253. package/src/secretEnv.ts +18 -3
  254. package/src/types.ts +60 -1
  255. package/src/viemErrors.ts +39 -0
package/src/abi.ts CHANGED
@@ -85,20 +85,13 @@ export const agenticIDAbi = [
85
85
  outputs: [{ name: '', type: 'bool' }],
86
86
  },
87
87
 
88
- // ── Trusted Attestors ──
88
+ // ── Trust (held by the TrustRegistry since 1.4.0; these read through it) ──
89
89
  {
90
90
  type: 'function',
91
- name: 'addTrustedAttestor',
92
- stateMutability: 'nonpayable',
93
- inputs: [{ name: 'attestor', type: 'address' }],
94
- outputs: [],
95
- },
96
- {
97
- type: 'function',
98
- name: 'removeTrustedAttestor',
99
- stateMutability: 'nonpayable',
100
- inputs: [{ name: 'attestor', type: 'address' }],
101
- outputs: [],
91
+ name: 'trustRegistry',
92
+ stateMutability: 'view',
93
+ inputs: [],
94
+ outputs: [{ name: '', type: 'address' }],
102
95
  },
103
96
  {
104
97
  type: 'function',
@@ -107,22 +100,6 @@ export const agenticIDAbi = [
107
100
  inputs: [{ name: 'attestor', type: 'address' }],
108
101
  outputs: [{ name: '', type: 'bool' }],
109
102
  },
110
-
111
- // ── Framework Hashes ──
112
- {
113
- type: 'function',
114
- name: 'addValidFrameworkHash',
115
- stateMutability: 'nonpayable',
116
- inputs: [{ name: 'frameworkHash', type: 'bytes32' }],
117
- outputs: [],
118
- },
119
- {
120
- type: 'function',
121
- name: 'removeValidFrameworkHash',
122
- stateMutability: 'nonpayable',
123
- inputs: [{ name: 'frameworkHash', type: 'bytes32' }],
124
- outputs: [],
125
- },
126
103
  {
127
104
  type: 'function',
128
105
  name: 'isValidFrameworkHash',
@@ -514,6 +491,49 @@ export const agenticIDAbi = [
514
491
  },
515
492
  ] as const;
516
493
 
494
+ /**
495
+ * TrustRegistry — the deployer's trust decisions, found through
496
+ * AgenticID.trustRegistry() (AgenticID 1.4.0+): trusted attestors, and code
497
+ * lists by kind — IMAGE (base images, formerly AgenticID's
498
+ * validFrameworkHashes), SEALED (sealed programs) and HARNESS (official
499
+ * harness versions). Each list keeps listing order; `latest` is the newest
500
+ * still listed. Read-only here: listing is the deployer's.
501
+ */
502
+ export const trustRegistryAbi = [
503
+ { type: 'function', name: 'VERSION', stateMutability: 'view', inputs: [], outputs: [{ name: '', type: 'string' }] },
504
+ { type: 'function', name: 'IMAGE', stateMutability: 'view', inputs: [], outputs: [{ name: '', type: 'bytes32' }] },
505
+ { type: 'function', name: 'SEALED', stateMutability: 'view', inputs: [], outputs: [{ name: '', type: 'bytes32' }] },
506
+ { type: 'function', name: 'HARNESS', stateMutability: 'view', inputs: [], outputs: [{ name: '', type: 'bytes32' }] },
507
+ {
508
+ type: 'function',
509
+ name: 'isListed',
510
+ stateMutability: 'view',
511
+ inputs: [{ name: 'kind', type: 'bytes32' }, { name: 'hash', type: 'bytes32' }],
512
+ outputs: [{ name: '', type: 'bool' }],
513
+ },
514
+ {
515
+ type: 'function',
516
+ name: 'latest',
517
+ stateMutability: 'view',
518
+ inputs: [{ name: 'kind', type: 'bytes32' }],
519
+ outputs: [{ name: '', type: 'bytes32' }],
520
+ },
521
+ {
522
+ type: 'function',
523
+ name: 'listed',
524
+ stateMutability: 'view',
525
+ inputs: [{ name: 'kind', type: 'bytes32' }],
526
+ outputs: [{ name: 'hashes', type: 'bytes32[]' }],
527
+ },
528
+ {
529
+ type: 'function',
530
+ name: 'isTrustedAttestor',
531
+ stateMutability: 'view',
532
+ inputs: [{ name: 'attestor', type: 'address' }],
533
+ outputs: [{ name: '', type: 'bool' }],
534
+ },
535
+ ] as const;
536
+
517
537
  /**
518
538
  * Official canonical ERC-8004 ReputationRegistry (the fixed 0x8004B… singleton;
519
539
  * v2.0.0). Feedback STORAGE lives here — clients call `giveFeedback` directly,
@@ -720,11 +740,38 @@ export const canonicalReputationAbi = [
720
740
  },
721
741
  ] as const;
722
742
 
743
+ /** The VersionedServeProof struct (IVerifiedFeedbackRegistry.sol), in field order. */
744
+ const VERSIONED_SERVE_PROOF = [
745
+ { name: 'version', type: 'uint16' },
746
+ { name: 'agentId', type: 'uint256' },
747
+ { name: 'submitter', type: 'address' },
748
+ { name: 'timestamp', type: 'uint256' },
749
+ { name: 'deadline', type: 'uint256' },
750
+ { name: 'taskHash', type: 'bytes32' },
751
+ { name: 'dataHashes', type: 'bytes32[]' },
752
+ { name: 'frameworkHash', type: 'bytes32' },
753
+ { name: 'sealedHash', type: 'bytes32' },
754
+ { name: 'harnessHash', type: 'bytes32' },
755
+ { name: 'inferenceURL', type: 'string' },
756
+ { name: 'model', type: 'string' },
757
+ { name: 'signature', type: 'bytes' },
758
+ ] as const;
759
+
760
+ /** The TaskReveal struct, in field order. */
761
+ const TASK_REVEAL = [
762
+ { name: 'method', type: 'string' },
763
+ { name: 'uri', type: 'string' },
764
+ { name: 'reqBodyHash', type: 'bytes32' },
765
+ { name: 'respBodyHash', type: 'bytes32' },
766
+ { name: 'statusCode', type: 'uint16' },
767
+ ] as const;
768
+
723
769
  /**
724
770
  * VerifiedFeedbackRegistry — the local TEE-verification layer over the
725
771
  * canonical ERC-8004 ReputationRegistry. `attestFeedback` marks a canonical
726
- * entry as backed by a ServeProof; the `getVerified*` reads expose the marks
727
- * so readers can intersect them with canonical entries.
772
+ * entry as backed by a ServeProof (`attestVersionedFeedback` for a proof that
773
+ * carries its version); the `getVerified*` reads expose the marks so readers
774
+ * can intersect them with canonical entries.
728
775
  */
729
776
  export const verifiedFeedbackAbi = [
730
777
  // Custom errors — so viem decodes reverts instead of showing a 4-byte selector.
@@ -758,8 +805,19 @@ export const verifiedFeedbackAbi = [
758
805
  {"type":"error","name":"VerifiedFeedbackValueOutOfRange","inputs":[{"name":"value","type":"int128"},{"name":"valueDecimals","type":"uint8"}]},
759
806
  {"type":"error","name":"VerifiedFeedbackEndpointRequired","inputs":[]},
760
807
  {"type":"error","name":"VerifiedFeedbackInvalidProofTimestamp","inputs":[]},
808
+ {"type":"error","name":"VerifiedFeedbackUnsupportedVersion","inputs":[{"name":"version","type":"uint16"}]},
809
+
810
+ {
811
+ type: 'function',
812
+ name: 'VERSION',
813
+ stateMutability: 'view',
814
+ inputs: [],
815
+ outputs: [{ name: '', type: 'string' }],
816
+ },
761
817
 
762
818
  // ── Attest ──
819
+ // LEGACY(v1): attestFeedback and attestFeedbackWithTask take v1 proofs
820
+ // (legacy/serveProofV1.ts); the registry keeps them.
763
821
  {
764
822
  type: 'function',
765
823
  name: 'attestFeedback',
@@ -807,6 +865,20 @@ export const verifiedFeedbackAbi = [
807
865
  ],
808
866
  outputs: [],
809
867
  },
868
+ // Versioned proofs (1.3.0+): the registry picks the digest by
869
+ // proof.version (2 only); an empty task.method skips the receipt opening.
870
+ {
871
+ type: 'function',
872
+ name: 'attestVersionedFeedback',
873
+ stateMutability: 'nonpayable',
874
+ inputs: [
875
+ { name: 'agentId', type: 'uint256' },
876
+ { name: 'feedbackIndex', type: 'uint64' },
877
+ { name: 'proof', type: 'tuple', components: VERSIONED_SERVE_PROOF },
878
+ { name: 'task', type: 'tuple', components: TASK_REVEAL },
879
+ ],
880
+ outputs: [],
881
+ },
810
882
 
811
883
  // ── Reads ──
812
884
  {
@@ -834,6 +906,21 @@ export const verifiedFeedbackAbi = [
834
906
  { name: 'frameworkHash', type: 'bytes32' },
835
907
  ],
836
908
  },
909
+ // 1.3.0+: the layers a v2 proof named; zero for a v1 entry.
910
+ {
911
+ type: 'function',
912
+ name: 'getServeLayers',
913
+ stateMutability: 'view',
914
+ inputs: [
915
+ { name: 'agentId', type: 'uint256' },
916
+ { name: 'clientAddress', type: 'address' },
917
+ { name: 'feedbackIndex', type: 'uint64' },
918
+ ],
919
+ outputs: [
920
+ { name: 'sealedHash', type: 'bytes32' },
921
+ { name: 'harnessHash', type: 'bytes32' },
922
+ ],
923
+ },
837
924
  {
838
925
  type: 'function',
839
926
  name: 'getVerifiedIndexes',
@@ -931,6 +1018,21 @@ export const verifiedFeedbackAbi = [
931
1018
  { name: 'uri', type: 'string', indexed: false },
932
1019
  ],
933
1020
  },
1021
+ // Emitted after FeedbackVerified for a versioned proof.
1022
+ {
1023
+ type: 'event',
1024
+ name: 'VersionedFeedbackVerified',
1025
+ inputs: [
1026
+ { name: 'agentId', type: 'uint256', indexed: true },
1027
+ { name: 'clientAddress', type: 'address', indexed: true },
1028
+ { name: 'feedbackIndex', type: 'uint64', indexed: true },
1029
+ { name: 'version', type: 'uint16', indexed: false },
1030
+ { name: 'sealedHash', type: 'bytes32', indexed: false },
1031
+ { name: 'harnessHash', type: 'bytes32', indexed: false },
1032
+ { name: 'inferenceURL', type: 'string', indexed: false },
1033
+ { name: 'model', type: 'string', indexed: false },
1034
+ ],
1035
+ },
934
1036
  ] as const;
935
1037
 
936
1038
  /**
@@ -941,6 +1043,7 @@ export const verifiedFeedbackAbi = [
941
1043
  */
942
1044
  export const feedbackBatcherAbi = [
943
1045
  {"type":"error","name":"BatcherNotSelf","inputs":[]},
1046
+ // LEGACY(v1): the batch for a v1 proof (legacy/serveProofV1.ts).
944
1047
  {
945
1048
  type: 'function',
946
1049
  name: 'giveFeedbackAndAttest',
@@ -974,6 +1077,26 @@ export const feedbackBatcherAbi = [
974
1077
  ],
975
1078
  outputs: [{ name: 'feedbackIndex', type: 'uint64' }],
976
1079
  },
1080
+ // giveFeedbackAndAttest for a versioned proof (VerifiedFeedbackRegistry
1081
+ // 1.3.0+). Batchers deployed before it lack this entry.
1082
+ {
1083
+ type: 'function',
1084
+ name: 'giveFeedbackAndAttestVersioned',
1085
+ stateMutability: 'nonpayable',
1086
+ inputs: [
1087
+ { name: 'agentId', type: 'uint256' },
1088
+ { name: 'value', type: 'int128' },
1089
+ { name: 'valueDecimals', type: 'uint8' },
1090
+ { name: 'tag1', type: 'string' },
1091
+ { name: 'tag2', type: 'string' },
1092
+ { name: 'endpoint', type: 'string' },
1093
+ { name: 'feedbackURI', type: 'string' },
1094
+ { name: 'feedbackHash', type: 'bytes32' },
1095
+ { name: 'proof', type: 'tuple', components: VERSIONED_SERVE_PROOF },
1096
+ { name: 'task', type: 'tuple', components: TASK_REVEAL },
1097
+ ],
1098
+ outputs: [{ name: 'feedbackIndex', type: 'uint64' }],
1099
+ },
977
1100
  {
978
1101
  type: 'function',
979
1102
  name: 'canonicalReputation',
@@ -0,0 +1,257 @@
1
+ /**
2
+ * @file attach.ts
3
+ * @description `/attach`: files and images staged for the owner's next
4
+ * message.
5
+ *
6
+ * An image (recognized by its bytes: PNG, JPEG, WebP, GIF) goes with the
7
+ * message itself; any other file is uploaded first (`uploadFile`, 0g-harness
8
+ * `POST /v1/files`) and the message names the path it landed at. The limits
9
+ * are 0g-harness's (docs/PROTOCOL.md there), checked here so a refusal comes
10
+ * when the file is staged, not after the message is typed.
11
+ */
12
+
13
+ import { closeSync, openSync, readFileSync, readSync, readdirSync, statSync } from 'node:fs';
14
+ import { homedir } from 'node:os';
15
+ import { basename, dirname, join, resolve } from 'node:path';
16
+ import type { AgentClient, ChatImage } from '../AgentClient';
17
+
18
+ export const ATTACH_LIMITS = {
19
+ imageBytes: 10 << 20,
20
+ imagesPerMessage: 8,
21
+ messageImageBytes: 32 << 20,
22
+ fileBytes: 25 << 20,
23
+ } as const;
24
+
25
+ /** One staged attachment. `image` is set when its bytes are an image. */
26
+ export interface Staged {
27
+ path: string;
28
+ name: string;
29
+ bytes: number;
30
+ image?: ChatImage['mediaType'];
31
+ }
32
+
33
+ /** `~` and `~/…` as the user's home. */
34
+ export function expandHome(p: string): string {
35
+ if (p === '~') return homedir();
36
+ if (p.startsWith('~/')) return join(homedir(), p.slice(2));
37
+ return p;
38
+ }
39
+
40
+ /** The image type these leading bytes are, or undefined. */
41
+ export function sniffImage(head: Uint8Array): ChatImage['mediaType'] | undefined {
42
+ const at = (i: number, bytes: number[]): boolean => bytes.every((b, k) => head[i + k] === b);
43
+ if (at(0, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) return 'image/png';
44
+ if (at(0, [0xff, 0xd8, 0xff])) return 'image/jpeg';
45
+ if (at(0, [0x47, 0x49, 0x46, 0x38])) return 'image/gif';
46
+ if (at(0, [0x52, 0x49, 0x46, 0x46]) && at(8, [0x57, 0x45, 0x42, 0x50])) return 'image/webp';
47
+ return undefined;
48
+ }
49
+
50
+ function head(path: string): Uint8Array {
51
+ const fd = openSync(path, 'r');
52
+ try {
53
+ const buf = new Uint8Array(16);
54
+ const n = readSync(fd, buf, 0, buf.length, 0);
55
+ return buf.subarray(0, n);
56
+ } finally {
57
+ closeSync(fd);
58
+ }
59
+ }
60
+
61
+ const size = (n: number): string => (n < 1024 ? `${n} B` : n < 1 << 20 ? `${(n / 1024).toFixed(1)} KiB` : `${(n / (1 << 20)).toFixed(1)} MiB`);
62
+
63
+ /**
64
+ * Stage one path for the next message, against what is staged already.
65
+ * Throws an Error whose message says why it cannot go.
66
+ */
67
+ export function stageFile(raw: string, staged: readonly Staged[]): Staged {
68
+ const path = resolve(expandHome(raw));
69
+ let st;
70
+ try {
71
+ st = statSync(path);
72
+ } catch {
73
+ throw new Error(`${raw}: no such file`);
74
+ }
75
+ if (!st.isFile()) throw new Error(`${raw}: not a regular file`);
76
+ if (staged.some((s) => s.path === path)) throw new Error(`${raw}: already attached`);
77
+ const image = sniffImage(head(path));
78
+ if (image) {
79
+ if (st.size > ATTACH_LIMITS.imageBytes) throw new Error(`${raw}: an image is at most ${size(ATTACH_LIMITS.imageBytes)} (this one is ${size(st.size)})`);
80
+ const images = staged.filter((s) => s.image);
81
+ if (images.length + 1 > ATTACH_LIMITS.imagesPerMessage) throw new Error(`${raw}: at most ${ATTACH_LIMITS.imagesPerMessage} images per message`);
82
+ const total = images.reduce((n, s) => n + s.bytes, 0) + st.size;
83
+ if (total > ATTACH_LIMITS.messageImageBytes) throw new Error(`${raw}: the images of one message are at most ${size(ATTACH_LIMITS.messageImageBytes)} together`);
84
+ } else if (st.size > ATTACH_LIMITS.fileBytes) {
85
+ throw new Error(`${raw}: a file is at most ${size(ATTACH_LIMITS.fileBytes)} (this one is ${size(st.size)})`);
86
+ }
87
+ return { path, name: basename(path), bytes: st.size, ...(image ? { image } : {}) };
88
+ }
89
+
90
+ /** One line per staged attachment. */
91
+ export function describeStaged(staged: readonly Staged[]): string[] {
92
+ return staged.map((s, i) => ` ${i + 1}. ${s.name} ${s.image ? `image (${s.image.slice(6)})` : 'file'}, ${size(s.bytes)}`);
93
+ }
94
+
95
+ /**
96
+ * What a message with these attachments sends: the images, and the text
97
+ * with a `[file uploaded: <path>]` line for each other file, uploaded first.
98
+ */
99
+ export async function prepareAttachments(
100
+ staged: readonly Staged[],
101
+ text: string,
102
+ client: Pick<AgentClient, 'uploadFile'>,
103
+ onUploaded?: (s: Staged, path: string) => void,
104
+ ): Promise<{ text: string; images: ChatImage[] }> {
105
+ const images: ChatImage[] = [];
106
+ let out = text;
107
+ for (const s of staged) {
108
+ const data = readFileSync(s.path);
109
+ if (s.image) {
110
+ images.push({ mediaType: s.image, data: data.toString('base64'), name: s.name });
111
+ continue;
112
+ }
113
+ if (!client.uploadFile) throw new Error('this agent takes no files: its framework has no upload route');
114
+ const up = await client.uploadFile(s.name, new Uint8Array(data.buffer, data.byteOffset, data.length));
115
+ onUploaded?.(s, up.path);
116
+ out += `${out ? '\n' : ''}[file uploaded: ${up.path}]`;
117
+ }
118
+ return { text: out, images };
119
+ }
120
+
121
+ /**
122
+ * Where a file dragged into the terminal can come from: the user's home, an
123
+ * external volume, and the temporary folders (macOS screenshots land in
124
+ * `/var/folders`). A path elsewhere (`/etc/hosts`) is text the user typed,
125
+ * never uploaded.
126
+ */
127
+ export function dropRoots(): string[] {
128
+ return [homedir(), '/Volumes', '/tmp', '/private/tmp', '/var/folders', '/private/var/folders', '/media', '/mnt'];
129
+ }
130
+
131
+ /** One file a message carries, as it appeared in the typed text. */
132
+ export interface DroppedFile {
133
+ path: string;
134
+ raw: string;
135
+ }
136
+
137
+ function droppable(raw: string, roots: readonly string[]): string | undefined {
138
+ const path = resolve(expandHome(raw));
139
+ if (!roots.some((r) => path.startsWith(r.endsWith('/') ? r : `${r}/`))) return undefined;
140
+ try {
141
+ return statSync(path).isFile() ? path : undefined;
142
+ } catch {
143
+ return undefined;
144
+ }
145
+ }
146
+
147
+ /**
148
+ * A typed message split into its text and the local files in it: a file
149
+ * dragged into the terminal leaves its path in the line (`/a/My\ File.png`,
150
+ * or quoted, `'/a/My File.png'`), and so does a pasted path. A path counts
151
+ * when it starts a word, names an existing regular file under
152
+ * {@link dropRoots}, and ends the word. A path inside backticks stays text.
153
+ */
154
+ export function findDroppedFiles(line: string, roots: readonly string[] = dropRoots()): Array<string | DroppedFile> {
155
+ const parts: Array<string | DroppedFile> = [];
156
+ let text = '';
157
+ const flush = (): void => {
158
+ if (text) parts.push(text);
159
+ text = '';
160
+ };
161
+ const wordEnd = (k: number): boolean => k >= line.length || /\s/.test(line[k]);
162
+ let i = 0;
163
+ while (i < line.length) {
164
+ const c = line[i];
165
+ const starts = i === 0 || /\s/.test(line[i - 1]);
166
+ if (c === '`') {
167
+ const j = line.indexOf('`', i + 1);
168
+ const end = j === -1 ? line.length : j + 1;
169
+ text += line.slice(i, end);
170
+ i = end;
171
+ continue;
172
+ }
173
+ if (starts && (c === "'" || c === '"')) {
174
+ const j = line.indexOf(c, i + 1);
175
+ const path = j > i + 1 && wordEnd(j + 1) ? droppable(line.slice(i + 1, j), roots) : undefined;
176
+ if (path) {
177
+ flush();
178
+ parts.push({ path, raw: line.slice(i, j + 1) });
179
+ i = j + 1;
180
+ continue;
181
+ }
182
+ }
183
+ if (starts && (c === '/' || (c === '~' && line[i + 1] === '/'))) {
184
+ let value = '';
185
+ let k = i;
186
+ while (k < line.length && !/\s/.test(line[k])) {
187
+ if (line[k] === '\\' && k + 1 < line.length) {
188
+ value += line[k + 1];
189
+ k += 2;
190
+ continue;
191
+ }
192
+ value += line[k];
193
+ k++;
194
+ }
195
+ const path = droppable(value, roots);
196
+ if (path) {
197
+ flush();
198
+ parts.push({ path, raw: line.slice(i, k) });
199
+ i = k;
200
+ continue;
201
+ }
202
+ }
203
+ text += c;
204
+ i++;
205
+ }
206
+ flush();
207
+ return parts;
208
+ }
209
+
210
+ /**
211
+ * Stage the files {@link findDroppedFiles} found, after what is staged
212
+ * already, and give back the message text: an image is named where its path
213
+ * was (`[image: <name>]`); another file's path is left out, as
214
+ * {@link prepareAttachments} names it once uploaded. When one cannot go, the
215
+ * ones staged here are dropped again and the reason comes back.
216
+ */
217
+ export function stageDropped(
218
+ parts: ReadonlyArray<string | DroppedFile>,
219
+ staged: Staged[],
220
+ onAttached?: (s: Staged) => void,
221
+ ): { text: string } | { refused: string } {
222
+ const before = staged.length;
223
+ let text = '';
224
+ for (const p of parts) {
225
+ if (typeof p === 'string') {
226
+ text += p;
227
+ continue;
228
+ }
229
+ try {
230
+ const one = stageFile(p.path, staged);
231
+ staged.push(one);
232
+ onAttached?.(one);
233
+ if (one.image) text += `[image: ${one.name}]`;
234
+ } catch (err) {
235
+ staged.length = before;
236
+ return { refused: (err as Error).message };
237
+ }
238
+ }
239
+ return { text: text.replace(/[ \t]{2,}/g, ' ').trim() };
240
+ }
241
+
242
+ /** Tab completion of a path being typed after `/attach`. */
243
+ export function completePath(word: string): string[] {
244
+ const typed = expandHome(word);
245
+ const dir = typed.endsWith('/') ? typed : dirname(typed);
246
+ const base = typed.endsWith('/') ? '' : basename(typed);
247
+ const shown = word.endsWith('/') ? word : word.slice(0, word.length - basename(word).length);
248
+ let names: string[];
249
+ try {
250
+ names = readdirSync(dir, { withFileTypes: true })
251
+ .filter((e) => e.name.startsWith(base) && (base.startsWith('.') || !e.name.startsWith('.')))
252
+ .map((e) => `${shown}${e.name}${e.isDirectory() ? '/' : ''}`);
253
+ } catch {
254
+ return [];
255
+ }
256
+ return names.sort();
257
+ }
@@ -47,6 +47,25 @@ export function cleanCell(v: unknown): string {
47
47
  .replace(/\p{Cf}/gu, '');
48
48
  }
49
49
 
50
+ /**
51
+ * The agent's text as printed in the conversation: escape sequences, control
52
+ * characters (newlines and tabs kept) and bidi controls are removed, so nothing the agent writes can restyle, hide or rewrite what the
53
+ * terminal shows next — the owner's own prompts included. Works on a chunk of
54
+ * a stream: a sequence cut between chunks loses its ESC and prints as text.
55
+ */
56
+ export function cleanStream(v: unknown): string {
57
+ return String(v ?? '')
58
+ .replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, '')
59
+ .replace(/\u009b[0-?]*[ -/]*[@-~]/g, '')
60
+ .replace(/\u001b\][^\u0007\u001b\u009c]*(?:\u0007|\u001b\\|\u009c)?/g, '')
61
+ .replace(/\u001b[PX^_][^\u001b\u009c]*(?:\u001b\\|\u009c)?/g, '')
62
+ // eslint-disable-next-line no-control-regex
63
+ .replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g, '')
64
+ .replace(/[\u2028\u2029]/g, '\n')
65
+ // bidi controls, which reorder what follows; joiners in emoji stay
66
+ .replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, '');
67
+ }
68
+
50
69
  /**
51
70
  * A cell of width `w`: null/undefined renders the em-dash placeholder;
52
71
  * over-long text truncates by CODE POINTS with an ellipsis so a long name
@@ -105,3 +124,88 @@ export function ownerCellText(owner: string | null | undefined, sealToAgent: Rea
105
124
  export function trustedCell(t: string, w: number): string {
106
125
  return `${cleanCell(t)} `.padEnd(w);
107
126
  }
127
+
128
+ /** A row of either listing (`list` and the shell's `list`). */
129
+ export interface ListRow {
130
+ agentId: bigint | number | null;
131
+ phase?: string | null;
132
+ sealId: string;
133
+ name?: string | null;
134
+ framework?: string | null;
135
+ agentSeal?: string | null;
136
+ }
137
+
138
+ /** Which columns a listing shows, and how wide OWNER and NAME are. */
139
+ export interface ListLayout {
140
+ framework: boolean;
141
+ agentSeal: boolean;
142
+ owner: boolean;
143
+ ownerWidth: number;
144
+ /** undefined: NAME is not cut (piped output). */
145
+ nameWidth?: number;
146
+ }
147
+
148
+ const ID_W = 13;
149
+ const PHASE_W = 11;
150
+ const FRAMEWORK_W = 12;
151
+ const SEAL_W = 13;
152
+ const NAME_MIN = 10;
153
+
154
+ /** The OWNER column's width for these owners: the widest cell plus a space, at least 14. */
155
+ export function ownerColumnWidth(owners: ReadonlyArray<string | null | undefined>, sealToAgent: ReadonlyMap<string, string>): number {
156
+ return Math.max(14, ...owners.map((o) => [...ownerCellText(o, sealToAgent)].length + 1));
157
+ }
158
+
159
+ /**
160
+ * The columns that fit a terminal `width` wide after `lead` columns (the
161
+ * shell's ownership mark); without a width (piped output) every column shows
162
+ * and NAME is cut at `pipedNameWidth` (not at all without it). AGENTID, PHASE and NAME always show; FRAMEWORK, OWNER
163
+ * and AGENTSEAL join, in that order, while NAME keeps at least 10 columns,
164
+ * and NAME takes what is left. A row never reaches the last column, so the
165
+ * terminal does not wrap it.
166
+ */
167
+ export function listLayout(width: number | undefined, lead: number, ownerWidth: number, pipedNameWidth?: number): ListLayout {
168
+ if (!width) return { framework: true, owner: true, agentSeal: true, ownerWidth, nameWidth: pipedNameWidth };
169
+ let used = lead + ID_W + PHASE_W;
170
+ const take = (w: number): boolean => {
171
+ if (used + w + NAME_MIN >= width) return false;
172
+ used += w;
173
+ return true;
174
+ };
175
+ const framework = take(FRAMEWORK_W);
176
+ const owner = take(ownerWidth);
177
+ const agentSeal = take(SEAL_W);
178
+ return { framework, owner, agentSeal, ownerWidth, nameWidth: Math.max(NAME_MIN, width - used - 1) };
179
+ }
180
+
181
+ /** The listing's header for a layout. */
182
+ export function listHeader(l: ListLayout): string {
183
+ return 'AGENTID'.padEnd(ID_W) + 'PHASE'.padEnd(PHASE_W) +
184
+ (l.framework ? 'FRAMEWORK'.padEnd(FRAMEWORK_W) : '') +
185
+ (l.agentSeal ? 'AGENTSEAL'.padEnd(SEAL_W) : '') +
186
+ (l.owner ? 'OWNER'.padEnd(l.ownerWidth) : '') + 'NAME';
187
+ }
188
+
189
+ /**
190
+ * One listing row for a layout, trailing spaces trimmed. An unminted row has
191
+ * no agentId: its sealId prefix (`0x` + 10 hex) stands in the AGENTID cell —
192
+ * the handle every command accepts for it. `noName` is what a row without a
193
+ * name shows.
194
+ */
195
+ export function listCells(
196
+ r: ListRow,
197
+ owner: string | null | undefined,
198
+ sealToAgent: ReadonlyMap<string, string>,
199
+ l: ListLayout,
200
+ noName = '—',
201
+ ): string {
202
+ const id = r.agentId != null ? cellText(r.agentId, ID_W) : cellText(`0x${r.sealId.slice(2, 12)}`, ID_W);
203
+ const name = r.name == null ? noName : l.nameWidth ? cellText(r.name, l.nameWidth) : cleanCell(r.name);
204
+ return (
205
+ id + cellText(r.phase ?? '?', PHASE_W) +
206
+ (l.framework ? cellText(r.framework, FRAMEWORK_W) : '') +
207
+ (l.agentSeal ? cellText(shortAddr(r.agentSeal), SEAL_W) : '') +
208
+ (l.owner ? trustedCell(ownerCellText(owner, sealToAgent), l.ownerWidth) : '') +
209
+ name
210
+ ).trimEnd();
211
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @file cred.ts
3
+ * @description `0g-agentdna cred <agent> [ls|set|rm|connect|disconnect|reveal|pending|approve|deny|log]`
4
+ * and `0g-agentdna cred pending|notify|presets` — the owner's credentials for an agent's
5
+ * sealed credential proxy (cli/credentials.ts holds the grammar and the
6
+ * operation the REPL shares).
7
+ *
8
+ * Every subcommand is owner-signed, so each needs AGENTIC_PRIVATE_KEY.
9
+ */
10
+
11
+ import { buildClient } from '../sdk';
12
+ import { CliError, setAgentAtHand } from '../errors';
13
+ import { print } from '../envelope';
14
+ import { parseAgentRef } from '../ref';
15
+ import { commandKeyPrompt, CRED_USAGE, credOp, credOwnerOp, readSecret } from '../credentials';
16
+ import { resolveSealId } from './settings';
17
+ import { cleanStream } from './cells';
18
+ import type { CommandContext } from '../types';
19
+
20
+ // What the agent and its server said (a request's reason, a name, an error)
21
+ // is in these lines: printed without control sequences or characters.
22
+ const show = (line: string): void => print(cleanStream(line));
23
+
24
+ export async function run(ctx: CommandContext): Promise<void> {
25
+ const [first, ...rest] = ctx.positionals;
26
+ if (!first) throw new CliError('BAD_AGENT_REF', 'missing <agent> argument', { remedy: CRED_USAGE });
27
+
28
+ if (first === 'presets') {
29
+ await credOwnerOp(undefined, ctx.positionals, { json: ctx.json, out: show, secret: readSecret });
30
+ return;
31
+ }
32
+ if (first === 'pending' || first === 'notify') {
33
+ const ag = await buildClient(ctx.env, { withWallet: true });
34
+ await credOwnerOp(ag, ctx.positionals, { json: ctx.json, out: show, secret: readSecret });
35
+ return;
36
+ }
37
+
38
+ // Grammar errors before any network work.
39
+ const ref = parseAgentRef(first);
40
+ setAgentAtHand(first);
41
+ const ag = await buildClient(ctx.env, { withWallet: true });
42
+ const sealId = await resolveSealId(ag, ref, first);
43
+ await credOp(ag, sealId, rest, { json: ctx.json, wait: !ctx.json, out: show, secret: readSecret, keyPrompt: commandKeyPrompt(ctx.json, show, { readPipe: true }) });
44
+ }