@promptbook/cli 0.103.0-52 → 0.103.0-54
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.
- package/apps/agents-server/README.md +1 -1
- package/apps/agents-server/config.ts +3 -3
- package/apps/agents-server/next.config.ts +1 -1
- package/apps/agents-server/public/sw.js +16 -0
- package/apps/agents-server/src/app/AddAgentButton.tsx +24 -4
- package/apps/agents-server/src/app/actions.ts +15 -13
- package/apps/agents-server/src/app/admin/api-tokens/ApiTokensClient.tsx +186 -0
- package/apps/agents-server/src/app/admin/api-tokens/page.tsx +13 -0
- package/apps/agents-server/src/app/admin/chat-feedback/ChatFeedbackClient.tsx +541 -0
- package/apps/agents-server/src/app/admin/chat-feedback/page.tsx +22 -0
- package/apps/agents-server/src/app/admin/chat-history/ChatHistoryClient.tsx +532 -0
- package/apps/agents-server/src/app/admin/chat-history/page.tsx +21 -0
- package/apps/agents-server/src/app/admin/metadata/MetadataClient.tsx +241 -27
- package/apps/agents-server/src/app/admin/models/page.tsx +22 -0
- package/apps/agents-server/src/app/admin/users/[userId]/UserDetailClient.tsx +131 -0
- package/apps/agents-server/src/app/admin/users/[userId]/page.tsx +21 -0
- package/apps/agents-server/src/app/admin/users/page.tsx +18 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +10 -2
- package/apps/agents-server/src/app/agents/[agentName]/ClearAgentChatFeedbackButton.tsx +63 -0
- package/apps/agents-server/src/app/agents/[agentName]/ClearAgentChatHistoryButton.tsx +63 -0
- package/apps/agents-server/src/app/agents/[agentName]/CloneAgentButton.tsx +41 -0
- package/apps/agents-server/src/app/agents/[agentName]/InstallPwaButton.tsx +74 -0
- package/apps/agents-server/src/app/agents/[agentName]/ServiceWorkerRegister.tsx +24 -0
- package/apps/agents-server/src/app/agents/[agentName]/_utils.ts +19 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/agents/route.ts +67 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/chat/completions/route.ts +176 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/profile/route.ts +3 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +177 -0
- package/apps/agents-server/src/app/agents/[agentName]/book/page.tsx +3 -0
- package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChat.tsx +53 -1
- package/apps/agents-server/src/app/agents/[agentName]/generateAgentMetadata.ts +11 -11
- package/apps/agents-server/src/app/agents/[agentName]/history/RestoreVersionButton.tsx +46 -0
- package/apps/agents-server/src/app/agents/[agentName]/history/actions.ts +12 -0
- package/apps/agents-server/src/app/agents/[agentName]/history/page.tsx +62 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/icon-256.png/route.tsx +80 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-fullhd.png/route.tsx +92 -0
- package/apps/agents-server/src/app/agents/[agentName]/images/screenshot-phone.png/route.tsx +92 -0
- package/apps/agents-server/src/app/agents/[agentName]/integration/page.tsx +61 -0
- package/apps/agents-server/src/app/agents/[agentName]/opengraph-image.tsx +102 -0
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +64 -24
- package/apps/agents-server/src/app/api/agents/[agentName]/clone/route.ts +47 -0
- package/apps/agents-server/src/app/api/agents/[agentName]/route.ts +19 -0
- package/apps/agents-server/src/app/api/agents/route.ts +22 -13
- package/apps/agents-server/src/app/api/api-tokens/route.ts +76 -0
- package/apps/agents-server/src/app/api/auth/login/route.ts +6 -44
- package/apps/agents-server/src/app/api/chat-feedback/[id]/route.ts +38 -0
- package/apps/agents-server/src/app/api/chat-feedback/route.ts +157 -0
- package/apps/agents-server/src/app/api/chat-history/[id]/route.ts +37 -0
- package/apps/agents-server/src/app/api/chat-history/route.ts +147 -0
- package/apps/agents-server/src/app/api/federated-agents/route.ts +17 -0
- package/apps/agents-server/src/app/api/upload/route.ts +9 -1
- package/apps/agents-server/src/app/docs/[docId]/page.tsx +63 -0
- package/apps/agents-server/src/app/docs/page.tsx +34 -0
- package/apps/agents-server/src/app/layout.tsx +29 -3
- package/apps/agents-server/src/app/manifest.ts +109 -0
- package/apps/agents-server/src/app/page.tsx +8 -45
- package/apps/agents-server/src/app/recycle-bin/RestoreAgentButton.tsx +40 -0
- package/apps/agents-server/src/app/recycle-bin/actions.ts +27 -0
- package/apps/agents-server/src/app/recycle-bin/page.tsx +58 -0
- package/apps/agents-server/src/app/restricted/page.tsx +33 -0
- package/apps/agents-server/src/app/test/og-image/README.md +1 -0
- package/apps/agents-server/src/app/test/og-image/opengraph-image.tsx +37 -0
- package/apps/agents-server/src/app/test/og-image/page.tsx +22 -0
- package/apps/agents-server/src/components/Footer/Footer.tsx +175 -0
- package/apps/agents-server/src/components/Header/Header.tsx +450 -79
- package/apps/agents-server/src/components/Homepage/AgentCard.tsx +46 -14
- package/apps/agents-server/src/components/Homepage/AgentsList.tsx +58 -0
- package/apps/agents-server/src/components/Homepage/Card.tsx +1 -1
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSection.tsx +21 -0
- package/apps/agents-server/src/components/Homepage/ExternalAgentsSectionClient.tsx +183 -0
- package/apps/agents-server/src/components/Homepage/ModelsSection.tsx +75 -0
- package/apps/agents-server/src/components/LayoutWrapper/LayoutWrapper.tsx +29 -3
- package/apps/agents-server/src/components/LoginDialog/LoginDialog.tsx +18 -17
- package/apps/agents-server/src/components/Portal/Portal.tsx +38 -0
- package/apps/agents-server/src/components/UsersList/UsersList.tsx +82 -131
- package/apps/agents-server/src/components/UsersList/useUsersAdmin.ts +139 -0
- package/apps/agents-server/src/database/metadataDefaults.ts +38 -6
- package/apps/agents-server/src/database/migrations/2025-12-0010-llm-cache.sql +12 -0
- package/apps/agents-server/src/database/migrations/2025-12-0060-api-tokens.sql +13 -0
- package/apps/agents-server/src/database/schema.ts +51 -0
- package/apps/agents-server/src/middleware.ts +193 -92
- package/apps/agents-server/src/tools/$provideCdnForServer.ts +3 -7
- package/apps/agents-server/src/tools/$provideExecutionToolsForServer.ts +10 -1
- package/apps/agents-server/src/tools/$provideServer.ts +2 -2
- package/apps/agents-server/src/utils/authenticateUser.ts +42 -0
- package/apps/agents-server/src/utils/cache/SupabaseCacheStorage.ts +55 -0
- package/apps/agents-server/src/utils/cdn/classes/VercelBlobStorage.ts +63 -0
- package/apps/agents-server/src/utils/chatFeedbackAdmin.ts +96 -0
- package/apps/agents-server/src/utils/chatHistoryAdmin.ts +96 -0
- package/apps/agents-server/src/utils/getEffectiveFederatedServers.ts +22 -0
- package/apps/agents-server/src/utils/getFederatedAgents.ts +31 -8
- package/apps/agents-server/src/utils/getFederatedServersFromMetadata.ts +10 -0
- package/apps/agents-server/src/utils/getVisibleCommitmentDefinitions.ts +12 -0
- package/apps/agents-server/src/utils/isUserAdmin.ts +2 -2
- package/apps/agents-server/vercel.json +7 -0
- package/esm/index.es.js +279 -2
- package/esm/index.es.js.map +1 -1
- package/esm/typings/servers.d.ts +8 -1
- package/esm/typings/src/_packages/components.index.d.ts +2 -0
- package/esm/typings/src/_packages/core.index.d.ts +6 -0
- package/esm/typings/src/_packages/types.index.d.ts +2 -0
- package/esm/typings/src/_packages/utils.index.d.ts +2 -0
- package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +7 -0
- package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +4 -0
- package/esm/typings/src/book-components/_common/HamburgerMenu/HamburgerMenu.d.ts +12 -0
- package/esm/typings/src/book-components/icons/MicIcon.d.ts +8 -0
- package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentCollectionInSupabase.d.ts +17 -0
- package/esm/typings/src/commitments/ACTION/ACTION.d.ts +4 -0
- package/esm/typings/src/commitments/DELETE/DELETE.d.ts +4 -0
- package/esm/typings/src/commitments/FORMAT/FORMAT.d.ts +4 -0
- package/esm/typings/src/commitments/GOAL/GOAL.d.ts +4 -0
- package/esm/typings/src/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +4 -0
- package/esm/typings/src/commitments/MEMORY/MEMORY.d.ts +4 -0
- package/esm/typings/src/commitments/MESSAGE/AgentMessageCommitmentDefinition.d.ts +32 -0
- package/esm/typings/src/commitments/MESSAGE/InitialMessageCommitmentDefinition.d.ts +4 -0
- package/esm/typings/src/commitments/MESSAGE/MESSAGE.d.ts +4 -0
- package/esm/typings/src/commitments/MESSAGE/UserMessageCommitmentDefinition.d.ts +32 -0
- package/esm/typings/src/commitments/META/META.d.ts +4 -0
- package/esm/typings/src/commitments/META_COLOR/META_COLOR.d.ts +4 -0
- package/esm/typings/src/commitments/META_IMAGE/META_IMAGE.d.ts +4 -0
- package/esm/typings/src/commitments/META_LINK/META_LINK.d.ts +4 -0
- package/esm/typings/src/commitments/MODEL/MODEL.d.ts +4 -0
- package/esm/typings/src/commitments/NOTE/NOTE.d.ts +4 -0
- package/esm/typings/src/commitments/PERSONA/PERSONA.d.ts +4 -0
- package/esm/typings/src/commitments/RULE/RULE.d.ts +4 -0
- package/esm/typings/src/commitments/SAMPLE/SAMPLE.d.ts +4 -0
- package/esm/typings/src/commitments/SCENARIO/SCENARIO.d.ts +4 -0
- package/esm/typings/src/commitments/STYLE/STYLE.d.ts +4 -0
- package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +5 -0
- package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +5 -0
- package/esm/typings/src/commitments/_base/NotYetImplementedCommitmentDefinition.d.ts +4 -0
- package/esm/typings/src/commitments/index.d.ts +20 -1
- package/esm/typings/src/execution/LlmExecutionTools.d.ts +9 -0
- package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +2 -1
- package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +10 -1
- package/esm/typings/src/utils/normalization/normalizeMessageText.d.ts +9 -0
- package/esm/typings/src/utils/normalization/normalizeMessageText.test.d.ts +1 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +279 -2
- package/umd/index.umd.js.map +1 -1
- package/apps/agents-server/src/utils/cdn/classes/DigitalOceanSpaces.ts +0 -119
|
@@ -5,7 +5,7 @@ const config = ConfigChecker.from({
|
|
|
5
5
|
|
|
6
6
|
// Note: To expose env variables to the browser, using this seemingly strange syntax:
|
|
7
7
|
// @see https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#exposing-environment-variables-to-the-browser
|
|
8
|
-
|
|
8
|
+
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
|
|
9
9
|
|
|
10
10
|
// Note: [🌇] Defa
|
|
11
11
|
NEXT_PUBLIC_VERCEL_ENV: process.env.NEXT_PUBLIC_VERCEL_ENV,
|
|
@@ -31,7 +31,7 @@ const config = ConfigChecker.from({
|
|
|
31
31
|
*
|
|
32
32
|
* Note: When `SERVERS` are used, this URL will be overridden by the server URL.
|
|
33
33
|
*/
|
|
34
|
-
export const
|
|
34
|
+
export const NEXT_PUBLIC_SITE_URL = config.get('NEXT_PUBLIC_SITE_URL').url().required().value;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* [♐️] Vercel environment: "development" | "preview" | "production"
|
|
@@ -118,7 +118,7 @@ export const NEXT_PUBLIC_VERCEL_GIT_PULL_REQUEST_ID = config.get('NEXT_PUBLIC_VE
|
|
|
118
118
|
/**
|
|
119
119
|
* List of servers where agents can be hosted
|
|
120
120
|
*
|
|
121
|
-
* List of domains where the agents-server is deployed, this overrides the `
|
|
121
|
+
* List of domains where the agents-server is deployed, this overrides the `NEXT_PUBLIC_SITE_URL` and `SUPABASE_TABLE_PREFIX` for each server.
|
|
122
122
|
*/
|
|
123
123
|
export const SERVERS = config.get('SERVERS').list().value;
|
|
124
124
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
self.addEventListener('install', (event) => {
|
|
2
|
+
// console.log('Service Worker installing.');
|
|
3
|
+
// Perform install steps
|
|
4
|
+
self.skipWaiting();
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
self.addEventListener('activate', (event) => {
|
|
8
|
+
// console.log('Service Worker activating.');
|
|
9
|
+
self.clients.claim();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
self.addEventListener('fetch', (event) => {
|
|
13
|
+
// console.log('Service Worker fetching.', event.request.url);
|
|
14
|
+
// Simple pass-through fetch
|
|
15
|
+
event.respondWith(fetch(event.request));
|
|
16
|
+
});
|
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useRouter } from 'next/navigation';
|
|
4
|
+
import { useState } from 'react';
|
|
4
5
|
import { Card } from '../components/Homepage/Card';
|
|
5
6
|
import { $createAgentAction } from './actions';
|
|
6
7
|
|
|
7
8
|
export function AddAgentButton() {
|
|
8
9
|
const router = useRouter();
|
|
10
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
9
11
|
|
|
10
12
|
const handleAddAgent = async () => {
|
|
11
|
-
|
|
13
|
+
setIsLoading(true);
|
|
14
|
+
const agentName = await $createAgentAction();
|
|
12
15
|
// TODO: Add proper error handling and UI feedback
|
|
13
|
-
|
|
16
|
+
if (agentName) {
|
|
17
|
+
router.push(`/agents/${agentName}`);
|
|
18
|
+
} else {
|
|
19
|
+
router.refresh();
|
|
20
|
+
setIsLoading(false);
|
|
21
|
+
}
|
|
14
22
|
};
|
|
15
23
|
|
|
16
24
|
return (
|
|
17
|
-
<div
|
|
18
|
-
|
|
25
|
+
<div
|
|
26
|
+
onClick={isLoading ? undefined : handleAddAgent}
|
|
27
|
+
className={`cursor-pointer h-full group ${isLoading ? 'pointer-events-none' : ''}`}
|
|
28
|
+
>
|
|
29
|
+
<Card className="flex items-center justify-center text-lg font-medium text-gray-500 group-hover:text-blue-500 group-hover:border-blue-400 border-dashed border-2">
|
|
30
|
+
{isLoading ? (
|
|
31
|
+
<>
|
|
32
|
+
<span className="mr-2 inline-block h-4 w-4 animate-spin rounded-full border-2 border-blue-500 border-t-transparent" />
|
|
33
|
+
Creating agent...
|
|
34
|
+
</>
|
|
35
|
+
) : (
|
|
36
|
+
'+ Add New Agent'
|
|
37
|
+
)}
|
|
38
|
+
</Card>
|
|
19
39
|
</div>
|
|
20
40
|
);
|
|
21
41
|
}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
3
|
import { $generateBookBoilerplate } from '@promptbook-local/core';
|
|
4
|
+
import { string_agent_name } from '@promptbook-local/types';
|
|
4
5
|
import { revalidatePath } from 'next/cache';
|
|
5
6
|
import { cookies } from 'next/headers';
|
|
6
7
|
import { $provideAgentCollectionForServer } from '../tools/$provideAgentCollectionForServer';
|
|
8
|
+
import { authenticateUser } from '../utils/authenticateUser';
|
|
7
9
|
import { isUserAdmin } from '../utils/isUserAdmin';
|
|
10
|
+
import { clearSession, setSession } from '../utils/session';
|
|
8
11
|
|
|
9
|
-
export async function $createAgentAction() {
|
|
12
|
+
export async function $createAgentAction(): Promise<string_agent_name> {
|
|
10
13
|
// TODO: [👹] Check permissions here
|
|
11
14
|
if (!(await isUserAdmin())) {
|
|
12
15
|
throw new Error('You are not authorized to create agents');
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
const collection = await $provideAgentCollectionForServer();
|
|
16
|
-
|
|
19
|
+
const agentSource = $generateBookBoilerplate();
|
|
20
|
+
|
|
21
|
+
const { agentName } = await collection.createAgent(agentSource);
|
|
22
|
+
|
|
23
|
+
return agentName;
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
export async function loginAction(formData: FormData) {
|
|
@@ -22,24 +29,19 @@ export async function loginAction(formData: FormData) {
|
|
|
22
29
|
|
|
23
30
|
console.info(`Login attempt for user: ${username}`);
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
secure: process.env.NODE_ENV === 'production',
|
|
30
|
-
path: '/',
|
|
31
|
-
maxAge: 60 * 60 * 24 * 30, // 30 days
|
|
32
|
-
});
|
|
32
|
+
const user = await authenticateUser(username, password);
|
|
33
|
+
|
|
34
|
+
if (user) {
|
|
35
|
+
await setSession(user);
|
|
33
36
|
revalidatePath('/', 'layout');
|
|
34
37
|
return { success: true };
|
|
35
38
|
} else {
|
|
36
|
-
return { success: false, message: 'Invalid
|
|
39
|
+
return { success: false, message: 'Invalid credentials' };
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
export async function logoutAction() {
|
|
41
|
-
|
|
42
|
-
cookieStore.delete('adminToken');
|
|
44
|
+
await clearSession();
|
|
43
45
|
revalidatePath('/', 'layout');
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Copy, Plus, Trash } from 'lucide-react';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
type ApiTokenEntry = {
|
|
7
|
+
id: number;
|
|
8
|
+
token: string;
|
|
9
|
+
note: string | null;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
isRevoked: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function ApiTokensClient() {
|
|
16
|
+
const [tokens, setTokens] = useState<ApiTokenEntry[]>([]);
|
|
17
|
+
const [loading, setLoading] = useState(true);
|
|
18
|
+
const [error, setError] = useState<string | null>(null);
|
|
19
|
+
const [note, setNote] = useState('');
|
|
20
|
+
const [isCreating, setIsCreating] = useState(false);
|
|
21
|
+
|
|
22
|
+
const fetchTokens = async () => {
|
|
23
|
+
try {
|
|
24
|
+
setLoading(true);
|
|
25
|
+
const response = await fetch('/api/api-tokens');
|
|
26
|
+
if (!response.ok) {
|
|
27
|
+
throw new Error('Failed to fetch tokens');
|
|
28
|
+
}
|
|
29
|
+
const data: ApiTokenEntry[] = await response.json();
|
|
30
|
+
setTokens(data);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
33
|
+
} finally {
|
|
34
|
+
setLoading(false);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
fetchTokens();
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
const handleCreate = async (e: React.FormEvent) => {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
setError(null);
|
|
45
|
+
setIsCreating(true);
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch('/api/api-tokens', {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: { 'Content-Type': 'application/json' },
|
|
51
|
+
body: JSON.stringify({ note }),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
const data = await response.json();
|
|
56
|
+
throw new Error(data.error || 'Failed to create token');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setNote('');
|
|
60
|
+
fetchTokens();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
63
|
+
} finally {
|
|
64
|
+
setIsCreating(false);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const handleDelete = async (id: number) => {
|
|
69
|
+
if (!confirm('Are you sure you want to delete this token?')) return;
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(`/api/api-tokens?id=${id}`, {
|
|
73
|
+
method: 'DELETE',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const data = await response.json();
|
|
78
|
+
throw new Error(data.error || 'Failed to delete token');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fetchTokens();
|
|
82
|
+
} catch (err) {
|
|
83
|
+
setError(err instanceof Error ? err.message : 'An error occurred');
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const copyToClipboard = (text: string) => {
|
|
88
|
+
navigator.clipboard.writeText(text);
|
|
89
|
+
// You could add a toast notification here
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
if (loading && tokens.length === 0) {
|
|
93
|
+
return <div className="p-8 text-center">Loading tokens...</div>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div className="container mx-auto p-8 max-w-4xl">
|
|
98
|
+
<h1 className="text-3xl font-bold mb-8">API Tokens</h1>
|
|
99
|
+
|
|
100
|
+
{error && (
|
|
101
|
+
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-6">{error}</div>
|
|
102
|
+
)}
|
|
103
|
+
|
|
104
|
+
<div className="bg-white shadow rounded-lg p-6 mb-8">
|
|
105
|
+
<h2 className="text-xl font-semibold mb-4">Create New Token</h2>
|
|
106
|
+
<form onSubmit={handleCreate} className="flex gap-4">
|
|
107
|
+
<input
|
|
108
|
+
type="text"
|
|
109
|
+
value={note}
|
|
110
|
+
onChange={(e) => setNote(e.target.value)}
|
|
111
|
+
className="flex-grow px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
112
|
+
placeholder="Description (optional)"
|
|
113
|
+
/>
|
|
114
|
+
<button
|
|
115
|
+
type="submit"
|
|
116
|
+
disabled={isCreating}
|
|
117
|
+
className="bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 transition-colors flex items-center gap-2 whitespace-nowrap"
|
|
118
|
+
>
|
|
119
|
+
<Plus className="w-4 h-4" />
|
|
120
|
+
{isCreating ? 'Creating...' : 'Create Token'}
|
|
121
|
+
</button>
|
|
122
|
+
</form>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div className="bg-white shadow rounded-lg overflow-hidden">
|
|
126
|
+
<table className="min-w-full divide-y divide-gray-200">
|
|
127
|
+
<thead className="bg-gray-50">
|
|
128
|
+
<tr>
|
|
129
|
+
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
130
|
+
Token
|
|
131
|
+
</th>
|
|
132
|
+
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
133
|
+
Note
|
|
134
|
+
</th>
|
|
135
|
+
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
136
|
+
Created At
|
|
137
|
+
</th>
|
|
138
|
+
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
139
|
+
Actions
|
|
140
|
+
</th>
|
|
141
|
+
</tr>
|
|
142
|
+
</thead>
|
|
143
|
+
<tbody className="bg-white divide-y divide-gray-200">
|
|
144
|
+
{tokens.length === 0 ? (
|
|
145
|
+
<tr>
|
|
146
|
+
<td colSpan={4} className="px-6 py-4 text-center text-gray-500">
|
|
147
|
+
No tokens found.
|
|
148
|
+
</td>
|
|
149
|
+
</tr>
|
|
150
|
+
) : (
|
|
151
|
+
tokens.map((entry) => (
|
|
152
|
+
<tr key={entry.id}>
|
|
153
|
+
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 font-mono">
|
|
154
|
+
<div className="flex items-center gap-2">
|
|
155
|
+
<span>{entry.token}</span>
|
|
156
|
+
<button
|
|
157
|
+
onClick={() => copyToClipboard(entry.token)}
|
|
158
|
+
className="text-gray-400 hover:text-gray-600"
|
|
159
|
+
title="Copy to clipboard"
|
|
160
|
+
>
|
|
161
|
+
<Copy className="w-4 h-4" />
|
|
162
|
+
</button>
|
|
163
|
+
</div>
|
|
164
|
+
</td>
|
|
165
|
+
<td className="px-6 py-4 text-sm text-gray-500">{entry.note || '-'}</td>
|
|
166
|
+
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
|
167
|
+
{new Date(entry.createdAt).toLocaleDateString()}
|
|
168
|
+
</td>
|
|
169
|
+
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
170
|
+
<button
|
|
171
|
+
onClick={() => handleDelete(entry.id)}
|
|
172
|
+
className="text-red-600 hover:text-red-900"
|
|
173
|
+
title="Delete token"
|
|
174
|
+
>
|
|
175
|
+
<Trash className="w-4 h-4" />
|
|
176
|
+
</button>
|
|
177
|
+
</td>
|
|
178
|
+
</tr>
|
|
179
|
+
))
|
|
180
|
+
)}
|
|
181
|
+
</tbody>
|
|
182
|
+
</table>
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ForbiddenPage } from '../../../components/ForbiddenPage/ForbiddenPage';
|
|
2
|
+
import { isUserAdmin } from '../../../utils/isUserAdmin';
|
|
3
|
+
import { ApiTokensClient } from './ApiTokensClient';
|
|
4
|
+
|
|
5
|
+
export default async function ApiTokensPage() {
|
|
6
|
+
const isAdmin = await isUserAdmin();
|
|
7
|
+
|
|
8
|
+
if (!isAdmin) {
|
|
9
|
+
return <ForbiddenPage />;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return <ApiTokensClient />;
|
|
13
|
+
}
|