thirdweb 5.84.0-nightly-0fdfb8aa778a344aa847503f668e48feb5f72548-20250115000312 → 5.84.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 (64) hide show
  1. package/dist/cjs/ai/chat.js +29 -0
  2. package/dist/cjs/ai/chat.js.map +1 -0
  3. package/dist/cjs/ai/common.js +69 -0
  4. package/dist/cjs/ai/common.js.map +1 -0
  5. package/dist/cjs/ai/execute.js +43 -0
  6. package/dist/cjs/ai/execute.js.map +1 -0
  7. package/dist/cjs/ai/index.js +8 -0
  8. package/dist/cjs/ai/index.js.map +1 -0
  9. package/dist/cjs/exports/ai.js +5 -0
  10. package/dist/cjs/exports/ai.js.map +1 -0
  11. package/dist/cjs/exports/wallets/engine.js +6 -0
  12. package/dist/cjs/exports/wallets/engine.js.map +1 -0
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/cjs/version.js.map +1 -1
  15. package/dist/cjs/wallets/engine/index.js +143 -0
  16. package/dist/cjs/wallets/engine/index.js.map +1 -0
  17. package/dist/cjs/wallets/smart/lib/signing.js +1 -1
  18. package/dist/esm/ai/chat.js +26 -0
  19. package/dist/esm/ai/chat.js.map +1 -0
  20. package/dist/esm/ai/common.js +66 -0
  21. package/dist/esm/ai/common.js.map +1 -0
  22. package/dist/esm/ai/execute.js +40 -0
  23. package/dist/esm/ai/execute.js.map +1 -0
  24. package/dist/esm/ai/index.js +3 -0
  25. package/dist/esm/ai/index.js.map +1 -0
  26. package/dist/esm/exports/ai.js +2 -0
  27. package/dist/esm/exports/ai.js.map +1 -0
  28. package/dist/esm/exports/wallets/engine.js +2 -0
  29. package/dist/esm/exports/wallets/engine.js.map +1 -0
  30. package/dist/esm/version.js +1 -1
  31. package/dist/esm/version.js.map +1 -1
  32. package/dist/esm/wallets/engine/index.js +140 -0
  33. package/dist/esm/wallets/engine/index.js.map +1 -0
  34. package/dist/esm/wallets/smart/lib/signing.js +1 -1
  35. package/dist/types/ai/chat.d.ts +24 -0
  36. package/dist/types/ai/chat.d.ts.map +1 -0
  37. package/dist/types/ai/common.d.ts +22 -0
  38. package/dist/types/ai/common.d.ts.map +1 -0
  39. package/dist/types/ai/execute.d.ts +29 -0
  40. package/dist/types/ai/execute.d.ts.map +1 -0
  41. package/dist/types/ai/index.d.ts +4 -0
  42. package/dist/types/ai/index.d.ts.map +1 -0
  43. package/dist/types/exports/ai.d.ts +2 -0
  44. package/dist/types/exports/ai.d.ts.map +1 -0
  45. package/dist/types/exports/wallets/engine.d.ts +2 -0
  46. package/dist/types/exports/wallets/engine.d.ts.map +1 -0
  47. package/dist/types/version.d.ts +1 -1
  48. package/dist/types/version.d.ts.map +1 -1
  49. package/dist/types/wallets/engine/index.d.ts +54 -0
  50. package/dist/types/wallets/engine/index.d.ts.map +1 -0
  51. package/dist/types/wallets/smart/lib/signing.d.ts +1 -1
  52. package/package.json +9 -1
  53. package/src/ai/chat.test.ts +31 -0
  54. package/src/ai/chat.ts +26 -0
  55. package/src/ai/common.ts +114 -0
  56. package/src/ai/execute.test.ts +43 -0
  57. package/src/ai/execute.ts +44 -0
  58. package/src/ai/index.ts +3 -0
  59. package/src/exports/ai.ts +1 -0
  60. package/src/exports/wallets/engine.ts +4 -0
  61. package/src/version.ts +1 -1
  62. package/src/wallets/engine/engine-account.test.ts +69 -0
  63. package/src/wallets/engine/index.ts +198 -0
  64. package/src/wallets/smart/lib/signing.ts +1 -1
