@cognidesk/http 0.0.3-dev.8 → 0.0.3-dev.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ChannelEventActor, ChannelEventActorType, NormalizedChannelPayloadInput, HandleChannelEventInput, ChannelEventEnvelopeInput, ChannelEventIdentity, ConversationChannelInput, ChannelEventKind, ChannelEventNature, ChannelEventDirection, ChannelEventIntent, ChannelEventSourceEvidence, CreateRuntimeConversationInput, ConversationRecord, HandleChannelEventResult, HandleUserMessageInput, HandleUserMessageResult, SubmitWidgetInput, RuntimeEvent, CustomRuntimeEventDefinition, JourneyEventDefinition, EmitJourneyEventResult, EmitIntermediateMessageInput, EmitGeneratedPreambleInput, CompactConversationInput, CompactConversationResult, RequestHandoffInput, ResumeConversationInput, ResolveChannelOutputInput, ResolveChannelOutputResult, StartVoiceConversationInput, StartVoiceResult, StartVoiceSegmentInput, ReplayConversationInput, ReplayConversationResult, RuntimeSnapshot, CognideskRuntime, VoiceSocketMetadata } from '@cognidesk/core';
1
+ import { ChannelEventActor, ChannelEventActorType, NormalizedChannelPayloadInput, HandleChannelEventInput, ChannelEventEnvelopeInput, ChannelEventIdentity, ConversationChannelInput, ChannelEventKind, ChannelEventNature, ChannelEventDirection, ChannelEventIntent, ChannelEventSourceEvidence, CreateRuntimeConversationInput, ConversationRecord, ListRuntimeConversationsOptions, HandleChannelEventResult, HandleUserMessageInput, HandleUserMessageResult, SubmitWidgetInput, RuntimeEvent, CustomRuntimeEventDefinition, JourneyEventDefinition, EmitJourneyEventResult, EmitIntermediateMessageInput, EmitGeneratedPreambleInput, CompactConversationInput, CompactConversationResult, RequestHandoffInput, ResumeConversationInput, ResolveChannelOutputInput, ResolveChannelOutputResult, StartVoiceConversationInput, StartVoiceResult, StartVoiceSegmentInput, ReplayConversationInput, ReplayConversationResult, RuntimeSnapshot, CognideskRuntime, VoiceSocketMetadata } from '@cognidesk/core';
2
2
  export { ChannelEventActor, ChannelEventActorType, ChannelEventBindingOutcome, ChannelEventDirection, ChannelEventEnvelope, ChannelEventEnvelopeInput, ChannelEventHandlingDisposition, ChannelEventIdentity, ChannelEventIntakeResult, ChannelEventIntakeStatus, ChannelEventIntent, ChannelEventKind, ChannelEventNature, ChannelEventSourceEvidence, ChannelEventSourceType, ChannelOutputDeliveryMode, ChannelOutputIntent, ChannelOutputIntentInput, ChannelOutputIntentKind, ChannelOutputResolution, ChannelOutputResolutionDecision, ChannelOutputResolutionOutcome, ChannelOutputResolutionPayload, ChannelOutputResolutionStatus, ChannelSourceEvidence, HandleChannelEventInput, HandleChannelEventResult, NormalizedChannelPayload, NormalizedChannelPayloadInput, ResolveChannelOutputInput, ResolveChannelOutputResult } from '@cognidesk/core';
3
3
 
4
4
  type ChannelEventActorInput = ChannelEventActor | ChannelEventActorType;
@@ -112,6 +112,7 @@ declare function createChannelHandoffReviewEventInput<TPayload = NormalizedChann
112
112
 
