Skip to content

Commit a22ed23

Browse files
committed
add section for knowledge base support in portal
1 parent ccb9cd5 commit a22ed23

File tree

44 files changed

+1721
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1721
-1
lines changed

apps/portal/src/app/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const supportLinks = [
124124
},
125125
{
126126
name: "Knowledge Base",
127-
href: "https://support.thirdweb.com",
127+
href: "/knowledge-base",
128128
},
129129
{
130130
name: "Contact Sales",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { ApiEndpoint } from "@/components/Document/APIEndpointMeta/ApiEndpoint";
2+
import {
3+
nebulaAPI401Response,
4+
nebulaAPI422Response,
5+
nebulaContextParameter,
6+
nebulaSecretKeyHeaderParameter,
7+
} from "../common";
8+
9+
const response200Example = `\
10+
{
11+
"message": "string",
12+
"actions": [
13+
{
14+
"session_id": "string",
15+
"request_id": "string",
16+
"type": "init",
17+
"source": "string",
18+
"data": "string"
19+
}
20+
],
21+
"session_id": "string",
22+
"request_id": "string"
23+
}`;
24+
25+
export function EndpointMetadata() {
26+
return (
27+
<ApiEndpoint
28+
metadata={{
29+
title: "Send Message",
30+
description: "Process a chat message and return the response",
31+
origin: "https://nebula-api.thirdweb.com",
32+
path: "/chat",
33+
method: "POST",
34+
request: {
35+
pathParameters: [],
36+
headers: [nebulaSecretKeyHeaderParameter],
37+
bodyParameters: [
38+
{
39+
name: "message",
40+
required: true,
41+
description: "The message to be processed.",
42+
type: "string",
43+
example: "Hello",
44+
},
45+
{
46+
name: "stream",
47+
required: false,
48+
description: "Whether to stream the response or not",
49+
type: "boolean",
50+
example: false,
51+
},
52+
{
53+
name: "session_id",
54+
type: "string",
55+
example: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
56+
required: false,
57+
description:
58+
"The session ID to associate with the message. If not provided, a new session will be created.",
59+
},
60+
nebulaContextParameter,
61+
],
62+
},
63+
responseExamples: {
64+
200: response200Example,
65+
401: nebulaAPI401Response,
66+
422: nebulaAPI422Response,
67+
},
68+
}}
69+
/>
70+
);
71+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { EndpointMetadata } from './EndpointMetadata';
2+
3+
<EndpointMetadata />
4+
5+
# Chat Actions
6+
7+
Chat actions represent blockchain transactions or operations that Nebula has prepared in response to your request. The response includes both a detailed explanation in the `message` field and the actual transaction data in the `actions` array.
8+
9+
**Example Response with Chat Action:**
10+
```json
11+
{
12+
"message": "The transaction to transfer 0.0001 ETH to the address resolved from the ENS name `vitalik.eth` (which is `0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045`) is set up successfully. The simulation indicates that the transaction is likely to succeed.\n\nPlease proceed by signing and confirming the transaction.",
13+
"actions": [
14+
{
15+
"session_id": "437a0df7-d512-4ef4-95b5-6168ccbbe097",
16+
"request_id": "c2b51ed6-da79-49ac-b411-206a42059509",
17+
"type": "sign_transaction",
18+
"source": "executor",
19+
"data": "{\"chainId\": 11155111, \"to\": \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\", \"data\": \"0x\", \"value\": \"0x5af3107a4000\"}"
20+
}
21+
],
22+
"session_id": "437a0df7-d512-4ef4-95b5-6168ccbbe097",
23+
"request_id": "c2b51ed6-da79-49ac-b411-206a42059509"
24+
}
25+
```
26+
27+
**Action Properties:**
28+
- `session_id`: Unique identifier for the current session
29+
- `request_id`: Unique identifier for the specific request
30+
- `type`: The type of action (e.g., "sign_transaction")
31+
- `source`: Origin of the action (e.g., "executor")
32+
- `data`: Transaction parameters including:
33+
- `chainId`: Network identifier (e.g., 11155111 for Sepolia)
34+
- `to`: Recipient's address
35+
- `data`: Transaction data (if any)
36+
- `value`: Amount to send in wei
37+
38+
When handling actions:
39+
1. Parse the `message` field for human-readable transaction details
40+
2. Extract the transaction data from the `actions` array
41+
3. Present transaction details to the user for review
42+
4. Use a local wallet to sign the transaction
43+
5. Broadcast the signed transaction to the network
44+
45+
**Example Implementation with thirdweb SDK:**
46+
```javascript
47+
import {
48+
createThirdwebClient,
49+
prepareTransaction,
50+
sendTransaction,
51+
privateKeyToAccount
52+
} from "thirdweb";
53+
54+
// Example function to handle the API response
55+
async function handleNebulaResponse(response) {
56+
// Initialize thirdweb client
57+
const client = createThirdwebClient({
58+
secretKey: process.env.THIRDWEB_SECRET_KEY
59+
});
60+
61+
// Initialize account
62+
const account = privateKeyToAccount({
63+
client,
64+
privateKey: process.env.EOA_PRIVATE_KEY
65+
});
66+
67+
// Check if we have any actions
68+
if (response.actions && response.actions.length > 0) {
69+
const action = response.actions[0];
70+
71+
// Parse the transaction data from the action
72+
const txData = JSON.parse(action.data);
73+
74+
try {
75+
// Prepare transaction with client
76+
const transaction = prepareTransaction({
77+
to: txData.to,
78+
data: txData.data,
79+
value: BigInt(txData.value),
80+
chain: txData.chainId,
81+
client
82+
});
83+
84+
// Send transaction with account
85+
const result = await sendTransaction({
86+
transaction,
87+
account
88+
});
89+
90+
return result;
91+
} catch (error) {
92+
console.error("Error processing transaction:", error);
93+
throw error;
94+
}
95+
}
96+
}
97+
98+
// Example usage
99+
const response = await fetch('https://nebula-api.thirdweb.com/chat', {
100+
method: 'POST',
101+
headers: {
102+
'Content-Type': 'application/json',
103+
'x-secret-key': 'YOUR_THIRDWEB_SECRET_KEY'
104+
},
105+
body: JSON.stringify({
106+
message: "send 0.0001 ETH on sepolia to vitalik.eth",
107+
execute_config: {
108+
mode: "client",
109+
signer_wallet_address: "0xc3F2b2a12Eba0f5989cD75B2964E31D56603a2cE"
110+
}
111+
})
112+
});
113+
114+
const data = await response.json();
115+
const result = await handleNebulaResponse(data);
116+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ApiEndpoint } from "@/components/Document/APIEndpointMeta/ApiEndpoint";
2+
import {
3+
nebulaAPI401Response,
4+
nebulaFullSessionResponse,
5+
nebulaSecretKeyHeaderParameter,
6+
nebulaSessionIdPathParameter,
7+
} from "../common";
8+
9+
export function EndpointMetadata() {
10+
return (
11+
<ApiEndpoint
12+
metadata={{
13+
title: "Clear Session",
14+
description:
15+
"Clears all messages for a specific session using the session ID.",
16+
origin: "https://nebula-api.thirdweb.com",
17+
path: "/session/{session_id}/clear",
18+
method: "POST",
19+
request: {
20+
pathParameters: [nebulaSessionIdPathParameter],
21+
headers: [nebulaSecretKeyHeaderParameter],
22+
bodyParameters: [],
23+
},
24+
responseExamples: {
25+
200: nebulaFullSessionResponse,
26+
401: nebulaAPI401Response,
27+
},
28+
}}
29+
/>
30+
);
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { EndpointMetadata } from './EndpointMetadata';
2+
3+
<EndpointMetadata />
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import type { APIParameter } from "../../../components/Document/APIEndpointMeta/ApiEndpoint";
2+
3+
export const nebulaFullSessionResponse = `\
4+
{
5+
"result": {
6+
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
7+
"title": "string",
8+
"context": {
9+
"chain_ids": ["1", "137"],
10+
"wallet_address": "0x..."
11+
},
12+
"history": [
13+
{}
14+
],
15+
"account_id": "string",
16+
"model_name": "string",
17+
"is_public": true,
18+
"memory": [
19+
{}
20+
],
21+
"action": [
22+
{}
23+
],
24+
"archive_at": "2025-01-08T17:22:45.016Z",
25+
"deleted_at": "2025-01-08T17:22:45.016Z",
26+
"created_at": "2025-01-08T17:22:45.016Z",
27+
"updated_at": "2025-01-08T17:22:45.016Z"
28+
}
29+
}`;
30+
31+
export const nebulaAPI401Response = `\
32+
{
33+
"error": {
34+
"message": "401: Authentication failed"
35+
}
36+
}`;
37+
38+
export const nebulaAPI422Response = `\
39+
{
40+
"detail": [
41+
{
42+
"loc": [
43+
"string",
44+
0
45+
],
46+
"msg": "string",
47+
"type": "string"
48+
}
49+
]
50+
}`;
51+
52+
export const nebulaSecretKeyHeaderParameter: APIParameter = {
53+
name: "x-secret-key",
54+
required: true,
55+
description: "Your thirdweb secret key for authentication.",
56+
type: "string",
57+
example: "YOUR_THIRDWEB_SECRET_KEY",
58+
};
59+
60+
export const nebulaSessionIdPathParameter: APIParameter = {
61+
name: "session_id",
62+
required: true,
63+
description: "The unique ID of the session",
64+
type: "string",
65+
example: "3fa85f64-5717-4562-b3fc-2c963f66afa6",
66+
};
67+
const nebulaContextFilterType = `\
68+
{
69+
chainIds: string[] | null;
70+
walletAddress: string | null;
71+
}`;
72+
73+
export const nebulaContextParameter: APIParameter = {
74+
name: "context",
75+
required: false,
76+
description: "Provide additional context information along with the message",
77+
type: nebulaContextFilterType,
78+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ApiEndpoint } from "@/components/Document/APIEndpointMeta/ApiEndpoint";
2+
import {
3+
nebulaAPI401Response,
4+
nebulaAPI422Response,
5+
nebulaContextParameter,
6+
nebulaFullSessionResponse,
7+
nebulaSecretKeyHeaderParameter,
8+
} from "../common";
9+
10+
export function EndpointMetadata() {
11+
return (
12+
<ApiEndpoint
13+
metadata={{
14+
title: "Create Session",
15+
description: "Creates a new session.",
16+
path: "/session",
17+
origin: "https://nebula-api.thirdweb.com",
18+
method: "POST",
19+
request: {
20+
headers: [nebulaSecretKeyHeaderParameter],
21+
pathParameters: [],
22+
bodyParameters: [
23+
{
24+
name: "title",
25+
description: "Set a custom title for the session.",
26+
type: "string",
27+
required: false,
28+
},
29+
nebulaContextParameter,
30+
],
31+
},
32+
responseExamples: {
33+
200: nebulaFullSessionResponse,
34+
401: nebulaAPI401Response,
35+
422: nebulaAPI422Response,
36+
},
37+
}}
38+
/>
39+
);
40+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { EndpointMetadata } from './EndpointMetadata';
2+
3+
<EndpointMetadata />
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ApiEndpoint } from "@/components/Document/APIEndpointMeta/ApiEndpoint";
2+
import {
3+
nebulaAPI401Response,
4+
nebulaAPI422Response,
5+
nebulaSecretKeyHeaderParameter,
6+
nebulaSessionIdPathParameter,
7+
} from "../common";
8+
9+
const response200Example = `\
10+
{
11+
"result": {
12+
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
13+
"deleted_at": "2025-01-08T19:27:37.296Z"
14+
}
15+
}`;
16+
17+
export function EndpointMetadata() {
18+
return (
19+
<ApiEndpoint
20+
metadata={{
21+
title: "Delete Session",
22+
method: "DELETE",
23+
description: "Deletes a session by ID",
24+
origin: "https://nebula-api.thirdweb.com",
25+
path: "/session/{session_id}",
26+
request: {
27+
pathParameters: [nebulaSessionIdPathParameter],
28+
headers: [nebulaSecretKeyHeaderParameter],
29+
bodyParameters: [],
30+
},
31+
responseExamples: {
32+
200: response200Example,
33+
422: nebulaAPI422Response,
34+
401: nebulaAPI401Response,
35+
},
36+
}}
37+
/>
38+
);
39+
}

0 commit comments

Comments
 (0)