@cognidesk/http 0.0.3-dev.3 → 0.0.3-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,118 @@
1
- import { CreateRuntimeConversationInput, ConversationRecord, HandleUserMessageInput, HandleUserMessageResult, SubmitWidgetInput, RuntimeEvent, CustomRuntimeEventDefinition, JourneyEventDefinition, EmitJourneyEventResult, EmitIntermediateMessageInput, EmitGeneratedPreambleInput, CompactConversationInput, CompactConversationResult, RequestHandoffInput, ResumeConversationInput, 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, 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
+ 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
+
4
+ type ChannelEventActorInput = ChannelEventActor | ChannelEventActorType;
5
+ interface ChannelEventShortcutEnvelope<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown> extends Omit<Partial<ChannelEventEnvelopeInput<TPayload, TRawPayload>>, "actor"> {
6
+ actor?: ChannelEventActorInput;
7
+ conversationId?: string;
8
+ agentId?: string;
9
+ text?: string;
10
+ message?: string;
11
+ subject?: string;
12
+ body?: string;
13
+ summary?: string;
14
+ attachments?: unknown[];
15
+ providerObject?: unknown;
16
+ status?: string;
17
+ turn?: unknown;
18
+ raw?: TRawPayload;
19
+ identity?: ChannelEventIdentity;
20
+ identityKey?: string;
21
+ dedupeKey?: string;
22
+ idempotencyKey?: string;
23
+ identityStreamId?: string;
24
+ sequence?: string | number;
25
+ identityMetadata?: Record<string, unknown>;
26
+ }
27
+ interface ChannelEventSubmitInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends Omit<HandleChannelEventInput<TPayload, TTurn>, "event"> {
28
+ event?: ChannelEventShortcutEnvelope<TPayload, TRawPayload>;
29
+ channel?: ConversationChannelInput;
30
+ id?: string;
31
+ kind?: ChannelEventKind;
32
+ nature?: ChannelEventNature;
33
+ direction?: ChannelEventDirection;
34
+ intent?: ChannelEventIntent;
35
+ actor?: ChannelEventActorInput;
36
+ occurredAt?: string;
37
+ payload?: TPayload;
38
+ source?: ChannelEventSourceEvidence<TRawPayload>;
39
+ metadata?: Record<string, unknown>;
40
+ text?: string;
41
+ message?: string;
42
+ subject?: string;
43
+ body?: string;
44
+ summary?: string;
45
+ attachments?: unknown[];
46
+ providerObject?: unknown;
47
+ status?: string;
48
+ turn?: TTurn;
49
+ sourceType?: ChannelEventSourceEvidence<TRawPayload>["sourceType"];
50
+ sourceId?: string;
51
+ provider?: string;
52
+ providerPackageId?: string;
53
+ eventId?: string;
54
+ streamId?: string;
55
+ deliveryId?: string;
56
+ receivedAt?: string;
57
+ verified?: boolean;
58
+ externalObjectIds?: Record<string, string>;
59
+ raw?: TRawPayload;
60
+ identity?: ChannelEventIdentity;
61
+ identityKey?: string;
62
+ dedupeKey?: string;
63
+ idempotencyKey?: string;
64
+ identityStreamId?: string;
65
+ sequence?: string | number;
66
+ identityMetadata?: Record<string, unknown>;
67
+ }
68
+ interface ChannelMessageEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
69
+ channel: ConversationChannelInput;
70
+ text: string;
71
+ direction?: Extract<ChannelEventDirection, "inbound" | "outbound">;
72
+ }
73
+ interface ProviderObjectChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
74
+ channel: ConversationChannelInput;
75
+ }
76
+ interface VoiceTurnChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
77
+ text?: string;
78
+ transcript?: string;
79
+ channel?: ConversationChannelInput;
80
+ }
81
+ interface OutboundContactChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
82
+ channel: ConversationChannelInput;
83
+ }
84
+ interface ScheduledChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
85
+ channel: ConversationChannelInput;
86
+ }
87
+ interface ChannelOutputResolutionEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
88
+ channel: ConversationChannelInput;
89
+ }
90
+ interface ChannelHandoffReviewEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
91
+ channel: ConversationChannelInput;
92
+ }
93
+ interface ChannelHandoffEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown> extends ChannelEventSubmitInput<TPayload, TRawPayload, TTurn> {
94
+ channel: ConversationChannelInput;
95
+ fromChannel?: ConversationChannelInput;
96
+ reason?: string;
97
+ reasonCode?: string;
98
+ reasonLabel?: string;
99
+ }
100
+ type ChannelEventRequestBody<TPayload = NormalizedChannelPayloadInput, TTurn = unknown> = Omit<HandleChannelEventInput<TPayload, TTurn>, "signal" | "onAssistantTextDelta">;
101
+
102
+ declare function createChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ChannelEventSubmitInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
103
+ declare function createChannelEventRequestBody<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ChannelEventSubmitInput<TPayload, TRawPayload, TTurn>): ChannelEventRequestBody<TPayload, TTurn>;
104
+ declare function createMessageChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ChannelMessageEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
105
+ declare function createProviderObjectChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ProviderObjectChannelEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
106
+ declare function createVoiceTurnChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: VoiceTurnChannelEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
107
+ declare function createOutboundContactChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: OutboundContactChannelEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
108
+ declare function createScheduledChannelEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ScheduledChannelEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
109
+ declare function createChannelOutputResolutionEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ChannelOutputResolutionEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
110
+ declare function createChannelHandoffEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ChannelHandoffEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
111
+ declare function createChannelHandoffReviewEventInput<TPayload = NormalizedChannelPayloadInput, TRawPayload = unknown, TTurn = unknown>(input: ChannelHandoffReviewEventInput<TPayload, TRawPayload, TTurn>): HandleChannelEventInput<TPayload, TTurn>;
2
112
 
