dewee-webchat 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +144 -2
- package/astro/DeweeChat.astro +21 -0
- package/dist/chunk-MKTHKYLY.js +10 -0
- package/dist/chunk-RGAYYTL7.js +1265 -0
- package/dist/dewee-webchat.js +252 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.js +17 -0
- package/dist/protocol-CS8_4zC0.d.ts +71 -0
- package/dist/react.d.ts +26 -0
- package/dist/react.js +44 -0
- package/dist/server.d.ts +125 -0
- package/dist/server.js +632 -0
- package/dist/vue.d.ts +254 -0
- package/dist/vue.js +66 -0
- package/package.json +99 -6
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { A as AgentInfo, H as HistoryMessage, C as ChatStreamEvent } from './protocol-CS8_4zC0.js';
|
|
2
|
+
export { P as PublicConfig, S as SessionResponse } from './protocol-CS8_4zC0.js';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
|
|
5
|
+
interface VisitorClaims {
|
|
6
|
+
/** Visitor id (random, 22 chars). */
|
|
7
|
+
v: string;
|
|
8
|
+
/** Expiry, epoch ms. */
|
|
9
|
+
exp: number;
|
|
10
|
+
}
|
|
11
|
+
declare function signVisitorToken(secret: string, claims: VisitorClaims): Promise<string>;
|
|
12
|
+
declare function verifyVisitorToken(secret: string, token: string): Promise<VisitorClaims | null>;
|
|
13
|
+
/** Returns true when the key may proceed. Implementations may be async (KV, DO, Redis…). */
|
|
14
|
+
type RateLimiter = (key: string, bucket: "session" | "chat") => boolean | Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Fixed-window in-memory limiter. Good enough for a single Node process; on serverless
|
|
17
|
+
* runtimes each isolate keeps its own counters, so pass a shared limiter for hard limits.
|
|
18
|
+
*/
|
|
19
|
+
declare function memoryRateLimiter(limits: {
|
|
20
|
+
chat: [number, number];
|
|
21
|
+
session: [number, number];
|
|
22
|
+
}): RateLimiter;
|
|
23
|
+
|
|
24
|
+
interface DeweeHandlerOptions {
|
|
25
|
+
/** Gateway runtime origin. Required unless every request brings its own credentials. */
|
|
26
|
+
gatewayUrl?: string;
|
|
27
|
+
/** Gateway token or operator API key (server-side only). */
|
|
28
|
+
token?: string;
|
|
29
|
+
tenantId?: string;
|
|
30
|
+
/** HMAC secret for visitor tokens (>= 32 random chars). */
|
|
31
|
+
secret?: string;
|
|
32
|
+
/** Agents visitors may talk to. The first is the default. `"*"` = every active agent. */
|
|
33
|
+
agents?: Array<string | AgentInfo> | "*";
|
|
34
|
+
defaultAgent?: string;
|
|
35
|
+
/** Let the widget switch between allowed agents. Default: true when more than one agent. */
|
|
36
|
+
allowAgentSwitch?: boolean;
|
|
37
|
+
/** Cross-origin sites allowed to call this backend. Same-origin is always allowed. */
|
|
38
|
+
allowedOrigins?: string[] | "*";
|
|
39
|
+
/**
|
|
40
|
+
* Let visitors bring their own gateway URL + token (sent per request, never stored).
|
|
41
|
+
* Meant for playgrounds. `allowedHosts` restricts which gateways may be targeted.
|
|
42
|
+
*/
|
|
43
|
+
allowClientCredentials?: boolean | {
|
|
44
|
+
allowedHosts?: string[];
|
|
45
|
+
};
|
|
46
|
+
/** Cloudflare Turnstile. When set, issuing a visitor session requires a valid challenge. */
|
|
47
|
+
turnstile?: {
|
|
48
|
+
siteKey: string;
|
|
49
|
+
secretKey: string;
|
|
50
|
+
};
|
|
51
|
+
/** Custom limiter, or false to disable. Default: in-memory 20 msgs/min, 10 sessions/10 min per IP. */
|
|
52
|
+
rateLimit?: RateLimiter | false;
|
|
53
|
+
maxMessageLength?: number;
|
|
54
|
+
/** Prefix for the per-visitor gateway user id. */
|
|
55
|
+
userIdPrefix?: string;
|
|
56
|
+
sessionTtlMs?: number;
|
|
57
|
+
/** Max duration of one agent run. */
|
|
58
|
+
timeoutMs?: number;
|
|
59
|
+
/** Observe traffic (logging/analytics). Errors thrown here are ignored. */
|
|
60
|
+
onChat?: (info: {
|
|
61
|
+
visitorId: string;
|
|
62
|
+
agent: string;
|
|
63
|
+
message: string;
|
|
64
|
+
reply?: string;
|
|
65
|
+
error?: string;
|
|
66
|
+
}) => void;
|
|
67
|
+
}
|
|
68
|
+
type Handler = (request: Request) => Promise<Response>;
|
|
69
|
+
declare function createDeweeHandler(options: DeweeHandlerOptions): Handler;
|
|
70
|
+
/** Reads options from environment variables (process.env, Workers env, import.meta.env…). */
|
|
71
|
+
declare function optionsFromEnv(env: Record<string, string | undefined>, overrides?: Partial<DeweeHandlerOptions>): DeweeHandlerOptions;
|
|
72
|
+
|
|
73
|
+
type FetchHandler = (request: Request) => Promise<Response>;
|
|
74
|
+
/** Wraps a fetch-style handler for `http.createServer`, Express (`app.all("/api/dewee/*", ...)`), etc. */
|
|
75
|
+
declare function toNodeHandler(handler: FetchHandler): (req: IncomingMessage & {
|
|
76
|
+
body?: unknown;
|
|
77
|
+
originalUrl?: string;
|
|
78
|
+
}, res: ServerResponse) => Promise<void>;
|
|
79
|
+
|
|
80
|
+
interface GatewayCredentials {
|
|
81
|
+
/** Gateway runtime origin, e.g. https://gateway.example.com */
|
|
82
|
+
url: string;
|
|
83
|
+
/** Gateway token or operator API key. Never sent to browsers. */
|
|
84
|
+
token: string;
|
|
85
|
+
/** Optional tenant id/slug for multi-tenant gateways. */
|
|
86
|
+
tenantId?: string;
|
|
87
|
+
}
|
|
88
|
+
declare class GatewayError extends Error {
|
|
89
|
+
code?: string | undefined;
|
|
90
|
+
constructor(message: string, code?: string | undefined);
|
|
91
|
+
}
|
|
92
|
+
/** One authenticated gateway connection. Short-lived: one per chat turn or lookup. */
|
|
93
|
+
declare class GatewayConnection {
|
|
94
|
+
private ws;
|
|
95
|
+
private seq;
|
|
96
|
+
private pending;
|
|
97
|
+
private listeners;
|
|
98
|
+
private closed;
|
|
99
|
+
private constructor();
|
|
100
|
+
static connect(creds: GatewayCredentials, userId: string, timeoutMs?: number): Promise<GatewayConnection>;
|
|
101
|
+
call<T = any>(method: string, params: unknown, timeoutMs?: number): Promise<T>;
|
|
102
|
+
onEvent(cb: (event: string, payload: any) => void): () => void;
|
|
103
|
+
close(): void;
|
|
104
|
+
private onMessage;
|
|
105
|
+
private fail;
|
|
106
|
+
}
|
|
107
|
+
declare function buildSessionKey(agent: string, conversationId: string): string;
|
|
108
|
+
interface StreamChatOptions {
|
|
109
|
+
creds: GatewayCredentials;
|
|
110
|
+
userId: string;
|
|
111
|
+
agent: string;
|
|
112
|
+
sessionKey: string;
|
|
113
|
+
message: string;
|
|
114
|
+
signal?: AbortSignal;
|
|
115
|
+
timeoutMs?: number;
|
|
116
|
+
}
|
|
117
|
+
/** Runs one chat turn and yields normalized stream events until the run ends. */
|
|
118
|
+
declare function streamChat(opts: StreamChatOptions): AsyncGenerator<ChatStreamEvent>;
|
|
119
|
+
/** Fetches a session transcript and folds tool calls/results into assistant turns. */
|
|
120
|
+
declare function fetchHistory(creds: GatewayCredentials, userId: string, agent: string, sessionKey: string): Promise<HistoryMessage[]>;
|
|
121
|
+
declare function foldHistory(raw: any[]): HistoryMessage[];
|
|
122
|
+
/** Lists agents via the gateway REST API. */
|
|
123
|
+
declare function listAgents(creds: GatewayCredentials): Promise<AgentInfo[]>;
|
|
124
|
+
|
|
125
|
+
export { AgentInfo, ChatStreamEvent, type DeweeHandlerOptions, GatewayConnection, type GatewayCredentials, GatewayError, HistoryMessage, type RateLimiter, type StreamChatOptions, buildSessionKey, createDeweeHandler, fetchHistory, foldHistory, listAgents, memoryRateLimiter, optionsFromEnv, signVisitorToken, streamChat, toNodeHandler, verifyVisitorToken };
|