@promptbook/cli 0.103.0-55 → 0.103.0-56
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/package-lock.json +1163 -0
- package/apps/agents-server/package.json +6 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentChatWrapper.tsx +3 -1
- package/apps/agents-server/src/app/agents/[agentName]/AgentOptionsMenu.tsx +216 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileChat.tsx +78 -0
- package/apps/agents-server/src/app/agents/[agentName]/AgentProfileView.tsx +233 -0
- package/apps/agents-server/src/app/agents/[agentName]/CloneAgentButton.tsx +4 -4
- package/apps/agents-server/src/app/agents/[agentName]/InstallPwaButton.tsx +2 -2
- package/apps/agents-server/src/app/agents/[agentName]/QrCodeModal.tsx +90 -0
- package/apps/agents-server/src/app/agents/[agentName]/agentLinks.tsx +80 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/book/route.ts +3 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +11 -1
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/models/route.ts +93 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/v1/chat/completions/route.ts +10 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/openai/v1/models/route.ts +93 -0
- package/apps/agents-server/src/app/agents/[agentName]/api/voice/route.ts +4 -0
- package/apps/agents-server/src/app/agents/[agentName]/chat/page.tsx +9 -2
- package/apps/agents-server/src/app/agents/[agentName]/integration/SdkCodeTabs.tsx +31 -0
- package/apps/agents-server/src/app/agents/[agentName]/integration/page.tsx +271 -30
- package/apps/agents-server/src/app/agents/[agentName]/links/page.tsx +61 -97
- package/apps/agents-server/src/app/agents/[agentName]/page.tsx +108 -165
- package/apps/agents-server/src/app/agents/[agentName]/website-integration/page.tsx +61 -0
- package/apps/agents-server/src/app/api/openai/v1/chat/completions/route.ts +6 -0
- package/apps/agents-server/src/app/api/openai/v1/models/route.ts +65 -0
- package/apps/agents-server/src/app/docs/[docId]/page.tsx +12 -32
- package/apps/agents-server/src/app/docs/page.tsx +42 -17
- package/apps/agents-server/src/app/globals.css +129 -0
- package/apps/agents-server/src/app/layout.tsx +8 -2
- package/apps/agents-server/src/app/manifest.ts +1 -1
- package/apps/agents-server/src/components/DocumentationContent/DocumentationContent.tsx +87 -0
- package/apps/agents-server/src/components/OpenMojiIcon/OpenMojiIcon.tsx +20 -0
- package/apps/agents-server/src/components/PrintButton/PrintButton.tsx +18 -0
- package/apps/agents-server/src/components/PrintHeader/PrintHeader.tsx +18 -0
- package/apps/agents-server/src/database/migrations/2025-12-0070-chat-history-source.sql +2 -0
- package/apps/agents-server/src/database/schema.ts +6 -0
- package/apps/agents-server/src/utils/handleChatCompletion.ts +186 -14
- package/apps/agents-server/src/utils/resolveInheritedAgentSource.ts +13 -6
- package/apps/agents-server/src/utils/validateApiKey.ts +128 -0
- package/apps/agents-server/tailwind.config.ts +1 -1
- package/esm/index.es.js +865 -441
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/_packages/core.index.d.ts +6 -8
- package/esm/typings/src/_packages/types.index.d.ts +1 -1
- package/esm/typings/src/book-components/Chat/LlmChat/LlmChatProps.d.ts +5 -0
- package/esm/typings/src/commitments/META_COLOR/META_COLOR.d.ts +6 -0
- package/esm/typings/src/commitments/META_FONT/META_FONT.d.ts +42 -0
- package/esm/typings/src/commitments/USE/USE.d.ts +53 -0
- package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.d.ts +38 -0
- package/esm/typings/src/commitments/USE_BROWSER/USE_BROWSER.test.d.ts +1 -0
- package/esm/typings/src/commitments/{IMPORTANT/IMPORTANT.d.ts → USE_MCP/USE_MCP.d.ts} +16 -5
- package/esm/typings/src/commitments/USE_SEARCH_ENGINE/USE_SEARCH_ENGINE.d.ts +38 -0
- package/esm/typings/src/commitments/index.d.ts +93 -1
- package/esm/typings/src/playground/playground.d.ts +3 -0
- package/esm/typings/src/utils/color/Color.d.ts +8 -0
- package/esm/typings/src/utils/color/css-colors.d.ts +1 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/umd/index.umd.js +861 -437
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/commitments/registry.d.ts +0 -68
- package/esm/typings/src/playground/playground1.d.ts +0 -2
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createClient } from '@supabase/supabase-js';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
import { SERVERS, SUPABASE_TABLE_PREFIX } from '../../config';
|
|
4
|
+
|
|
5
|
+
// Note: Re-implementing normalizeTo_PascalCase to avoid importing from @promptbook-local/utils which might have Node.js dependencies
|
|
6
|
+
function normalizeTo_PascalCase(text: string): string {
|
|
7
|
+
return text
|
|
8
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => {
|
|
9
|
+
return word.toUpperCase();
|
|
10
|
+
})
|
|
11
|
+
.replace(/\s+/g, '');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ApiKeyValidationResult = {
|
|
15
|
+
isValid: boolean;
|
|
16
|
+
token?: string;
|
|
17
|
+
error?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Validates an API key from the Authorization header.
|
|
22
|
+
* Returns validation result with status and optional error message.
|
|
23
|
+
*
|
|
24
|
+
* Note: This function provides explicit API key validation in addition to middleware.
|
|
25
|
+
* Use this when you need to verify API key validity and return specific error messages.
|
|
26
|
+
*/
|
|
27
|
+
export async function validateApiKey(request: NextRequest): Promise<ApiKeyValidationResult> {
|
|
28
|
+
const authHeader = request.headers.get('authorization');
|
|
29
|
+
|
|
30
|
+
// If no auth header, check if user has a session cookie (logged in via web)
|
|
31
|
+
if (!authHeader) {
|
|
32
|
+
const hasSession = request.cookies.has('sessionToken');
|
|
33
|
+
if (hasSession) {
|
|
34
|
+
return { isValid: true };
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
isValid: false,
|
|
38
|
+
error: 'Missing Authorization header. Provide a valid API key using "Authorization: Bearer ptbk_..."',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!authHeader.startsWith('Bearer ')) {
|
|
43
|
+
return {
|
|
44
|
+
isValid: false,
|
|
45
|
+
error: 'Invalid Authorization header format. Expected "Bearer <token>"',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const token = authHeader.split(' ')[1];
|
|
50
|
+
|
|
51
|
+
if (!token) {
|
|
52
|
+
return {
|
|
53
|
+
isValid: false,
|
|
54
|
+
error: 'No token provided in Authorization header',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!token.startsWith('ptbk_')) {
|
|
59
|
+
return {
|
|
60
|
+
isValid: false,
|
|
61
|
+
error: 'Invalid API key format. API keys must start with "ptbk_"',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Determine the table prefix based on the host
|
|
66
|
+
const host = request.headers.get('host');
|
|
67
|
+
let tablePrefix = SUPABASE_TABLE_PREFIX;
|
|
68
|
+
|
|
69
|
+
if (host && SERVERS && SERVERS.length > 0) {
|
|
70
|
+
if (SERVERS.some((server) => server === host)) {
|
|
71
|
+
let serverName = host;
|
|
72
|
+
serverName = serverName.replace(/\.ptbk\.io$/, '');
|
|
73
|
+
serverName = normalizeTo_PascalCase(serverName);
|
|
74
|
+
tablePrefix = `server_${serverName}_`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
|
79
|
+
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
|
80
|
+
|
|
81
|
+
if (!supabaseUrl || !supabaseKey) {
|
|
82
|
+
console.error('Supabase configuration missing for API key validation');
|
|
83
|
+
return {
|
|
84
|
+
isValid: false,
|
|
85
|
+
error: 'Server configuration error',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const supabase = createClient(supabaseUrl, supabaseKey, {
|
|
91
|
+
auth: {
|
|
92
|
+
persistSession: false,
|
|
93
|
+
autoRefreshToken: false,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const { data, error } = await supabase
|
|
98
|
+
.from(`${tablePrefix}ApiTokens`)
|
|
99
|
+
.select('id, isRevoked')
|
|
100
|
+
.eq('token', token)
|
|
101
|
+
.single();
|
|
102
|
+
|
|
103
|
+
if (error || !data) {
|
|
104
|
+
return {
|
|
105
|
+
isValid: false,
|
|
106
|
+
error: 'Invalid API key',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (data.isRevoked) {
|
|
111
|
+
return {
|
|
112
|
+
isValid: false,
|
|
113
|
+
error: 'API key has been revoked',
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
isValid: true,
|
|
119
|
+
token,
|
|
120
|
+
};
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error('Error validating API key:', error);
|
|
123
|
+
return {
|
|
124
|
+
isValid: false,
|
|
125
|
+
error: 'Error validating API key',
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|