113
113
  interface CognideskHttpRuntime {
114
114
  createConversation(input: CreateRuntimeConversationInput): Promise<ConversationRecord>;
115
+ listConversations?(input?: ListRuntimeConversationsOptions): Promise<ConversationRecord[]>;
115
116
  handleChannelEvent?(input: HandleChannelEventInput): Promise<HandleChannelEventResult>;
116
117
  handleUserMessage(input: HandleUserMessageInput): Promise<HandleUserMessageResult>;
117
118
  submitWidget?(input: SubmitWidgetInput): Promise<RuntimeEvent>;
package/dist/index.js CHANGED
@@ -109,10 +109,10 @@ function stripBasePath(pathname, basePath) {
109
109
  if (!pathname.startsWith(`${basePath}/`)) return null;
110
110
  return pathname.slice(basePath.length);
111
111
  }
112
- function parseOptionalInteger(value) {
112
+ function parseOptionalInteger(value, name = "after") {
113
113
  if (value === null || value === "") return void 0;
114
114
  if (!/^(0|[1-9]\d*)$/.test(value)) {
115
- throw new HttpInputError("after must be a non-negative integer.");
115
+ throw new HttpInputError(`${name} must be a non-negative integer.`);
116
116
  }
117
117
  return Number(value);
118
118
  }
@@ -760,6 +760,30 @@ function createCognideskHttpHandler(options) {
760
760
  }
761
761
  const authorizationResponse = await authorizeRequest(options, { request, url, path }, responseOptions);
762
762
  if (authorizationResponse) return authorizationResponse;
763
+ if (request.method === "GET" && path === "/conversations") {
764
+ if (!options.runtime.listConversations) return json({ error: "Conversation listing is not supported by this runtime" }, 501, responseOptions);
765
+ const limit = parseOptionalInteger(url.searchParams.get("limit"), "limit");
766
+ const agentId = optionalSearchString(url.searchParams, "agentId");
767
+ const beforeUpdatedAt = optionalSearchString(url.searchParams, "beforeUpdatedAt") ?? optionalSearchString(url.searchParams, "before");
768
+ const afterUpdatedAt = optionalSearchString(url.searchParams, "afterUpdatedAt") ?? optionalSearchString(url.searchParams, "after");
769
+ const beforeId = optionalSearchString(url.searchParams, "beforeId");
770
+ const afterId = optionalSearchString(url.searchParams, "afterId");
771
+ if (beforeId && !beforeUpdatedAt || beforeUpdatedAt && beforeId === void 0 && url.searchParams.has("beforeId")) {
772
+ throw new HttpInputError("beforeUpdatedAt and beforeId must be provided together.");
773
+ }
774
+ if (afterId && !afterUpdatedAt || afterUpdatedAt && afterId === void 0 && url.searchParams.has("afterId")) {
775
+ throw new HttpInputError("afterUpdatedAt and afterId must be provided together.");
776
+ }
777
+ const conversations = await options.runtime.listConversations({
778
+ ...agentId ? { agentId } : {},
779
+ ...beforeUpdatedAt && beforeId ? { before: { updatedAt: beforeUpdatedAt, id: beforeId } } : {},
780
+ ...afterUpdatedAt && afterId ? { after: { updatedAt: afterUpdatedAt, id: afterId } } : {},
781
+ ...beforeUpdatedAt && !beforeId ? { beforeUpdatedAt } : {},
782
+ ...afterUpdatedAt && !afterId ? { afterUpdatedAt } : {},
783
+ ...limit !== void 0 ? { limit } : {}
784
+ });
785
+ return json({ conversations }, 200, responseOptions);
786
+ }
763
787
  if (request.method === "POST" && path === "/conversations") {
764
788
  const body = await readObject(request);
765
789
  const agentId = optionalString(body, "agentId") ?? options.agentId;
@@ -1040,6 +1064,12 @@ function createCognideskHttpHandler(options) {
1040
1064
  }
1041
1065
  };
1042
1066
  }
1067
+ function optionalSearchString(params, key) {
1068
+ const value = params.get(key);
1069
+ if (value === null) return void 0;
1070
+ const trimmed = value.trim();
1071
+ return trimmed.length > 0 ? trimmed : void 0;
1072
+ }
1043
1073
  export {
1044
1074
  createChannelEventInput,
1045
1075
  createChannelEventRequestBody,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cognidesk/http",
3
- "version": "0.0.3-dev.8",
3
+ "version": "0.0.3-dev.9",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "lint": "tsc -p tsconfig.json --noEmit"
19
19
  },
20
20
  "dependencies": {
21
- "@cognidesk/core": "0.0.3-dev.8"
21
+ "@cognidesk/core": "0.0.3-dev.9"
22
22
  },
23
23
  "devDependencies": {
24
24
  "tsup": "^8.5.0",