@promptbook/remote-server 0.98.0-9 → 0.99.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.
@@ -138,6 +138,9 @@ 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
+ *
141
144
  * @private within the repository - too low-level in comparison with other `MAX_...`
142
145
  */
143
146
  export declare const CONNECTION_TIMEOUT_MS: number;
@@ -147,6 +150,13 @@ export declare const CONNECTION_TIMEOUT_MS: number;
147
150
  * @private within the repository - too low-level in comparison with other `MAX_...`
148
151
  */
149
152
  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;
150
160
  /**
151
161
  * Short time interval to prevent race conditions in milliseconds
152
162
  *
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Connection progress utilities for better user experience during authentication
3
+ */
4
+ /**
5
+ * Connection status types for better progress indication
6
+ *
7
+ * @private
8
+ */
9
+ export type ConnectionStatus = 'connecting' | 'authenticating' | 'connected' | 'disconnected' | 'error' | 'timeout';
10
+ /**
11
+ * Progress callback function type for connection status updates
12
+ *
13
+ * @private
14
+ */
15
+ export type ConnectionProgressCallback = (status: ConnectionStatus, message?: string) => void;
16
+ /**
17
+ * Enhanced connection options with progress reporting
18
+ *
19
+ * @private
20
+ */
21
+ export interface ConnectionProgressOptions {
22
+ onProgress?: ConnectionProgressCallback;
23
+ enableProgressReporting?: boolean;
24
+ }
25
+ /**
26
+ * Default progress messages for different connection states
27
+ *
28
+ * @private
29
+ */
30
+ export declare const DEFAULT_PROGRESS_MESSAGES: {
31
+ readonly connecting: "Connecting to Promptbook server...";
32
+ readonly authenticating: "Authenticating with social provider (Facebook, Google, etc.)...";
33
+ readonly connected: "Successfully connected to Promptbook server";
34
+ readonly disconnected: "Disconnected from Promptbook server";
35
+ readonly error: "Connection failed";
36
+ readonly timeout: "Connection timed out - this may happen during social login flows";
37
+ };
38
+ /**
39
+ * Creates a progress reporter for connection status
40
+ * This can be used by frontend applications to show connection progress
41
+ *
42
+ * @private
43
+ */
44
+ export declare function createConnectionProgressReporter(callback?: ConnectionProgressCallback): ConnectionProgressCallback;
45
+ /**
46
+ * Timeout constants with descriptions for different connection types
47
+ *
48
+ * @private
49
+ */
50
+ export declare const CONNECTION_TIMEOUTS: {
51
+ /** Standard timeout for regular connections */
52
+ readonly STANDARD: number;
53
+ /** Extended timeout for OAuth flows that require user interaction */
54
+ readonly OAUTH: number;
55
+ /** Short timeout for quick health checks */
56
+ readonly HEALTH_CHECK: number;
57
+ };
58
+ /**
59
+ * Helper function to get appropriate timeout based on connection type
60
+ *
61
+ * @private
62
+ */
63
+ export declare function getConnectionTimeout(type: 'standard' | 'oauth' | 'health_check'): number;
64
+ /**
65
+ * Creates a timeout wrapper with progress reporting
66
+ *
67
+ * @private
68
+ */
69
+ export declare function createTimeoutWithProgress(timeoutMs: number, onProgress?: ConnectionProgressCallback): Promise<never>;
70
+ /**
71
+ * Note: [💞] Ignore a discrepancy between file name and entity name
72
+ */
@@ -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.98.0-8`).
18
+ * It follows semantic versioning (e.g., `0.98.0`).
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.98.0-9",
3
+ "version": "0.99.0-0",
4
4
  "description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -15,51 +15,72 @@
15
15
  ],
16
16
  "keywords": [
17
17
  "ai",
18
- "llm",
19
- "prompt",
20
- "template",
18
+ "ai-agents",
19
+ "ai-application-framework",
20
+ "ai-assistant",
21
+ "ai-automation",
22
+ "ai-development",
23
+ "ai-framework",
24
+ "ai-ops",
25
+ "ai-orchestration",
26
+ "ai-pipeline",
27
+ "ai-platform",
28
+ "ai-scripting",
29
+ "ai-sdk",
30
+ "ai-workflow",
31
+ "api-integration",
32
+ "automation-framework",
33
+ "book-language",
34
+ "browser",
35
+ "chatbot",
36
+ "cloud",
37
+ "content-generation",
38
+ "conversational-ai",
39
+ "cross-platform",
40
+ "cross-provider",
41
+ "developer-tools",
42
+ "distributed",
43
+ "embeddings",
44
+ "function-calling",
45
+ "generative-ai",
46
+ "human-readable",
47
+ "javascript",
48
+ "knowledge-base",
21
49
  "language-model",
22
- "chatgpt",
23
- "autogpt",
50
+ "large-language-models",
51
+ "llm",
52
+ "llmops",
24
53
  "machine-learning",
54
+ "markdown-dsl",
55
+ "mlops",
56
+ "model-agnostic",
57
+ "multi-model",
58
+ "multimodal",
59
+ "natural-language",
25
60
  "natural-language-processing",
26
61
  "nlp",
27
- "openai",
28
- "o3",
29
- "o3-mini",
30
- "deepseek",
31
- "gpt-3",
32
- "gpt-4",
33
- "gpt-4o",
34
- "gpt-4o-mini",
35
- "o1",
36
- "o1-mini",
37
- "o1-preview",
38
- "anthropic",
39
- "claude",
40
- "claude-3",
41
- "claude-3-opus",
42
- "claude-3-sonnet",
43
- "claude-3-haiku",
44
- "gemini",
45
- "gemini-pro",
46
- "gemini-flash",
47
- "mixtral",
48
- "mistral",
49
- "ollama",
50
- "ai-orchestration",
62
+ "nodejs",
63
+ "orchestration",
64
+ "pipeline",
65
+ "plain-english",
66
+ "prompt",
67
+ "prompt-chaining",
51
68
  "prompt-engineering",
52
- "llmops",
53
- "multimodal",
54
- "reasoning",
69
+ "prompt-management",
70
+ "prompt-template",
55
71
  "rag",
56
- "embeddings",
57
- "function-calling",
58
- "large-language-models",
59
- "ai-application-framework",
72
+ "reasoning",
73
+ "remote-execution",
74
+ "server",
75
+ "task-automation",
76
+ "template",
60
77
  "text-generation",
61
- "ai-agents",
62
- "LLMOps"
78
+ "text-processing",
79
+ "typescript",
80
+ "unified-interface",
81
+ "vendor-agnostic",
82
+ "workflow",
83
+ "workflow-engine"
63
84
  ],
64
85
  "license": "BUSL-1.1",
65
86
  "bugs": {
@@ -74,7 +95,7 @@
74
95
  "module": "./esm/index.es.js",
75
96
  "typings": "./esm/typings/src/_packages/remote-server.index.d.ts",
76
97
  "peerDependencies": {
77
- "@promptbook/core": "0.98.0-9"
98
+ "@promptbook/core": "0.99.0-0"
78
99
  },
79
100
  "dependencies": {
80
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.98.0-9';
51
+ const PROMPTBOOK_ENGINE_VERSION = '0.99.0-0';
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
@@ -6381,6 +6381,46 @@
6381
6381
  return pipelineExecutor;
6382
6382
  }
6383
6383
 
6384
+ /**
6385
+ * Detects if the code is running in a browser environment in main thread (Not in a web worker)
6386
+ *
6387
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
6388
+ *
6389
+ * @public exported from `@promptbook/utils`
6390
+ */
6391
+ const $isRunningInBrowser = new Function(`
6392
+ try {
6393
+ return this === window;
6394
+ } catch (e) {
6395
+ return false;
6396
+ }
6397
+ `);
6398
+ /**
6399
+ * TODO: [🎺]
6400
+ */
6401
+
6402
+ /**
6403
+ * Detects if the code is running in a web worker
6404
+ *
6405
+ * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
6406
+ *
6407
+ * @public exported from `@promptbook/utils`
6408
+ */
6409
+ const $isRunningInWebWorker = new Function(`
6410
+ try {
6411
+ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
6412
+ return true;
6413
+ } else {
6414
+ return false;
6415
+ }
6416
+ } catch (e) {
6417
+ return false;
6418
+ }
6419
+ `);
6420
+ /**
6421
+ * TODO: [🎺]
6422
+ */
6423
+
6384
6424
  /**
6385
6425
  * Register for LLM tools.
6386
6426
  *
@@ -6549,9 +6589,10 @@
6549
6589
  .list()
6550
6590
  .find(({ packageName, className }) => llmConfiguration.packageName === packageName && llmConfiguration.className === className);
6551
6591
  if (registeredItem === undefined) {
6552
- console.log('!!! $llmToolsRegister.list()', $llmToolsRegister.list());
6592
+ // console.log('$llmToolsRegister.list()', $llmToolsRegister.list());
6553
6593
  throw new Error(spaceTrim__default["default"]((block) => `