@@ -0,0 +1,140 @@
1
+ import { toHex } from "../../utils/encoding/hex.js";
2
+ /**
3
+ * Creates an account that uses your engine backend wallet for sending transactions and signing messages.
4
+ *
5
+ * @param options - The options for the engine account.
6
+ * @returns An account that uses your engine backend wallet.
7
+ *
8
+ * @beta
9
+ * @wallet
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { engineAccount } from "thirdweb/wallets/engine";
14
+ *
15
+ * const engineAcc = engineAccount({
16
+ * engineUrl: "https://engine.thirdweb.com",
17
+ * authToken: "your-auth-token",
18
+ * walletAddress: "0x...",
19
+ * });
20
+ *
21
+ * // then use the account as you would any other account
22
+ * const transaction = claimTo({
23
+ * contract,
24
+ * to: "0x...",
25
+ * quantity: 1n,
26
+ * });
27
+ * const result = await sendTransaction({ transaction, account: engineAcc });
28
+ * console.log("Transaction sent:", result.transactionHash);
29
+ * ```
30
+ */
31
+ export function engineAccount(options) {
32
+ const { engineUrl, authToken, walletAddress, chain } = options;
33
+ // these are shared across all methods
34
+ const headers = {
35
+ "x-backend-wallet-address": walletAddress,
36
+ Authorization: `Bearer ${authToken}`,
37
+ "Content-Type": "application/json",
38
+ };
39
+ return {
40
+ address: walletAddress,
41
+ sendTransaction: async (transaction) => {
42
+ const ENGINE_URL = new URL(engineUrl);
43
+ ENGINE_URL.pathname = `/backend-wallet/${transaction.chainId}/send-transaction`;
44
+ const engineData = {
45
+ // add to address if we have it (is optional to pass to engine)
46
+ toAddress: transaction.to || undefined,
47
+ // engine wants a hex string here so we serialize it
48
+ data: transaction.data || "0x",
49
+ // value is always required
50
+ value: toHex(transaction.value ?? 0n),
51
+ };
52
+ // TODO: gas overrides etc?
53
+ const engineRes = await fetch(ENGINE_URL, {
54
+ method: "POST",
55
+ headers,
56
+ body: JSON.stringify(engineData),
57
+ });
58
+ if (!engineRes.ok) {
59
+ const body = await engineRes.text();
60
+ throw new Error(`Engine request failed with status ${engineRes.status} - ${body}`);
61
+ }
62
+ const engineJson = (await engineRes.json());
63
+ // wait for the queueId to be processed
64
+ ENGINE_URL.pathname = `/transaction/status/${engineJson.result.queueId}`;
65
+ const startTime = Date.now();
66
+ const TIMEOUT_IN_MS = 5 * 60 * 1000; // 5 minutes in milliseconds
67
+ while (Date.now() - startTime < TIMEOUT_IN_MS) {
68
+ const queueRes = await fetch(ENGINE_URL, {
69
+ method: "GET",
70
+ headers,
71
+ });
72
+ if (!queueRes.ok) {
73
+ const body = await queueRes.text();
74
+ throw new Error(`Engine request failed with status ${queueRes.status} - ${body}`);
75
+ }
76
+ const queueJSON = (await queueRes.json());
77
+ if (queueJSON.result.status === "errored" &&
78
+ queueJSON.result.errorMessage) {
79
+ throw new Error(queueJSON.result.errorMessage);
80
+ }
81
+ if (queueJSON.result.transactionHash) {
82
+ return {
83
+ transactionHash: queueJSON.result.transactionHash,
84
+ };
85
+ }
86
+ // wait 1s before checking again
87
+ await new Promise((resolve) => setTimeout(resolve, 1000));
88
+ }
89
+ throw new Error("Transaction timed out after 5 minutes");
90
+ },
91
+ signMessage: async ({ message }) => {
92
+ let engineMessage;
93
+ let isBytes = false;
94
+ if (typeof message === "string") {
95
+ engineMessage = message;
96
+ }
97
+ else {
98
+ engineMessage = toHex(message.raw);
99
+ isBytes = true;
100
+ }
101
+ const ENGINE_URL = new URL(engineUrl);
102
+ ENGINE_URL.pathname = "/backend-wallet/sign-message";
103
+ const engineRes = await fetch(ENGINE_URL, {
104
+ method: "POST",
105
+ headers,
106
+ body: JSON.stringify({
107
+ message: engineMessage,
108
+ isBytes,
109
+ chainId: chain?.id,
110
+ }),
111
+ });
112
+ if (!engineRes.ok) {
113
+ const body = await engineRes.text();
114
+ throw new Error(`Engine request failed with status ${engineRes.status} - ${body}`);
115
+ }
116
+ const engineJson = (await engineRes.json());
117
+ return engineJson.result;
118
+ },
119
+ signTypedData: async (_typedData) => {
120
+ const ENGINE_URL = new URL(engineUrl);
121
+ ENGINE_URL.pathname = "/backend-wallet/sign-typed-data";
122
+ const engineRes = await fetch(ENGINE_URL, {
123
+ method: "POST",
124
+ headers,
125
+ body: JSON.stringify({
126
+ domain: _typedData.domain,
127
+ types: _typedData.types,
128
+ value: _typedData.message,
129
+ }),
130
+ });
131
+ if (!engineRes.ok) {
132
+ engineRes.body?.cancel();
133
+ throw new Error(`Engine request failed with status ${engineRes.status}`);
134
+ }
135
+ const engineJson = (await engineRes.json());
136
+ return engineJson.result;
137
+ },
138
+ };
139
+ }
140
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources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,GAAG,iCAAiC,CAAC;YACxD,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,UAAU,EAAE;gBACxC,MAAM,EAAE,MAAM;gBACd,OAAO;gBACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,MAAM,EAAE,UAAU,CAAC,MAAM;oBACzB,KAAK,EAAE,UAAU,CAAC,KAAK;oBACvB,KAAK,EAAE,UAAU,CAAC,OAAO;iBAC1B,CAAC;aACH,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;gBAClB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CACb,qCAAqC,SAAS,CAAC,MAAM,EAAE,CACxD,CAAC;YACJ,CAAC;YACD,MAAM,UAAU,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,CAEzC,CAAC;YACF,OAAO,UAAU,CAAC,MAAM,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -214,7 +214,7 @@ async function checkFor712Factory({ factoryContract, accountContract, originalMs
214
214
  * });