3
113
  interface CognideskHttpRuntime {
4
114
  createConversation(input: CreateRuntimeConversationInput): Promise<ConversationRecord>;
115
+ handleChannelEvent?(input: HandleChannelEventInput): Promise<HandleChannelEventResult>;
5
116
  handleUserMessage(input: HandleUserMessageInput): Promise<HandleUserMessageResult>;
6
117
  submitWidget?(input: SubmitWidgetInput): Promise<RuntimeEvent>;
7
118
  emitCustomEvent?(input: {
@@ -38,6 +149,7 @@ interface CognideskHttpRuntime {
38
149
  conversation: ConversationRecord;
39
150
  event: RuntimeEvent;
40
151
  }>;
152
+ resolveChannelOutput?(input: ResolveChannelOutputInput): Promise<ResolveChannelOutputResult>;
41
153
  startVoiceConversation?(input: StartVoiceConversationInput): Promise<StartVoiceResult>;
42
154
  startVoiceSegment?(input: StartVoiceSegmentInput): Promise<StartVoiceResult>;
43
155
  replayConversation?(input: ReplayConversationInput): Promise<ReplayConversationResult>;
@@ -52,6 +164,28 @@ interface VoiceSocketHandshakeInput {
52
164
  interface VoiceSocketHandshake {
53
165
  createSocket(input: VoiceSocketHandshakeInput): Promise<VoiceSocketMetadata>;
54
166
  }
167
+ interface CognideskHttpAuthorizeInput {
168
+ /** Original request before the HTTP handler reads the body or calls the runtime. */
169
+ request: Request;
170
+ /** Parsed request URL. */
171
+ url: URL;
172
+ /** Request path after the configured basePath has been stripped. */
173
+ path: string;
174
+ }
175
+ type CognideskHttpAuthorizeResult = boolean | Response;
176
+ type CognideskHttpAuthorize = (input: CognideskHttpAuthorizeInput) => CognideskHttpAuthorizeResult | Promise<CognideskHttpAuthorizeResult>;
177
+ interface CognideskHttpCorsOptions {
178
+ /** Exact browser origins allowed to call the handler, for example "https://app.example.com". */
179
+ origins: string | readonly string[];
180
+ /** Defaults to GET, POST, and OPTIONS. */
181
+ methods?: string | readonly string[];
182
+ /** Defaults to content-type and authorization. */
183
+ allowedHeaders?: string | readonly string[];
184
+ exposedHeaders?: string | readonly string[];
185
+ credentials?: boolean;
186
+ maxAgeSeconds?: number;
187
+ }
188
+ type CognideskHttpCorsConfig = boolean | CognideskHttpCorsOptions;
55
189
  interface CognideskHttpHandlerOptions {
56
190
  runtime: CognideskHttpRuntime | CognideskRuntime;
57
191
  basePath?: string;
@@ -60,12 +194,28 @@ interface CognideskHttpHandlerOptions {
60
194
  customEvents?: CustomRuntimeEventDefinition[];
61
195
  journeyEvents?: JourneyEventDefinition[];
62
196
  ssePollIntervalMs?: number;
63
- cors?: boolean;
197
+ /**
198
+ * Enable CORS. `true` keeps the legacy wildcard behavior; prefer an object
199
+ * with explicit origins for browser-facing deployments.
200
+ */
201
+ cors?: CognideskHttpCorsConfig;
202
+ /**
203
+ * Authorize non-preflight requests before the runtime is called. Return true
204
+ * to allow, false for a default 401, or a Response for a custom denial.
205
+ */
206
+ authorize?: CognideskHttpAuthorize;
207
+ /**
208
+ * Include raw thrown Error messages in 500 responses. Defaults to false so
209
+ * internal runtime details are not exposed to HTTP clients.
210
+ */
211
+ exposeInternalErrors?: boolean;
64
212
  }
65
213
  interface CognideskHttpHandler {
66
214
  handle(request: Request): Promise<Response>;
67
215
  }
216
+ type CreateChannelEventBody = ChannelEventSubmitInput;
217
+ type ResolveChannelOutputBody<TPayload = unknown> = Omit<ResolveChannelOutputInput<TPayload>, "signal">;
68
218
 
69
219
  declare function createCognideskHttpHandler(options: CognideskHttpHandlerOptions): CognideskHttpHandler;
70
220
 
71
- export { type CognideskHttpHandler, type CognideskHttpHandlerOptions, type CognideskHttpRuntime, createCognideskHttpHandler };
221
+ export { type ChannelEventActorInput, type ChannelEventRequestBody, type ChannelEventShortcutEnvelope, type ChannelEventSubmitInput, type ChannelHandoffEventInput, type ChannelHandoffReviewEventInput, type ChannelMessageEventInput, type ChannelOutputResolutionEventInput, type CognideskHttpAuthorize, type CognideskHttpAuthorizeInput, type CognideskHttpAuthorizeResult, type CognideskHttpCorsConfig, type CognideskHttpCorsOptions, type CognideskHttpHandler, type CognideskHttpHandlerOptions, type CognideskHttpRuntime, type CreateChannelEventBody, type OutboundContactChannelEventInput, type ProviderObjectChannelEventInput, type ResolveChannelOutputBody, type ScheduledChannelEventInput, type VoiceTurnChannelEventInput, createChannelEventInput, createChannelEventRequestBody, createChannelHandoffEventInput, createChannelHandoffReviewEventInput, createChannelOutputResolutionEventInput, createCognideskHttpHandler, createMessageChannelEventInput, createOutboundContactChannelEventInput, createProviderObjectChannelEventInput, createScheduledChannelEventInput, createVoiceTurnChannelEventInput };