@minded-ai/mindedjs 2.0.5 → 2.0.6-beta-1

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 (132) hide show
  1. package/dist/cli/index.js +0 -0
  2. package/dist/guidelines/guidelinesManager.d.ts +37 -0
  3. package/dist/guidelines/guidelinesManager.d.ts.map +1 -0
  4. package/dist/guidelines/guidelinesManager.js +172 -0
  5. package/dist/guidelines/guidelinesManager.js.map +1 -0
  6. package/dist/internalTools/documentExtraction.d.ts +69 -0
  7. package/dist/internalTools/documentExtraction.d.ts.map +1 -0
  8. package/dist/internalTools/documentExtraction.js +65 -0
  9. package/dist/internalTools/documentExtraction.js.map +1 -0
  10. package/dist/internalTools/managedDocumentParser/managedDocumentParser.d.ts +10 -0
  11. package/dist/internalTools/managedDocumentParser/managedDocumentParser.d.ts.map +1 -0
  12. package/dist/internalTools/managedDocumentParser/managedDocumentParser.js +80 -0
  13. package/dist/internalTools/managedDocumentParser/managedDocumentParser.js.map +1 -0
  14. package/dist/internalTools/retell.d.ts +12 -0
  15. package/dist/internalTools/retell.d.ts.map +1 -0
  16. package/dist/internalTools/retell.js +44 -0
  17. package/dist/internalTools/retell.js.map +1 -0
  18. package/dist/internalTools/sendPlaceholderMessage.d.ts +14 -0
  19. package/dist/internalTools/sendPlaceholderMessage.d.ts.map +1 -0
  20. package/dist/internalTools/sendPlaceholderMessage.js +51 -0
  21. package/dist/internalTools/sendPlaceholderMessage.js.map +1 -0
  22. package/dist/pii-gateway/gateway.d.ts +17 -0
  23. package/dist/pii-gateway/gateway.d.ts.map +1 -0
  24. package/dist/pii-gateway/gateway.js +77 -0
  25. package/dist/pii-gateway/gateway.js.map +1 -0
  26. package/dist/pii-gateway/index.d.ts +4 -0
  27. package/dist/pii-gateway/index.d.ts.map +1 -0
  28. package/dist/pii-gateway/index.js +14 -0
  29. package/dist/pii-gateway/index.js.map +1 -0
  30. package/dist/pii-gateway/proxy.d.ts +80 -0
  31. package/dist/pii-gateway/proxy.d.ts.map +1 -0
  32. package/dist/pii-gateway/proxy.js +106 -0
  33. package/dist/pii-gateway/proxy.js.map +1 -0
  34. package/dist/pii-gateway/types.d.ts +27 -0
  35. package/dist/pii-gateway/types.d.ts.map +1 -0
  36. package/dist/pii-gateway/types.js +3 -0
  37. package/dist/pii-gateway/types.js.map +1 -0
  38. package/dist/platform/mindedChatOpenAI.d.ts +5 -0
  39. package/dist/platform/mindedChatOpenAI.d.ts.map +1 -0
  40. package/dist/platform/mindedChatOpenAI.js +23 -0
  41. package/dist/platform/mindedChatOpenAI.js.map +1 -0
  42. package/dist/platform/mindedUtils.d.ts +1 -0
  43. package/dist/platform/mindedUtils.d.ts.map +1 -0
  44. package/dist/platform/mindedUtils.js +2 -0
  45. package/dist/platform/mindedUtils.js.map +1 -0
  46. package/dist/platform/parallelAzureChatOpenAI.d.ts +39 -0
  47. package/dist/platform/parallelAzureChatOpenAI.d.ts.map +1 -0
  48. package/dist/platform/parallelAzureChatOpenAI.js +114 -0
  49. package/dist/platform/parallelAzureChatOpenAI.js.map +1 -0
  50. package/dist/platform/parallelChatOpenAI.d.ts +38 -0
  51. package/dist/platform/parallelChatOpenAI.d.ts.map +1 -0
  52. package/dist/platform/parallelChatOpenAI.js +111 -0
  53. package/dist/platform/parallelChatOpenAI.js.map +1 -0
  54. package/dist/platform/parallelMindedChatOpenAI.d.ts +39 -0
  55. package/dist/platform/parallelMindedChatOpenAI.d.ts.map +1 -0
  56. package/dist/platform/parallelMindedChatOpenAI.js +111 -0
  57. package/dist/platform/parallelMindedChatOpenAI.js.map +1 -0
  58. package/dist/platform/piiGateway/proxy.d.ts +20 -0
  59. package/dist/platform/piiGateway/proxy.d.ts.map +1 -0
  60. package/dist/platform/piiGateway/proxy.js +24 -0
  61. package/dist/platform/piiGateway/proxy.js.map +1 -0
  62. package/dist/types/Agent.d.ts +2 -0
  63. package/dist/types/Agent.d.ts.map +1 -0
  64. package/dist/types/Agent.js +18 -0
  65. package/dist/types/Agent.js.map +1 -0
  66. package/dist/types/Flows.d.ts +2 -0
  67. package/dist/types/Flows.d.ts.map +1 -0
  68. package/dist/types/Flows.js +18 -0
  69. package/dist/types/Flows.js.map +1 -0
  70. package/dist/types/LLM.d.ts +2 -0
  71. package/dist/types/LLM.d.ts.map +1 -0
  72. package/dist/types/LLM.js +18 -0
  73. package/dist/types/LLM.js.map +1 -0
  74. package/dist/types/LangGraph.d.ts +2 -0
  75. package/dist/types/LangGraph.d.ts.map +1 -0
  76. package/dist/types/LangGraph.js +18 -0
  77. package/dist/types/LangGraph.js.map +1 -0
  78. package/dist/types/Platform.d.ts +2 -0
  79. package/dist/types/Platform.d.ts.map +1 -0
  80. package/dist/types/Platform.js +18 -0
  81. package/dist/types/Platform.js.map +1 -0
  82. package/dist/types/Tools.d.ts +2 -0
  83. package/dist/types/Tools.d.ts.map +1 -0
  84. package/dist/types/Tools.js +18 -0
  85. package/dist/types/Tools.js.map +1 -0
  86. package/dist/types/Triggers.d.ts +2 -0
  87. package/dist/types/Triggers.d.ts.map +1 -0
  88. package/dist/types/Triggers.js +18 -0
  89. package/dist/types/Triggers.js.map +1 -0
  90. package/dist/types/Triggers.types.d.ts +25 -0
  91. package/dist/types/Triggers.types.d.ts.map +1 -0
  92. package/dist/types/Triggers.types.js +3 -0
  93. package/dist/types/Triggers.types.js.map +1 -0
  94. package/dist/types/Voice.d.ts +2 -0
  95. package/dist/types/Voice.d.ts.map +1 -0
  96. package/dist/types/Voice.js +18 -0
  97. package/dist/types/Voice.js.map +1 -0
  98. package/dist/types/index.d.ts +9 -0
  99. package/dist/types/index.d.ts.map +1 -0
  100. package/dist/types/index.js +25 -0
  101. package/dist/types/index.js.map +1 -0
  102. package/dist/utils/LogicalConditionDebugger.d.ts +57 -0
  103. package/dist/utils/LogicalConditionDebugger.d.ts.map +1 -0
  104. package/dist/utils/LogicalConditionDebugger.js +143 -0
  105. package/dist/utils/LogicalConditionDebugger.js.map +1 -0
  106. package/dist/utils/documentProcessor.d.ts +87 -0
  107. package/dist/utils/documentProcessor.d.ts.map +1 -0
  108. package/dist/utils/documentProcessor.js +726 -0
  109. package/dist/utils/documentProcessor.js.map +1 -0
  110. package/dist/utils/extractStateMemoryResponse.d.ts +1 -0
  111. package/dist/utils/extractStateMemoryResponse.d.ts.map +1 -0
  112. package/dist/utils/extractStateMemoryResponse.js +89 -0
  113. package/dist/utils/extractStateMemoryResponse.js.map +1 -0
  114. package/dist/utils/extractToolGuidelineParams.d.ts +4 -0
  115. package/dist/utils/extractToolGuidelineParams.d.ts.map +1 -0
  116. package/dist/utils/extractToolGuidelineParams.js +20 -0
  117. package/dist/utils/extractToolGuidelineParams.js.map +1 -0
  118. package/dist/utils/extractToolMemoryResponse.d.ts +4 -0
  119. package/dist/utils/extractToolMemoryResponse.d.ts.map +1 -0
  120. package/dist/utils/extractToolMemoryResponse.js +16 -0
  121. package/dist/utils/extractToolMemoryResponse.js.map +1 -0
  122. package/dist/utils/parseAttachments.d.ts +14 -0
  123. package/dist/utils/parseAttachments.d.ts.map +1 -0
  124. package/dist/utils/parseAttachments.js +54 -0
  125. package/dist/utils/parseAttachments.js.map +1 -0
  126. package/package.json +2 -2
  127. package/src/agent.ts +5 -0
  128. package/src/cli/lambdaHandlerTemplate.ts +53 -38
  129. package/src/debugging/llmCallbackHandler.ts +6 -7
  130. package/src/internalTools/timer.ts +1 -1
  131. package/src/platform/mindedConnection.ts +38 -20
  132. package/src/utils/logger.ts +1 -0
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PIIGateway = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const mindedConnectionTypes_1 = require("../platform/mindedConnectionTypes");
6
+ class PIIGateway {
7
+ constructor(mindedConnection, sessionId) {
8
+ this.mindedConnection = mindedConnection;
9
+ this.sessionId = sessionId;
10
+ }
11
+ async makeRequest(method, url, data, config) {
12
+ var _a;
13
+ if (!((_a = this.mindedConnection) === null || _a === void 0 ? void 0 : _a.isConnected)) {
14
+ throw new Error('Minded connection is not established. PII-secured HTTP requests require a connection to the Minded platform.');
15
+ }
16
+ try {
17
+ const requestId = (0, uuid_1.v4)();
18
+ const requestPayload = {
19
+ type: mindedConnectionTypes_1.MindedConnectionSocketMessageType.PII_HTTP_REQUEST,
20
+ requestId,
21
+ method,
22
+ url,
23
+ headers: config === null || config === void 0 ? void 0 : config.headers,
24
+ params: config === null || config === void 0 ? void 0 : config.params,
25
+ data,
26
+ sessionId: this.sessionId,
27
+ };
28
+ const response = await this.mindedConnection.awaitEmit(mindedConnectionTypes_1.MindedConnectionSocketMessageType.PII_HTTP_REQUEST, requestPayload, 30000);
29
+ if (response.error) {
30
+ throw new Error(`HTTP request failed: ${response.error}`);
31
+ }
32
+ // Verify that the response requestId matches our request
33
+ if (response.requestId && response.requestId !== requestId) {
34
+ console.warn(`Response requestId (${response.requestId}) does not match request requestId (${requestId})`);
35
+ }
36
+ // Return generic HttpResponse format
37
+ return {
38
+ data: response.data,
39
+ status: response.status || 200,
40
+ statusText: response.statusText || 'OK',
41
+ headers: response.headers || {},
42
+ config: config || {},
43
+ };
44
+ }
45
+ catch (error) {
46
+ throw new Error(`Secure HTTP request failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
47
+ }
48
+ }
49
+ async get(url, config) {
50
+ return this.makeRequest('GET', url, undefined, config);
51
+ }
52
+ async post(url, data, config) {
53
+ return this.makeRequest('POST', url, data, config);
54
+ }
55
+ async put(url, data, config) {
56
+ return this.makeRequest('PUT', url, data, config);
57
+ }
58
+ async delete(url, config) {
59
+ return this.makeRequest('DELETE', url, undefined, config);
60
+ }
61
+ async patch(url, data, config) {
62
+ return this.makeRequest('PATCH', url, data, config);
63
+ }
64
+ async head(url, config) {
65
+ return this.makeRequest('HEAD', url, undefined, config);
66
+ }
67
+ async options(url, config) {
68
+ return this.makeRequest('OPTIONS', url, undefined, config);
69
+ }
70
+ async request(config) {
71
+ var _a;
72
+ const method = (((_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'GET');
73
+ return this.makeRequest(method, config.url || '', config.data, config);
74
+ }
75
+ }
76
+ exports.PIIGateway = PIIGateway;
77
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/pii-gateway/gateway.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAEpC,6EAA2H;AAG3H,MAAa,UAAU;IAIrB,YAAY,gBAAkC,EAAE,SAAiB;QAC/D,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAEO,KAAK,CAAC,WAAW,CACvB,MAAwE,EACxE,GAAW,EACX,IAAU,EACV,MAA0B;;QAE1B,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,gBAAgB,0CAAE,WAAW,CAAA,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,8GAA8G,CAAC,CAAC;QAClI,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAC3B,MAAM,cAAc,GAAqB;gBACvC,IAAI,EAAE,yDAAiC,CAAC,gBAAgB;gBACxD,SAAS;gBACT,MAAM;gBACN,GAAG;gBACH,OAAO,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAiC;gBAClD,MAAM,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM;gBACtB,IAAI;gBACJ,SAAS,EAAE,IAAI,CAAC,SAAS;aAC1B,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CACpD,yDAAiC,CAAC,gBAAgB,EAClD,cAAc,EACd,KAAK,CACN,CAAC;YAEF,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,CAAC,KAAK,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O,IAAI,CAAC,WAAW,CAAI,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,KAAK,CAAU,GAAW,EAAE,IAAU,EAAE,MAA0B;QACtE,OAAO,IAAI,CAAC,WAAW,CAAI,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,IAAI,CAAU,GAAW,EAAE,MAA0B;QACzD,OAAO,IAAI,CAAC,WAAW,CAAI,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,OAAO,CAAU,GAAW,EAAE,MAA0B;QAC5D,OAAO,IAAI,CAAC,WAAW,CAAI,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,OAAO,CAAU,MAAyB;;QAC9C,MAAM,MAAM,GAAG,CAAC,CAAA,MAAA,MAAM,CAAC,MAAM,0CAAE,WAAW,EAAE,KAAI,KAAK,CAAQ,CAAC;QAC9D,OAAO,IAAI,CAAC,WAAW,CAAI,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5E,CAAC;CACF;AA5FD,gCA4FC"}
@@ -0,0 +1,4 @@
1
+ export type { HttpRequestConfig, HttpResponse, PIIGatewayInstance } from './types';
2
+ export { PIIGateway } from './gateway';
3
+ export { piiGateway, getPIIGateway, createPIIGateway, _setGlobalPIIGateway, _clearGlobalPIIGateway } from './proxy';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pii-gateway/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGnF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._clearGlobalPIIGateway = exports._setGlobalPIIGateway = exports.createPIIGateway = exports.getPIIGateway = exports.piiGateway = exports.PIIGateway = void 0;
4
+ // Export core gateway class
5
+ var gateway_1 = require("./gateway");
6
+ Object.defineProperty(exports, "PIIGateway", { enumerable: true, get: function () { return gateway_1.PIIGateway; } });
7
+ // Export proxy and management functions
8
+ var proxy_1 = require("./proxy");
9
+ Object.defineProperty(exports, "piiGateway", { enumerable: true, get: function () { return proxy_1.piiGateway; } });
10
+ Object.defineProperty(exports, "getPIIGateway", { enumerable: true, get: function () { return proxy_1.getPIIGateway; } });
11
+ Object.defineProperty(exports, "createPIIGateway", { enumerable: true, get: function () { return proxy_1.createPIIGateway; } });
12
+ Object.defineProperty(exports, "_setGlobalPIIGateway", { enumerable: true, get: function () { return proxy_1._setGlobalPIIGateway; } });
13
+ Object.defineProperty(exports, "_clearGlobalPIIGateway", { enumerable: true, get: function () { return proxy_1._clearGlobalPIIGateway; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pii-gateway/index.ts"],"names":[],"mappings":";;;AAGA,4BAA4B;AAC5B,qCAAuC;AAA9B,qGAAA,UAAU,OAAA;AAEnB,wCAAwC;AACxC,iCAAoH;AAA3G,mGAAA,UAAU,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAAE,+GAAA,sBAAsB,OAAA"}
@@ -0,0 +1,80 @@
1
+ import { MindedConnection } from '../platform/mindedConnection';
2
+ import { PIIGatewayInstance } from './types';
3
+ /**
4
+ * Global PII Gateway that is automatically initialized when a trigger with sessionId is received.
5
+ * This provides seamless access to PII masking capabilities within workflows and custom tools.
6
+ *
7
+ * The gateway acts as a proxy that automatically uses the current session's PII context.
8
+ * All standard HTTP methods (get, post, put, delete, patch, head, options, request) are available.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { piiGateway } from '@minded-ai/mindedjs';
13
+ *
14
+ * // Within a custom tool or workflow (after trigger is received)
15
+ * async function fetchUserData() {
16
+ * const response = await piiGateway.get('/api/user/profile');
17
+ * return response.data;
18
+ * }
19
+ *
20
+ * // POST request
21
+ * const createResponse = await piiGateway.post('/api/users', {
22
+ * name: 'John Doe',
23
+ * email: 'john@example.com'
24
+ * });
25
+ * ```
26
+ */
27
+ export declare const piiGateway: PIIGatewayInstance;
28
+ /**
29
+ * Get the global PII Gateway instance that is automatically initialized when a trigger with sessionId is received.
30
+ * This provides seamless access to PII masking capabilities within workflows and custom tools.
31
+ *
32
+ * @returns The PII Gateway instance for the current session
33
+ * @throws {Error} When no active session or PII gateway is not initialized
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { getPIIGateway } from '@minded-ai/mindedjs';
38
+ *
39
+ * // Within a custom tool or workflow (after trigger is received)
40
+ * async function fetchUserData() {
41
+ * const piiGateway = getPIIGateway();
42
+ * const response = await piiGateway.get('/api/user/profile');
43
+ * return response.data;
44
+ * }
45
+ * ```
46
+ */
47
+ export declare function getPIIGateway(): PIIGatewayInstance;
48
+ /**
49
+ * Create a PII Gateway instance with a specific Minded connection and session ID.
50
+ * This is used internally by the Agent and for advanced use cases.
51
+ *
52
+ * @param mindedConnection - The Minded connection to use for the requests
53
+ * @param sessionId - Session ID for PII context (required for proper masking)
54
+ * @returns A PII Gateway instance
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * import { createPIIGateway } from '@minded-ai/mindedjs';
59
+ *
60
+ * const piiGateway = createPIIGateway(mindedConnection, 'session-123');
61
+ * const response = await piiGateway.get('/api/data');
62
+ * ```
63
+ */
64
+ export declare function createPIIGateway(mindedConnection: MindedConnection, sessionId: string): PIIGatewayInstance;
65
+ /**
66
+ * Internal function used by the Agent to set the global PII gateway when a trigger is received.
67
+ * This ensures the PII masking is automatically available to SDK users.
68
+ *
69
+ * @internal
70
+ * @param mindedConnection - The Minded connection to use
71
+ * @param sessionId - The session ID from the trigger
72
+ */
73
+ export declare function _setGlobalPIIGateway(mindedConnection: MindedConnection, sessionId: string): void;
74
+ /**
75
+ * Internal function to clear the global PII gateway.
76
+ *
77
+ * @internal
78
+ */
79
+ export declare function _clearGlobalPIIGateway(): void;
80
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../src/pii-gateway/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM7C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,UAAU,EAAE,kBAOvB,CAAC;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,IAAI,kBAAkB,CAKlD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,GAAG,kBAAkB,CAE1G;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAEhG;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.piiGateway = void 0;
4
+ exports.getPIIGateway = getPIIGateway;
5
+ exports.createPIIGateway = createPIIGateway;
6
+ exports._setGlobalPIIGateway = _setGlobalPIIGateway;
7
+ exports._clearGlobalPIIGateway = _clearGlobalPIIGateway;
8
+ const gateway_1 = require("./gateway");
9
+ // Global PII gateway instance that gets automatically set when triggers are received
10
+ let globalPIIGateway = null;
11
+ /**
12
+ * Global PII Gateway that is automatically initialized when a trigger with sessionId is received.
13
+ * This provides seamless access to PII masking capabilities within workflows and custom tools.
14
+ *
15
+ * The gateway acts as a proxy that automatically uses the current session's PII context.
16
+ * All standard HTTP methods (get, post, put, delete, patch, head, options, request) are available.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { piiGateway } from '@minded-ai/mindedjs';
21
+ *
22
+ * // Within a custom tool or workflow (after trigger is received)
23
+ * async function fetchUserData() {
24
+ * const response = await piiGateway.get('/api/user/profile');
25
+ * return response.data;
26
+ * }
27
+ *
28
+ * // POST request
29
+ * const createResponse = await piiGateway.post('/api/users', {
30
+ * name: 'John Doe',
31
+ * email: 'john@example.com'
32
+ * });
33
+ * ```
34
+ */
35
+ exports.piiGateway = new Proxy({}, {
36
+ get(target, prop) {
37
+ if (!globalPIIGateway) {
38
+ throw new Error('PII Gateway is not available. Ensure a trigger with sessionId has been received first.');
39
+ }
40
+ return globalPIIGateway[prop];
41
+ },
42
+ });
43
+ /**
44
+ * Get the global PII Gateway instance that is automatically initialized when a trigger with sessionId is received.
45
+ * This provides seamless access to PII masking capabilities within workflows and custom tools.
46
+ *
47
+ * @returns The PII Gateway instance for the current session
48
+ * @throws {Error} When no active session or PII gateway is not initialized
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { getPIIGateway } from '@minded-ai/mindedjs';
53
+ *
54
+ * // Within a custom tool or workflow (after trigger is received)
55
+ * async function fetchUserData() {
56
+ * const piiGateway = getPIIGateway();
57
+ * const response = await piiGateway.get('/api/user/profile');
58
+ * return response.data;
59
+ * }
60
+ * ```
61
+ */
62
+ function getPIIGateway() {
63
+ if (!globalPIIGateway) {
64
+ throw new Error('PII Gateway is not available. Ensure a trigger with sessionId has been received first.');
65
+ }
66
+ return globalPIIGateway;
67
+ }
68
+ /**
69
+ * Create a PII Gateway instance with a specific Minded connection and session ID.
70
+ * This is used internally by the Agent and for advanced use cases.
71
+ *
72
+ * @param mindedConnection - The Minded connection to use for the requests
73
+ * @param sessionId - Session ID for PII context (required for proper masking)
74
+ * @returns A PII Gateway instance
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * import { createPIIGateway } from '@minded-ai/mindedjs';
79
+ *
80
+ * const piiGateway = createPIIGateway(mindedConnection, 'session-123');
81
+ * const response = await piiGateway.get('/api/data');
82
+ * ```
83
+ */
84
+ function createPIIGateway(mindedConnection, sessionId) {
85
+ return new gateway_1.PIIGateway(mindedConnection, sessionId);
86
+ }
87
+ /**
88
+ * Internal function used by the Agent to set the global PII gateway when a trigger is received.
89
+ * This ensures the PII masking is automatically available to SDK users.
90
+ *
91
+ * @internal
92
+ * @param mindedConnection - The Minded connection to use
93
+ * @param sessionId - The session ID from the trigger
94
+ */
95
+ function _setGlobalPIIGateway(mindedConnection, sessionId) {
96
+ globalPIIGateway = new gateway_1.PIIGateway(mindedConnection, sessionId);
97
+ }
98
+ /**
99
+ * Internal function to clear the global PII gateway.
100
+ *
101
+ * @internal
102
+ */
103
+ function _clearGlobalPIIGateway() {
104
+ globalPIIGateway = null;
105
+ }
106
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/pii-gateway/proxy.ts"],"names":[],"mappings":";;;AA2DA,sCAKC;AAkBD,4CAEC;AAUD,oDAEC;AAOD,wDAEC;AAvGD,uCAAuC;AAEvC,qFAAqF;AACrF,IAAI,gBAAgB,GAAsB,IAAI,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACU,QAAA,UAAU,GAAuB,IAAI,KAAK,CAAC,EAAwB,EAAE;IAChF,GAAG,CAAC,MAAM,EAAE,IAAI;QACd,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAC;QAC5G,CAAC;QACD,OAAQ,gBAAwB,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;CACF,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,aAAa;IAC3B,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAC;IAC5G,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,gBAAgB,CAAC,gBAAkC,EAAE,SAAiB;IACpF,OAAO,IAAI,oBAAU,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAAC,gBAAkC,EAAE,SAAiB;IACxF,gBAAgB,GAAG,IAAI,oBAAU,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB;IACpC,gBAAgB,GAAG,IAAI,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,27 @@
1
+ export interface HttpRequestConfig {
2
+ method?: string;
3
+ url?: string;
4
+ headers?: Record<string, string>;
5
+ params?: Record<string, any>;
6
+ data?: any;
7
+ timeout?: number;
8
+ [key: string]: any;
9
+ }
10
+ export interface HttpResponse<T = any> {
11
+ data: T;
12
+ status: number;
13
+ statusText: string;
14
+ headers: Record<string, string>;
15
+ config: HttpRequestConfig;
16
+ }
17
+ export interface PIIGatewayInstance {
18
+ get<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
19
+ post<T = any>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
20
+ put<T = any>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
21
+ delete<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
22
+ patch<T = any>(url: string, data?: any, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
23
+ head<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
24
+ options<T = any>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
25
+ request<T = any>(config: HttpRequestConfig): Promise<HttpResponse<T>>;
26
+ }
27
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pii-gateway/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,GAAG;IACnC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5F,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACnF,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9F,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACjF,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACpF,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CACvE"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pii-gateway/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { ChatOpenAI, ChatOpenAIFields } from "@langchain/openai";
2
+ export declare class MindedChatOpenAI extends ChatOpenAI {
3
+ constructor(fields?: ChatOpenAIFields);
4
+ }
5
+ //# sourceMappingURL=mindedChatOpenAI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mindedChatOpenAI.d.ts","sourceRoot":"","sources":["../../src/platform/mindedChatOpenAI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGjE,qBAAa,gBAAiB,SAAQ,UAAU;gBAClC,MAAM,CAAC,EAAE,gBAAgB;CActC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MindedChatOpenAI = void 0;
4
+ const openai_1 = require("@langchain/openai");
5
+ const config_1 = require("./config");
6
+ class MindedChatOpenAI extends openai_1.ChatOpenAI {
7
+ constructor(fields) {
8
+ const { token, baseUrl } = (0, config_1.getConfig)();
9
+ const mindedBaseUrl = `${baseUrl}/sdk/llmGateway/chatOpenAI`;
10
+ if (!token) {
11
+ throw new Error('Minded token not found');
12
+ }
13
+ super({
14
+ ...fields,
15
+ apiKey: token,
16
+ configuration: {
17
+ baseURL: mindedBaseUrl,
18
+ },
19
+ });
20
+ }
21
+ }
22
+ exports.MindedChatOpenAI = MindedChatOpenAI;
23
+ //# sourceMappingURL=mindedChatOpenAI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mindedChatOpenAI.js","sourceRoot":"","sources":["../../src/platform/mindedChatOpenAI.ts"],"names":[],"mappings":";;;AAAA,8CAAiE;AACjE,qCAAqC;AAErC,MAAa,gBAAiB,SAAQ,mBAAU;IAC9C,YAAY,MAAyB;QACnC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAA,kBAAS,GAAE,CAAC;QACvC,MAAM,aAAa,GAAG,GAAG,OAAO,4BAA4B,CAAC;QAC7D,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC;YACJ,GAAG,MAAM;YACT,MAAM,EAAE,KAAK;YACb,aAAa,EAAE;gBACb,OAAO,EAAE,aAAa;aACvB;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAfD,4CAeC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=mindedUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mindedUtils.d.ts","sourceRoot":"","sources":["../../src/platform/mindedUtils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=mindedUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mindedUtils.js","sourceRoot":"","sources":["../../src/platform/mindedUtils.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import { AzureChatOpenAI } from '@langchain/openai';
2
+ import { BaseMessage } from '@langchain/core/messages';
3
+ import { ChatGenerationChunk, ChatResult } from '@langchain/core/outputs';
4
+ import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
5
+ import type { AzureOpenAIInput } from '@langchain/openai';
6
+ export interface ParallelAzureChatOpenAIFields extends Partial<AzureOpenAIInput> {
7
+ /**
8
+ * Number of parallel requests to make. Defaults to 1 (no parallelization).
9
+ * When > 1, multiple identical requests are sent and the fastest response is used.
10
+ */
11
+ numParallelRequests?: number;
12
+ /**
13
+ * Whether to log timing information for parallel requests
14
+ */
15
+ logTimings?: boolean;
16
+ }
17
+ /**
18
+ * Extended AzureChatOpenAI that supports parallel request optimization.
19
+ * When numParallelRequests > 1, it sends multiple identical requests
20
+ * and returns the fastest response to reduce latency.
21
+ */
22
+ export declare class ParallelAzureChatOpenAI extends AzureChatOpenAI {
23
+ private numParallelRequests;
24
+ private logTimings;
25
+ constructor(fields?: ParallelAzureChatOpenAIFields);
26
+ /**
27
+ * Helper function that returns a promise that resolves with the second fulfilled promise
28
+ */
29
+ private promiseSecondFulfillment;
30
+ /**
31
+ * Override the _generate method to implement parallel requests
32
+ */
33
+ _generate(messages: BaseMessage[], options?: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
34
+ /**
35
+ * Override the _streamResponseChunks method to implement parallel streaming
36
+ */
37
+ _streamResponseChunks(messages: BaseMessage[], options?: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
38
+ }
39
+ //# sourceMappingURL=parallelAzureChatOpenAI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallelAzureChatOpenAI.d.ts","sourceRoot":"","sources":["../../src/platform/parallelAzureChatOpenAI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,WAAW,6BAA8B,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC9E;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,eAAe;IAC1D,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,UAAU,CAAU;gBAEhB,MAAM,CAAC,EAAE,6BAA6B;IAMlD;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAmBhC;;OAEG;IACG,SAAS,CACb,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,EACnC,UAAU,CAAC,EAAE,wBAAwB,GACpC,OAAO,CAAC,UAAU,CAAC;IAoEtB;;OAEG;IACI,qBAAqB,CAC1B,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,EACnC,UAAU,CAAC,EAAE,wBAAwB,GACpC,cAAc,CAAC,mBAAmB,CAAC;CAavC"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParallelAzureChatOpenAI = void 0;
4
+ const openai_1 = require("@langchain/openai");
5
+ const logger_1 = require("../utils/logger");
6
+ /**
7
+ * Extended AzureChatOpenAI that supports parallel request optimization.
8
+ * When numParallelRequests > 1, it sends multiple identical requests
9
+ * and returns the fastest response to reduce latency.
10
+ */
11
+ class ParallelAzureChatOpenAI extends openai_1.AzureChatOpenAI {
12
+ constructor(fields) {
13
+ super(fields);
14
+ this.numParallelRequests = (fields === null || fields === void 0 ? void 0 : fields.numParallelRequests) || 1;
15
+ this.logTimings = (fields === null || fields === void 0 ? void 0 : fields.logTimings) || false;
16
+ }
17
+ /**
18
+ * Helper function that returns a promise that resolves with the second fulfilled promise
19
+ */
20
+ promiseSecondFulfillment(promises) {
21
+ return new Promise((resolve) => {
22
+ let fulfillCount = 0;
23
+ for (const p of promises) {
24
+ Promise.resolve(p)
25
+ .then((value) => {
26
+ fulfillCount++;
27
+ if (fulfillCount === 2) {
28
+ resolve(value);
29
+ }
30
+ })
31
+ .catch(() => {
32
+ // Ignoring rejections for second fulfillment tracking
33
+ });
34
+ }
35
+ });
36
+ }
37
+ /**
38
+ * Override the _generate method to implement parallel requests
39
+ */
40
+ async _generate(messages, options, runManager) {
41
+ // If parallel requests are disabled, use the parent implementation
42
+ if (this.numParallelRequests <= 1) {
43
+ return super._generate(messages, options, runManager);
44
+ }
45
+ const startTime = Date.now();
46
+ // Create array of identical requests
47
+ const requests = Array.from({ length: this.numParallelRequests }, () => super._generate(messages, options, runManager));
48
+ let fastestRequestTime = 0;
49
+ let secondFastestRequestTime = 0;
50
+ // Race all requests and return the fastest
51
+ const racePromise = Promise.race(requests).then((result) => {
52
+ fastestRequestTime = (Date.now() - startTime) / 1000.0;
53
+ if (this.logTimings) {
54
+ logger_1.logger.debug({
55
+ msg: '[ParallelLLM] Fastest request completed',
56
+ requestTime: fastestRequestTime,
57
+ numParallelRequests: this.numParallelRequests,
58
+ provider: 'azure',
59
+ });
60
+ }
61
+ return result;
62
+ });
63
+ // Track second fastest if we have 3+ requests
64
+ if (requests.length >= 3) {
65
+ this.promiseSecondFulfillment(requests)
66
+ .then(() => {
67
+ secondFastestRequestTime = (Date.now() - startTime) / 1000.0;
68
+ })
69
+ .catch(() => {
70
+ // Ignore errors in timing tracking
71
+ });
72
+ }
73
+ // Track all completion times if we have 2+ requests
74
+ if (requests.length >= 2 && this.logTimings) {
75
+ Promise.all(requests)
76
+ .then(() => {
77
+ const allFinishTime = (Date.now() - startTime) / 1000.0;
78
+ const timeSaved = allFinishTime - fastestRequestTime;
79
+ const timeSavedFromSecond = secondFastestRequestTime > 0 ? secondFastestRequestTime - fastestRequestTime : 0;
80
+ logger_1.logger.debug({
81
+ msg: '[ParallelLLM] Time saved using parallel requests',
82
+ fastestRequestTime,
83
+ secondFastestRequestTime: secondFastestRequestTime || 'N/A',
84
+ allFinishTime,
85
+ timeSaved,
86
+ timeSavedFromSecond,
87
+ numParallelRequests: this.numParallelRequests,
88
+ provider: 'azure',
89
+ });
90
+ })
91
+ .catch(() => {
92
+ // Ignore errors in timing tracking
93
+ });
94
+ }
95
+ return racePromise;
96
+ }
97
+ /**
98
+ * Override the _streamResponseChunks method to implement parallel streaming
99
+ */
100
+ async *_streamResponseChunks(messages, options, runManager) {
101
+ // For streaming, we'll use the parent implementation for now
102
+ // Parallel streaming is more complex and may not provide the same benefits
103
+ if (this.numParallelRequests > 1 && this.logTimings) {
104
+ logger_1.logger.debug({
105
+ msg: '[ParallelLLM] Streaming mode - using single request',
106
+ reason: 'Parallel streaming not implemented',
107
+ provider: 'azure',
108
+ });
109
+ }
110
+ yield* super._streamResponseChunks(messages, options, runManager);
111
+ }
112
+ }
113
+ exports.ParallelAzureChatOpenAI = ParallelAzureChatOpenAI;
114
+ //# sourceMappingURL=parallelAzureChatOpenAI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallelAzureChatOpenAI.js","sourceRoot":"","sources":["../../src/platform/parallelAzureChatOpenAI.ts"],"names":[],"mappings":";;;AAAA,8CAAoD;AAIpD,4CAAyC;AAgBzC;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,wBAAe;IAI1D,YAAY,MAAsC;QAChD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,mBAAmB,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,mBAAmB,KAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,UAAU,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,KAAI,KAAK,CAAC;IAChD,CAAC;IAED;;OAEG;IACK,wBAAwB,CAAI,QAAsB;QACxD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,YAAY,GAAG,CAAC,CAAC;YAErB,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;gBACzB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;qBACf,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;oBACd,YAAY,EAAE,CAAC;oBACf,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;wBACvB,OAAO,CAAC,KAAK,CAAC,CAAC;oBACjB,CAAC;gBACH,CAAC,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE;oBACV,sDAAsD;gBACxD,CAAC,CAAC,CAAC;YACP,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CACb,QAAuB,EACvB,OAAmC,EACnC,UAAqC;QAErC,mEAAmE;QACnE,IAAI,IAAI,CAAC,mBAAmB,IAAI,CAAC,EAAE,CAAC;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,EAAE,UAAU,CAAC,CAAC;IACrE,CAAC;CACF;AA/HD,0DA+HC"}
@@ -0,0 +1,38 @@
1
+ import { ChatOpenAI, ChatOpenAIFields } from '@langchain/openai';
2
+ import { BaseMessage } from '@langchain/core/messages';
3
+ import { ChatGenerationChunk, ChatResult } from '@langchain/core/outputs';
4
+ import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
5
+ export interface ParallelChatOpenAIFields extends ChatOpenAIFields {
6
+ /**
7
+ * Number of parallel requests to make. Defaults to 1 (no parallelization).
8
+ * When > 1, multiple identical requests are sent and the fastest response is used.
9
+ */
10
+ numParallelRequests?: number;
11
+ /**
12
+ * Whether to log timing information for parallel requests
13
+ */
14
+ logTimings?: boolean;
15
+ }
16
+ /**
17
+ * Extended ChatOpenAI that supports parallel request optimization.
18
+ * When numParallelRequests > 1, it sends multiple identical requests
19
+ * and returns the fastest response to reduce latency.
20
+ */
21
+ export declare class ParallelChatOpenAI extends ChatOpenAI {
22
+ private numParallelRequests;
23
+ private logTimings;
24
+ constructor(fields?: ParallelChatOpenAIFields);
25
+ /**
26
+ * Helper function that returns a promise that resolves with the second fulfilled promise
27
+ */
28
+ private promiseSecondFulfillment;
29
+ /**
30
+ * Override the _generate method to implement parallel requests
31
+ */
32
+ _generate(messages: BaseMessage[], options?: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
33
+ /**
34
+ * Override the _streamResponseChunks method to implement parallel streaming
35
+ */
36
+ _streamResponseChunks(messages: BaseMessage[], options?: this['ParsedCallOptions'], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
37
+ }
38
+ //# sourceMappingURL=parallelChatOpenAI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallelChatOpenAI.d.ts","sourceRoot":"","sources":["../../src/platform/parallelChatOpenAI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAG7E,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,UAAU,CAAU;gBAEhB,MAAM,CAAC,EAAE,wBAAwB;IAM7C;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAmBhC;;OAEG;IACG,SAAS,CACb,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,EACnC,UAAU,CAAC,EAAE,wBAAwB,GACpC,OAAO,CAAC,UAAU,CAAC;IAkEtB;;OAEG;IACI,qBAAqB,CAC1B,QAAQ,EAAE,WAAW,EAAE,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,EACnC,UAAU,CAAC,EAAE,wBAAwB,GACpC,cAAc,CAAC,mBAAmB,CAAC;CAYvC"}