mavenagi 1.2.63 → 1.2.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BaseClient.js +2 -2
- package/api/resources/actions/client/Client.js +3 -3
- package/api/resources/agents/client/Client.js +5 -5
- package/api/resources/agents/client/requests/AgentPatchRequest.d.ts +23 -3
- package/api/resources/agents/types/Agent.d.ts +9 -1
- package/api/resources/agents/types/AgentPrompting.d.ts +14 -2
- package/api/resources/appDirectory/client/Client.js +5 -5
- package/api/resources/assets/client/Client.js +1 -1
- package/api/resources/capabilities/client/Client.d.ts +68 -0
- package/api/resources/capabilities/client/Client.js +243 -3
- package/api/resources/capabilities/client/requests/CapabilitiesSearchRequest.d.ts +4 -1
- package/api/resources/capabilities/client/requests/CapabilityExecutionsSearchRequest.d.ts +36 -0
- package/api/resources/capabilities/client/requests/CapabilityExecutionsSearchRequest.js +3 -0
- package/api/resources/capabilities/client/requests/GetCapabilityByTypeRequest.d.ts +4 -1
- package/api/resources/capabilities/client/requests/SimulateCapabilityByTypeRequest.d.ts +14 -0
- package/api/resources/capabilities/client/requests/SimulateCapabilityByTypeRequest.js +3 -0
- package/api/resources/capabilities/client/requests/index.d.ts +2 -0
- package/api/resources/capabilities/types/ActionSimulationInput.d.ts +5 -0
- package/api/resources/capabilities/types/ActionSimulationInput.js +3 -0
- package/api/resources/capabilities/types/CapabilityExecution.d.ts +14 -0
- package/api/resources/capabilities/types/CapabilityExecution.js +3 -0
- package/api/resources/capabilities/types/CapabilityExecutionBase.d.ts +32 -0
- package/api/resources/capabilities/types/CapabilityExecutionBase.js +3 -0
- package/api/resources/capabilities/types/CapabilityExecutionCompletionReason.d.ts +36 -0
- package/api/resources/capabilities/types/CapabilityExecutionCompletionReason.js +39 -0
- package/api/resources/capabilities/types/CapabilityExecutionRetryability.d.ts +17 -0
- package/api/resources/capabilities/types/CapabilityExecutionRetryability.js +20 -0
- package/api/resources/capabilities/types/CapabilityExecutionStatus.d.ts +10 -0
- package/api/resources/capabilities/types/CapabilityExecutionStatus.js +13 -0
- package/api/resources/capabilities/types/CapabilityExecutionsSearchResponse.d.ts +62 -0
- package/api/resources/capabilities/types/CapabilityExecutionsSearchResponse.js +3 -0
- package/api/resources/capabilities/types/CapabilitySimulationInput.d.ts +11 -0
- package/api/resources/capabilities/types/CapabilitySimulationInput.js +3 -0
- package/api/resources/capabilities/types/CapabilitySimulationResult.d.ts +10 -0
- package/api/resources/capabilities/types/CapabilitySimulationResult.js +3 -0
- package/api/resources/capabilities/types/ConversationContextSimulationInput.d.ts +14 -0
- package/api/resources/capabilities/types/ConversationContextSimulationInput.js +3 -0
- package/api/resources/capabilities/types/ConversationKickoffCapabilityExecution.d.ts +7 -0
- package/api/resources/capabilities/types/ConversationKickoffCapabilityExecution.js +3 -0
- package/api/resources/capabilities/types/SimulatedUser.d.ts +9 -0
- package/api/resources/capabilities/types/SimulatedUser.js +3 -0
- package/api/resources/capabilities/types/SimulatedUserData.d.ts +6 -0
- package/api/resources/capabilities/types/SimulatedUserData.js +3 -0
- package/api/resources/capabilities/types/TriggerCapabilityExecution.d.ts +19 -0
- package/api/resources/capabilities/types/TriggerCapabilityExecution.js +3 -0
- package/api/resources/capabilities/types/index.d.ts +14 -0
- package/api/resources/capabilities/types/index.js +14 -0
- package/api/resources/charters/client/Client.js +7 -5
- package/api/resources/charters/client/requests/CharterDeleteRequest.d.ts +6 -6
- package/api/resources/charters/client/requests/CharterGetAncestorsRequest.d.ts +12 -0
- package/api/resources/charters/client/requests/CharterGetRequest.d.ts +9 -1
- package/api/resources/charters/client/requests/CharterPatchRequest.d.ts +5 -6
- package/api/resources/charters/types/CharterBase.d.ts +9 -4
- package/api/resources/charters/types/CharterChildrenExclusionPolicy.d.ts +2 -0
- package/api/resources/charters/types/CharterChildrenExclusionPolicy.js +2 -0
- package/api/resources/charters/types/CharterContent.d.ts +2 -0
- package/api/resources/charters/types/CharterListChildrenRequest.d.ts +10 -0
- package/api/resources/charters/types/CharterPatchReferences.d.ts +2 -0
- package/api/resources/charters/types/CharterReferences.d.ts +2 -0
- package/api/resources/charters/types/CharterResponse.d.ts +5 -1
- package/api/resources/charters/types/CharterSearchFilter.d.ts +9 -1
- package/api/resources/charters/types/CharterStatus.d.ts +4 -0
- package/api/resources/charters/types/CharterStatus.js +4 -0
- package/api/resources/charters/types/CharterSummary.d.ts +5 -1
- package/api/resources/charters/types/index.d.ts +0 -1
- package/api/resources/charters/types/index.js +0 -1
- package/api/resources/commons/types/ActionExecutionStatus.d.ts +6 -0
- package/api/resources/commons/types/ActionExecutionStatus.js +9 -0
- package/api/resources/commons/types/ActionProperties.d.ts +1 -1
- package/api/resources/commons/types/AdditionalDataKey.d.ts +3 -0
- package/api/resources/commons/types/AdditionalDataKey.js +3 -0
- package/api/resources/commons/types/AppUserRequest.d.ts +11 -0
- package/api/resources/commons/types/BotLogicCharterDetail.d.ts +3 -1
- package/api/resources/commons/types/BotLogicSegmentsItem.d.ts +3 -0
- package/api/resources/commons/types/BotMessage.d.ts +5 -0
- package/api/resources/commons/types/BotMessageStatusReason.d.ts +13 -0
- package/api/resources/commons/types/BotMessageStatusReason.js +16 -0
- package/api/resources/commons/types/Capability.d.ts +4 -0
- package/api/resources/commons/types/Capability.js +4 -0
- package/api/resources/commons/types/CapabilityStatus.d.ts +2 -2
- package/api/resources/commons/types/CapabilityStatus.js +2 -2
- package/api/resources/commons/types/ConversationAnalysis.d.ts +2 -2
- package/api/resources/commons/types/ConversationMetadataValueSource.d.ts +7 -0
- package/api/resources/commons/types/ConversationMetadataValueSource.js +3 -0
- package/api/resources/commons/types/ConversationSummary.d.ts +5 -3
- package/api/resources/commons/types/ConversationValueSource.d.ts +10 -0
- package/api/resources/commons/types/ConversationValueSource.js +3 -0
- package/api/resources/commons/types/EntityType.d.ts +5 -0
- package/api/resources/commons/types/EntityType.js +5 -0
- package/api/resources/commons/types/ErrorReason.d.ts +6 -0
- package/api/resources/commons/types/ErrorReason.js +6 -0
- package/api/resources/commons/types/EventFilter.d.ts +1 -0
- package/api/resources/commons/types/ExecuteActionResponse.d.ts +14 -0
- package/api/resources/commons/types/ExecuteActionResponse.js +3 -0
- package/api/resources/commons/types/ExecutionMode.d.ts +10 -0
- package/api/resources/commons/types/ExecutionMode.js +13 -0
- package/api/resources/commons/types/FunctionVersionBinding.d.ts +11 -0
- package/api/resources/commons/types/FunctionVersionBinding.js +3 -0
- package/api/resources/commons/types/InboxItemDuplicateDocuments.d.ts +1 -1
- package/api/resources/commons/types/InboxItemStatus.d.ts +1 -1
- package/api/resources/commons/types/InboxItemStatus.js +1 -1
- package/api/resources/commons/types/LlmInclusionStatus.d.ts +3 -0
- package/api/resources/commons/types/LlmInclusionStatus.js +3 -0
- package/api/resources/commons/types/MetadataConversationValueFilter.d.ts +15 -0
- package/api/resources/commons/types/MetadataConversationValueFilter.js +3 -0
- package/api/resources/commons/types/MetadataFilter.d.ts +33 -6
- package/api/resources/commons/types/Quality.d.ts +2 -0
- package/api/resources/commons/types/Quality.js +2 -0
- package/api/resources/commons/types/QualityReason.d.ts +4 -0
- package/api/resources/commons/types/QualityReason.js +4 -0
- package/api/resources/commons/types/RelationshipType.d.ts +2 -2
- package/api/resources/commons/types/RelationshipType.js +2 -2
- package/api/resources/commons/types/ResolutionStatus.d.ts +2 -0
- package/api/resources/commons/types/ResolutionStatus.js +2 -0
- package/api/resources/commons/types/ResponseConfig.d.ts +2 -0
- package/api/resources/commons/types/SimulationActionBehavior.d.ts +18 -0
- package/api/resources/commons/types/SimulationActionBehavior.js +3 -0
- package/api/resources/commons/types/SimulationActionCallApp.d.ts +1 -0
- package/api/resources/commons/types/SimulationActionCallApp.js +3 -0
- package/api/resources/commons/types/SimulationActionMock.d.ts +6 -0
- package/api/resources/commons/types/SimulationActionMock.js +3 -0
- package/api/resources/commons/types/SimulationContext.d.ts +19 -0
- package/api/resources/commons/types/SystemEventName.d.ts +5 -2
- package/api/resources/commons/types/SystemEventName.js +5 -2
- package/api/resources/commons/types/UserEvent.d.ts +1 -1
- package/api/resources/commons/types/UserEventName.d.ts +1 -1
- package/api/resources/commons/types/UserEventName.js +1 -1
- package/api/resources/commons/types/index.d.ts +12 -0
- package/api/resources/commons/types/index.js +12 -0
- package/api/resources/conversation/client/Client.d.ts +17 -9
- package/api/resources/conversation/client/Client.js +27 -19
- package/api/resources/conversation/client/requests/ConversationDeleteRequest.d.ts +1 -1
- package/api/resources/conversation/types/BillableFilterField.d.ts +3 -3
- package/api/resources/conversation/types/BillableFilterField.js +3 -3
- package/api/resources/conversation/types/ConversationField.d.ts +8 -0
- package/api/resources/conversation/types/ConversationField.js +8 -0
- package/api/resources/conversation/types/ConversationFilter.d.ts +7 -1
- package/api/resources/conversation/types/ConversationPatchRequest.d.ts +1 -1
- package/api/resources/customers/client/Client.js +2 -2
- package/api/resources/customers/types/CustomerFilter.d.ts +16 -1
- package/api/resources/customers/types/CustomerResponse.d.ts +2 -2
- package/api/resources/events/client/Client.js +1 -1
- package/api/resources/inbox/client/Client.js +6 -6
- package/api/resources/integrations/client/Client.js +1 -1
- package/api/resources/intelligentFields/client/Client.d.ts +4 -3
- package/api/resources/intelligentFields/client/Client.js +7 -6
- package/api/resources/intelligentFields/client/requests/IntelligentFieldGetRequest.d.ts +9 -1
- package/api/resources/intelligentFields/types/EnumOption.d.ts +1 -1
- package/api/resources/intelligentFields/types/IntelligentFieldBase.d.ts +1 -1
- package/api/resources/intelligentFields/types/IntelligentFieldCore.d.ts +5 -1
- package/api/resources/intelligentFields/types/IntelligentFieldType.d.ts +1 -1
- package/api/resources/intelligentFields/types/IntelligentFieldType.js +1 -1
- package/api/resources/intelligentFields/types/IntelligentFieldValueSearchRequest.d.ts +5 -4
- package/api/resources/knowledge/client/Client.js +13 -13
- package/api/resources/knowledge/types/KnowledgeBaseIndexingStatus.d.ts +1 -1
- package/api/resources/knowledge/types/KnowledgeBaseIndexingStatus.js +1 -1
- package/api/resources/knowledge/types/KnowledgeBaseResponse.d.ts +3 -1
- package/api/resources/knowledge/types/KnowledgeBaseType.d.ts +2 -0
- package/api/resources/knowledge/types/KnowledgeBaseType.js +2 -0
- package/api/resources/knowledge/types/KnowledgeBaseVersion.d.ts +2 -0
- package/api/resources/knowledge/types/KnowledgeBaseVersionStatus.d.ts +4 -0
- package/api/resources/knowledge/types/KnowledgeBaseVersionStatus.js +4 -0
- package/api/resources/organizations/client/Client.js +4 -4
- package/api/resources/segments/client/Client.d.ts +1 -1
- package/api/resources/segments/client/Client.js +4 -4
- package/api/resources/segments/types/SegmentStatus.d.ts +4 -0
- package/api/resources/segments/types/SegmentStatus.js +4 -0
- package/api/resources/triggers/client/Client.js +3 -3
- package/api/resources/triggers/types/EventTriggerBase.d.ts +2 -0
- package/api/resources/users/client/Client.d.ts +42 -1
- package/api/resources/users/client/Client.js +116 -4
- package/api/resources/users/types/AgentUser.d.ts +3 -0
- package/api/resources/users/types/AgentUserFilter.d.ts +4 -0
- package/api/resources/voiceConversations/client/Client.d.ts +1 -1
- package/api/resources/voiceConversations/client/Socket.d.ts +2 -2
- package/api/resources/voiceConversations/client/Socket.js +16 -17
- package/core/fetcher/Fetcher.js +33 -3
- package/core/fetcher/getErrorResponseBody.js +20 -7
- package/core/fetcher/getResponseBody.d.ts +16 -0
- package/core/fetcher/getResponseBody.js +27 -22
- package/core/fetcher/makePassthroughRequest.js +20 -4
- package/core/fetcher/makeRequest.d.ts +6 -1
- package/core/fetcher/makeRequest.js +38 -5
- package/core/fetcher/requestWithRetries.d.ts +1 -1
- package/core/fetcher/requestWithRetries.js +23 -2
- package/core/fetcher/signals.d.ts +1 -0
- package/core/fetcher/signals.js +3 -2
- package/core/stream/Stream.d.ts +3 -0
- package/core/stream/Stream.js +5 -0
- package/core/url/encodePathParam.d.ts +3 -1
- package/core/url/encodePathParam.js +8 -2
- package/core/websocket/ws.d.ts +16 -2
- package/core/websocket/ws.js +110 -20
- package/errors/MavenAGIError.js +16 -2
- package/package.json +1 -1
- package/reference.md +273 -13
- package/serialization/resources/agents/client/requests/AgentPatchRequest.d.ts +2 -0
- package/serialization/resources/agents/client/requests/AgentPatchRequest.js +2 -0
- package/serialization/resources/agents/types/Agent.d.ts +2 -0
- package/serialization/resources/agents/types/Agent.js +2 -0
- package/serialization/resources/capabilities/client/requests/CapabilityExecutionsSearchRequest.d.ts +16 -0
- package/serialization/resources/capabilities/client/requests/CapabilityExecutionsSearchRequest.js +50 -0
- package/serialization/resources/capabilities/client/requests/index.d.ts +1 -0
- package/serialization/resources/capabilities/client/requests/index.js +3 -1
- package/serialization/resources/capabilities/types/ActionSimulationInput.d.ts +10 -0
- package/serialization/resources/capabilities/types/ActionSimulationInput.js +44 -0
- package/serialization/resources/capabilities/types/CapabilityExecution.d.ts +15 -0
- package/serialization/resources/capabilities/types/CapabilityExecution.js +49 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionBase.d.ts +20 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionBase.js +52 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionCompletionReason.d.ts +7 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionCompletionReason.js +50 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionRetryability.d.ts +7 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionRetryability.js +39 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionStatus.d.ts +7 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionStatus.js +39 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionsSearchResponse.d.ts +11 -0
- package/serialization/resources/capabilities/types/CapabilityExecutionsSearchResponse.js +45 -0
- package/serialization/resources/capabilities/types/CapabilitySimulationInput.d.ts +11 -0
- package/serialization/resources/capabilities/types/CapabilitySimulationInput.js +47 -0
- package/serialization/resources/capabilities/types/CapabilitySimulationResult.d.ts +11 -0
- package/serialization/resources/capabilities/types/CapabilitySimulationResult.js +47 -0
- package/serialization/resources/capabilities/types/ConversationContextSimulationInput.d.ts +12 -0
- package/serialization/resources/capabilities/types/ConversationContextSimulationInput.js +46 -0
- package/serialization/resources/capabilities/types/ConversationKickoffCapabilityExecution.d.ts +9 -0
- package/serialization/resources/capabilities/types/ConversationKickoffCapabilityExecution.js +40 -0
- package/serialization/resources/capabilities/types/SimulatedUser.d.ts +10 -0
- package/serialization/resources/capabilities/types/SimulatedUser.js +44 -0
- package/serialization/resources/capabilities/types/SimulatedUserData.d.ts +10 -0
- package/serialization/resources/capabilities/types/SimulatedUserData.js +42 -0
- package/serialization/resources/capabilities/types/TriggerCapabilityExecution.d.ts +15 -0
- package/serialization/resources/capabilities/types/TriggerCapabilityExecution.js +49 -0
- package/serialization/resources/capabilities/types/index.d.ts +14 -0
- package/serialization/resources/capabilities/types/index.js +14 -0
- package/serialization/resources/charters/types/CharterContent.d.ts +1 -1
- package/serialization/resources/charters/types/CharterContent.js +1 -1
- package/serialization/resources/charters/types/CharterListChildrenRequest.d.ts +2 -0
- package/serialization/resources/charters/types/CharterListChildrenRequest.js +2 -0
- package/serialization/resources/charters/types/CharterResponse.d.ts +1 -1
- package/serialization/resources/charters/types/CharterResponse.js +1 -1
- package/serialization/resources/charters/types/CharterSummary.d.ts +1 -1
- package/serialization/resources/charters/types/CharterSummary.js +1 -1
- package/serialization/resources/charters/types/index.d.ts +0 -1
- package/serialization/resources/charters/types/index.js +0 -1
- package/serialization/resources/commons/types/ActionExecutionStatus.d.ts +7 -0
- package/serialization/resources/commons/types/ActionExecutionStatus.js +39 -0
- package/serialization/resources/commons/types/AdditionalDataKey.d.ts +1 -1
- package/serialization/resources/commons/types/AdditionalDataKey.js +1 -0
- package/serialization/resources/commons/types/AppUserRequest.d.ts +2 -0
- package/serialization/resources/commons/types/AppUserRequest.js +2 -0
- package/serialization/resources/commons/types/BotLogicCharterDetail.d.ts +2 -0
- package/serialization/resources/commons/types/BotLogicCharterDetail.js +2 -0
- package/serialization/resources/commons/types/BotMessage.d.ts +2 -0
- package/serialization/resources/commons/types/BotMessage.js +2 -0
- package/serialization/resources/commons/types/BotMessageStatusReason.d.ts +7 -0
- package/serialization/resources/commons/types/BotMessageStatusReason.js +43 -0
- package/serialization/resources/commons/types/ConversationMetadataValueSource.d.ts +9 -0
- package/serialization/resources/commons/types/ConversationMetadataValueSource.js +41 -0
- package/serialization/resources/commons/types/ConversationValueSource.d.ts +11 -0
- package/serialization/resources/commons/types/ConversationValueSource.js +47 -0
- package/serialization/resources/commons/types/EntityType.d.ts +1 -1
- package/serialization/resources/commons/types/EntityType.js +5 -0
- package/serialization/resources/commons/types/ErrorReason.d.ts +1 -1
- package/serialization/resources/commons/types/ErrorReason.js +2 -0
- package/serialization/resources/commons/types/ExecuteActionResponse.d.ts +13 -0
- package/serialization/resources/commons/types/ExecuteActionResponse.js +45 -0
- package/serialization/resources/commons/types/ExecutionMode.d.ts +7 -0
- package/serialization/resources/commons/types/ExecutionMode.js +39 -0
- package/serialization/resources/commons/types/FunctionVersionBinding.d.ts +11 -0
- package/serialization/resources/commons/types/FunctionVersionBinding.js +43 -0
- package/serialization/resources/commons/types/MetadataConversationValueFilter.d.ts +11 -0
- package/serialization/resources/commons/types/MetadataConversationValueFilter.js +43 -0
- package/serialization/resources/commons/types/MetadataFilter.d.ts +5 -1
- package/serialization/resources/commons/types/MetadataFilter.js +2 -0
- package/serialization/resources/commons/types/SimulationActionBehavior.d.ts +15 -0
- package/serialization/resources/commons/types/SimulationActionBehavior.js +49 -0
- package/serialization/resources/commons/types/SimulationActionCallApp.d.ts +7 -0
- package/serialization/resources/commons/types/SimulationActionCallApp.js +39 -0
- package/serialization/resources/commons/types/SimulationActionMock.d.ts +12 -0
- package/serialization/resources/commons/types/SimulationActionMock.js +44 -0
- package/serialization/resources/commons/types/SimulationContext.d.ts +4 -0
- package/serialization/resources/commons/types/SimulationContext.js +4 -0
- package/serialization/resources/commons/types/SystemEventName.d.ts +1 -1
- package/serialization/resources/commons/types/SystemEventName.js +1 -0
- package/serialization/resources/commons/types/index.d.ts +12 -0
- package/serialization/resources/commons/types/index.js +12 -0
- package/serialization/resources/users/types/AgentUser.d.ts +2 -0
- package/serialization/resources/users/types/AgentUser.js +2 -0
- package/serialization/resources/users/types/AgentUserFilter.d.ts +2 -0
- package/serialization/resources/users/types/AgentUserFilter.js +2 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- /package/api/resources/{charters → commons}/types/CharterType.d.ts +0 -0
- /package/api/resources/{charters → commons}/types/CharterType.js +0 -0
- /package/serialization/resources/{charters → commons}/types/CharterType.d.ts +0 -0
- /package/serialization/resources/{charters → commons}/types/CharterType.js +0 -0
|
@@ -3,6 +3,8 @@ export interface AgentUserFilter {
|
|
|
3
3
|
/**
|
|
4
4
|
* Full-text search query for matching agent users by content.
|
|
5
5
|
* When you search with this parameter, you're performing a full-text search across the user identifiers.
|
|
6
|
+
*
|
|
7
|
+
* Shown in Agent Designer as "Content includes".
|
|
6
8
|
*/
|
|
7
9
|
search?: string;
|
|
8
10
|
/** Filter by identifiers */
|
|
@@ -19,4 +21,6 @@ export interface AgentUserFilter {
|
|
|
19
21
|
isAnonymous?: boolean;
|
|
20
22
|
/** Filter by intelligent field values. All conditions are ANDed together. */
|
|
21
23
|
intelligentFields?: MavenAGI.IntelligentFieldFilter;
|
|
24
|
+
/** Whether to include simulation users in search results. Defaults to only non-simulation users. */
|
|
25
|
+
simulationFilter?: MavenAGI.SimulationFilter;
|
|
22
26
|
}
|
|
@@ -21,7 +21,7 @@ export declare namespace VoiceConversationsClient {
|
|
|
21
21
|
connectionTimeoutInSeconds?: number;
|
|
22
22
|
/** A signal to abort the WebSocket connection. */
|
|
23
23
|
abortSignal?: AbortSignal;
|
|
24
|
-
/** Decides whether a close event should trigger a reconnect. Return false to treat the close as terminal. Defaults to reconnecting on any close code other than 1000. */
|
|
24
|
+
/** Decides whether a server close event should trigger a reconnect. Not consulted for connection errors, timeouts, or internal closes. Return false to treat the close as terminal. Defaults to reconnecting on any server close code other than 1000. */
|
|
25
25
|
shouldReconnect?: (event: core.CloseEvent) => boolean;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -46,11 +46,11 @@ export declare class VoiceConversationsSocket {
|
|
|
46
46
|
off<T extends keyof VoiceConversationsSocket.EventHandlers>(event: T, callback: VoiceConversationsSocket.EventHandlers[T]): void;
|
|
47
47
|
sendConfig(message: MavenAGI.Config): void;
|
|
48
48
|
sendUserAudioChunk(message: MavenAGI.UserAudioChunk): void;
|
|
49
|
-
/** Connect to the websocket and register event handlers. */
|
|
49
|
+
/** Connect to the websocket and register event handlers. Safe to call multiple times: each handler is only registered if it is not already attached. */
|
|
50
50
|
connect(): VoiceConversationsSocket;
|
|
51
51
|
/** Close the websocket and unregister event handlers. */
|
|
52
52
|
close(): void;
|
|
53
|
-
/** Returns a promise that resolves when the websocket is open. */
|
|
53
|
+
/** Returns a promise that resolves when the websocket is open, and rejects if it errors or closes before opening. */
|
|
54
54
|
waitForOpen(): Promise<core.ReconnectingWebSocket>;
|
|
55
55
|
/** Asserts that the websocket is open. */
|
|
56
56
|
private assertSocketIsOpen;
|
|
@@ -136,13 +136,21 @@ class VoiceConversationsSocket {
|
|
|
136
136
|
});
|
|
137
137
|
this.socket.send(JSON.stringify(jsonPayload));
|
|
138
138
|
}
|
|
139
|
-
/** Connect to the websocket and register event handlers. */
|
|
139
|
+
/** Connect to the websocket and register event handlers. Safe to call multiple times: each handler is only registered if it is not already attached. */
|
|
140
140
|
connect() {
|
|
141
141
|
this.socket.reconnect();
|
|
142
|
-
this.socket.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.socket.
|
|
142
|
+
if (!this.socket.hasEventListener("open", this.handleOpen)) {
|
|
143
|
+
this.socket.addEventListener("open", this.handleOpen);
|
|
144
|
+
}
|
|
145
|
+
if (!this.socket.hasEventListener("message", this.handleMessage)) {
|
|
146
|
+
this.socket.addEventListener("message", this.handleMessage);
|
|
147
|
+
}
|
|
148
|
+
if (!this.socket.hasEventListener("close", this.handleClose)) {
|
|
149
|
+
this.socket.addEventListener("close", this.handleClose);
|
|
150
|
+
}
|
|
151
|
+
if (!this.socket.hasEventListener("error", this.handleError)) {
|
|
152
|
+
this.socket.addEventListener("error", this.handleError);
|
|
153
|
+
}
|
|
146
154
|
return this;
|
|
147
155
|
}
|
|
148
156
|
/** Close the websocket and unregister event handlers. */
|
|
@@ -154,20 +162,11 @@ class VoiceConversationsSocket {
|
|
|
154
162
|
this.socket.removeEventListener("close", this.handleClose);
|
|
155
163
|
this.socket.removeEventListener("error", this.handleError);
|
|
156
164
|
}
|
|
157
|
-
/** Returns a promise that resolves when the websocket is open. */
|
|
165
|
+
/** Returns a promise that resolves when the websocket is open, and rejects if it errors or closes before opening. */
|
|
158
166
|
waitForOpen() {
|
|
159
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
return new Promise((resolve, reject) => {
|
|
164
|
-
this.socket.addEventListener("open", () => {
|
|
165
|
-
resolve(this.socket);
|
|
166
|
-
});
|
|
167
|
-
this.socket.addEventListener("error", (event) => {
|
|
168
|
-
reject(event);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
168
|
+
yield this.socket.waitForOpen();
|
|
169
|
+
return this.socket;
|
|
171
170
|
});
|
|
172
171
|
}
|
|
173
172
|
/** Asserts that the websocket is open. */
|
package/core/fetcher/Fetcher.js
CHANGED
|
@@ -24,6 +24,7 @@ const makeRequest_1 = require("./makeRequest");
|
|
|
24
24
|
const RawResponse_1 = require("./RawResponse");
|
|
25
25
|
const redactUrl_1 = require("./redactUrl");
|
|
26
26
|
const requestWithRetries_1 = require("./requestWithRetries");
|
|
27
|
+
const signals_1 = require("./signals");
|
|
27
28
|
const SENSITIVE_HEADERS = new Set([
|
|
28
29
|
"authorization",
|
|
29
30
|
"www-authenticate",
|
|
@@ -95,6 +96,11 @@ function getHeaders(args) {
|
|
|
95
96
|
return newHeaders;
|
|
96
97
|
});
|
|
97
98
|
}
|
|
99
|
+
function isJsonContentType(contentType) {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
const mediaType = (_b = (_a = contentType === null || contentType === void 0 ? void 0 : contentType.split(";")[0]) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase()) !== null && _b !== void 0 ? _b : "";
|
|
102
|
+
return mediaType === "application/json" || mediaType === "text/json" || mediaType.endsWith("+json");
|
|
103
|
+
}
|
|
98
104
|
function fetcherImpl(args) {
|
|
99
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
106
|
var _a, _b, _c;
|
|
@@ -122,10 +128,19 @@ function fetcherImpl(args) {
|
|
|
122
128
|
};
|
|
123
129
|
logger.debug("Making HTTP request", metadata);
|
|
124
130
|
}
|
|
131
|
+
// Bodies that are read in full here stay covered by the timeout; streamed bodies are read by the caller.
|
|
132
|
+
const keepTimeoutUntilBodyRead = args.responseType !== "streaming" && args.responseType !== "sse" && args.responseType !== "binary-response";
|
|
133
|
+
const attemptResponses = [];
|
|
125
134
|
try {
|
|
126
135
|
const response = yield (0, requestWithRetries_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
// A retry means the previous attempt is over; stop its timer now rather than at the end.
|
|
137
|
+
for (const previousResponse of attemptResponses) {
|
|
138
|
+
(0, makeRequest_1.clearResponseTimeout)(previousResponse);
|
|
139
|
+
}
|
|
140
|
+
const attemptResponse = yield (0, makeRequest_1.makeRequest)(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex, args.responseType === "streaming" || args.responseType === "sse", keepTimeoutUntilBodyRead);
|
|
141
|
+
attemptResponses.push(attemptResponse);
|
|
142
|
+
return attemptResponse;
|
|
143
|
+
}), args.maxRetries, args.abortSignal);
|
|
129
144
|
if (response.status >= 200 && response.status < 400) {
|
|
130
145
|
if (logger.isDebug()) {
|
|
131
146
|
const metadata = {
|
|
@@ -137,6 +152,16 @@ function fetcherImpl(args) {
|
|
|
137
152
|
logger.debug("HTTP request succeeded", metadata);
|
|
138
153
|
}
|
|
139
154
|
const body = yield (0, getResponseBody_1.getResponseBody)(response, args.responseType);
|
|
155
|
+
// Only a body the server labelled as JSON is an error here; void endpoints may return plain text.
|
|
156
|
+
if ((0, getResponseBody_1.isResponseBodyError)(body) &&
|
|
157
|
+
body.error.reason === "non-json" &&
|
|
158
|
+
isJsonContentType(response.headers.get("Content-Type"))) {
|
|
159
|
+
return {
|
|
160
|
+
ok: false,
|
|
161
|
+
error: body.error,
|
|
162
|
+
rawResponse: (0, RawResponse_1.toRawResponse)(response),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
140
165
|
return {
|
|
141
166
|
ok: true,
|
|
142
167
|
body: body,
|
|
@@ -184,7 +209,7 @@ function fetcherImpl(args) {
|
|
|
184
209
|
rawResponse: RawResponse_1.abortRawResponse,
|
|
185
210
|
};
|
|
186
211
|
}
|
|
187
|
-
else if (error instanceof Error && error.name === "AbortError") {
|
|
212
|
+
else if (error === signals_1.TIMEOUT || (error instanceof Error && error.name === "AbortError")) {
|
|
188
213
|
if (logger.isError()) {
|
|
189
214
|
const metadata = {
|
|
190
215
|
method: args.method,
|
|
@@ -239,6 +264,11 @@ function fetcherImpl(args) {
|
|
|
239
264
|
rawResponse: RawResponse_1.unknownRawResponse,
|
|
240
265
|
};
|
|
241
266
|
}
|
|
267
|
+
finally {
|
|
268
|
+
for (const attemptResponse of attemptResponses) {
|
|
269
|
+
(0, makeRequest_1.clearResponseTimeout)(attemptResponse);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
242
272
|
});
|
|
243
273
|
}
|
|
244
274
|
exports.fetcher = fetcherImpl;
|
|
@@ -12,12 +12,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.getErrorResponseBody = getErrorResponseBody;
|
|
13
13
|
const json_1 = require("../json");
|
|
14
14
|
const getResponseBody_1 = require("./getResponseBody");
|
|
15
|
+
/** Parses a JSON error body, falling back to the raw text so the status and body are never lost. */
|
|
16
|
+
function parseJsonErrorBody(text) {
|
|
17
|
+
if (text.length === 0) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return (0, json_1.fromJson)(text);
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
return text;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
function getErrorResponseBody(response) {
|
|
16
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
29
|
var _a, _b, _c;
|
|
18
30
|
let contentType = (_a = response.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
19
31
|
if (contentType == null || contentType.length === 0) {
|
|
20
|
-
|
|
32
|
+
const body = yield (0, getResponseBody_1.getResponseBody)(response);
|
|
33
|
+
if ((0, getResponseBody_1.isResponseBodyError)(body)) {
|
|
34
|
+
return body.error.reason === "non-json" ? body.error.rawBody : undefined;
|
|
35
|
+
}
|
|
36
|
+
return body;
|
|
21
37
|
}
|
|
22
38
|
if (contentType.indexOf(";") !== -1) {
|
|
23
39
|
contentType = (_c = (_b = contentType.split(";")[0]) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : "";
|
|
@@ -28,14 +44,11 @@ function getErrorResponseBody(response) {
|
|
|
28
44
|
case "application/ld+json":
|
|
29
45
|
case "application/problem+json":
|
|
30
46
|
case "application/vnd.api+json":
|
|
31
|
-
case "text/json":
|
|
32
|
-
|
|
33
|
-
return text.length > 0 ? (0, json_1.fromJson)(text) : undefined;
|
|
34
|
-
}
|
|
47
|
+
case "text/json":
|
|
48
|
+
return parseJsonErrorBody(yield response.text());
|
|
35
49
|
default:
|
|
36
50
|
if (contentType.startsWith("application/vnd.") && contentType.endsWith("+json")) {
|
|
37
|
-
|
|
38
|
-
return text.length > 0 ? (0, json_1.fromJson)(text) : undefined;
|
|
51
|
+
return parseJsonErrorBody(yield response.text());
|
|
39
52
|
}
|
|
40
53
|
// Fallback to plain text if content type is not recognized
|
|
41
54
|
// Even if no body is present, the response will be an empty string
|
|
@@ -1 +1,17 @@
|
|
|
1
|
+
export type ResponseBodyError = {
|
|
2
|
+
ok: false;
|
|
3
|
+
error: {
|
|
4
|
+
reason: "non-json";
|
|
5
|
+
statusCode: number;
|
|
6
|
+
rawBody: string;
|
|
7
|
+
} | {
|
|
8
|
+
reason: "body-is-null";
|
|
9
|
+
statusCode: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Returns true when `value` is a failure record created by `getResponseBody` (for example malformed JSON),
|
|
14
|
+
* as opposed to a parsed JSON body that happens to have the same shape.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isResponseBodyError(value: unknown): value is ResponseBodyError;
|
|
1
17
|
export declare function getResponseBody(response: Response, responseType?: string): Promise<unknown>;
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isResponseBodyError = isResponseBodyError;
|
|
12
13
|
exports.getResponseBody = getResponseBody;
|
|
13
14
|
const json_1 = require("../json");
|
|
14
15
|
const BinaryResponse_1 = require("./BinaryResponse");
|
|
@@ -21,6 +22,19 @@ function retainResponse(target, response) {
|
|
|
21
22
|
writable: false,
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
const responseBodyErrors = new WeakSet();
|
|
26
|
+
function responseBodyError(error) {
|
|
27
|
+
const record = { ok: false, error };
|
|
28
|
+
responseBodyErrors.add(record);
|
|
29
|
+
return record;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns true when `value` is a failure record created by `getResponseBody` (for example malformed JSON),
|
|
33
|
+
* as opposed to a parsed JSON body that happens to have the same shape.
|
|
34
|
+
*/
|
|
35
|
+
function isResponseBodyError(value) {
|
|
36
|
+
return typeof value === "object" && value != null && responseBodyErrors.has(value);
|
|
37
|
+
}
|
|
24
38
|
function getResponseBody(response, responseType) {
|
|
25
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
40
|
switch (responseType) {
|
|
@@ -32,25 +46,19 @@ function getResponseBody(response, responseType) {
|
|
|
32
46
|
return yield response.arrayBuffer();
|
|
33
47
|
case "sse":
|
|
34
48
|
if (response.body == null) {
|
|
35
|
-
return {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
statusCode: response.status,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
49
|
+
return responseBodyError({
|
|
50
|
+
reason: "body-is-null",
|
|
51
|
+
statusCode: response.status,
|
|
52
|
+
});
|
|
42
53
|
}
|
|
43
54
|
retainResponse(response.body, response);
|
|
44
55
|
return response.body;
|
|
45
56
|
case "streaming":
|
|
46
57
|
if (response.body == null) {
|
|
47
|
-
return {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
statusCode: response.status,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
58
|
+
return responseBodyError({
|
|
59
|
+
reason: "body-is-null",
|
|
60
|
+
statusCode: response.status,
|
|
61
|
+
});
|
|
54
62
|
}
|
|
55
63
|
retainResponse(response.body, response);
|
|
56
64
|
return response.body;
|
|
@@ -65,14 +73,11 @@ function getResponseBody(response, responseType) {
|
|
|
65
73
|
return responseBody;
|
|
66
74
|
}
|
|
67
75
|
catch (_err) {
|
|
68
|
-
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
rawBody: text,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
+
return responseBodyError({
|
|
77
|
+
reason: "non-json",
|
|
78
|
+
statusCode: response.status,
|
|
79
|
+
rawBody: text,
|
|
80
|
+
});
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
return undefined;
|
|
@@ -18,6 +18,7 @@ const makeRequest_1 = require("./makeRequest");
|
|
|
18
18
|
const redactUrl_1 = require("./redactUrl");
|
|
19
19
|
const requestWithRetries_1 = require("./requestWithRetries");
|
|
20
20
|
const Supplier_1 = require("./Supplier");
|
|
21
|
+
const signals_1 = require("./signals");
|
|
21
22
|
/**
|
|
22
23
|
* Makes a passthrough HTTP request using the SDK's configuration (auth, retry, logging, etc.)
|
|
23
24
|
* while mimicking the standard `fetch` API.
|
|
@@ -122,10 +123,20 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
|
|
|
122
123
|
hasBody: body != null,
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
let response;
|
|
127
|
+
try {
|
|
128
|
+
response = yield (0, requestWithRetries_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
return (0, makeRequest_1.makeRequest)(fetchFn, fullUrl, method, mergedHeaders, body !== null && body !== void 0 ? body : undefined, timeoutMs, abortSignal, (effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.credentials) === "include", undefined, // duplex
|
|
130
|
+
false);
|
|
131
|
+
}), maxRetries, abortSignal);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
// Match `fetch`: a timeout rejects with an Error named "TimeoutError", not the bare abort reason.
|
|
135
|
+
if (error === signals_1.TIMEOUT) {
|
|
136
|
+
throw createTimeoutError();
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
129
140
|
if (logger.isDebug()) {
|
|
130
141
|
logger.debug("Passthrough HTTP request completed", {
|
|
131
142
|
method,
|
|
@@ -136,6 +147,11 @@ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
|
|
|
136
147
|
return response;
|
|
137
148
|
});
|
|
138
149
|
}
|
|
150
|
+
function createTimeoutError() {
|
|
151
|
+
const error = new Error("The request timed out.");
|
|
152
|
+
error.name = "TimeoutError";
|
|
153
|
+
return error;
|
|
154
|
+
}
|
|
139
155
|
/**
|
|
140
156
|
* Returns true when the resolved request URL points at the same origin as the
|
|
141
157
|
* configured base URL. Relative paths are always joined onto the base URL, so
|
|
@@ -3,4 +3,9 @@ export declare function isCacheNoStoreSupported(): boolean;
|
|
|
3
3
|
* Reset the cached result of `isCacheNoStoreSupported`. Exposed for testing only.
|
|
4
4
|
*/
|
|
5
5
|
export declare function resetCacheNoStoreSupported(): void;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Clears the timeout that `makeRequest` kept running (with `keepTimeoutUntilBodyRead`) so that it also
|
|
8
|
+
* covered reading the response body.
|
|
9
|
+
*/
|
|
10
|
+
export declare function clearResponseTimeout(response: Response): void;
|
|
11
|
+
export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Headers | Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half", disableCache?: boolean, keepTimeoutUntilBodyRead?: boolean) => Promise<Response>;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.makeRequest = void 0;
|
|
13
13
|
exports.isCacheNoStoreSupported = isCacheNoStoreSupported;
|
|
14
14
|
exports.resetCacheNoStoreSupported = resetCacheNoStoreSupported;
|
|
15
|
+
exports.clearResponseTimeout = clearResponseTimeout;
|
|
15
16
|
const signals_1 = require("./signals");
|
|
16
17
|
/**
|
|
17
18
|
* Cached result of checking whether the current runtime supports
|
|
@@ -38,23 +39,55 @@ function isCacheNoStoreSupported() {
|
|
|
38
39
|
function resetCacheNoStoreSupported() {
|
|
39
40
|
_cacheNoStoreSupported = undefined;
|
|
40
41
|
}
|
|
41
|
-
const
|
|
42
|
+
const responseTimeouts = new WeakMap();
|
|
43
|
+
/**
|
|
44
|
+
* Clears the timeout that `makeRequest` kept running (with `keepTimeoutUntilBodyRead`) so that it also
|
|
45
|
+
* covered reading the response body.
|
|
46
|
+
*/
|
|
47
|
+
function clearResponseTimeout(response) {
|
|
48
|
+
const timeoutId = responseTimeouts.get(response);
|
|
49
|
+
if (timeoutId != null) {
|
|
50
|
+
clearTimeout(timeoutId);
|
|
51
|
+
responseTimeouts.delete(response);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex, disableCache, keepTimeoutUntilBodyRead) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
55
|
const signals = [];
|
|
43
56
|
let timeoutAbortId;
|
|
57
|
+
let timeoutSignal;
|
|
44
58
|
if (timeoutMs != null) {
|
|
45
59
|
const { signal, abortId } = (0, signals_1.getTimeoutSignal)(timeoutMs);
|
|
46
60
|
timeoutAbortId = abortId;
|
|
61
|
+
timeoutSignal = signal;
|
|
47
62
|
signals.push(signal);
|
|
48
63
|
}
|
|
49
64
|
if (abortSignal != null) {
|
|
50
65
|
signals.push(abortSignal);
|
|
51
66
|
}
|
|
52
67
|
const newSignals = (0, signals_1.anySignal)(signals);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
let response;
|
|
69
|
+
try {
|
|
70
|
+
response = yield fetchFn(url, Object.assign({ method: method, headers, body: requestBody, signal: newSignals, credentials: withCredentials ? "include" : undefined,
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
duplex }, (disableCache && isCacheNoStoreSupported() ? { cache: "no-store" } : {})));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (timeoutAbortId != null) {
|
|
76
|
+
clearTimeout(timeoutAbortId);
|
|
77
|
+
}
|
|
78
|
+
// Some runtimes (e.g. Node 18) reject with their own error instead of the abort reason.
|
|
79
|
+
if ((timeoutSignal === null || timeoutSignal === void 0 ? void 0 : timeoutSignal.aborted) && !(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)) {
|
|
80
|
+
throw signals_1.TIMEOUT;
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
56
84
|
if (timeoutAbortId != null) {
|
|
57
|
-
|
|
85
|
+
if (keepTimeoutUntilBodyRead) {
|
|
86
|
+
responseTimeouts.set(response, timeoutAbortId);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
clearTimeout(timeoutAbortId);
|
|
90
|
+
}
|
|
58
91
|
}
|
|
59
92
|
return response;
|
|
60
93
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function requestWithRetries(requestFn: () => Promise<Response>, maxRetries?: number): Promise<Response>;
|
|
1
|
+
export declare function requestWithRetries(requestFn: () => Promise<Response>, maxRetries?: number, abortSignal?: AbortSignal): Promise<Response>;
|
|
@@ -52,13 +52,34 @@ function getRetryDelayFromHeaders(response, retryAttempt) {
|
|
|
52
52
|
}
|
|
53
53
|
return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Waits `ms` milliseconds, or rejects as soon as `abortSignal` aborts. The timer and
|
|
57
|
+
* the abort listener are always removed, so a cancelled wait never keeps the process alive.
|
|
58
|
+
*/
|
|
59
|
+
function sleep(ms, abortSignal) {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
62
|
+
reject(abortSignal.reason);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const onAbort = () => {
|
|
66
|
+
clearTimeout(timeoutId);
|
|
67
|
+
reject(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.reason);
|
|
68
|
+
};
|
|
69
|
+
const timeoutId = setTimeout(() => {
|
|
70
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener("abort", onAbort);
|
|
71
|
+
resolve();
|
|
72
|
+
}, ms);
|
|
73
|
+
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
74
|
+
});
|
|
75
|
+
}
|
|
55
76
|
function requestWithRetries(requestFn_1) {
|
|
56
|
-
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
|
|
77
|
+
return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES, abortSignal) {
|
|
57
78
|
let response = yield requestFn();
|
|
58
79
|
for (let i = 0; i < maxRetries; ++i) {
|
|
59
80
|
if (isRetryableStatusCode(response.status)) {
|
|
60
81
|
const delay = getRetryDelayFromHeaders(response, i);
|
|
61
|
-
yield
|
|
82
|
+
yield sleep(delay, abortSignal);
|
|
62
83
|
response = yield requestFn();
|
|
63
84
|
}
|
|
64
85
|
else {
|
package/core/fetcher/signals.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TIMEOUT = void 0;
|
|
3
4
|
exports.getTimeoutSignal = getTimeoutSignal;
|
|
4
5
|
exports.anySignal = anySignal;
|
|
5
|
-
|
|
6
|
+
exports.TIMEOUT = "timeout";
|
|
6
7
|
function getTimeoutSignal(timeoutMs) {
|
|
7
8
|
const controller = new AbortController();
|
|
8
|
-
const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
|
|
9
|
+
const abortId = setTimeout(() => controller.abort(exports.TIMEOUT), timeoutMs);
|
|
9
10
|
return { signal: controller.signal, abortId };
|
|
10
11
|
}
|
|
11
12
|
function anySignal(...args) {
|
package/core/stream/Stream.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export declare namespace Stream {
|
|
|
38
38
|
type: "sse";
|
|
39
39
|
streamTerminator?: string;
|
|
40
40
|
eventDiscriminator?: string;
|
|
41
|
+
/** Event names whose union variant wraps the `data:` payload as `{ <eventDiscriminator>, data }`. */
|
|
42
|
+
envelopeEvents?: string[];
|
|
41
43
|
resumable?: boolean;
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -58,6 +60,7 @@ export declare class Stream<T> implements AsyncIterable<T> {
|
|
|
58
60
|
private messageTerminator;
|
|
59
61
|
private streamTerminator;
|
|
60
62
|
private eventDiscriminator;
|
|
63
|
+
private envelopeEvents;
|
|
61
64
|
private resumable;
|
|
62
65
|
private reconnectionEnabled;
|
|
63
66
|
private maxReconnectionAttempts;
|
package/core/stream/Stream.js
CHANGED
|
@@ -56,6 +56,7 @@ class Stream {
|
|
|
56
56
|
this.messageTerminator = "\n";
|
|
57
57
|
this.streamTerminator = eventShape.streamTerminator;
|
|
58
58
|
this.eventDiscriminator = eventShape.eventDiscriminator;
|
|
59
|
+
this.envelopeEvents = eventShape.envelopeEvents != null ? new Set(eventShape.envelopeEvents) : undefined;
|
|
59
60
|
this.resumable = (_a = eventShape.resumable) !== null && _a !== void 0 ? _a : false;
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
@@ -415,9 +416,13 @@ class Stream {
|
|
|
415
416
|
};
|
|
416
417
|
}
|
|
417
418
|
injectDiscriminator(parsed, eventType) {
|
|
419
|
+
var _a;
|
|
418
420
|
if (this.eventDiscriminator == null || eventType == null) {
|
|
419
421
|
return parsed;
|
|
420
422
|
}
|
|
423
|
+
if ((_a = this.envelopeEvents) === null || _a === void 0 ? void 0 : _a.has(eventType)) {
|
|
424
|
+
return { [this.eventDiscriminator]: eventType, data: parsed };
|
|
425
|
+
}
|
|
421
426
|
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
422
427
|
return parsed;
|
|
423
428
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.encodePathParam = encodePathParam;
|
|
4
|
-
function encodePathParam(param) {
|
|
4
|
+
function encodePathParam(param, InvalidPathParameterError) {
|
|
5
5
|
if (param === null) {
|
|
6
6
|
return "null";
|
|
7
7
|
}
|
|
@@ -17,5 +17,11 @@ function encodePathParam(param) {
|
|
|
17
17
|
param = String(param);
|
|
18
18
|
break;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
const encoded = encodeURIComponent(param);
|
|
21
|
+
// "." and ".." are dot segments: URL resolution would remove them and send the request to a different path.
|
|
22
|
+
if (encoded === "." || encoded === "..") {
|
|
23
|
+
const message = `Invalid path parameter "${encoded}": "." and ".." are not allowed because they change the request path.`;
|
|
24
|
+
throw InvalidPathParameterError != null ? new InvalidPathParameterError({ message }) : new Error(message);
|
|
25
|
+
}
|
|
26
|
+
return encoded;
|
|
21
27
|
}
|
package/core/websocket/ws.d.ts
CHANGED
|
@@ -23,8 +23,9 @@ export declare namespace ReconnectingWebSocket {
|
|
|
23
23
|
startClosed?: boolean;
|
|
24
24
|
debug?: boolean;
|
|
25
25
|
/**
|
|
26
|
-
* Decides whether a close event should trigger a reconnect. Return `false` to treat the close as terminal.
|
|
27
|
-
* Not consulted when `close()` was called or the abort signal fired.
|
|
26
|
+
* Decides whether a server close event should trigger a reconnect. Return `false` to treat the close as terminal.
|
|
27
|
+
* Not consulted for internal closes, when `close()` was called, or when the abort signal fired.
|
|
28
|
+
* Defaults to `event.code !== 1000`.
|
|
28
29
|
*/
|
|
29
30
|
shouldReconnect?: (event: Events.CloseEvent) => boolean;
|
|
30
31
|
};
|
|
@@ -48,6 +49,7 @@ export declare class ReconnectingWebSocket {
|
|
|
48
49
|
private _binaryType;
|
|
49
50
|
private _closeCalled;
|
|
50
51
|
private _messageQueue;
|
|
52
|
+
private _openWaiters;
|
|
51
53
|
private readonly _url;
|
|
52
54
|
private readonly _protocols?;
|
|
53
55
|
private readonly _options;
|
|
@@ -130,6 +132,15 @@ export declare class ReconnectingWebSocket {
|
|
|
130
132
|
* Register an event handler of a specific event type
|
|
131
133
|
*/
|
|
132
134
|
addEventListener<T extends keyof Events.WebSocketEventListenerMap>(type: T, listener: Events.WebSocketEventListenerMap[T]): void;
|
|
135
|
+
/**
|
|
136
|
+
* Resolves once the connection is open. Rejects on an error event, or once the connection is closed and no
|
|
137
|
+
* connection attempt or reconnect is pending (for example after close(), an abort, or a terminal close).
|
|
138
|
+
*/
|
|
139
|
+
waitForOpen(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Returns whether the given listener is registered for the event type
|
|
142
|
+
*/
|
|
143
|
+
hasEventListener<T extends keyof Events.WebSocketEventListenerMap>(type: T, listener: Events.WebSocketEventListenerMap[T]): boolean;
|
|
133
144
|
dispatchEvent(event: Event): boolean;
|
|
134
145
|
/**
|
|
135
146
|
* Removes an event listener
|
|
@@ -141,6 +152,8 @@ export declare class ReconnectingWebSocket {
|
|
|
141
152
|
private _getNextUrl;
|
|
142
153
|
private _connect;
|
|
143
154
|
private _handleAbort;
|
|
155
|
+
private _willNotOpen;
|
|
156
|
+
private _notifyOpenWaiters;
|
|
144
157
|
private _handleTimeout;
|
|
145
158
|
private _disconnect;
|
|
146
159
|
private _acceptOpen;
|
|
@@ -149,6 +162,7 @@ export declare class ReconnectingWebSocket {
|
|
|
149
162
|
private _handleMessage;
|
|
150
163
|
private _handleError;
|
|
151
164
|
private _handleClose;
|
|
165
|
+
private _emitClose;
|
|
152
166
|
private _isReconnectableClose;
|
|
153
167
|
private _removeListeners;
|
|
154
168
|
private _addListeners;
|