@promptbook/remote-server 0.100.0-1 โ†’ 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.
@@ -138,9 +138,6 @@ export declare const SMALL_NUMBER = 0.001;
138
138
  /**
139
139
  * Timeout for the connections in milliseconds
140
140
  *
141
- * Note: Increased from 7 seconds to 30 seconds to accommodate OAuth flows
142
- * like Facebook login which may require user interaction and redirects
143
- *
144
141
  * @private within the repository - too low-level in comparison with other `MAX_...`
145
142
  */
146
143
  export declare const CONNECTION_TIMEOUT_MS: number;
@@ -150,13 +147,6 @@ export declare const CONNECTION_TIMEOUT_MS: number;
150
147
  * @private within the repository - too low-level in comparison with other `MAX_...`
151
148
  */
152
149
  export declare const CONNECTION_RETRIES_LIMIT = 5;
153
- /**
154
- * Timeout specifically for OAuth authentication flows in milliseconds
155
- * OAuth flows typically require more time due to user interaction and redirects
156
- *
157
- * @private within the repository - too low-level in comparison with other `MAX_...`
158
- */
159
- export declare const OAUTH_TIMEOUT_MS: number;
160
150
  /**
161
151
  * Short time interval to prevent race conditions in milliseconds
162
152
  *
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.100.0-0`).
18
+ * It follows semantic versioning (e.g., `0.100.0-1`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/remote-server",
3
- "version": "0.100.0-1",
3
+ "version": "0.100.0-2",
4
4
  "description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -95,7 +95,7 @@
95
95
  "module": "./esm/index.es.js",
96
96
  "typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
97
97
  "peerDependencies": {
98
- "@promptbook/core": "0.100.0-1"
98
+ "@promptbook/core": "0.100.0-2"
99
99
  },
100
100
  "dependencies": {
101
101
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -48,7 +48,7 @@
48
48
  * @generated
49
49
  * @see https://github.com/webgptorg/promptbook
50
50
  */
