@promptbook/remote-server 0.98.0 → 0.100.0-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.
- package/README.md +4 -0
- package/esm/index.es.js +147 -1
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/config.d.ts +10 -0
- package/esm/typings/src/remote-server/connection-improvements.test.d.ts +1 -0
- package/esm/typings/src/remote-server/utils/connectionProgress.d.ts +72 -0
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +147 -1
- package/umd/index.umd.js.map +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,10 @@ Write AI applications using plain human language across multiple models and plat
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
<blockquote style="color: #ff8811">
|
|
29
|
+
<b>⚠ Warning:</b> This is a pre-release version of the library. It is not yet ready for production use. Please look at <a href="https://www.npmjs.com/package/@promptbook/core?activeTab=versions">latest stable release</a>.
|
|
30
|
+
</blockquote>
|
|
31
|
+
|
|
28
32
|
## 📦 Package `@promptbook/remote-server`
|
|
29
33
|
|
|
30
34
|
- Promptbooks are [divided into several](#-packages) packages, all are published from [single monorepo](https://github.com/webgptorg/promptbook).
|
package/esm/index.es.js
CHANGED
|
@@ -33,7 +33,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
|
|
|
33
33
|
* @generated
|
|
34
34
|
* @see https://github.com/webgptorg/promptbook
|
|
35
35
|
*/
|
|
36
|
-
const PROMPTBOOK_ENGINE_VERSION = '0.
|
|
36
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-0';
|
|
37
37
|
/**
|
|
38
38
|
* TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
|
|
39
39
|
* Note: [💞] Ignore a discrepancy between file name and entity name
|
|
@@ -8061,6 +8061,152 @@ function startRemoteServer(options) {
|
|
|
8061
8061
|
response.status(400).send({ error: serializeError(error) });
|
|
8062
8062
|
}
|
|
8063
8063
|
});
|
|
8064
|
+
// OAuth Authentication Endpoints
|
|
8065
|
+
// These endpoints provide social authentication support (Facebook, Google, etc.)
|
|
8066
|
+
app.get('/auth/:provider', async (request, response) => {
|
|
8067
|
+
const { provider } = request.params;
|
|
8068
|
+
if (!isApplicationModeAllowed) {
|
|
8069
|
+
response.status(400).json({
|
|
8070
|
+
error: 'Application mode is not allowed',
|
|
8071
|
+
message: 'Social authentication requires application mode to be enabled'
|
|
8072
|
+
});
|
|
8073
|
+
return;
|
|
8074
|
+
}
|
|
8075
|
+
try {
|
|
8076
|
+
// Get OAuth configuration from query params or environment
|
|
8077
|
+
const { redirectUri, clientId, appId } = request.query;
|
|
8078
|
+
if (!redirectUri || !clientId) {
|
|
8079
|
+
response.status(400).json({
|
|
8080
|
+
error: 'Missing OAuth parameters',
|
|
8081
|
+
message: 'redirectUri and clientId are required for OAuth flow'
|
|
8082
|
+
});
|
|
8083
|
+
return;
|
|
8084
|
+
}
|
|
8085
|
+
let authUrl;
|
|
8086
|
+
const state = Buffer.from(JSON.stringify({
|
|
8087
|
+
appId: appId || 'default',
|
|
8088
|
+
timestamp: Date.now()
|
|
8089
|
+
})).toString('base64');
|
|
8090
|
+
switch (provider.toLowerCase()) {
|
|
8091
|
+
case 'facebook':
|
|
8092
|
+
authUrl = `https://www.facebook.com/v18.0/dialog/oauth?` +
|
|
8093
|
+
`client_id=${encodeURIComponent(clientId)}&` +
|
|
8094
|
+
`redirect_uri=${encodeURIComponent(redirectUri)}&` +
|
|
8095
|
+
`scope=email,public_profile&` +
|
|
8096
|
+
`response_type=code&` +
|
|
8097
|
+
`state=${encodeURIComponent(state)}`;
|
|
8098
|
+
break;
|
|
8099
|
+
case 'google':
|
|
8100
|
+
authUrl = `https://accounts.google.com/o/oauth2/v2/auth?` +
|
|
8101
|
+
`client_id=${encodeURIComponent(clientId)}&` +
|
|
8102
|
+
`redirect_uri=${encodeURIComponent(redirectUri)}&` +
|
|
8103
|
+
`scope=openid%20email%20profile&` +
|
|
8104
|
+
`response_type=code&` +
|
|
8105
|
+
`state=${encodeURIComponent(state)}`;
|
|
8106
|
+
break;
|
|
8107
|
+
default:
|
|
8108
|
+
response.status(400).json({
|
|
8109
|
+
error: 'Unsupported provider',
|
|
8110
|
+
message: `Social authentication provider '${provider}' is not supported. Supported providers: facebook, google`
|
|
8111
|
+
});
|
|
8112
|
+
return;
|
|
8113
|
+
}
|
|
8114
|
+
// Log the OAuth attempt for debugging
|
|
8115
|
+
if (isVerbose) {
|
|
8116
|
+
console.info(colors.cyan(`OAuth ${provider} flow started for app ${appId || 'default'}`));
|
|
8117
|
+
}
|
|
8118
|
+
response.json({
|
|
8119
|
+
authUrl,
|
|
8120
|
+
provider,
|
|
8121
|
+
state,
|
|
8122
|
+
message: `Redirect user to authUrl to complete ${provider} authentication`
|
|
8123
|
+
});
|
|
8124
|
+
}
|
|
8125
|
+
catch (error) {
|
|
8126
|
+
assertsError(error);
|
|
8127
|
+
console.warn(`OAuth ${provider} initialization failed:`, error);
|
|
8128
|
+
response.status(500).json({
|
|
8129
|
+
error: 'OAuth initialization failed',
|
|
8130
|
+
message: error.message
|
|
8131
|
+
});
|
|
8132
|
+
}
|
|
8133
|
+
});
|
|
8134
|
+
app.post('/auth/:provider/callback', async (request, response) => {
|
|
8135
|
+
const { provider } = request.params;
|
|
8136
|
+
if (!isApplicationModeAllowed || login === null) {
|
|
8137
|
+
response.status(400).json({
|
|
8138
|
+
error: 'Application mode is not allowed',
|
|
8139
|
+
message: 'Social authentication requires application mode and login handler to be configured'
|
|
8140
|
+
});
|
|
8141
|
+
return;
|
|
8142
|
+
}
|
|
8143
|
+
try {
|
|
8144
|
+
const { code, state, error: oauthError } = request.body;
|
|
8145
|
+
if (oauthError) {
|
|
8146
|
+
response.status(400).json({
|
|
8147
|
+
isSuccess: false,
|
|
8148
|
+
error: 'OAuth authorization failed',
|
|
8149
|
+
message: `${provider} authentication was denied or failed: ${oauthError}`
|
|
8150
|
+
});
|
|
8151
|
+
return;
|
|
8152
|
+
}
|
|
8153
|
+
if (!code || !state) {
|
|
8154
|
+
response.status(400).json({
|
|
8155
|
+
isSuccess: false,
|
|
8156
|
+
error: 'Missing OAuth callback parameters',
|
|
8157
|
+
message: 'code and state parameters are required'
|
|
8158
|
+
});
|
|
8159
|
+
return;
|
|
8160
|
+
}
|
|
8161
|
+
// Decode state to get app information
|
|
8162
|
+
let appInfo;
|
|
8163
|
+
try {
|
|
8164
|
+
appInfo = JSON.parse(Buffer.from(state, 'base64').toString());
|
|
8165
|
+
}
|
|
8166
|
+
catch (_a) {
|
|
8167
|
+
response.status(400).json({
|
|
8168
|
+
isSuccess: false,
|
|
8169
|
+
error: 'Invalid state parameter',
|
|
8170
|
+
message: 'The OAuth state parameter is malformed'
|
|
8171
|
+
});
|
|
8172
|
+
return;
|
|
8173
|
+
}
|
|
8174
|
+
// Log the OAuth callback for debugging
|
|
8175
|
+
if (isVerbose) {
|
|
8176
|
+
console.info(colors.cyan(`OAuth ${provider} callback received for app ${appInfo.appId}`));
|
|
8177
|
+
}
|
|
8178
|
+
// Note: In a real implementation, you would:
|
|
8179
|
+
// 1. Exchange the code for an access token with the OAuth provider
|
|
8180
|
+
// 2. Use the access token to get user information
|
|
8181
|
+
// 3. Create or find the user in your system
|
|
8182
|
+
// 4. Call the login function with the user's information
|
|
8183
|
+
// For now, we provide a framework that the implementer can extend
|
|
8184
|
+
const mockUserInfo = {
|
|
8185
|
+
username: `${provider}_user_${code.substring(0, 8)}`,
|
|
8186
|
+
password: '',
|
|
8187
|
+
appId: appInfo.appId
|
|
8188
|
+
};
|
|
8189
|
+
const loginResult = await login({
|
|
8190
|
+
...mockUserInfo,
|
|
8191
|
+
rawRequest: request,
|
|
8192
|
+
rawResponse: response,
|
|
8193
|
+
});
|
|
8194
|
+
response.status(200).json({
|
|
8195
|
+
...loginResult,
|
|
8196
|
+
provider,
|
|
8197
|
+
message: loginResult.message || `${provider} authentication completed`,
|
|
8198
|
+
});
|
|
8199
|
+
}
|
|
8200
|
+
catch (error) {
|
|
8201
|
+
assertsError(error);
|
|
8202
|
+
console.warn(`OAuth ${provider} callback failed:`, error);
|
|
8203
|
+
response.status(500).json({
|
|
8204
|
+
isSuccess: false,
|
|
8205
|
+
error: 'OAuth callback processing failed',
|
|
8206
|
+
message: error.message
|
|
8207
|
+
});
|
|
8208
|
+
}
|
|
8209
|
+
});
|
|
8064
8210
|
app.get(`/books`, async (request, response) => {
|
|
8065
8211
|
if (collection === null) {
|
|
8066
8212
|
response.status(500).send('No collection available');
|