215
215
  * ```
216
216
  *
217
- * @wallets
217
+ * @wallet
218
218
  */
219
219
  export async function deploySmartAccount(args) {
220
220
  const { chain, client, smartAccount, accountContract } = args;
@@ -0,0 +1,24 @@
1
+ import { type Input, type Output } from "./common.js";
2
+ /**
3
+ * Chat with Nebula.
4
+ *
5
+ * @param input - The input for the chat.
6
+ * @returns The chat response.
7
+ * @beta
8
+ * @nebula
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { Nebula } from "thirdweb/ai";
13
+ *
14
+ * const response = await Nebula.chat({
15
+ * client: TEST_CLIENT,
16
+ * prompt: "What's the symbol of this contract: 0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8",
17
+ * context: {
18
+ * chains: [sepolia],
19
+ * },
20
+ * });
21
+ * ```
22
+ */
23
+ export declare function chat(input: Input): Promise<Output>;
24
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../src/ai/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,MAAM,EAAe,MAAM,aAAa,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAExD"}
@@ -0,0 +1,22 @@
1
+ import type { Chain } from "../chains/types.js";
2
+ import type { ThirdwebClient } from "../client/client.js";
3
+ import { type PreparedTransaction } from "../transaction/prepare-transaction.js";
4
+ import type { Account } from "../wallets/interfaces/wallet.js";
5
+ export type Input = {
6
+ client: ThirdwebClient;
7
+ prompt: string | string[];
8
+ account?: Account;
9
+ context?: {
10
+ chains?: Chain[];
11
+ walletAddresses?: string[];
12
+ contractAddresses?: string[];
13
+ };
14
+ sessionId?: string;
15
+ };
16
+ export type Output = {
17
+ message: string;
18
+ sessionId: string;
19
+ transactions: PreparedTransaction[];
20
+ };
21
+ export declare function nebulaFetch(mode: "execute" | "chat", input: Input): Promise<Output>;
22
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/ai/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,uCAAuC,CAAC;AAK/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAI/D,MAAM,MAAM,KAAK,GAAG;IAClB,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;QACjB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;KAC9B,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,mBAAmB,EAAE,CAAC;CACrC,CAAC;AAYF,wBAAsB,WAAW,CAC/B,IAAI,EAAE,SAAS,GAAG,MAAM,EACxB,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,MAAM,CAAC,CAmEjB"}
@@ -0,0 +1,29 @@
1
+ import type { SendTransactionResult } from "../transaction/types.js";
2
+ import type { Account } from "../wallets/interfaces/wallet.js";
3
+ import { type Input } from "./common.js";
4
+ /**
5
+ * Execute a transaction based on a prompt.
6
+ *
7
+ * @param input - The input for the transaction.
8
+ * @returns The transaction hash.
9
+ * @beta
10
+ * @nebula
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { Nebula } from "thirdweb/ai";
15
+ *
16
+ * const result = await Nebula.execute({
17
+ * client: TEST_CLIENT,
18
+ * prompt: "send 0.0001 ETH to vitalik.eth",
19
+ * account: TEST_ACCOUNT_A,
20
+ * context: {
21
+ * chains: [sepolia],
22
+ * },
23
+ * });
24
+ * ```
25
+ */
26
+ export declare function execute(input: Input & {
27
+ account: Account;
28
+ }): Promise<SendTransactionResult>;
29
+ //# sourceMappingURL=execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/ai/execute.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,KAAK,KAAK,EAAe,MAAM,aAAa,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,KAAK,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAClC,OAAO,CAAC,qBAAqB,CAAC,CAchC"}
@@ -0,0 +1,4 @@
1
+ export { chat } from "./chat.js";
2
+ export { execute } from "./execute.js";
3
+ export type { Input, Output } from "./common.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ai/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * as Nebula from "../ai/index.js";
2
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../../src/exports/ai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { type EngineAccountOptions, engineAccount, } from "../../wallets/engine/index.js";
2
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../../src/exports/wallets/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EACzB,aAAa,GACd,MAAM,+BAA+B,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const version = "5.84.0-nightly-0fdfb8aa778a344aa847503f668e48feb5f72548-20250115000312";
1
+ export declare const version = "5.84.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,2EAA2E,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { Chain } from "../../chains/types.js";
2
+ import type { Account } from "../interfaces/wallet.js";
3
+ /**
4
+ * Options for creating an engine account.
5
+ */
6
+ export type EngineAccountOptions = {
7
+ /**
8
+ * The URL of your engine instance.
9
+ */
10
+ engineUrl: string;
11
+ /**
12
+ * The auth token to use with the engine instance.
13
+ */
14
+ authToken: string;
15
+ /**
16
+ * The backend wallet to use for sending transactions inside engine.
17
+ */
18
+ walletAddress: string;
19
+ /**
20
+ * The chain to use for signing messages and typed data (smart backend wallet only).
21
+ */
22
+ chain?: Chain;
23
+ };
24
+ /**
25
+ * Creates an account that uses your engine backend wallet for sending transactions and signing messages.
26
+ *
27
+ * @param options - The options for the engine account.
28
+ * @returns An account that uses your engine backend wallet.
29
+ *
30
+ * @beta
31
+ * @wallet
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { engineAccount } from "thirdweb/wallets/engine";
36
+ *
37
+ * const engineAcc = engineAccount({
38
+ * engineUrl: "https://engine.thirdweb.com",
39
+ * authToken: "your-auth-token",
40
+ * walletAddress: "0x...",
41
+ * });
42
+ *
43
+ * // then use the account as you would any other account
44
+ * const transaction = claimTo({
45
+ * contract,
46
+ * to: "0x...",
47
+ * quantity: 1n,
48
+ * });
49
+ * const result = await sendTransaction({ transaction, account: engineAcc });
50
+ * console.log("Transaction sent:", result.transactionHash);
51
+ * ```
52
+ */
53
+ export declare function engineAccount(options: EngineAccountOptions): Account;
54
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/wallets/engine/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,KAAK,EAAE,OAAO,EAAyB,MAAM,yBAAyB,CAAC;AAE9E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CA6IpE"}
@@ -48,7 +48,7 @@ export declare function confirmContractDeployment(args: {
48
48
  * });
