@inkeep/agents-manage-api 0.14.2 → 0.14.5

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/dist/index.cjs CHANGED
@@ -4020,6 +4020,76 @@ function getBaseUrlFromRequest(c) {
4020
4020
  const url = new URL(c.req.url);
4021
4021
  return `${url.protocol}//${url.host}`;
4022
4022
  }
4023
+ function generateOAuthCallbackPage(params) {
4024
+ const { title, message, isSuccess } = params;
4025
+ return `
4026
+ <!DOCTYPE html>
4027
+ <html>
4028
+ <head>
4029
+ <title>${title}</title>
4030
+ <meta charset="utf-8">
4031
+ <style>
4032
+ body {
4033
+ background-color: #000;
4034
+ color: #fff;
4035
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
4036
+ display: flex;
4037
+ align-items: center;
4038
+ justify-content: center;
4039
+ height: 100vh;
4040
+ margin: 0;
4041
+ text-align: center;
4042
+ }
4043
+ .container {
4044
+ max-width: 400px;
4045
+ padding: 2rem;
4046
+ }
4047
+ .title {
4048
+ font-size: 1.2rem;
4049
+ margin-bottom: 1rem;
4050
+ }
4051
+ .message {
4052
+ color: #ccc;
4053
+ line-height: 1.5;
4054
+ }
4055
+ .countdown {
4056
+ margin-top: 1rem;
4057
+ font-size: 0.9rem;
4058
+ }
4059
+ </style>
4060
+ </head>
4061
+ <body>
4062
+ <div class="container">
4063
+ <div class="title">${title}</div>
4064
+ <div class="message">${message}</div>
4065
+ <div class="message countdown">
4066
+ ${isSuccess ? "Closing automatically..." : ""}
4067
+ </div>
4068
+ </div>
4069
+ <script>
4070
+ ${isSuccess && `
4071
+ // Success: Send PostMessage then auto-close
4072
+ if (window.opener) {
4073
+ try {
4074
+ window.opener.postMessage({
4075
+ type: 'oauth-success',
4076
+ timestamp: Date.now()
4077
+ }, '*');
4078
+ } catch (error) {
4079
+ console.error('PostMessage failed:', error);
4080
+ }
4081
+ }
4082
+
4083
+ // Auto-close after brief delay
4084
+ setTimeout(() => {
4085
+ window.close();
4086
+ }, 1000);
4087
+ `}
4088
+ </script>
4089
+ </body>
4090
+ </html>
4091
+ `;
4092
+ }
4023
4093
  var OAuthLoginQuerySchema = zodOpenapi.z.object({
4024
4094
  tenantId: zodOpenapi.z.string().min(1, "Tenant ID is required"),
4025
4095
  projectId: zodOpenapi.z.string().min(1, "Project ID is required"),
@@ -4137,16 +4207,24 @@ app17.openapi(
4137
4207
  logger5.info({ state, hasCode: !!code }, "OAuth callback received");
4138
4208
  if (error) {
4139
4209
  logger5.error({ error, error_description }, "OAuth authorization failed");
4140
- const errorMessage = "OAuth Authorization Failed. Please try again.";
4141
- return c.text(errorMessage, 400);
4210
+ const errorMessage = error_description || error || "OAuth Authorization Failed. Please try again.";
4211
+ const errorPage = generateOAuthCallbackPage({
4212
+ title: "Authentication Failed",
4213
+ message: errorMessage,
4214
+ isSuccess: false
4215
+ });
4216
+ return c.html(errorPage);
4142
4217
  }
4143
4218
  const pkceData = retrievePKCEVerifier(state);
4144
4219
  if (!pkceData) {
4145
4220
  logger5.error({ state }, "Invalid or expired OAuth state");
4146
- return c.text(
4147
- "OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.",
4148
- 400
4149
- );
4221
+ const errorMessage = "OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.";
4222
+ const expiredPage = generateOAuthCallbackPage({
4223
+ title: "Session Expired",
4224
+ message: errorMessage,
4225
+ isSuccess: false
4226
+ });
4227
+ return c.html(expiredPage);
4150
4228
  }
4151
4229
  const { codeVerifier, toolId, tenantId, projectId, clientId } = pkceData;
4152
4230
  const tool = await agentsCore.getToolById(dbClient_default)({
@@ -4216,50 +4294,21 @@ app17.openapi(
4216
4294
  }
4217
4295
  });
4218
4296
  logger5.info({ toolId, credentialId: newCredential.id }, "OAuth flow completed successfully");
4219
- const successPage = `
4220
- <!DOCTYPE html>
4221
- <html>
4222
- <head>
4223
- <title>Authentication Complete</title>
4224
- <meta charset="utf-8">
4225
- </head>
4226
- <body>
4227
- <p>Authentication successful. Closing in <span id="countdown">3</span> seconds...</p>
4228
- <script>
4229
- let countdown = 3;
4230
- const countdownEl = document.getElementById('countdown');
4231
-
4232
- // Notify parent window of successful authentication
4233
- if (window.opener) {
4234
- window.opener.postMessage({
4235
- type: 'oauth-success',
4236
- toolId: '${toolId}'
4237
- }, '*');
4238
- }
4239
-
4240
- const timer = setInterval(() => {
4241
- countdown--;
4242
- countdownEl.textContent = countdown;
4243
-
4244
- if (countdown <= 0) {
4245
- clearInterval(timer);
4246
- window.close();
4247
- }
4248
- }, 1000);
4249
-
4250
- // Also try to close immediately for some browsers
4251
- setTimeout(() => {
4252
- window.close();
4253
- }, 3000);
4254
- </script>
4255
- </body>
4256
- </html>
4257
- `;
4297
+ const successPage = generateOAuthCallbackPage({
4298
+ title: "Authentication Complete",
4299
+ message: "You have been successfully authenticated.",
4300
+ isSuccess: true
4301
+ });
4258
4302
  return c.html(successPage);
4259
4303
  } catch (error) {
4260
4304
  logger5.error({ error }, "OAuth callback processing failed");
4261
4305
  const errorMessage = "OAuth Processing Failed. Please try again.";
4262
- return c.text(errorMessage, 500);
4306
+ const errorPage = generateOAuthCallbackPage({
4307
+ title: "Processing Failed",
4308
+ message: errorMessage,
4309
+ isSuccess: false
4310
+ });
4311
+ return c.html(errorPage);
4263
4312
  }
4264
4313
  }
4265
4314
  );
