@promptbook/remote-server 0.100.0-0 โ 0.100.0-2
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/esm/index.es.js +31 -148
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/config.d.ts +0 -10
- package/esm/typings/src/version.d.ts +1 -1
- package/package.json +2 -2
- package/umd/index.umd.js +31 -148
- package/umd/index.umd.js.map +1 -1
- package/esm/typings/src/remote-server/connection-improvements.test.d.ts +0 -1
- package/esm/typings/src/remote-server/utils/connectionProgress.d.ts +0 -72
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.100.0-
|
|
36
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-2';
|
|
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
|
|
@@ -3827,7 +3827,36 @@ async function makeKnowledgeSourceHandler(knowledgeSource, tools, options) {
|
|
|
3827
3827
|
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3828
3828
|
throw new LimitReachedError(`File is too large (${Math.round(fileContent.length / 1024 / 1024)}MB). Maximum allowed size is ${Math.round(DEFAULT_MAX_FILE_SIZE / 1024 / 1024)}MB.`);
|
|
3829
3829
|
}
|
|
3830
|
-
|
|
3830
|
+
// Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
|
|
3831
|
+
try {
|
|
3832
|
+
await tools.fs.writeFile(join(rootDirname, filepath), fileContent);
|
|
3833
|
+
}
|
|
3834
|
+
catch (error) {
|
|
3835
|
+
// Note: If we can't write to cache, we'll process the file directly from memory
|
|
3836
|
+
// This handles read-only filesystems like Vercel
|
|
3837
|
+
if (error instanceof Error && (error.message.includes('EROFS') ||
|
|
3838
|
+
error.message.includes('read-only') ||
|
|
3839
|
+
error.message.includes('EACCES') ||
|
|
3840
|
+
error.message.includes('EPERM'))) {
|
|
3841
|
+
// Return a handler that works directly with the downloaded content
|
|
3842
|
+
return {
|
|
3843
|
+
source: name,
|
|
3844
|
+
filename: null,
|
|
3845
|
+
url,
|
|
3846
|
+
mimeType,
|
|
3847
|
+
async asJson() {
|
|
3848
|
+
return JSON.parse(fileContent.toString('utf-8'));
|
|
3849
|
+
},
|
|
3850
|
+
async asText() {
|
|
3851
|
+
return fileContent.toString('utf-8');
|
|
3852
|
+
},
|
|
3853
|
+
};
|
|
3854
|
+
}
|
|
3855
|
+
else {
|
|
3856
|
+
// Re-throw other unexpected errors
|
|
3857
|
+
throw error;
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3831
3860
|
// TODO: [๐ต] Check the file security
|
|
3832
3861
|
// TODO: [๐งน][๐ง ] Delete the file after the scraping is done
|
|
3833
3862
|
return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
|
|
@@ -8061,152 +8090,6 @@ function startRemoteServer(options) {
|
|
|
8061
8090
|
response.status(400).send({ error: serializeError(error) });
|
|
8062
8091
|
}
|
|
8063
8092
|
});
|
|
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
|
-
});
|
|
8210
8093
|
app.get(`/books`, async (request, response) => {
|
|
8211
8094
|
if (collection === null) {
|
|
8212
8095
|
response.status(500).send('No collection available');
|