51
- const PROMPTBOOK_ENGINE_VERSION = '0.100.0-1';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.0-2';
52
52
  /**
53
53
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
54
54
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -3842,7 +3842,36 @@
3842
3842
  if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
3843
3843
  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.`);
3844
3844
  }
3845
- await tools.fs.writeFile(path.join(rootDirname, filepath), fileContent);
3845
+ // Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
3846
+ try {
3847
+ await tools.fs.writeFile(path.join(rootDirname, filepath), fileContent);
3848
+ }
3849
+ catch (error) {
3850
+ // Note: If we can't write to cache, we'll process the file directly from memory
3851
+ // This handles read-only filesystems like Vercel
3852
+ if (error instanceof Error && (error.message.includes('EROFS') ||
3853
+ error.message.includes('read-only') ||
3854
+ error.message.includes('EACCES') ||
3855
+ error.message.includes('EPERM'))) {
3856
+ // Return a handler that works directly with the downloaded content
3857
+ return {
3858
+ source: name,
3859
+ filename: null,
3860
+ url,
3861
+ mimeType,
3862
+ async asJson() {
3863
+ return JSON.parse(fileContent.toString('utf-8'));
3864
+ },
3865
+ async asText() {
3866
+ return fileContent.toString('utf-8');
3867
+ },
3868
+ };
3869
+ }
3870
+ else {
3871
+ // Re-throw other unexpected errors
3872
+ throw error;
3873
+ }
3874
+ }
3846
3875
  // TODO: [๐Ÿ’ต] Check the file security
3847
3876
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
3848
3877
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
@@ -8076,152 +8105,6 @@
8076
8105
  response.status(400).send({ error: serializeError(error) });
8077
8106
  }
8078
8107
  });
8079
- // OAuth Authentication Endpoints
8080
- // These endpoints provide social authentication support (Facebook, Google, etc.)
8081
- app.get('/auth/:provider', async (request, response) => {
8082
- const { provider } = request.params;
8083
- if (!isApplicationModeAllowed) {
8084
- response.status(400).json({
8085
- error: 'Application mode is not allowed',
8086
- message: 'Social authentication requires application mode to be enabled'
8087
- });
8088
- return;
8089
- }
8090
- try {
8091
- // Get OAuth configuration from query params or environment
8092
- const { redirectUri, clientId, appId } = request.query;
8093
- if (!redirectUri || !clientId) {
8094
- response.status(400).json({
8095
- error: 'Missing OAuth parameters',
8096
- message: 'redirectUri and clientId are required for OAuth flow'
8097
- });
8098
- return;
8099
- }
8100
- let authUrl;
8101
- const state = Buffer.from(JSON.stringify({
8102
- appId: appId || 'default',
8103
- timestamp: Date.now()
8104
- })).toString('base64');
8105
- switch (provider.toLowerCase()) {
8106
- case 'facebook':
8107
- authUrl = `https://www.facebook.com/v18.0/dialog/oauth?` +
8108
- `client_id=${encodeURIComponent(clientId)}&` +
8109
- `redirect_uri=${encodeURIComponent(redirectUri)}&` +
8110
- `scope=email,public_profile&` +
8111
- `response_type=code&` +
8112
- `state=${encodeURIComponent(state)}`;
8113
- break;
8114
- case 'google':
8115
- authUrl = `https://accounts.google.com/o/oauth2/v2/auth?` +
8116
- `client_id=${encodeURIComponent(clientId)}&` +
8117
- `redirect_uri=${encodeURIComponent(redirectUri)}&` +
8118
- `scope=openid%20email%20profile&` +
8119
- `response_type=code&` +
8120
- `state=${encodeURIComponent(state)}`;
8121
- break;
8122
- default:
8123
- response.status(400).json({
8124
- error: 'Unsupported provider',
8125
- message: `Social authentication provider '${provider}' is not supported. Supported providers: facebook, google`
8126
- });
8127
- return;
8128
- }
8129
- // Log the OAuth attempt for debugging
8130
- if (isVerbose) {
8131
- console.info(colors__default["default"].cyan(`OAuth ${provider} flow started for app ${appId || 'default'}`));
8132
- }
8133
- response.json({
8134
- authUrl,
8135
- provider,
8136
- state,
8137
- message: `Redirect user to authUrl to complete ${provider} authentication`
8138
- });
8139
- }
8140
- catch (error) {
8141
- assertsError(error);
8142
- console.warn(`OAuth ${provider} initialization failed:`, error);
8143
- response.status(500).json({
8144
- error: 'OAuth initialization failed',
8145
- message: error.message
8146
- });
8147
- }
8148
- });
8149
- app.post('/auth/:provider/callback', async (request, response) => {
8150
- const { provider } = request.params;
8151
- if (!isApplicationModeAllowed || login === null) {
8152
- response.status(400).json({
8153
- error: 'Application mode is not allowed',
8154
- message: 'Social authentication requires application mode and login handler to be configured'
8155
- });
8156
- return;
8157
- }
8158
- try {
8159
- const { code, state, error: oauthError } = request.body;
8160
- if (oauthError) {
8161
- response.status(400).json({
8162
- isSuccess: false,
8163
- error: 'OAuth authorization failed',
8164
- message: `${provider} authentication was denied or failed: ${oauthError}`
8165
- });
8166
- return;
8167
- }
8168
- if (!code || !state) {
8169
- response.status(400).json({
8170
- isSuccess: false,
8171
- error: 'Missing OAuth callback parameters',
8172
- message: 'code and state parameters are required'
8173
- });
8174
- return;
8175
- }
8176
- // Decode state to get app information
8177
- let appInfo;
8178
- try {
8179
- appInfo = JSON.parse(Buffer.from(state, 'base64').toString());
8180
- }
8181
- catch (_a) {
8182
- response.status(400).json({
8183
- isSuccess: false,
8184
- error: 'Invalid state parameter',
8185
- message: 'The OAuth state parameter is malformed'
8186
- });
8187
- return;
8188
- }
8189
- // Log the OAuth callback for debugging
8190
- if (isVerbose) {
8191
- console.info(colors__default["default"].cyan(`OAuth ${provider} callback received for app ${appInfo.appId}`));
8192
- }
8193
- // Note: In a real implementation, you would:
8194
- // 1. Exchange the code for an access token with the OAuth provider
8195
- // 2. Use the access token to get user information
8196
- // 3. Create or find the user in your system
8197
- // 4. Call the login function with the user's information
8198
- // For now, we provide a framework that the implementer can extend
8199
- const mockUserInfo = {
8200
- username: `${provider}_user_${code.substring(0, 8)}`,
8201
- password: '',
8202
- appId: appInfo.appId
8203
- };
8204
- const loginResult = await login({
8205
- ...mockUserInfo,
8206
- rawRequest: request,
8207
- rawResponse: response,
8208
- });
8209
- response.status(200).json({
8210
- ...loginResult,
8211
- provider,
8212
- message: loginResult.message || `${provider} authentication completed`,
8213
- });
8214
- }
8215
- catch (error) {
8216
- assertsError(error);
8217
- console.warn(`OAuth ${provider} callback failed:`, error);
8218
- response.status(500).json({
8219
- isSuccess: false,
8220
- error: 'OAuth callback processing failed',
8221
- message: error.message
8222
- });
8223
- }
8224
- });
8225
8108
  app.get(`/books`, async (request, response) => {
8226
8109
  if (collection === null) {
8227
8110
  response.status(500).send('No collection available');