49
49
  * ```
50
50
  *
51
- * @wallets
51
+ * @wallet
52
52
  */
53
53
  export declare function deploySmartAccount(args: {
54
54
  smartAccount: Account;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thirdweb",
3
- "version": "5.84.0-nightly-0fdfb8aa778a344aa847503f668e48feb5f72548-20250115000312",
3
+ "version": "5.84.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/thirdweb-dev/js.git#main"
@@ -123,6 +123,11 @@
123
123
  "import": "./dist/esm/exports/social.js",
124
124
  "default": "./dist/cjs/exports/social.js"
125
125
  },
126
+ "./ai": {
127
+ "types": "./dist/types/exports/ai.d.ts",
128
+ "import": "./dist/esm/exports/ai.js",
129
+ "default": "./dist/cjs/exports/ai.js"
130
+ },
126
131
  "./package.json": "./package.json"
127
132
  },
128
133
  "typesVersions": {
@@ -180,6 +185,9 @@
180
185
  ],
181
186
  "social": [
182
187
  "./dist/types/exports/social.d.ts"
188
+ ],
189
+ "ai": [
190
+ "./dist/types/exports/ai.d.ts"
183
191
  ]
184
192
  }
185
193
  },
@@ -0,0 +1,31 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TEST_CLIENT } from "../../test/src/test-clients.js";
3
+ import { TEST_ACCOUNT_A, TEST_ACCOUNT_B } from "../../test/src/test-wallets.js";
4
+ import { sepolia } from "../chains/chain-definitions/sepolia.js";
5
+ import * as Nebula from "./index.js";
6
+
7
+ describe.runIf(process.env.TW_SECRET_KEY)("chat", () => {
8
+ it("should respond with a message", async () => {
9
+ const response = await Nebula.chat({
10
+ client: TEST_CLIENT,
11
+ prompt: `What's the symbol of this contract: 0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8`,
12
+ context: {
13
+ chains: [sepolia],
14
+ },
15
+ });
16
+ expect(response.message).toContain("CAT");
17
+ });
18
+
19
+ it("should respond with a transaction", async () => {
20
+ const response = await Nebula.chat({
21
+ client: TEST_CLIENT,
22
+ prompt: `send 0.0001 ETH on sepolia to ${TEST_ACCOUNT_B.address}`,
23
+ account: TEST_ACCOUNT_A,
24
+ context: {
25
+ chains: [sepolia],
26
+ walletAddresses: [TEST_ACCOUNT_A.address],
27
+ },
28
+ });
29
+ expect(response.transactions.length).toBe(1);
30
+ });
31
+ });
package/src/ai/chat.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { type Input, type Output, nebulaFetch } from "./common.js";
2
+
3
+ /**
4
+ * Chat with Nebula.
5
+ *
6
+ * @param input - The input for the chat.
7
+ * @returns The chat response.
8
+ * @beta
9
+ * @nebula
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { Nebula } from "thirdweb/ai";
14
+ *
15
+ * const response = await Nebula.chat({
16
+ * client: TEST_CLIENT,
17
+ * prompt: "What's the symbol of this contract: 0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8",
18
+ * context: {
19
+ * chains: [sepolia],
20
+ * },
21
+ * });
22
+ * ```
23
+ */
24
+ export async function chat(input: Input): Promise<Output> {
25
+ return nebulaFetch("chat", input);
26
+ }
@@ -0,0 +1,114 @@
1
+ import type { Chain } from "../chains/types.js";
2
+ import { getCachedChain } from "../chains/utils.js";
3
+ import type { ThirdwebClient } from "../client/client.js";
4
+ import {
5
+ type PreparedTransaction,
6
+ prepareTransaction,
7
+ } from "../transaction/prepare-transaction.js";
8
+ import type { Address } from "../utils/address.js";
9
+ import { toBigInt } from "../utils/bigint.js";
10
+ import type { Hex } from "../utils/encoding/hex.js";
11
+ import { getClientFetch } from "../utils/fetch.js";
12
+ import type { Account } from "../wallets/interfaces/wallet.js";
13
+
14
+ const NEBULA_API_URL = "https://nebula-api.thirdweb.com";
15
+
16
+ export type Input = {
17
+ client: ThirdwebClient;
18
+ prompt: string | string[];
19
+ account?: Account;
20
+ context?: {
21
+ chains?: Chain[];
22
+ walletAddresses?: string[];
23
+ contractAddresses?: string[];
24
+ };
25
+ sessionId?: string;
26
+ };
27
+
28
+ export type Output = {
29
+ message: string;
30
+ sessionId: string;
31
+ transactions: PreparedTransaction[];
32
+ };
33
+
34
+ type ApiResponse = {
35
+ message: string;
36
+ session_id: string;
37
+ actions?: {
38
+ type: "init" | "presence" | "sign_transaction";
39
+ source: string;
40
+ data: string;
41
+ }[];
42
+ };
43
+
44
+ export async function nebulaFetch(
45
+ mode: "execute" | "chat",
46
+ input: Input,
47
+ ): Promise<Output> {
48
+ const fetch = getClientFetch(input.client);
49
+ const response = await fetch(`${NEBULA_API_URL}/${mode}`, {
50
+ method: "POST",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ },
54
+ body: JSON.stringify({
55
+ message: input.prompt, // TODO: support array of messages
56
+ session_id: input.sessionId,
57
+ ...(input.account
58
+ ? {
59
+ execute_config: {
60
+ mode: "client",
61
+ signer_wallet_address: input.account.address,
62
+ },
63
+ }
64
+ : {}),
65
+ ...(input.context
66
+ ? {
67
+ context_filter: {
68
+ chain_ids:
69
+ input.context.chains?.map((c) => c.id.toString()) || [],
70
+ signer_wallet_address: input.context.walletAddresses || [],
71
+ contract_addresses: input.context.contractAddresses || [],
72
+ },
73
+ }
74
+ : {}),
75
+ }),
76
+ });
77
+ if (!response.ok) {
78
+ const error = await response.text();
79
+ throw new Error(`Nebula API error: ${error}`);
80
+ }
81
+ const data = (await response.json()) as ApiResponse;
82
+
83
+ // parse transactions if present
84
+ let transactions: PreparedTransaction[] = [];
85
+ if (data.actions) {
86
+ transactions = data.actions
87
+ .map((action) => {
88
+ // only parse sign_transaction actions
89
+ if (action.type === "sign_transaction") {
90
+ const tx = JSON.parse(action.data) as {
91
+ chainId: number;
92
+ to: Address | undefined;
93
+ value: Hex;
94
+ data: Hex;
95
+ };
96
+ return prepareTransaction({
97
+ chain: getCachedChain(tx.chainId),
98
+ client: input.client,
99
+ to: tx.to,
100
+ value: tx.value ? toBigInt(tx.value) : undefined,
101
+ data: tx.data,
102
+ });
103
+ }
104
+ return undefined;
105
+ })
106
+ .filter((tx) => tx !== undefined);
107
+ }
108
+
109
+ return {
110
+ message: data.message,
111
+ sessionId: data.session_id,
112
+ transactions,
113
+ };
114
+ }
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { TEST_CLIENT } from "../../test/src/test-clients.js";
3
+ import { TEST_ACCOUNT_A, TEST_ACCOUNT_B } from "../../test/src/test-wallets.js";
4
+ import { sepolia } from "../chains/chain-definitions/sepolia.js";
5
+ import { getContract } from "../contract/contract.js";
6
+ import * as Nebula from "./index.js";
7
+
8
+ describe("execute", () => {
9
+ it("should execute a tx", async () => {
10
+ await expect(
11
+ Nebula.execute({
12
+ client: TEST_CLIENT,
13
+ prompt: `send 0.0001 ETH to ${TEST_ACCOUNT_B.address}`,
14
+ account: TEST_ACCOUNT_A,
15
+ context: {
16
+ chains: [sepolia],
17
+ walletAddresses: [TEST_ACCOUNT_A.address],
18
+ },
19
+ }),
20
+ ).rejects.toThrow(/insufficient funds for gas/); // shows that the tx was sent
21
+ });
22
+
23
+ // TODO make this work reliably
24
+ it.skip("should execute a contract call", async () => {
25
+ const nftContract = getContract({
26
+ client: TEST_CLIENT,
27
+ chain: sepolia,
28
+ address: "0xe2cb0eb5147b42095c2FfA6F7ec953bb0bE347D8",
29
+ });
30
+
31
+ const response = await Nebula.execute({
32
+ client: TEST_CLIENT,
33
+ prompt: `approve 1 token of token id 0 to ${TEST_ACCOUNT_B.address} using the approve function`,
34
+ account: TEST_ACCOUNT_A,
35
+ context: {
36
+ chains: [nftContract.chain],
37
+ walletAddresses: [TEST_ACCOUNT_A.address],
38
+ contractAddresses: [nftContract.address],
39
+ },
40
+ });
41
+ expect(response.transactionHash).toBeDefined();
42
+ });
43
+ });
@@ -0,0 +1,44 @@
1
+ import { sendTransaction } from "../transaction/actions/send-transaction.js";
2
+ import type { SendTransactionResult } from "../transaction/types.js";
3
+ import type { Account } from "../wallets/interfaces/wallet.js";
4
+ import { type Input, nebulaFetch } from "./common.js";
5
+
6
+ /**
7
+ * Execute a transaction based on a prompt.
8
+ *
9
+ * @param input - The input for the transaction.
10
+ * @returns The transaction hash.
11
+ * @beta
12
+ * @nebula
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { Nebula } from "thirdweb/ai";
17
+ *
18
+ * const result = await Nebula.execute({
19
+ * client: TEST_CLIENT,
20
+ * prompt: "send 0.0001 ETH to vitalik.eth",
21
+ * account: TEST_ACCOUNT_A,
22
+ * context: {
23
+ * chains: [sepolia],
24
+ * },
25
+ * });
26
+ * ```
27
+ */
28
+ export async function execute(
29
+ input: Input & { account: Account },
30
+ ): Promise<SendTransactionResult> {
31
+ const result = await nebulaFetch("execute", input);
32
+ // TODO: optionally only return the transaction without executing it?
33
+ if (result.transactions.length === 0) {
34
+ throw new Error(result.message);
35
+ }
36
+ const tx = result.transactions[0];
37
+ if (!tx) {
38
+ throw new Error(result.message);
39
+ }
40
+ return sendTransaction({
41
+ transaction: tx,
42
+ account: input.account,
43
+ });
44
+ }
@@ -0,0 +1,3 @@
1
+ export { chat } from "./chat.js";
2
+ export { execute } from "./execute.js";
3
+ export type { Input, Output } from "./common.js";
@@ -0,0 +1 @@
1
+ export * as Nebula from "../ai/index.js";
@@ -0,0 +1,4 @@
1
+ export {
2
+ type EngineAccountOptions,
3
+ engineAccount,
4
+ } from "../../wallets/engine/index.js";
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.84.0-nightly-0fdfb8aa778a344aa847503f668e48feb5f72548-20250115000312";
1
+ export const version = "5.84.0";