@auth0/ai 1.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.
Files changed (108) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +44 -0
  3. package/dist/cjs/TokenResponse.js +3 -0
  4. package/dist/cjs/TokenResponse.js.map +1 -0
  5. package/dist/cjs/authorizers/ciba/CIBAAuthorizationRequest.js +3 -0
  6. package/dist/cjs/authorizers/ciba/CIBAAuthorizationRequest.js.map +1 -0
  7. package/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js +201 -0
  8. package/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -0
  9. package/dist/cjs/authorizers/ciba/CIBAAuthorizerParams.js +3 -0
  10. package/dist/cjs/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -0
  11. package/dist/cjs/authorizers/ciba/asyncLocalStorage.js +14 -0
  12. package/dist/cjs/authorizers/ciba/asyncLocalStorage.js.map +1 -0
  13. package/dist/cjs/authorizers/ciba/index.js +9 -0
  14. package/dist/cjs/authorizers/ciba/index.js.map +1 -0
  15. package/dist/cjs/authorizers/device-authorizer.js +130 -0
  16. package/dist/cjs/authorizers/device-authorizer.js.map +1 -0
  17. package/dist/cjs/authorizers/federated-connections/asyncLocalStorage.js +14 -0
  18. package/dist/cjs/authorizers/federated-connections/asyncLocalStorage.js.map +1 -0
  19. package/dist/cjs/authorizers/federated-connections/index.js +129 -0
  20. package/dist/cjs/authorizers/federated-connections/index.js.map +1 -0
  21. package/dist/cjs/authorizers/fga/fga-client.js +30 -0
  22. package/dist/cjs/authorizers/fga/fga-client.js.map +1 -0
  23. package/dist/cjs/authorizers/fga/fga-filter.js +94 -0
  24. package/dist/cjs/authorizers/fga/fga-filter.js.map +1 -0
  25. package/dist/cjs/authorizers/fga/index.js +37 -0
  26. package/dist/cjs/authorizers/fga/index.js.map +1 -0
  27. package/dist/cjs/authorizers/index.js +3 -0
  28. package/dist/cjs/authorizers/index.js.map +1 -0
  29. package/dist/cjs/credentials.js +3 -0
  30. package/dist/cjs/credentials.js.map +1 -0
  31. package/dist/cjs/errors.js +46 -0
  32. package/dist/cjs/errors.js.map +1 -0
  33. package/dist/cjs/index.js +22 -0
  34. package/dist/cjs/index.js.map +1 -0
  35. package/dist/cjs/interrupts/Auth0Interrupt.js +46 -0
  36. package/dist/cjs/interrupts/Auth0Interrupt.js.map +1 -0
  37. package/dist/cjs/interrupts/CIBAInterrupts.js +89 -0
  38. package/dist/cjs/interrupts/CIBAInterrupts.js.map +1 -0
  39. package/dist/cjs/interrupts/FederatedConnectionInterrupt.js +31 -0
  40. package/dist/cjs/interrupts/FederatedConnectionInterrupt.js.map +1 -0
  41. package/dist/cjs/interrupts/index.js +17 -0
  42. package/dist/cjs/interrupts/index.js.map +1 -0
  43. package/dist/cjs/parameters.js +13 -0
  44. package/dist/cjs/parameters.js.map +1 -0
  45. package/dist/esm/TokenResponse.d.ts +15 -0
  46. package/dist/esm/TokenResponse.js +2 -0
  47. package/dist/esm/TokenResponse.js.map +1 -0
  48. package/dist/esm/authorizers/ciba/CIBAAuthorizationRequest.d.ts +20 -0
  49. package/dist/esm/authorizers/ciba/CIBAAuthorizationRequest.js +2 -0
  50. package/dist/esm/authorizers/ciba/CIBAAuthorizationRequest.js.map +1 -0
  51. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.d.ts +31 -0
  52. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js +197 -0
  53. package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -0
  54. package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.d.ts +66 -0
  55. package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js +2 -0
  56. package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -0
  57. package/dist/esm/authorizers/ciba/asyncLocalStorage.d.ts +16 -0
  58. package/dist/esm/authorizers/ciba/asyncLocalStorage.js +10 -0
  59. package/dist/esm/authorizers/ciba/asyncLocalStorage.js.map +1 -0
  60. package/dist/esm/authorizers/ciba/index.d.ts +4 -0
  61. package/dist/esm/authorizers/ciba/index.js +3 -0
  62. package/dist/esm/authorizers/ciba/index.js.map +1 -0
  63. package/dist/esm/authorizers/device-authorizer.d.ts +15 -0
  64. package/dist/esm/authorizers/device-authorizer.js +90 -0
  65. package/dist/esm/authorizers/device-authorizer.js.map +1 -0
  66. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.d.ts +26 -0
  67. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js +10 -0
  68. package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js.map +1 -0
  69. package/dist/esm/authorizers/federated-connections/index.d.ts +38 -0
  70. package/dist/esm/authorizers/federated-connections/index.js +123 -0
  71. package/dist/esm/authorizers/federated-connections/index.js.map +1 -0
  72. package/dist/esm/authorizers/fga/fga-client.d.ts +16 -0
  73. package/dist/esm/authorizers/fga/fga-client.js +27 -0
  74. package/dist/esm/authorizers/fga/fga-client.js.map +1 -0
  75. package/dist/esm/authorizers/fga/fga-filter.d.ts +63 -0
  76. package/dist/esm/authorizers/fga/fga-filter.js +90 -0
  77. package/dist/esm/authorizers/fga/fga-filter.js.map +1 -0
  78. package/dist/esm/authorizers/fga/index.d.ts +21 -0
  79. package/dist/esm/authorizers/fga/index.js +33 -0
  80. package/dist/esm/authorizers/fga/index.js.map +1 -0
  81. package/dist/esm/authorizers/index.d.ts +13 -0
  82. package/dist/esm/authorizers/index.js +2 -0
  83. package/dist/esm/authorizers/index.js.map +1 -0
  84. package/dist/esm/credentials.d.ts +10 -0
  85. package/dist/esm/credentials.js +2 -0
  86. package/dist/esm/credentials.js.map +1 -0
  87. package/dist/esm/errors.d.ts +19 -0
  88. package/dist/esm/errors.js +37 -0
  89. package/dist/esm/errors.js.map +1 -0
  90. package/dist/esm/index.d.ts +9 -0
  91. package/dist/esm/index.js +6 -0
  92. package/dist/esm/index.js.map +1 -0
  93. package/dist/esm/interrupts/Auth0Interrupt.d.ts +37 -0
  94. package/dist/esm/interrupts/Auth0Interrupt.js +42 -0
  95. package/dist/esm/interrupts/Auth0Interrupt.js.map +1 -0
  96. package/dist/esm/interrupts/CIBAInterrupts.d.ts +62 -0
  97. package/dist/esm/interrupts/CIBAInterrupts.js +79 -0
  98. package/dist/esm/interrupts/CIBAInterrupts.js.map +1 -0
  99. package/dist/esm/interrupts/FederatedConnectionInterrupt.d.ts +33 -0
  100. package/dist/esm/interrupts/FederatedConnectionInterrupt.js +26 -0
  101. package/dist/esm/interrupts/FederatedConnectionInterrupt.js.map +1 -0
  102. package/dist/esm/interrupts/index.d.ts +4 -0
  103. package/dist/esm/interrupts/index.js +4 -0
  104. package/dist/esm/interrupts/index.js.map +1 -0
  105. package/dist/esm/parameters.d.ts +3 -0
  106. package/dist/esm/parameters.js +9 -0
  107. package/dist/esm/parameters.js.map +1 -0
  108. package/package.json +76 -0
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Auth0Interrupt = exports.InterruptName = void 0;
4
+ exports.InterruptName = "AUTH0_AI_INTERRUPT";
5
+ /**
6
+ * Auth0Interrupt is the base class for all interruptions
7
+ * in the Auth0 AI sdk.
8
+ *
9
+ * It is serializable to a JSON object.
10
+ */
11
+ class Auth0Interrupt extends Error {
12
+ constructor(message, code) {
13
+ super(message);
14
+ this.name = exports.InterruptName;
15
+ this.code = code;
16
+ }
17
+ /**
18
+ *
19
+ * Serialize the interrupt to a JSON object.
20
+ *
21
+ * @returns - The JSON object representation of the interrupt.
22
+ */
23
+ toJSON() {
24
+ return {
25
+ ...Object.fromEntries(Object.entries(this).filter(([key]) => key !== "stack" && key !== "toJSON")),
26
+ message: this.message,
27
+ };
28
+ }
29
+ /**
30
+ *
31
+ * Checks if an interrupt is of a specific type asserting its data component.
32
+ *
33
+ * This method assert the data part of the interrupt.
34
+ *
35
+ * @param clazz - The class of the interrupt to check.
36
+ * @param interrupt - The interrupt to check.
37
+ *
38
+ * @returns - True if the interrupt is of the specified type.
39
+ */
40
+ static isInterrupt(interrupt) {
41
+ return (interrupt.name === "AUTH0_AI_INTERRUPT" &&
42
+ (typeof this.code === "undefined" || interrupt.code === this.code));
43
+ }
44
+ }
45
+ exports.Auth0Interrupt = Auth0Interrupt;
46
+ //# sourceMappingURL=Auth0Interrupt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Auth0Interrupt.js","sourceRoot":"","sources":["../../../src/interrupts/Auth0Interrupt.ts"],"names":[],"mappings":";;;AAMa,QAAA,aAAa,GAAG,oBAA6B,CAAC;AAE3D;;;;;GAKG;AACH,MAAa,cAAe,SAAQ,KAAK;IAIvC,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAG,qBAAa,CAAC;QAKnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,MAAM;QACJ,OAAO;YACL,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CACzB,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,QAAQ,CAC/C,CACF;YACD,OAAO,EAAE,IAAI,CAAC,OAAO;SACM,CAAC;IAChC,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS,CAAC,IAAI,KAAK,oBAAoB;YACvC,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CACnE,CAAC;IACJ,CAAC;CACF;AA9CD,wCA8CC","sourcesContent":["// Define a type alias for the generalized type\nexport type Auth0InterruptData<T extends Auth0Interrupt> = Omit<\n Omit<T, keyof Error>,\n \"toJSON\"\n> & { message: string };\n\nexport const InterruptName = \"AUTH0_AI_INTERRUPT\" as const;\n\n/**\n * Auth0Interrupt is the base class for all interruptions\n * in the Auth0 AI sdk.\n *\n * It is serializable to a JSON object.\n */\nexport class Auth0Interrupt extends Error {\n name = InterruptName;\n code: string;\n\n constructor(message: string, code: string) {\n super(message);\n this.code = code;\n }\n\n /**\n *\n * Serialize the interrupt to a JSON object.\n *\n * @returns - The JSON object representation of the interrupt.\n */\n toJSON(): Auth0InterruptData<this> {\n return {\n ...Object.fromEntries(\n Object.entries(this).filter(\n ([key]) => key !== \"stack\" && key !== \"toJSON\"\n )\n ),\n message: this.message,\n } as Auth0InterruptData<this>;\n }\n\n /**\n *\n * Checks if an interrupt is of a specific type asserting its data component.\n *\n * This method assert the data part of the interrupt.\n *\n * @param clazz - The class of the interrupt to check.\n * @param interrupt - The interrupt to check.\n *\n * @returns - True if the interrupt is of the specified type.\n */\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T & { code?: string },\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt.name === \"AUTH0_AI_INTERRUPT\" &&\n (typeof this.code === \"undefined\" || interrupt.code === this.code)\n );\n }\n}\n"]}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidGrantInterrupt = exports.AuthorizationPollingInterrupt = exports.AuthorizationPendingInterrupt = exports.AuthorizationRequestExpiredInterrupt = exports.UserDoesNotHavePushNotificationsInterrupt = exports.AccessDeniedInterrupt = exports.CIBAInterrupt = void 0;
4
+ const Auth0Interrupt_1 = require("./Auth0Interrupt");
5
+ /**
6
+ * Base class for CIBA interrupts.
7
+ */
8
+ class CIBAInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
9
+ constructor(message, code) {
10
+ super(message, code);
11
+ }
12
+ static isInterrupt(interrupt) {
13
+ return (interrupt &&
14
+ Auth0Interrupt_1.Auth0Interrupt.isInterrupt(interrupt) &&
15
+ typeof interrupt.code === "string" &&
16
+ interrupt.code.startsWith("CIBA_"));
17
+ }
18
+ static hasRequestData(interrupt) {
19
+ return CIBAInterrupt.isInterrupt(interrupt) && "request" in interrupt;
20
+ }
21
+ }
22
+ exports.CIBAInterrupt = CIBAInterrupt;
23
+ /**
24
+ * An interrupt that is thrown when the user denies the authorization request.
25
+ */
26
+ class AccessDeniedInterrupt extends CIBAInterrupt {
27
+ constructor(message, request) {
28
+ super(message, AccessDeniedInterrupt.code);
29
+ this.request = request;
30
+ }
31
+ }
32
+ exports.AccessDeniedInterrupt = AccessDeniedInterrupt;
33
+ AccessDeniedInterrupt.code = "CIBA_ACCESS_DENIED";
34
+ /**
35
+ * An interrupt that is thrown when the user does not have push notifications enabled.
36
+ */
37
+ class UserDoesNotHavePushNotificationsInterrupt extends CIBAInterrupt {
38
+ constructor(message) {
39
+ super(message, UserDoesNotHavePushNotificationsInterrupt.code);
40
+ }
41
+ }
42
+ exports.UserDoesNotHavePushNotificationsInterrupt = UserDoesNotHavePushNotificationsInterrupt;
43
+ UserDoesNotHavePushNotificationsInterrupt.code = "CIBA_USER_DOES_NOT_HAVE_PUSH_NOTIFICATIONS";
44
+ /**
45
+ * An interrupt that is thrown when the authorization request has expired.
46
+ */
47
+ class AuthorizationRequestExpiredInterrupt extends CIBAInterrupt {
48
+ constructor(message, request) {
49
+ super(message, AuthorizationRequestExpiredInterrupt.code);
50
+ this.request = request;
51
+ }
52
+ }
53
+ exports.AuthorizationRequestExpiredInterrupt = AuthorizationRequestExpiredInterrupt;
54
+ AuthorizationRequestExpiredInterrupt.code = "CIBA_AUTHORIZATION_REQUEST_EXPIRED";
55
+ /**
56
+ * An interrupt that is thrown when the authorization is still pending
57
+ * and the Authorizer is in `mode: interrupt`.
58
+ */
59
+ class AuthorizationPendingInterrupt extends CIBAInterrupt {
60
+ constructor(message, request) {
61
+ super(message, AuthorizationPendingInterrupt.code);
62
+ this.request = request;
63
+ }
64
+ }
65
+ exports.AuthorizationPendingInterrupt = AuthorizationPendingInterrupt;
66
+ AuthorizationPendingInterrupt.code = "CIBA_AUTHORIZATION_PENDING";
67
+ /**
68
+ * An interrupt that is thrown when the authorization polling fails.
69
+ */
70
+ class AuthorizationPollingInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
71
+ constructor(message, request) {
72
+ super(message, AuthorizationPollingInterrupt.code);
73
+ this.request = request;
74
+ }
75
+ }
76
+ exports.AuthorizationPollingInterrupt = AuthorizationPollingInterrupt;
77
+ AuthorizationPollingInterrupt.code = "CIBA_AUTHORIZATION_POLLING_ERROR";
78
+ /**
79
+ * An interrupt that is thrown when the authorization polling fails.
80
+ */
81
+ class InvalidGrantInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
82
+ constructor(message, request) {
83
+ super(message, AuthorizationPollingInterrupt.code);
84
+ this.request = request;
85
+ }
86
+ }
87
+ exports.InvalidGrantInterrupt = InvalidGrantInterrupt;
88
+ InvalidGrantInterrupt.code = "CIBA_INVALID_GRANT";
89
+ //# sourceMappingURL=CIBAInterrupts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CIBAInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/CIBAInterrupts.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAMtE;;GAEG;AACH,MAAa,aAAc,SAAQ,+BAAc;IAC/C,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,+BAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CACnC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,SAAc;QAClC,OAAO,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,SAAS,CAAC;IACxE,CAAC;CACF;AApBD,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6B,CAAC,IAAI,CAAC,CAAC;QAFnC,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC","sourcesContent":["import { CIBAAuthorizationRequest } from \"../authorizers/ciba/CIBAAuthorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: CIBAAuthorizationRequest;\n}\n\n/**\n * Base class for CIBA interrupts.\n */\nexport class CIBAInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T,\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n interrupt.code.startsWith(\"CIBA_\")\n );\n }\n\n static hasRequestData(interrupt: any): interrupt is WithRequestData {\n return CIBAInterrupt.isInterrupt(interrupt) && \"request\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the user does not have push notifications enabled.\n */\nexport class UserDoesNotHavePushNotificationsInterrupt extends CIBAInterrupt {\n public static code: string =\n \"CIBA_USER_DOES_NOT_HAVE_PUSH_NOTIFICATIONS\" as const;\n constructor(message: string) {\n super(message, UserDoesNotHavePushNotificationsInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends Auth0Interrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class InvalidGrantInterrupt\n extends Auth0Interrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FederatedConnectionError = exports.FederatedConnectionInterrupt = void 0;
4
+ const Auth0Interrupt_1 = require("./Auth0Interrupt");
5
+ /**
6
+ * Error thrown when a tool call requires an access token for an external service.
7
+ *
8
+ * Throw this error if the service returns Unauthorized for the current access token.
9
+ */
10
+ class FederatedConnectionInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
11
+ constructor(message, connection, scopes, requiredScopes) {
12
+ super(message, FederatedConnectionInterrupt.code);
13
+ this.connection = connection;
14
+ this.scopes = scopes;
15
+ this.requiredScopes = requiredScopes;
16
+ }
17
+ }
18
+ exports.FederatedConnectionInterrupt = FederatedConnectionInterrupt;
19
+ FederatedConnectionInterrupt.code = "FEDERATED_CONNECTION_ERROR";
20
+ /**
21
+ * Error thrown when a tool call requires an access token for an external service.
22
+ *
23
+ * The authorizer will automatically convert this class of error to FederatedConnectionInterrupt.
24
+ */
25
+ class FederatedConnectionError extends Error {
26
+ constructor(message) {
27
+ super(message);
28
+ }
29
+ }
30
+ exports.FederatedConnectionError = FederatedConnectionError;
31
+ //# sourceMappingURL=FederatedConnectionInterrupt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FederatedConnectionInterrupt.js","sourceRoot":"","sources":["../../../src/interrupts/FederatedConnectionInterrupt.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAElD;;;;GAIG;AACH,MAAa,4BAA6B,SAAQ,+BAAc;IAoB9D,YACE,OAAe,EACf,UAAkB,EAClB,MAAgB,EAChB,cAAwB;QAExB,KAAK,CAAC,OAAO,EAAE,4BAA4B,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;;AA9BH,oEA+BC;AAbe,iCAAI,GAAG,4BAAqC,CAAC;AAe7D;;;;GAIG;AACH,MAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,4DAIC","sourcesContent":["import { Auth0Interrupt } from \"./Auth0Interrupt\";\n\n/**\n * Error thrown when a tool call requires an access token for an external service.\n *\n * Throw this error if the service returns Unauthorized for the current access token.\n */\nexport class FederatedConnectionInterrupt extends Auth0Interrupt {\n /**\n * The auth0 connection name.\n */\n public readonly connection: string;\n\n /**\n * The scopes required to access the external service as stated\n * in the authorizer.\n */\n public readonly scopes: string[];\n\n /**\n * The union between the current scopes of the Access Token plus the required scopes.\n * This is the list of scopes that will be used to request a new Access Token.\n */\n public readonly requiredScopes: string[];\n\n public static code = \"FEDERATED_CONNECTION_ERROR\" as const;\n\n constructor(\n message: string,\n connection: string,\n scopes: string[],\n requiredScopes: string[]\n ) {\n super(message, FederatedConnectionInterrupt.code);\n this.connection = connection;\n this.scopes = scopes;\n this.requiredScopes = requiredScopes;\n }\n}\n\n/**\n * Error thrown when a tool call requires an access token for an external service.\n *\n * The authorizer will automatically convert this class of error to FederatedConnectionInterrupt.\n */\nexport class FederatedConnectionError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidGrantInterrupt = exports.AuthorizationPollingInterrupt = exports.AuthorizationPendingInterrupt = exports.AuthorizationRequestExpiredInterrupt = exports.UserDoesNotHavePushNotificationsInterrupt = exports.AccessDeniedInterrupt = exports.CIBAInterrupt = exports.FederatedConnectionError = exports.FederatedConnectionInterrupt = exports.Auth0Interrupt = void 0;
4
+ var Auth0Interrupt_1 = require("./Auth0Interrupt");
5
+ Object.defineProperty(exports, "Auth0Interrupt", { enumerable: true, get: function () { return Auth0Interrupt_1.Auth0Interrupt; } });
6
+ var FederatedConnectionInterrupt_1 = require("./FederatedConnectionInterrupt");
7
+ Object.defineProperty(exports, "FederatedConnectionInterrupt", { enumerable: true, get: function () { return FederatedConnectionInterrupt_1.FederatedConnectionInterrupt; } });
8
+ Object.defineProperty(exports, "FederatedConnectionError", { enumerable: true, get: function () { return FederatedConnectionInterrupt_1.FederatedConnectionError; } });
9
+ var CIBAInterrupts_1 = require("./CIBAInterrupts");
10
+ Object.defineProperty(exports, "CIBAInterrupt", { enumerable: true, get: function () { return CIBAInterrupts_1.CIBAInterrupt; } });
11
+ Object.defineProperty(exports, "AccessDeniedInterrupt", { enumerable: true, get: function () { return CIBAInterrupts_1.AccessDeniedInterrupt; } });
12
+ Object.defineProperty(exports, "UserDoesNotHavePushNotificationsInterrupt", { enumerable: true, get: function () { return CIBAInterrupts_1.UserDoesNotHavePushNotificationsInterrupt; } });
13
+ Object.defineProperty(exports, "AuthorizationRequestExpiredInterrupt", { enumerable: true, get: function () { return CIBAInterrupts_1.AuthorizationRequestExpiredInterrupt; } });
14
+ Object.defineProperty(exports, "AuthorizationPendingInterrupt", { enumerable: true, get: function () { return CIBAInterrupts_1.AuthorizationPendingInterrupt; } });
15
+ Object.defineProperty(exports, "AuthorizationPollingInterrupt", { enumerable: true, get: function () { return CIBAInterrupts_1.AuthorizationPollingInterrupt; } });
16
+ Object.defineProperty(exports, "InvalidGrantInterrupt", { enumerable: true, get: function () { return CIBAInterrupts_1.InvalidGrantInterrupt; } });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interrupts/index.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AAEvB,+EAGwC;AAFtC,4IAAA,4BAA4B,OAAA;AAC5B,wIAAA,wBAAwB,OAAA;AAG1B,mDAQ0B;AAPxB,+GAAA,aAAa,OAAA;AACb,uHAAA,qBAAqB,OAAA;AACrB,2IAAA,yCAAyC,OAAA;AACzC,sIAAA,oCAAoC,OAAA;AACpC,+HAAA,6BAA6B,OAAA;AAC7B,+HAAA,6BAA6B,OAAA;AAC7B,uHAAA,qBAAqB,OAAA","sourcesContent":["export { Auth0Interrupt } from \"./Auth0Interrupt\";\n\nexport {\n FederatedConnectionInterrupt,\n FederatedConnectionError,\n} from \"./FederatedConnectionInterrupt\";\n\nexport {\n CIBAInterrupt,\n AccessDeniedInterrupt,\n UserDoesNotHavePushNotificationsInterrupt,\n AuthorizationRequestExpiredInterrupt,\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n InvalidGrantInterrupt,\n} from \"./CIBAInterrupts\";\n"]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveParameter = void 0;
4
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
5
+ const isCallback = (maybeFunction) => typeof maybeFunction === "function";
6
+ const resolveParameter = (resolver, context) => {
7
+ if (isCallback(resolver)) {
8
+ return resolver(...context);
9
+ }
10
+ return resolver;
11
+ };
12
+ exports.resolveParameter = resolveParameter;
13
+ //# sourceMappingURL=parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../src/parameters.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAC/D,MAAM,UAAU,GAAG,CACjB,aAA+C,EACpB,EAAE,CAAC,OAAO,aAAa,KAAK,UAAU,CAAC;AAO7D,MAAM,gBAAgB,GAAG,CAI9B,QAA2D,EAC3D,OAAwB,EACI,EAAE;IAC9B,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW3B","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-function-type */\nconst isCallback = (\n maybeFunction: any | ((...args: any[]) => void)\n): maybeFunction is Function => typeof maybeFunction === \"function\";\n\nexport type AuthorizerToolParameter<\n ToolExecuteArgs extends any[],\n TResult = string\n> = TResult | ((...args: ToolExecuteArgs) => Promise<TResult> | TResult);\n\nexport const resolveParameter = <\n ToolExecuteArgs extends any[],\n TResult = string\n>(\n resolver: AuthorizerToolParameter<ToolExecuteArgs, TResult>,\n context: ToolExecuteArgs\n): TResult | Promise<TResult> => {\n if (isCallback(resolver)) {\n return resolver(...context);\n }\n return resolver;\n};\n"]}
@@ -0,0 +1,15 @@
1
+ export type TokenResponse = {
2
+ /** Bearer token for API authorization */
3
+ access_token: string;
4
+ /** Refresh token (requires `offline_access` scope) */
5
+ refresh_token?: string;
6
+ /** JWT containing user identity claims */
7
+ id_token: string;
8
+ /** Typically "Bearer" */
9
+ token_type?: string;
10
+ /** Token validity in seconds (default: 86400) */
11
+ expires_in: number;
12
+ /** Granted permissions space */
13
+ scope: string;
14
+ };
15
+ //# sourceMappingURL=TokenResponse.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TokenResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TokenResponse.js","sourceRoot":"","sources":["../../src/TokenResponse.ts"],"names":[],"mappings":"","sourcesContent":["export type TokenResponse = {\n /** Bearer token for API authorization */\n access_token: string;\n /** Refresh token (requires `offline_access` scope) */\n refresh_token?: string;\n /** JWT containing user identity claims */\n id_token: string;\n /** Typically \"Bearer\" */\n token_type?: string;\n /** Token validity in seconds (default: 86400) */\n expires_in: number;\n /** Granted permissions space */\n scope: string;\n};\n"]}
@@ -0,0 +1,20 @@
1
+ export type CIBAAuthorizationRequest = {
2
+ /**
3
+ * The authorization request ID.
4
+ * Use this ID to check the status of the authorization request.
5
+ */
6
+ id: string;
7
+ /**
8
+ * The time the authorization request was made.
9
+ */
10
+ requestedAt: number;
11
+ /**
12
+ * The time in seconds for the authorization request to expire.
13
+ */
14
+ expiresIn: number;
15
+ /**
16
+ * The interval to use when polling the status.
17
+ */
18
+ interval: number;
19
+ };
20
+ //# sourceMappingURL=CIBAAuthorizationRequest.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CIBAAuthorizationRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CIBAAuthorizationRequest.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizationRequest.ts"],"names":[],"mappings":"","sourcesContent":["export type CIBAAuthorizationRequest = {\n /**\n * The authorization request ID.\n * Use this ID to check the status of the authorization request.\n */\n id: string;\n\n /**\n * The time the authorization request was made.\n */\n requestedAt: number;\n\n /**\n * The time in seconds for the authorization request to expire.\n */\n expiresIn: number;\n\n /**\n * The interval to use when polling the status.\n */\n interval: number;\n};\n"]}
@@ -0,0 +1,31 @@
1
+ import { AuthenticationClient } from "auth0";
2
+ import { AuthorizerParams } from "../";
3
+ import { Credentials } from "../../credentials";
4
+ import { AuthorizationPendingInterrupt, AuthorizationPollingInterrupt } from "../../interrupts";
5
+ import { CIBAAuthorizationRequest } from "./CIBAAuthorizationRequest";
6
+ import { CIBAAuthorizerParams } from "./CIBAAuthorizerParams";
7
+ /**
8
+ * Requests authorization by prompting the user via an out-of-band channel from
9
+ * the backend.
10
+ */
11
+ export declare class CIBAAuthorizerBase<ToolExecuteArgs extends any[]> {
12
+ private readonly params;
13
+ auth0: AuthenticationClient;
14
+ constructor(auth0: AuthorizerParams, params: CIBAAuthorizerParams<ToolExecuteArgs>);
15
+ private start;
16
+ private getCredentialsInternal;
17
+ protected getCredentials(authRequest: CIBAAuthorizationRequest): Promise<Credentials | undefined>;
18
+ protected getCredentialsPolling(authRequest: CIBAAuthorizationRequest): Promise<Credentials | undefined>;
19
+ protected deleteAuthRequest(): Promise<void> | undefined;
20
+ /**
21
+ *
22
+ * Wraps the execute method of a AI tool to handle CIBA authorization.
23
+ *
24
+ * @param getContext - A function that returns the context of the tool execution.
25
+ * @param execute - The tool execute method.
26
+ * @returns The wrapped execute method.
27
+ */
28
+ protect(getContext: (...args: ToolExecuteArgs) => any, execute: (...args: ToolExecuteArgs) => any): (...args: ToolExecuteArgs) => any;
29
+ protected handleAuthorizationInterrupts(err: AuthorizationPendingInterrupt | AuthorizationPollingInterrupt): void;
30
+ }
31
+ //# sourceMappingURL=CIBAAuthorizerBase.d.ts.map
@@ -0,0 +1,197 @@
1
+ import { AuthenticationClient } from "auth0";
2
+ import { AccessDeniedInterrupt, AuthorizationPendingInterrupt, AuthorizationPollingInterrupt, AuthorizationRequestExpiredInterrupt, InvalidGrantInterrupt, UserDoesNotHavePushNotificationsInterrupt, } from "../../interrupts";
3
+ import { resolveParameter } from "../../parameters";
4
+ import { asyncLocalStorage } from "./asyncLocalStorage";
5
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6
+ function ensureOpenIdScope(scopes) {
7
+ return scopes.includes("openid") ? scopes : ["openid", ...scopes];
8
+ }
9
+ /**
10
+ * Requests authorization by prompting the user via an out-of-band channel from
11
+ * the backend.
12
+ */
13
+ export class CIBAAuthorizerBase {
14
+ constructor(auth0, params) {
15
+ this.params = params;
16
+ this.auth0 = new AuthenticationClient({
17
+ domain: (auth0 === null || auth0 === void 0 ? void 0 : auth0.domain) || process.env.AUTH0_DOMAIN,
18
+ clientId: (auth0 === null || auth0 === void 0 ? void 0 : auth0.clientId) || process.env.AUTH0_CLIENT_ID,
19
+ clientSecret: (auth0 === null || auth0 === void 0 ? void 0 : auth0.clientSecret) || process.env.AUTH0_CLIENT_SECRET,
20
+ clientAssertionSigningAlg: auth0 === null || auth0 === void 0 ? void 0 : auth0.clientAssertionSigningAlg,
21
+ clientAssertionSigningKey: auth0 === null || auth0 === void 0 ? void 0 : auth0.clientAssertionSigningKey,
22
+ idTokenSigningAlg: auth0 === null || auth0 === void 0 ? void 0 : auth0.idTokenSigningAlg,
23
+ clockTolerance: auth0 === null || auth0 === void 0 ? void 0 : auth0.clockTolerance,
24
+ useMTLS: auth0 === null || auth0 === void 0 ? void 0 : auth0.useMTLS,
25
+ });
26
+ }
27
+ async start(toolContext) {
28
+ var _a;
29
+ const requestedAt = Date.now() / 1000;
30
+ const authorizeParams = {
31
+ scope: ensureOpenIdScope(this.params.scopes).join(" "),
32
+ binding_message: "",
33
+ userId: "",
34
+ audience: this.params.audience || "",
35
+ request_expiry: (_a = this.params.requestExpiry) === null || _a === void 0 ? void 0 : _a.toString(),
36
+ };
37
+ authorizeParams.binding_message = await resolveParameter(this.params.bindingMessage, toolContext);
38
+ authorizeParams.userId = await resolveParameter(this.params.userID, toolContext);
39
+ try {
40
+ const response = await this.auth0.backchannel.authorize(authorizeParams);
41
+ return {
42
+ id: response.auth_req_id,
43
+ requestedAt: requestedAt,
44
+ expiresIn: response.expires_in,
45
+ interval: response.interval,
46
+ };
47
+ }
48
+ catch (err) {
49
+ if (err.error == "invalid_request") {
50
+ throw new UserDoesNotHavePushNotificationsInterrupt(err.error_description);
51
+ }
52
+ throw err;
53
+ }
54
+ }
55
+ async getCredentialsInternal(authRequest) {
56
+ try {
57
+ const elapsedSeconds = Date.now() / 1000 - authRequest.requestedAt;
58
+ if (elapsedSeconds >= authRequest.expiresIn) {
59
+ throw new AuthorizationRequestExpiredInterrupt("The authorization request has expired.", authRequest);
60
+ }
61
+ const response = await this.auth0.backchannel.backchannelGrant({
62
+ auth_req_id: authRequest.id,
63
+ });
64
+ const credentials = {
65
+ accessToken: {
66
+ type: response.token_type || "bearer",
67
+ value: response.access_token,
68
+ },
69
+ refreshToken: response.refresh_token
70
+ ? {
71
+ type: response.token_type || "bearer",
72
+ value: response.refresh_token,
73
+ }
74
+ : undefined,
75
+ idToken: response.id_token
76
+ ? {
77
+ type: response.token_type || "bearer",
78
+ value: response.id_token,
79
+ }
80
+ : undefined,
81
+ };
82
+ return credentials;
83
+ }
84
+ catch (e) {
85
+ if (e.error === "authorization_pending") {
86
+ throw new AuthorizationPendingInterrupt(e.error_description, authRequest);
87
+ }
88
+ if (e.error === "slow_down") {
89
+ throw new AuthorizationPollingInterrupt(e.error_description, authRequest);
90
+ }
91
+ if (e.error == "invalid_grant") {
92
+ throw new InvalidGrantInterrupt(e.error_description, authRequest);
93
+ }
94
+ if (e.error == "invalid_request") {
95
+ throw new UserDoesNotHavePushNotificationsInterrupt(e.error_description);
96
+ }
97
+ if (e.error == "access_denied") {
98
+ throw new AccessDeniedInterrupt(e.error_description, authRequest);
99
+ }
100
+ throw e;
101
+ }
102
+ }
103
+ async getCredentials(authRequest) {
104
+ return this.getCredentialsInternal(authRequest);
105
+ }
106
+ async getCredentialsPolling(authRequest) {
107
+ let credentials = undefined;
108
+ do {
109
+ try {
110
+ credentials = await this.getCredentialsInternal(authRequest);
111
+ }
112
+ catch (err) {
113
+ if (err instanceof AuthorizationPendingInterrupt ||
114
+ err instanceof AuthorizationPollingInterrupt) {
115
+ await sleep(err.request.interval * 1000);
116
+ }
117
+ else {
118
+ throw err;
119
+ }
120
+ }
121
+ } while (!credentials);
122
+ return credentials;
123
+ }
124
+ deleteAuthRequest() {
125
+ const store = asyncLocalStorage.getStore();
126
+ if (!store) {
127
+ throw new Error("This method should be called from within a tool.");
128
+ }
129
+ if (!this.params.onAuthorizationRequest ||
130
+ this.params.onAuthorizationRequest === "interrupt") {
131
+ return this.params.storeAuthorizationResponse(undefined, ...store.args);
132
+ }
133
+ }
134
+ /**
135
+ *
136
+ * Wraps the execute method of a AI tool to handle CIBA authorization.
137
+ *
138
+ * @param getContext - A function that returns the context of the tool execution.
139
+ * @param execute - The tool execute method.
140
+ * @returns The wrapped execute method.
141
+ */
142
+ protect(getContext, execute) {
143
+ return async (...args) => {
144
+ let authRequest;
145
+ if (asyncLocalStorage.getStore()) {
146
+ throw new Error("Cannot nest tool calls that require CIBA authorization.");
147
+ }
148
+ const storeValue = {
149
+ args,
150
+ context: getContext(...args),
151
+ };
152
+ return asyncLocalStorage.run(storeValue, async () => {
153
+ let credentials;
154
+ const interruptMode = typeof this.params.onAuthorizationRequest === "undefined" ||
155
+ this.params.onAuthorizationRequest === "interrupt";
156
+ try {
157
+ if (interruptMode) {
158
+ authRequest = await resolveParameter(this.params.getAuthorizationResponse, args);
159
+ if (!authRequest) {
160
+ //Initial request
161
+ authRequest = await this.start(args);
162
+ await this.params.storeAuthorizationResponse(authRequest, ...args);
163
+ }
164
+ credentials = await this.getCredentials(authRequest);
165
+ }
166
+ else {
167
+ authRequest = await this.start(args);
168
+ credentials = await this.getCredentialsPolling(authRequest);
169
+ }
170
+ }
171
+ catch (err) {
172
+ const shouldInterrupt = err instanceof AuthorizationPendingInterrupt ||
173
+ err instanceof AuthorizationPollingInterrupt;
174
+ if (shouldInterrupt) {
175
+ return this.handleAuthorizationInterrupts(err);
176
+ }
177
+ else {
178
+ await this.deleteAuthRequest();
179
+ if (typeof this.params.onUnauthorized === "function") {
180
+ return this.params.onUnauthorized(err, ...args);
181
+ }
182
+ else {
183
+ return err;
184
+ }
185
+ }
186
+ }
187
+ await this.deleteAuthRequest();
188
+ storeValue.credentials = credentials;
189
+ return execute(...args);
190
+ });
191
+ };
192
+ }
193
+ handleAuthorizationInterrupts(err) {
194
+ throw err;
195
+ }
196
+ }
197
+ //# sourceMappingURL=CIBAAuthorizerBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CIBAAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAI7C,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,6BAA6B,EAC7B,oCAAoC,EACpC,qBAAqB,EACrB,yCAAyC,GAC1C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAqB,MAAM,qBAAqB,CAAC;AAI3E,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAChF,SAAS,iBAAiB,CAAC,MAAgB;IACzC,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;AACpE,CAAC;AACD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAG7B,YACE,KAAuB,EACN,MAA6C;QAA7C,WAAM,GAAN,MAAM,CAAuC;QAE9D,IAAI,CAAC,KAAK,GAAG,IAAI,oBAAoB,CAAC;YACpC,MAAM,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,KAAI,OAAO,CAAC,GAAG,CAAC,YAAa;YAClD,QAAQ,EAAE,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,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBAC/B,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;gBACrC,OAAO,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAES,6BAA6B,CACrC,GAAkE;QAElE,MAAM,GAAG,CAAC;IACZ,CAAC;CACF","sourcesContent":["import { AuthenticationClient } from \"auth0\";\n\nimport { AuthorizerParams } from \"../\";\nimport { Credentials } from \"../../credentials\";\nimport {\n AccessDeniedInterrupt,\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n AuthorizationRequestExpiredInterrupt,\n InvalidGrantInterrupt,\n UserDoesNotHavePushNotificationsInterrupt,\n} from \"../../interrupts\";\nimport { resolveParameter } from \"../../parameters\";\nimport { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\nimport { CIBAAuthorizerParams } from \"./CIBAAuthorizerParams\";\n\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\nfunction ensureOpenIdScope(scopes: string[]): string[] {\n return scopes.includes(\"openid\") ? scopes : [\"openid\", ...scopes];\n}\n/**\n * Requests authorization by prompting the user via an out-of-band channel from\n * the backend.\n */\nexport class CIBAAuthorizerBase<ToolExecuteArgs extends any[]> {\n auth0: AuthenticationClient;\n\n constructor(\n auth0: AuthorizerParams,\n private readonly params: CIBAAuthorizerParams<ToolExecuteArgs>\n ) {\n this.auth0 = new AuthenticationClient({\n domain: auth0?.domain || process.env.AUTH0_DOMAIN!,\n clientId: auth0?.clientId || process.env.AUTH0_CLIENT_ID!,\n clientSecret: auth0?.clientSecret || process.env.AUTH0_CLIENT_SECRET,\n clientAssertionSigningAlg: auth0?.clientAssertionSigningAlg,\n clientAssertionSigningKey: auth0?.clientAssertionSigningKey,\n idTokenSigningAlg: auth0?.idTokenSigningAlg,\n clockTolerance: auth0?.clockTolerance,\n useMTLS: auth0?.useMTLS,\n });\n }\n\n private async start(\n toolContext: ToolExecuteArgs\n ): Promise<CIBAAuthorizationRequest> {\n const requestedAt = Date.now() / 1000;\n const authorizeParams = {\n scope: ensureOpenIdScope(this.params.scopes).join(\" \"),\n binding_message: \"\",\n userId: \"\",\n audience: this.params.audience || \"\",\n request_expiry: this.params.requestExpiry?.toString(),\n };\n\n authorizeParams.binding_message = await resolveParameter(\n this.params.bindingMessage,\n toolContext\n );\n\n authorizeParams.userId = await resolveParameter(\n this.params.userID,\n toolContext\n );\n\n try {\n const response = await this.auth0.backchannel.authorize(authorizeParams);\n\n return {\n id: response.auth_req_id,\n requestedAt: requestedAt,\n expiresIn: response.expires_in,\n interval: response.interval,\n };\n } catch (err: any) {\n if (err.error == \"invalid_request\") {\n throw new UserDoesNotHavePushNotificationsInterrupt(\n err.error_description\n );\n }\n throw err;\n }\n }\n\n private async getCredentialsInternal(\n authRequest: CIBAAuthorizationRequest\n ): Promise<Credentials | undefined> {\n try {\n const elapsedSeconds = Date.now() / 1000 - authRequest.requestedAt;\n\n if (elapsedSeconds >= authRequest.expiresIn) {\n throw new AuthorizationRequestExpiredInterrupt(\n \"The authorization request has expired.\",\n authRequest\n );\n }\n\n const response = await this.auth0.backchannel.backchannelGrant({\n auth_req_id: authRequest.id,\n });\n\n const credentials = {\n accessToken: {\n type: response.token_type || \"bearer\",\n value: response.access_token,\n },\n refreshToken: response.refresh_token\n ? {\n type: response.token_type || \"bearer\",\n value: response.refresh_token,\n }\n : undefined,\n idToken: response.id_token\n ? {\n type: response.token_type || \"bearer\",\n value: response.id_token,\n }\n : undefined,\n };\n\n return credentials;\n } catch (e: any) {\n if (e.error === \"authorization_pending\") {\n throw new AuthorizationPendingInterrupt(\n e.error_description,\n authRequest\n );\n }\n\n if (e.error === \"slow_down\") {\n throw new AuthorizationPollingInterrupt(\n e.error_description,\n authRequest\n );\n }\n\n if (e.error == \"invalid_grant\") {\n throw new InvalidGrantInterrupt(e.error_description, authRequest);\n }\n\n if (e.error == \"invalid_request\") {\n throw new UserDoesNotHavePushNotificationsInterrupt(\n e.error_description\n );\n }\n\n if (e.error == \"access_denied\") {\n throw new AccessDeniedInterrupt(e.error_description, authRequest);\n }\n\n throw e;\n }\n }\n\n protected async getCredentials(authRequest: CIBAAuthorizationRequest) {\n return this.getCredentialsInternal(authRequest);\n }\n\n protected async getCredentialsPolling(\n authRequest: CIBAAuthorizationRequest\n ): Promise<Credentials | undefined> {\n let credentials: Credentials | undefined = undefined;\n\n do {\n try {\n credentials = await this.getCredentialsInternal(authRequest);\n } catch (err) {\n if (\n err instanceof AuthorizationPendingInterrupt ||\n err instanceof AuthorizationPollingInterrupt\n ) {\n await sleep(err.request.interval * 1000);\n } else {\n throw err;\n }\n }\n } while (!credentials);\n\n return credentials;\n }\n\n protected deleteAuthRequest() {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\"This method should be called from within a tool.\");\n }\n if (\n !this.params.onAuthorizationRequest ||\n this.params.onAuthorizationRequest === \"interrupt\"\n ) {\n return this.params.storeAuthorizationResponse(\n undefined,\n ...(store.args as ToolExecuteArgs)\n );\n }\n }\n\n /**\n *\n * Wraps the execute method of a AI tool to handle CIBA authorization.\n *\n * @param getContext - A function that returns the context of the tool execution.\n * @param execute - The tool execute method.\n * @returns The wrapped execute method.\n */\n protect(\n getContext: (...args: ToolExecuteArgs) => any,\n execute: (...args: ToolExecuteArgs) => any\n ): (...args: ToolExecuteArgs) => any {\n return async (...args: ToolExecuteArgs) => {\n let authRequest: CIBAAuthorizationRequest | undefined;\n if (asyncLocalStorage.getStore()) {\n throw new Error(\n \"Cannot nest tool calls that require CIBA authorization.\"\n );\n }\n\n const storeValue: AsyncStorageValue<any> = {\n args,\n context: getContext(...args),\n };\n\n return asyncLocalStorage.run(storeValue, async () => {\n let credentials: Credentials | undefined;\n\n const interruptMode =\n typeof this.params.onAuthorizationRequest === \"undefined\" ||\n this.params.onAuthorizationRequest === \"interrupt\";\n\n try {\n if (interruptMode) {\n authRequest = await resolveParameter(\n this.params.getAuthorizationResponse,\n args\n );\n if (!authRequest) {\n //Initial request\n authRequest = await this.start(args);\n await this.params.storeAuthorizationResponse(\n authRequest,\n ...args\n );\n }\n credentials = await this.getCredentials(authRequest);\n } else {\n authRequest = await this.start(args);\n credentials = await this.getCredentialsPolling(authRequest);\n }\n } catch (err) {\n const shouldInterrupt =\n err instanceof AuthorizationPendingInterrupt ||\n err instanceof AuthorizationPollingInterrupt;\n if (shouldInterrupt) {\n return this.handleAuthorizationInterrupts(err);\n } else {\n await this.deleteAuthRequest();\n if (typeof this.params.onUnauthorized === \"function\") {\n return this.params.onUnauthorized(err as Error, ...args);\n } else {\n return err;\n }\n }\n }\n await this.deleteAuthRequest();\n storeValue.credentials = credentials;\n return execute(...args);\n });\n };\n }\n\n protected handleAuthorizationInterrupts(\n err: AuthorizationPendingInterrupt | AuthorizationPollingInterrupt\n ) {\n throw err;\n }\n}\n"]}
@@ -0,0 +1,66 @@
1
+ import { CIBAInterrupt } from "../../interrupts";
2
+ import { AuthorizerToolParameter } from "../../parameters";
3
+ import { CIBAAuthorizationRequest } from "./CIBAAuthorizationRequest";
4
+ export type OnAuthorizationRequest = "block" | "interrupt";
5
+ export type CIBAAuthorizerParams<ToolExecuteArgs extends any[]> = {
6
+ /**
7
+ * The user ID to request authorization for.
8
+ */
9
+ userID: AuthorizerToolParameter<ToolExecuteArgs>;
10
+ /**
11
+ * The binding message to send to the user.
12
+ */
13
+ bindingMessage: AuthorizerToolParameter<ToolExecuteArgs>;
14
+ /**
15
+ * The scope to request authorization for.
16
+ */
17
+ scopes: string[];
18
+ /**
19
+ * The audience to request authorization for.
20
+ */
21
+ audience?: string;
22
+ /**
23
+ * The time in seconds for the authorization request to expire.
24
+ */
25
+ requestExpiry?: number;
26
+ /**
27
+ * The behavior when the authorization request is made.
28
+ *
29
+ * - `block`: The tool execution is blocked until the user completes the authorization.
30
+ * - `interrupt`: The tool execution is interrupted until the user completes the authorization.
31
+ *
32
+ * Defaults to `interrupt`.
33
+ * Note: The block mode is only useful for development purposes and should not be used in production.
34
+ */
35
+ onAuthorizationRequest?: OnAuthorizationRequest;
36
+ /**
37
+ *
38
+ * Optional callback to generate a tool result when the invocation is not authorized.
39
+ *
40
+ * By default it will return the instance of the Error.
41
+ *
42
+ * @param args - The tool execution arguments.
43
+ * @returns The response to return when the invocation is not authorized.
44
+ */
45
+ onUnauthorized?: (err: Error | CIBAInterrupt, ...args: ToolExecuteArgs) => any;
46
+ } & ({
47
+ onAuthorizationRequest: "block";
48
+ } | {
49
+ onAuthorizationRequest?: "interrupt";
50
+ /**
51
+ * Retrieves the authorization response data.
52
+ * @param args - The tool execution arguments.
53
+ * @returns The authorization response data.
54
+ * @remarks The data should be stored in a way that it can be retrieved later by the `storeAuthorizationResponse` parameter.
55
+ */
56
+ getAuthorizationResponse: AuthorizerToolParameter<ToolExecuteArgs, CIBAAuthorizationRequest | undefined>;
57
+ /**
58
+ * Stores the authorization response data.
59
+ * @param request - The authorization response data.
60
+ * @param args - The tool execution arguments.
61
+ * @returns A promise that resolves when the data is stored.
62
+ * @remarks The data should be stored in a way that it can be retrieved later by the `getAuthorizationResponse` parameter.
63
+ **/
64
+ storeAuthorizationResponse: (request: CIBAAuthorizationRequest | undefined, ...args: ToolExecuteArgs) => Promise<void>;
65
+ });
66
+ //# sourceMappingURL=CIBAAuthorizerParams.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CIBAAuthorizerParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CIBAAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { CIBAInterrupt } from \"../../interrupts\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\n\nexport type OnAuthorizationRequest = \"block\" | \"interrupt\";\n\nexport type CIBAAuthorizerParams<ToolExecuteArgs extends any[]> = {\n /**\n * The user ID to request authorization for.\n */\n userID: AuthorizerToolParameter<ToolExecuteArgs>;\n\n /**\n * The binding message to send to the user.\n */\n bindingMessage: AuthorizerToolParameter<ToolExecuteArgs>;\n\n /**\n * The scope to request authorization for.\n */\n scopes: string[];\n\n /**\n * The audience to request authorization for.\n */\n audience?: string;\n\n /**\n * The time in seconds for the authorization request to expire.\n */\n requestExpiry?: number;\n\n /**\n * The behavior when the authorization request is made.\n *\n * - `block`: The tool execution is blocked until the user completes the authorization.\n * - `interrupt`: The tool execution is interrupted until the user completes the authorization.\n *\n * Defaults to `interrupt`.\n * Note: The block mode is only useful for development purposes and should not be used in production.\n */\n onAuthorizationRequest?: OnAuthorizationRequest;\n\n /**\n *\n * Optional callback to generate a tool result when the invocation is not authorized.\n *\n * By default it will return the instance of the Error.\n *\n * @param args - The tool execution arguments.\n * @returns The response to return when the invocation is not authorized.\n */\n onUnauthorized?: (\n err: Error | CIBAInterrupt,\n ...args: ToolExecuteArgs\n ) => any;\n} & (\n | {\n onAuthorizationRequest: \"block\";\n }\n | {\n onAuthorizationRequest?: \"interrupt\";\n\n /**\n * Retrieves the authorization response data.\n * @param args - The tool execution arguments.\n * @returns The authorization response data.\n * @remarks The data should be stored in a way that it can be retrieved later by the `storeAuthorizationResponse` parameter.\n */\n getAuthorizationResponse: AuthorizerToolParameter<\n ToolExecuteArgs,\n CIBAAuthorizationRequest | undefined\n >;\n\n /**\n * Stores the authorization response data.\n * @param request - The authorization response data.\n * @param args - The tool execution arguments.\n * @returns A promise that resolves when the data is stored.\n * @remarks The data should be stored in a way that it can be retrieved later by the `getAuthorizationResponse` parameter.\n **/\n storeAuthorizationResponse: (\n request: CIBAAuthorizationRequest | undefined,\n ...args: ToolExecuteArgs\n ) => Promise<void>;\n }\n);\n"]}