@0gfoundation/0g-agentdna 0.0.0-stage → 0.2.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 (206) hide show
  1. package/GUIDE.md +975 -0
  2. package/LICENSE +21 -0
  3. package/MIGRATION.md +84 -0
  4. package/MIGRATION.zh.md +70 -0
  5. package/PROVIDERS.md +273 -0
  6. package/PROVIDERS.zh.md +234 -0
  7. package/README.md +334 -2
  8. package/dist/AgentClient.d.ts +312 -0
  9. package/dist/AgentClient.d.ts.map +1 -0
  10. package/dist/AgentClient.js +715 -0
  11. package/dist/AgentClient.js.map +1 -0
  12. package/dist/AgenticID.d.ts +823 -0
  13. package/dist/AgenticID.d.ts.map +1 -0
  14. package/dist/AgenticID.js +1188 -0
  15. package/dist/AgenticID.js.map +1 -0
  16. package/dist/AgenticIDClient.d.ts +68 -0
  17. package/dist/AgenticIDClient.d.ts.map +1 -0
  18. package/dist/AgenticIDClient.js +198 -0
  19. package/dist/AgenticIDClient.js.map +1 -0
  20. package/dist/AttestorClient.d.ts +465 -0
  21. package/dist/AttestorClient.d.ts.map +1 -0
  22. package/dist/AttestorClient.js +1030 -0
  23. package/dist/AttestorClient.js.map +1 -0
  24. package/dist/Providers.d.ts +72 -0
  25. package/dist/Providers.d.ts.map +1 -0
  26. package/dist/Providers.js +182 -0
  27. package/dist/Providers.js.map +1 -0
  28. package/dist/ReputationClient.d.ts +213 -0
  29. package/dist/ReputationClient.d.ts.map +1 -0
  30. package/dist/ReputationClient.js +708 -0
  31. package/dist/ReputationClient.js.map +1 -0
  32. package/dist/SandboxClient.d.ts +107 -0
  33. package/dist/SandboxClient.d.ts.map +1 -0
  34. package/dist/SandboxClient.js +200 -0
  35. package/dist/SandboxClient.js.map +1 -0
  36. package/dist/ServeProof.d.ts +161 -0
  37. package/dist/ServeProof.d.ts.map +1 -0
  38. package/dist/ServeProof.js +230 -0
  39. package/dist/ServeProof.js.map +1 -0
  40. package/dist/ServeSession.d.ts +180 -0
  41. package/dist/ServeSession.d.ts.map +1 -0
  42. package/dist/ServeSession.js +336 -0
  43. package/dist/ServeSession.js.map +1 -0
  44. package/dist/Settings.d.ts +179 -0
  45. package/dist/Settings.d.ts.map +1 -0
  46. package/dist/Settings.js +247 -0
  47. package/dist/Settings.js.map +1 -0
  48. package/dist/abi.d.ts +2216 -0
  49. package/dist/abi.d.ts.map +1 -0
  50. package/dist/abi.js +1248 -0
  51. package/dist/abi.js.map +1 -0
  52. package/dist/cli/commands/cells.d.ts +34 -0
  53. package/dist/cli/commands/cells.d.ts.map +1 -0
  54. package/dist/cli/commands/cells.js +66 -0
  55. package/dist/cli/commands/cells.js.map +1 -0
  56. package/dist/cli/commands/doctor.d.ts +15 -0
  57. package/dist/cli/commands/doctor.d.ts.map +1 -0
  58. package/dist/cli/commands/doctor.js +236 -0
  59. package/dist/cli/commands/doctor.js.map +1 -0
  60. package/dist/cli/commands/interactive.d.ts +107 -0
  61. package/dist/cli/commands/interactive.d.ts.map +1 -0
  62. package/dist/cli/commands/interactive.js +3034 -0
  63. package/dist/cli/commands/interactive.js.map +1 -0
  64. package/dist/cli/commands/list.d.ts +31 -0
  65. package/dist/cli/commands/list.d.ts.map +1 -0
  66. package/dist/cli/commands/list.js +115 -0
  67. package/dist/cli/commands/list.js.map +1 -0
  68. package/dist/cli/commands/providers.d.ts +3 -0
  69. package/dist/cli/commands/providers.d.ts.map +1 -0
  70. package/dist/cli/commands/providers.js +21 -0
  71. package/dist/cli/commands/providers.js.map +1 -0
  72. package/dist/cli/commands/settings.d.ts +22 -0
  73. package/dist/cli/commands/settings.d.ts.map +1 -0
  74. package/dist/cli/commands/settings.js +188 -0
  75. package/dist/cli/commands/settings.js.map +1 -0
  76. package/dist/cli/commands/status.d.ts +16 -0
  77. package/dist/cli/commands/status.d.ts.map +1 -0
  78. package/dist/cli/commands/status.js +148 -0
  79. package/dist/cli/commands/status.js.map +1 -0
  80. package/dist/cli/commands/update.d.ts +21 -0
  81. package/dist/cli/commands/update.d.ts.map +1 -0
  82. package/dist/cli/commands/update.js +95 -0
  83. package/dist/cli/commands/update.js.map +1 -0
  84. package/dist/cli/config.d.ts +73 -0
  85. package/dist/cli/config.d.ts.map +1 -0
  86. package/dist/cli/config.js +239 -0
  87. package/dist/cli/config.js.map +1 -0
  88. package/dist/cli/env.d.ts +36 -0
  89. package/dist/cli/env.d.ts.map +1 -0
  90. package/dist/cli/env.js +74 -0
  91. package/dist/cli/env.js.map +1 -0
  92. package/dist/cli/envelope.d.ts +33 -0
  93. package/dist/cli/envelope.d.ts.map +1 -0
  94. package/dist/cli/envelope.js +62 -0
  95. package/dist/cli/envelope.js.map +1 -0
  96. package/dist/cli/errors.d.ts +48 -0
  97. package/dist/cli/errors.d.ts.map +1 -0
  98. package/dist/cli/errors.js +81 -0
  99. package/dist/cli/errors.js.map +1 -0
  100. package/dist/cli/inference.d.ts +21 -0
  101. package/dist/cli/inference.d.ts.map +1 -0
  102. package/dist/cli/inference.js +60 -0
  103. package/dist/cli/inference.js.map +1 -0
  104. package/dist/cli/logo.d.ts +21 -0
  105. package/dist/cli/logo.d.ts.map +1 -0
  106. package/dist/cli/logo.js +131 -0
  107. package/dist/cli/logo.js.map +1 -0
  108. package/dist/cli/main.d.ts +14 -0
  109. package/dist/cli/main.d.ts.map +1 -0
  110. package/dist/cli/main.js +223 -0
  111. package/dist/cli/main.js.map +1 -0
  112. package/dist/cli/proofs.d.ts +67 -0
  113. package/dist/cli/proofs.d.ts.map +1 -0
  114. package/dist/cli/proofs.js +133 -0
  115. package/dist/cli/proofs.js.map +1 -0
  116. package/dist/cli/ref.d.ts +39 -0
  117. package/dist/cli/ref.d.ts.map +1 -0
  118. package/dist/cli/ref.js +48 -0
  119. package/dist/cli/ref.js.map +1 -0
  120. package/dist/cli/sdk.d.ts +24 -0
  121. package/dist/cli/sdk.d.ts.map +1 -0
  122. package/dist/cli/sdk.js +65 -0
  123. package/dist/cli/sdk.js.map +1 -0
  124. package/dist/cli/settings.d.ts +66 -0
  125. package/dist/cli/settings.d.ts.map +1 -0
  126. package/dist/cli/settings.js +137 -0
  127. package/dist/cli/settings.js.map +1 -0
  128. package/dist/cli/tokenize.d.ts +61 -0
  129. package/dist/cli/tokenize.d.ts.map +1 -0
  130. package/dist/cli/tokenize.js +157 -0
  131. package/dist/cli/tokenize.js.map +1 -0
  132. package/dist/cli/types.d.ts +25 -0
  133. package/dist/cli/types.d.ts.map +1 -0
  134. package/dist/cli/types.js +8 -0
  135. package/dist/cli/types.js.map +1 -0
  136. package/dist/constants.d.ts +107 -0
  137. package/dist/constants.d.ts.map +1 -0
  138. package/dist/constants.js +74 -0
  139. package/dist/constants.js.map +1 -0
  140. package/dist/context.d.ts +108 -0
  141. package/dist/context.d.ts.map +1 -0
  142. package/dist/context.js +64 -0
  143. package/dist/context.js.map +1 -0
  144. package/dist/index.d.ts +45 -0
  145. package/dist/index.d.ts.map +1 -0
  146. package/dist/index.js +118 -0
  147. package/dist/index.js.map +1 -0
  148. package/dist/provider-catalog.json +23 -0
  149. package/dist/seal.d.ts +47 -0
  150. package/dist/seal.d.ts.map +1 -0
  151. package/dist/seal.js +145 -0
  152. package/dist/seal.js.map +1 -0
  153. package/dist/secretEnv.d.ts +119 -0
  154. package/dist/secretEnv.d.ts.map +1 -0
  155. package/dist/secretEnv.js +199 -0
  156. package/dist/secretEnv.js.map +1 -0
  157. package/dist/taskHash.d.ts +39 -0
  158. package/dist/taskHash.d.ts.map +1 -0
  159. package/dist/taskHash.js +119 -0
  160. package/dist/taskHash.js.map +1 -0
  161. package/dist/types.d.ts +336 -0
  162. package/dist/types.d.ts.map +1 -0
  163. package/dist/types.js +19 -0
  164. package/dist/types.js.map +1 -0
  165. package/package.json +75 -4
  166. package/scripts/sync-providers.cjs +8 -0
  167. package/src/AgentClient.ts +897 -0
  168. package/src/AgenticID.ts +1382 -0
  169. package/src/AgenticIDClient.ts +238 -0
  170. package/src/AttestorClient.ts +1306 -0
  171. package/src/Providers.ts +176 -0
  172. package/src/ReputationClient.ts +821 -0
  173. package/src/SandboxClient.ts +227 -0
  174. package/src/ServeProof.ts +290 -0
  175. package/src/ServeSession.ts +421 -0
  176. package/src/Settings.ts +296 -0
  177. package/src/abi.ts +1282 -0
  178. package/src/cli/commands/cells.ts +61 -0
  179. package/src/cli/commands/doctor.ts +235 -0
  180. package/src/cli/commands/interactive.ts +2715 -0
  181. package/src/cli/commands/list.ts +117 -0
  182. package/src/cli/commands/providers.ts +16 -0
  183. package/src/cli/commands/settings.ts +197 -0
  184. package/src/cli/commands/status.ts +170 -0
  185. package/src/cli/commands/update.ts +86 -0
  186. package/src/cli/config.ts +225 -0
  187. package/src/cli/env.ts +90 -0
  188. package/src/cli/envelope.ts +57 -0
  189. package/src/cli/errors.ts +114 -0
  190. package/src/cli/inference.ts +57 -0
  191. package/src/cli/logo.ts +125 -0
  192. package/src/cli/main.ts +235 -0
  193. package/src/cli/proofs.ts +160 -0
  194. package/src/cli/ref.ts +58 -0
  195. package/src/cli/sdk.ts +65 -0
  196. package/src/cli/settings.ts +153 -0
  197. package/src/cli/tokenize.ts +131 -0
  198. package/src/cli/types.ts +27 -0
  199. package/src/constants.ts +106 -0
  200. package/src/context.ts +161 -0
  201. package/src/index.ts +129 -0
  202. package/src/provider-catalog.json +23 -0
  203. package/src/seal.ts +163 -0
  204. package/src/secretEnv.ts +250 -0
  205. package/src/taskHash.ts +100 -0
  206. package/src/types.ts +357 -0