package/dist/index.js CHANGED
@@ -4016,6 +4016,76 @@ function getBaseUrlFromRequest(c) {
4016
4016
  const url = new URL(c.req.url);
4017
4017
  return `${url.protocol}//${url.host}`;
4018
4018
  }
4019
+ function generateOAuthCallbackPage(params) {
4020
+ const { title, message, isSuccess } = params;
4021
+ return `
4022
+ <!DOCTYPE html>
4023
+ <html>
4024
+ <head>
4025
+ <title>${title}</title>
4026
+ <meta charset="utf-8">
4027
+ <style>
4028
+ body {
4029
+ background-color: #000;
4030
+ color: #fff;
4031
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
4032
+ display: flex;
4033
+ align-items: center;
4034
+ justify-content: center;
4035
+ height: 100vh;
4036
+ margin: 0;
4037
+ text-align: center;
4038
+ }
4039
+ .container {
4040
+ max-width: 400px;
4041
+ padding: 2rem;
4042
+ }
4043
+ .title {
4044
+ font-size: 1.2rem;
4045
+ margin-bottom: 1rem;
4046
+ }
4047
+ .message {
4048
+ color: #ccc;
4049
+ line-height: 1.5;
4050
+ }
4051
+ .countdown {
4052
+ margin-top: 1rem;
4053
+ font-size: 0.9rem;
4054
+ }
4055
+ </style>
4056
+ </head>
4057
+ <body>
4058
+ <div class="container">
4059
+ <div class="title">${title}</div>
4060
+ <div class="message">${message}</div>
4061
+ <div class="message countdown">
4062
+ ${isSuccess ? "Closing automatically..." : ""}
4063
+ </div>
4064
+ </div>
4065
+ <script>
4066
+ ${isSuccess && `
4067
+ // Success: Send PostMessage then auto-close
4068
+ if (window.opener) {
4069
+ try {
4070
+ window.opener.postMessage({
4071
+ type: 'oauth-success',
4072
+ timestamp: Date.now()
4073
+ }, '*');
4074
+ } catch (error) {
4075
+ console.error('PostMessage failed:', error);
4076
+ }
4077
+ }
4078
+
4079
+ // Auto-close after brief delay
4080
+ setTimeout(() => {
4081
+ window.close();
4082
+ }, 1000);
4083
+ `}
4084
+ </script>
4085
+ </body>
4086
+ </html>
4087
+ `;
4088
+ }
4019
4089
  var OAuthLoginQuerySchema = z$1.object({
4020
4090
  tenantId: z$1.string().min(1, "Tenant ID is required"),
4021
4091
  projectId: z$1.string().min(1, "Project ID is required"),
@@ -4133,16 +4203,24 @@ app17.openapi(
4133
4203
  logger5.info({ state, hasCode: !!code }, "OAuth callback received");
4134
4204
  if (error) {
4135
4205
  logger5.error({ error, error_description }, "OAuth authorization failed");
4136
- const errorMessage = "OAuth Authorization Failed. Please try again.";
4137
- return c.text(errorMessage, 400);
4206
+ const errorMessage = error_description || error || "OAuth Authorization Failed. Please try again.";
4207
+ const errorPage = generateOAuthCallbackPage({
4208
+ title: "Authentication Failed",
4209
+ message: errorMessage,
4210
+ isSuccess: false
4211
+ });
4212
+ return c.html(errorPage);
4138
4213
  }
4139
4214
  const pkceData = retrievePKCEVerifier(state);
4140
4215
  if (!pkceData) {
4141
4216
  logger5.error({ state }, "Invalid or expired OAuth state");
4142
- return c.text(
4143
- "OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.",
4144
- 400
4145
- );
4217
+ const errorMessage = "OAuth Session Expired: The OAuth session has expired or is invalid. Please try again.";
4218
+ const expiredPage = generateOAuthCallbackPage({
4219
+ title: "Session Expired",
4220
+ message: errorMessage,
4221
+ isSuccess: false
4222
+ });
4223
+ return c.html(expiredPage);
4146
4224
  }
4147
4225
  const { codeVerifier, toolId, tenantId, projectId, clientId } = pkceData;
4148
4226
  const tool = await getToolById(dbClient_default)({
@@ -4212,50 +4290,21 @@ app17.openapi(
4212
4290
  }
4213
4291
  });
4214
4292
  logger5.info({ toolId, credentialId: newCredential.id }, "OAuth flow completed successfully");
4215
- const successPage = `
4216
- <!DOCTYPE html>
4217
- <html>
4218
- <head>
4219
- <title>Authentication Complete</title>
4220
- <meta charset="utf-8">
4221
- </head>
4222
- <body>
4223
- <p>Authentication successful. Closing in <span id="countdown">3</span> seconds...</p>
4224
- <script>
4225
- let countdown = 3;
4226
- const countdownEl = document.getElementById('countdown');
4227
-
4228
- // Notify parent window of successful authentication
4229
- if (window.opener) {
4230
- window.opener.postMessage({
4231
- type: 'oauth-success',
4232
- toolId: '${toolId}'
4233
- }, '*');
4234
- }
4235
-
4236
- const timer = setInterval(() => {
4237
- countdown--;
4238
- countdownEl.textContent = countdown;
4239
-
4240
- if (countdown <= 0) {
4241
- clearInterval(timer);
4242
- window.close();
4243
- }
4244
- }, 1000);
4245
-
4246
- // Also try to close immediately for some browsers
4247
- setTimeout(() => {
4248
- window.close();
4249
- }, 3000);
4250
- </script>
4251
- </body>
4252
- </html>
4253
- `;
4293
+ const successPage = generateOAuthCallbackPage({
4294
+ title: "Authentication Complete",
4295
+ message: "You have been successfully authenticated.",
4296
+ isSuccess: true
4297
+ });
4254
4298
  return c.html(successPage);
4255
4299
  } catch (error) {
4256
4300
  logger5.error({ error }, "OAuth callback processing failed");
4257
4301
  const errorMessage = "OAuth Processing Failed. Please try again.";
4258
- return c.text(errorMessage, 500);
4302
+ const errorPage = generateOAuthCallbackPage({
4303
+ title: "Processing Failed",
4304
+ message: errorMessage,
4305
+ isSuccess: false
4306
+ });
4307
+ return c.html(errorPage);
4259
4308
  }
4260
4309
  }
4261
4310
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-manage-api",
3
- "version": "0.14.2",
3
+ "version": "0.14.5",
4
4
  "description": "Agents Manage API for Inkeep Agent Framework - handles CRUD operations and OAuth",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "openid-client": "^6.6.4",
24
24
  "pino": "^9.7.0",
25
25
  "zod": "^4.1.11",
26
- "@inkeep/agents-core": "^0.14.2"
26
+ "@inkeep/agents-core": "^0.14.5"
27
27
  },
28
28
  "optionalDependencies": {
29
29
  "keytar": "^7.9.0"