6554
6594
  There is no constructor for LLM provider \`${llmConfiguration.className}\` from \`${llmConfiguration.packageName}\`
6595
+ Running in ${!$isRunningInBrowser() ? '' : 'browser environment'}${!$isRunningInNode() ? '' : 'node environment'}${!$isRunningInWebWorker() ? '' : 'worker environment'}
6555
6596
 
6556
6597
  You have probably forgotten install and import the provider package.
6557
6598
  To fix this issue, you can:
@@ -6669,24 +6710,6 @@
6669
6710
  * TODO: [🌺] Use some intermediate util splitWords
6670
6711
  */
6671
6712
 
6672
- /**
6673
- * Detects if the code is running in a browser environment in main thread (Not in a web worker)
6674
- *
6675
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
6676
- *
6677
- * @public exported from `@promptbook/utils`
6678
- */
6679
- new Function(`
6680
- try {
6681
- return this === window;
6682
- } catch (e) {
6683
- return false;
6684
- }
6685
- `);
6686
- /**
6687
- * TODO: [🎺]
6688
- */
6689
-
6690
6713
  /**
6691
6714
  * Detects if the code is running in jest environment
6692
6715
  *
@@ -6705,28 +6728,6 @@
6705
6728
  * TODO: [🎺]
6706
6729
  */
6707
6730
 
6708
- /**
6709
- * Detects if the code is running in a web worker
6710
- *
6711
- * Note: `$` is used to indicate that this function is not a pure function - it looks at the global object to determine the environment
6712
- *
6713
- * @public exported from `@promptbook/utils`
6714
- */
6715
- new Function(`
6716
- try {
6717
- if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
6718
- return true;
6719
- } else {
6720
- return false;
6721
- }
6722
- } catch (e) {
6723
- return false;
6724
- }
6725
- `);
6726
- /**
6727
- * TODO: [🎺]
6728
- */
6729
-
6730
6731
  /**
6731
6732
  * Makes first letter of a string uppercase
6732
6733
  *
@@ -8075,6 +8076,152 @@
8075
8076
  response.status(400).send({ error: serializeError(error) });
8076
8077
  }
8077
8078
  });
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
+ });
8078
8225
  app.get(`/books`, async (request, response) => {
8079
8226
  if (collection === null) {
8080
8227
  response.status(500).send('No collection available');
@@ -8318,7 +8465,6 @@
8318
8465
  catch (error) {
8319
8466
  assertsError(error);
8320
8467
  socket.emit('error', serializeError(error));
8321
- // <- TODO: [🚋] There is a problem with the remote server handling errors and sending them back to the client
8322
8468
  }
8323
8469
  finally {
8324
8470
  socket.disconnect();