@promptbook/remote-server 0.100.0-1 → 0.100.0-11
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 +49 -149
- 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/esm/typings/src/wizard/wizard.d.ts +14 -4
- package/package.json +2 -2
- package/umd/index.umd.js +49 -149
- 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
|
@@ -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-
|
|
18
|
+
* It follows semantic versioning (e.g., `0.100.0-10`).
|
|
19
19
|
*
|
|
20
20
|
* @generated
|
|
21
21
|
*/
|
|
@@ -6,6 +6,15 @@ import type { InputParameters } from '../types/typeAliases';
|
|
|
6
6
|
import type { string_filename } from '../types/typeAliases';
|
|
7
7
|
import type { string_parameter_value } from '../types/typeAliases';
|
|
8
8
|
import type { string_pipeline_url } from '../types/typeAliases';
|
|
9
|
+
/**
|
|
10
|
+
* Options for wizard methods
|
|
11
|
+
*/
|
|
12
|
+
interface WizardOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Whether to enable verbose logging
|
|
15
|
+
*/
|
|
16
|
+
isVerbose?: boolean;
|
|
17
|
+
}
|
|
9
18
|
/**
|
|
10
19
|
* Wizard for simple usage of the Promptbook
|
|
11
20
|
* Look at `wizard` for more details
|
|
@@ -26,7 +35,7 @@ declare class Wizard {
|
|
|
26
35
|
*
|
|
27
36
|
* Note: This works similar to the `ptbk run` command
|
|
28
37
|
*/
|
|
29
|
-
execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters): Promise<{
|
|
38
|
+
execute(book: string_pipeline_url | string_filename | PipelineString, inputParameters: InputParameters, options?: WizardOptions): Promise<{
|
|
30
39
|
/**
|
|
31
40
|
* Simple result of the execution
|
|
32
41
|
*/
|
|
@@ -36,9 +45,9 @@ declare class Wizard {
|
|
|
36
45
|
/**
|
|
37
46
|
* Provides the tools automatically for the Node.js environment
|
|
38
47
|
*
|
|
39
|
-
* @param
|
|
48
|
+
* @param options
|
|
40
49
|
*/
|
|
41
|
-
getExecutionTools(): Promise<Required<Pick<ExecutionTools, 'fs' | 'fetch'>>>;
|
|
50
|
+
getExecutionTools(options?: WizardOptions): Promise<Required<Pick<ExecutionTools, 'fs' | 'fetch'>>>;
|
|
42
51
|
/**
|
|
43
52
|
* Load book from the source
|
|
44
53
|
*
|
|
@@ -49,8 +58,9 @@ declare class Wizard {
|
|
|
49
58
|
* 3) As a string
|
|
50
59
|
*
|
|
51
60
|
* @param pipelineSource
|
|
61
|
+
* @param options
|
|
52
62
|
*/
|
|
53
|
-
getCompiledBook(pipelineSource: string_filename | string_pipeline_url | PipelineString): Promise<PipelineJson>;
|
|
63
|
+
getCompiledBook(pipelineSource: string_filename | string_pipeline_url | PipelineString, options?: WizardOptions): Promise<PipelineJson>;
|
|
54
64
|
}
|
|
55
65
|
/**
|
|
56
66
|
* Wizard for simple usage of the Promptbook
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promptbook/remote-server",
|
|
3
|
-
"version": "0.100.0-
|
|
3
|
+
"version": "0.100.0-11",
|
|
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-
|
|
98
|
+
"@promptbook/core": "0.100.0-11"
|
|
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-
|
|
51
|
+
const PROMPTBOOK_ENGINE_VERSION = '0.100.0-11';
|
|
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
|
|
@@ -3837,12 +3837,58 @@
|
|
|
3837
3837
|
// <- TODO: [🥬] Encapsulate sha256 to some private utility function
|
|
3838
3838
|
const rootDirname = path.join(process.cwd(), DEFAULT_DOWNLOAD_CACHE_DIRNAME);
|
|
3839
3839
|
const filepath = path.join(...nameToSubfolderPath(hash /* <- TODO: [🎎] Maybe add some SHA256 prefix */), `${basename.substring(0, MAX_FILENAME_LENGTH)}.${mimeTypeToExtension(mimeType)}`);
|
|
3840
|
-
|
|
3840
|
+
// Note: Try to create cache directory, but don't fail if filesystem has issues
|
|
3841
|
+
try {
|
|
3842
|
+
await tools.fs.mkdir(path.dirname(path.join(rootDirname, filepath)), { recursive: true });
|
|
3843
|
+
}
|
|
3844
|
+
catch (error) {
|
|
3845
|
+
// Note: If we can't create cache directory, we'll handle it when trying to write the file
|
|
3846
|
+
// This handles read-only filesystems, permission issues, and missing parent directories
|
|
3847
|
+
if (error instanceof Error && (error.message.includes('EROFS') ||
|
|
3848
|
+
error.message.includes('read-only') ||
|
|
3849
|
+
error.message.includes('EACCES') ||
|
|
3850
|
+
error.message.includes('EPERM') ||
|
|
3851
|
+
error.message.includes('ENOENT'))) ;
|
|
3852
|
+
else {
|
|
3853
|
+
// Re-throw other unexpected errors
|
|
3854
|
+
throw error;
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3841
3857
|
const fileContent = Buffer.from(await response.arrayBuffer());
|
|
3842
3858
|
if (fileContent.length > DEFAULT_MAX_FILE_SIZE /* <- TODO: Allow to pass different value to remote server */) {
|
|
3843
3859
|
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
3860
|
}
|
|
3845
|
-
|
|
3861
|
+
// Note: Try to cache the downloaded file, but don't fail if the filesystem is read-only
|
|
3862
|
+
try {
|
|
3863
|
+
await tools.fs.writeFile(path.join(rootDirname, filepath), fileContent);
|
|
3864
|
+
}
|
|
3865
|
+
catch (error) {
|
|
3866
|
+
// Note: If we can't write to cache, we'll process the file directly from memory
|
|
3867
|
+
// This handles read-only filesystems like Vercel
|
|
3868
|
+
if (error instanceof Error && (error.message.includes('EROFS') ||
|
|
3869
|
+
error.message.includes('read-only') ||
|
|
3870
|
+
error.message.includes('EACCES') ||
|
|
3871
|
+
error.message.includes('EPERM') ||
|
|
3872
|
+
error.message.includes('ENOENT'))) {
|
|
3873
|
+
// Return a handler that works directly with the downloaded content
|
|
3874
|
+
return {
|
|
3875
|
+
source: name,
|
|
3876
|
+
filename: null,
|
|
3877
|
+
url,
|
|
3878
|
+
mimeType,
|
|
3879
|
+
async asJson() {
|
|
3880
|
+
return JSON.parse(fileContent.toString('utf-8'));
|
|
3881
|
+
},
|
|
3882
|
+
async asText() {
|
|
3883
|
+
return fileContent.toString('utf-8');
|
|
3884
|
+
},
|
|
3885
|
+
};
|
|
3886
|
+
}
|
|
3887
|
+
else {
|
|
3888
|
+
// Re-throw other unexpected errors
|
|
3889
|
+
throw error;
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3846
3892
|
// TODO: [💵] Check the file security
|
|
3847
3893
|
// TODO: [🧹][🧠] Delete the file after the scraping is done
|
|
3848
3894
|
return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
|
|
@@ -8076,152 +8122,6 @@
|
|
|
8076
8122
|
response.status(400).send({ error: serializeError(error) });
|
|
8077
8123
|
}
|
|
8078
8124
|
});
|
|
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
8125
|
app.get(`/books`, async (request, response) => {
|
|
8226
8126
|
if (collection === null) {
|
|
8227
8127
|
response.status(500).send('No collection available');
|