@@ -0,0 +1,238 @@
1
+ /**
2
+ * @file AgenticIDClient.ts
3
+ * @description Internal client for the AgenticID contract (seal-bound transfer +
4
+ * the reads that transfer/clone/reputation use). Consumers use the `AgenticID`
5
+ * facade's `agent` namespace, not this directly.
6
+ */
7
+
8
+ import {
9
+ type Address,
10
+ type Hash,
11
+ type TransactionReceipt,
12
+ type WriteContractReturnType,
13
+ } from 'viem';
14
+ import { agenticIDAbi, cloneGateAbi, standardCloneAuthorizerAbi } from './abi';
15
+ import { RECEIPT_WAIT } from './constants';
16
+ import { requireWallet, type Ctx } from './context';
17
+
18
+ export interface IntelligentDataResult {
19
+ dataDescription: string;
20
+ dataHash: Hash;
21
+ }
22
+
23
+ export class AgenticIDClient {
24
+ constructor(private readonly ctx: Ctx) {}
25
+
26
+ private get address(): Address {
27
+ return this.ctx.addresses.agenticID;
28
+ }
29
+
30
+ // ── Seal-bound transfer ────────────────────────────────────────────────────
31
+
32
+ async transferFrom(from: Address, to: Address, tokenId: bigint): Promise<WriteContractReturnType> {
33
+ const { walletClient, account } = requireWallet(this.ctx);
34
+ return walletClient.writeContract({
35
+ address: this.address,
36
+ abi: agenticIDAbi,
37
+ functionName: 'transferFrom',
38
+ args: [from, to, tokenId],
39
+ account,
40
+ chain: this.ctx.chain,
41
+ });
42
+ }
43
+
44
+ async safeTransferFrom(
45
+ from: Address,
46
+ to: Address,
47
+ tokenId: bigint,
48
+ data: `0x${string}` = '0x',
49
+ ): Promise<WriteContractReturnType> {
50
+ const { walletClient, account } = requireWallet(this.ctx);
51
+ return walletClient.writeContract({
52
+ address: this.address,
53
+ abi: agenticIDAbi,
54
+ functionName: 'safeTransferFrom',
55
+ args: [from, to, tokenId, data],
56
+ account,
57
+ chain: this.ctx.chain,
58
+ });
59
+ }
60
+
61
+ // ── Reads ──────────────────────────────────────────────────────────────────
62
+
63
+ async getAgentSeal(agentId: bigint): Promise<Address> {
64
+ return this.ctx.publicClient.readContract({
65
+ address: this.address, abi: agenticIDAbi, functionName: 'getAgentSeal', args: [agentId],
66
+ }) as Promise<Address>;
67
+ }
68
+
69
+ async getSealId(agentId: bigint): Promise<Hash> {
70
+ return this.ctx.publicClient.readContract({
71
+ address: this.address, abi: agenticIDAbi, functionName: 'getSealId', args: [agentId],
72
+ }) as Promise<Hash>;
73
+ }
74
+
75
+ /**
76
+ * The agent's on-chain URI (ERC-8004 canonical). Points at the agent's
77
+ * AgentCard (a JSON doc on 0G storage) whose `url` field is the live serve
78
+ * endpoint. Empty string until the attestor's two-phase setAgentURI fills it
79
+ * (i.e. before the agent is provisioned).
80
+ */
81
+ async tokenURI(tokenId: bigint): Promise<string> {
82
+ return this.ctx.publicClient.readContract({
83
+ address: this.address, abi: agenticIDAbi, functionName: 'tokenURI', args: [tokenId],
84
+ }) as Promise<string>;
85
+ }
86
+
87
+ async getAgentIdBySealId(sealId: Hash): Promise<bigint> {
88
+ return this.ctx.publicClient.readContract({
89
+ address: this.address, abi: agenticIDAbi, functionName: 'getAgentIdBySealId', args: [sealId],
90
+ }) as Promise<bigint>;
91
+ }
92
+
93
+ async isSealIdBound(sealId: Hash): Promise<boolean> {
94
+ return this.ctx.publicClient.readContract({
95
+ address: this.address, abi: agenticIDAbi, functionName: 'isSealIdBound', args: [sealId],
96
+ }) as Promise<boolean>;
97
+ }
98
+
99
+ async intelligentDatasOf(tokenId: bigint): Promise<IntelligentDataResult[]> {
100
+ const result = (await this.ctx.publicClient.readContract({
101
+ address: this.address, abi: agenticIDAbi, functionName: 'intelligentDatasOf', args: [tokenId],
102
+ })) as readonly { dataDescription: string; dataHash: Hash }[];
103
+ return result.map((d) => ({ dataDescription: d.dataDescription, dataHash: d.dataHash }));
104
+ }
105
+
106
+ async sealedKeysOf(tokenId: bigint): Promise<`0x${string}`[]> {
107
+ const result = (await this.ctx.publicClient.readContract({
108
+ address: this.address, abi: agenticIDAbi, functionName: 'sealedKeysOf', args: [tokenId],
109
+ })) as readonly `0x${string}`[];
110
+ return [...result];
111
+ }
112
+
113
+ async ownerOf(tokenId: bigint): Promise<Address> {
114
+ return this.ctx.publicClient.readContract({
115
+ address: this.address, abi: agenticIDAbi, functionName: 'ownerOf', args: [tokenId],
116
+ }) as Promise<Address>;
117
+ }
118
+
119
+ // ── Policy-mode cloning (issue #133) ──────────────────────────────────────
120
+
121
+ /**
122
+ * Configure (or clear, with `0x0`) this token's clone authorizer — the
123
+ * `ICloneAuthorizer` policy contract that decides which contract-mode
124
+ * clones may mint. Owner-only on chain. Setting an authorizer is the
125
+ * publisher's one-time opt-in to marketplace fork flows; clearing it
126
+ * revokes, and an ownership transfer auto-invalidates it (the gate binds
127
+ * the config to the owner who set it). Lives on the CloneGate satellite.
128
+ */
129
+ /** CloneGate address, or a named error when this environment has none. */
130
+ private get cloneGateAddress(): Address {
131
+ const a = this.ctx.addresses.cloneGate;
132
+ if (!a || a === '0x0000000000000000000000000000000000000000') {
133
+ throw new Error(
134
+ 'cloneGate: this environment has no CloneGate deployed ' +
135
+ '(the attestor /config reports no clone_gate_addr) — ' +
136
+ 'policy-mode cloning is unavailable here',
137
+ );
138
+ }
139
+ return a;
140
+ }
141
+
142
+ async setCloneAuthorizer(tokenId: bigint, authorizer: Address): Promise<WriteContractReturnType> {
143
+ const { walletClient, account } = requireWallet(this.ctx);
144
+ return walletClient.writeContract({
145
+ address: this.cloneGateAddress,
146
+ abi: cloneGateAbi,
147
+ functionName: 'setCloneAuthorizer',
148
+ args: [tokenId, authorizer],
149
+ account,
150
+ chain: this.ctx.chain,
151
+ });
152
+ }
153
+
154
+ /**
155
+ * The token's configured clone authorizer (`0x0` = none configured →
156
+ * contract-mode clones fail closed).
157
+ */
158
+ async cloneAuthorizerOf(tokenId: bigint): Promise<Address> {
159
+ return this.ctx.publicClient.readContract({
160
+ address: this.cloneGateAddress, abi: cloneGateAbi, functionName: 'cloneAuthorizerOf', args: [tokenId],
161
+ }) as Promise<Address>;
162
+ }
163
+
164
+ /**
165
+ * For a clone, the agentId it was forked from (0n = not a clone). Survives
166
+ * transfers — lineage is a historical fact.
167
+ */
168
+ async cloneSourceOf(agentId: bigint): Promise<bigint> {
169
+ return this.ctx.publicClient.readContract({
170
+ address: this.cloneGateAddress, abi: cloneGateAbi, functionName: 'cloneSourceOf', args: [agentId],
171
+ }) as Promise<bigint>;
172
+ }
173
+
174
+ // ── Standard-policy purchase management (StandardCloneAuthorizer) ─────────
175
+ // These helpers speak the OFFICIAL stock policy's ABI to whatever authorizer
176
+ // the token has configured (resolved live via cloneAuthorizerOf). They only
177
+ // work when that policy IS the StandardCloneAuthorizer — a custom policy has
178
+ // its own management surface and these calls would revert against it.
179
+
180
+ /** The token's effective authorizer, or a named error when none is configured. */
181
+ private async requireAuthorizer(sourceAgentId: bigint): Promise<Address> {
182
+ const a = await this.cloneAuthorizerOf(sourceAgentId);
183
+ if (a === '0x0000000000000000000000000000000000000000') {
184
+ throw new Error(
185
+ `agent ${sourceAgentId} has no effective clone authorizer — the owner must ` +
186
+ `setCloneAuthorizer first (and still hold the token)`,
187
+ );
188
+ }
189
+ return a;
190
+ }
191
+
192
+ /** Seller: allow `buyer` to fork this agent (a permission switch; idempotent). */
193
+ async grantClone(sourceAgentId: bigint, buyer: Address): Promise<WriteContractReturnType> {
194
+ const authorizer = await this.requireAuthorizer(sourceAgentId);
195
+ const { walletClient, account } = requireWallet(this.ctx);
196
+ return walletClient.writeContract({
197
+ address: authorizer,
198
+ abi: standardCloneAuthorizerAbi,
199
+ functionName: 'grant',
200
+ args: [sourceAgentId, buyer],
201
+ account,
202
+ chain: this.ctx.chain,
203
+ });
204
+ }
205
+
206
+ /** Seller: close the door for `buyer` (refund, or manual one-shot consumption). */
207
+ async revokeClone(sourceAgentId: bigint, buyer: Address): Promise<WriteContractReturnType> {
208
+ const authorizer = await this.requireAuthorizer(sourceAgentId);
209
+ const { walletClient, account } = requireWallet(this.ctx);
210
+ return walletClient.writeContract({
211
+ address: authorizer,
212
+ abi: standardCloneAuthorizerAbi,
213
+ functionName: 'revoke',
214
+ args: [sourceAgentId, buyer],
215
+ account,
216
+ chain: this.ctx.chain,
217
+ });
218
+ }
219
+
220
+ /** The grant's recorded seller + whether it is currently effective ((0x0, false) = no grant). */
221
+ async cloneGrantOf(sourceAgentId: bigint, buyer: Address): Promise<{ grantor: Address; effective: boolean }> {
222
+ const authorizer = await this.requireAuthorizer(sourceAgentId);
223
+ const [grantor, effective] = (await this.ctx.publicClient.readContract({
224
+ address: authorizer, abi: standardCloneAuthorizerAbi, functionName: 'grantOf', args: [sourceAgentId, buyer],
225
+ })) as readonly [Address, boolean];
226
+ return { grantor, effective };
227
+ }
228
+
229
+ async balanceOf(owner: Address): Promise<bigint> {
230
+ return this.ctx.publicClient.readContract({
231
+ address: this.address, abi: agenticIDAbi, functionName: 'balanceOf', args: [owner],
232
+ }) as Promise<bigint>;
233
+ }
234
+
235
+ async waitForTransaction(txHash: Hash): Promise<TransactionReceipt> {
236
+ return this.ctx.publicClient.waitForTransactionReceipt({ hash: txHash, ...RECEIPT_WAIT });
237
+ }
238
+ }