dewee-webchat 0.1.1 → 0.2.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/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
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';
1
+ import { A as AgentInfo, H as HistoryMessage, C as ChatStreamEvent, a as ActionManifestEntry } from './protocol-B72Ry-fY.js';
2
+ export { b as ActionSensitivity, c as ChatRequestBody, P as PublicConfig, S as SessionResponse } from './protocol-B72Ry-fY.js';
3
3
  import { IncomingMessage, ServerResponse } from 'node:http';
4
4
 
5
5
  interface VisitorClaims {
@@ -122,4 +122,28 @@ declare function foldHistory(raw: any[]): HistoryMessage[];
122
122
  /** Lists agents via the gateway REST API. */
123
123
  declare function listAgents(creds: GatewayCredentials): Promise<AgentInfo[]>;
124
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 };
125
+ declare const ACTION_LIMITS: {
126
+ readonly maxActions: 32;
127
+ readonly maxDescription: 1000;
128
+ readonly maxParametersBytes: 4096;
129
+ readonly maxManifestBytes: 16384;
130
+ readonly maxPageContextBytes: 4096;
131
+ };
132
+ /** Validates and normalizes `body.actions` (fixed key order, so the hash is stable). Throws ActionInputError. */
133
+ declare function normalizeManifest(input: unknown): ActionManifestEntry[];
134
+ /** Short, opaque manifest fingerprint: first 16 hex chars of SHA-256 over the normalized JSON. */
135
+ declare function hashManifest(manifest: ActionManifestEntry[]): Promise<string>;
136
+ interface PageBlockInput {
137
+ manifest?: ActionManifestEntry[];
138
+ hash?: string;
139
+ /** False when the agent already received this exact manifest in the conversation. */
140
+ includeManifest?: boolean;
141
+ /** Pre-serialized page context JSON. */
142
+ pageContext?: string;
143
+ }
144
+ /** Builds the block prepended to the visitor message, or "" when there is nothing to add. */
145
+ declare function buildPageBlock(p: PageBlockInput): string;
146
+ /** Removes a leading page block from a stored user message (history display). */
147
+ declare function stripPageBlock(content: string): string;
148
+
149
+ export { ACTION_LIMITS, ActionManifestEntry, AgentInfo, ChatStreamEvent, type DeweeHandlerOptions, GatewayConnection, type GatewayCredentials, GatewayError, HistoryMessage, type RateLimiter, type StreamChatOptions, buildPageBlock, buildSessionKey, createDeweeHandler, fetchHistory, foldHistory, hashManifest, listAgents, memoryRateLimiter, normalizeManifest, optionsFromEnv, signVisitorToken, streamChat, stripPageBlock, toNodeHandler, verifyVisitorToken };
package/dist/server.js CHANGED
@@ -1,8 +1,15 @@
1
1
  import {
2
+ ACTION_LIMITS,
3
+ ActionInputError,
2
4
  HEADER_GATEWAY_TOKEN,
3
5
  HEADER_GATEWAY_URL,
4
- VERSION
5
- } from "./chunk-WD6V3TAX.js";
6
+ VERSION,
7
+ buildPageBlock,
8
+ hashManifest,
9
+ normalizeManifest,
10
+ serializePageContext,
11
+ stripPageBlock
12
+ } from "./chunk-JX6AH37X.js";
6
13
 
7
14
  // src/server/gateway-client.ts
8
15
  var GatewayError = class extends Error {
@@ -220,7 +227,7 @@ function foldHistory(raw) {
220
227
  for (const m of raw) {
221
228
  if (m.role === "user") {
222
229
  current = null;
223
- out.push({ role: "user", content: String(m.content ?? ""), createdAt: m.created_at });
230
+ out.push({ role: "user", content: stripPageBlock(String(m.content ?? "")), createdAt: m.created_at });
224
231
  } else if (m.role === "assistant") {
225
232
  if (!current) {
226
233
  current = { role: "assistant", content: "", createdAt: m.created_at };
@@ -468,6 +475,17 @@ function createDeweeHandler(options) {
468
475
  const conversationId = typeof body?.conversationId === "string" && ID_RE.test(body.conversationId) ? body.conversationId : randomId(9);
469
476
  const agent = await pickAgent(body?.agent, creds, isByo);
470
477
  if (!agent) return fail(req, 403, "Agent not allowed", "agent_not_allowed");
478
+ let pageBlock = "";
479
+ let actionsHash;
480
+ try {
481
+ const manifest = body?.actions != null ? normalizeManifest(body.actions) : void 0;
482
+ const pageContext = serializePageContext(body?.pageContext);
483
+ if (manifest?.length) actionsHash = await hashManifest(manifest);
484
+ pageBlock = buildPageBlock({ manifest, hash: actionsHash, includeManifest: body?.actionsHash !== actionsHash, pageContext });
485
+ } catch (e) {
486
+ if (e instanceof ActionInputError) return fail(req, e.status, e.message, e.code);
487
+ throw e;
488
+ }
471
489
  const sessionKey = buildSessionKey(agent, `webchat-${visitorId}-${conversationId}`);
472
490
  const abort = new AbortController();
473
491
  req.signal?.addEventListener("abort", () => abort.abort(), { once: true });
@@ -482,8 +500,8 @@ function createDeweeHandler(options) {
482
500
  let reply = "";
483
501
  let errMsg;
484
502
  try {
485
- await send({ type: "start", conversationId, agent });
486
- for await (const ev of streamChat({ creds, userId: o.userIdPrefix + visitorId, agent, sessionKey, message, signal: abort.signal, timeoutMs: o.timeoutMs })) {
503
+ await send(actionsHash ? { type: "start", conversationId, agent, actionsHash } : { type: "start", conversationId, agent });
504
+ for await (const ev of streamChat({ creds, userId: o.userIdPrefix + visitorId, agent, sessionKey, message: pageBlock + message, signal: abort.signal, timeoutMs: o.timeoutMs })) {
487
505
  if (ev.type === "start") continue;
488
506
  if (ev.type === "done") reply = ev.content;
489
507
  if (ev.type === "error") errMsg = ev.message;
@@ -616,17 +634,22 @@ function toNodeHandler(handler) {
616
634
  };
617
635
  }
618
636
  export {
637
+ ACTION_LIMITS,
619
638
  GatewayConnection,
620
639
  GatewayError,
640
+ buildPageBlock,
621
641
  buildSessionKey,
622
642
  createDeweeHandler,
623
643
  fetchHistory,
624
644
  foldHistory,
645
+ hashManifest,
625
646
  listAgents,
626
647
  memoryRateLimiter,
648
+ normalizeManifest,
627
649
  optionsFromEnv,
628
650
  signVisitorToken,
629
651
  streamChat,
652
+ stripPageBlock,
630
653
  toNodeHandler,
631
654
  verifyVisitorToken
632
655
  };
package/dist/vue.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as vue from 'vue';
2
2
  import { PropType } from 'vue';
3
- export { DeweeChatConfig, DeweeChatElement } from './index.js';
4
- import './protocol-CS8_4zC0.js';
3
+ export { ActionConfirmHook, ActionEventDetail, DeweeChatConfig, DeweeChatElement, PageAction, PageActionContext } from './index.js';
4
+ import './protocol-B72Ry-fY.js';
5
5
 
6
6
  declare const DeweeChat: vue.DefineComponent<vue.ExtractPropTypes<{
7
7
  endpoint: {
@@ -108,9 +108,29 @@ declare const DeweeChat: vue.DefineComponent<vue.ExtractPropTypes<{
108
108
  type: PropType<any>;
109
109
  default: undefined;
110
110
  };
111
+ actions: {
112
+ type: PropType<any>;
113
+ default: undefined;
114
+ };
115
+ confirm: {
116
+ type: PropType<any>;
117
+ default: undefined;
118
+ };
119
+ getPageContext: {
120
+ type: PropType<any>;
121
+ default: undefined;
122
+ };
123
+ maxActionRounds: {
124
+ type: PropType<any>;
125
+ default: undefined;
126
+ };
127
+ actionTimeoutMs: {
128
+ type: PropType<any>;
129
+ default: undefined;
130
+ };
111
131
  }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
112
132
  [key: string]: any;
113
- }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("open" | "ready" | "send" | "reply" | "error" | "close")[], "open" | "ready" | "send" | "reply" | "error" | "close", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
133
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("open" | "ready" | "send" | "reply" | "error" | "close" | "action")[], "open" | "ready" | "send" | "reply" | "error" | "close" | "action", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
114
134
  endpoint: {
115
135
  type: PropType<any>;
116
136
  default: undefined;
@@ -215,6 +235,26 @@ declare const DeweeChat: vue.DefineComponent<vue.ExtractPropTypes<{
215
235
  type: PropType<any>;
216
236
  default: undefined;
217
237
  };
238
+ actions: {
239
+ type: PropType<any>;
240
+ default: undefined;
241
+ };
242
+ confirm: {
243
+ type: PropType<any>;
244
+ default: undefined;
245
+ };
246
+ getPageContext: {
247
+ type: PropType<any>;
248
+ default: undefined;
249
+ };
250
+ maxActionRounds: {
251
+ type: PropType<any>;
252
+ default: undefined;
253
+ };
254
+ actionTimeoutMs: {
255
+ type: PropType<any>;
256
+ default: undefined;
257
+ };
218
258
  }>> & Readonly<{
219
259
  onOpen?: ((...args: any[]) => any) | undefined;
220
260
  onReady?: ((...args: any[]) => any) | undefined;
@@ -222,6 +262,7 @@ declare const DeweeChat: vue.DefineComponent<vue.ExtractPropTypes<{
222
262
  onReply?: ((...args: any[]) => any) | undefined;
223
263
  onError?: ((...args: any[]) => any) | undefined;
224
264
  onClose?: ((...args: any[]) => any) | undefined;
265
+ onAction?: ((...args: any[]) => any) | undefined;
225
266
  }>, {
226
267
  endpoint: any;
227
268
  agent: any;
@@ -249,6 +290,11 @@ declare const DeweeChat: vue.DefineComponent<vue.ExtractPropTypes<{
249
290
  width: any;
250
291
  height: any;
251
292
  zIndex: any;
293
+ actions: any;
294
+ confirm: any;
295
+ getPageContext: any;
296
+ maxActionRounds: any;
297
+ actionTimeoutMs: any;
252
298
  }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
253
299
 
254
300
  export { DeweeChat, DeweeChat as default };
package/dist/vue.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  defineDeweeChat
3
- } from "./chunk-D4JM2FOB.js";
4
- import "./chunk-WD6V3TAX.js";
3
+ } from "./chunk-YV6PXYJZ.js";
4
+ import "./chunk-JX6AH37X.js";
5
5
 
6
6
  // src/vue.ts
7
7
  import { defineComponent, h, onMounted, ref, watch } from "vue";
@@ -31,10 +31,15 @@ var keys = [
31
31
  "gatewayToken",
32
32
  "width",
33
33
  "height",
34
- "zIndex"
34
+ "zIndex",
35
+ "actions",
36
+ "confirm",
37
+ "getPageContext",
38
+ "maxActionRounds",
39
+ "actionTimeoutMs"
35
40
  ];
36
41
  var props = Object.fromEntries(keys.map((k) => [k, { type: null, default: void 0 }]));
37
- var EVENTS = ["ready", "send", "reply", "error", "open", "close"];
42
+ var EVENTS = ["ready", "send", "reply", "error", "open", "close", "action"];
38
43
  var DeweeChat = defineComponent({
39
44
  name: "DeweeChat",
40
45
  props,
@@ -54,7 +59,9 @@ var DeweeChat = defineComponent({
54
59
  open: () => el.value?.open(),
55
60
  close: () => el.value?.close(),
56
61
  send: (text) => el.value?.send(text),
57
- newConversation: () => el.value?.newConversation()
62
+ newConversation: () => el.value?.newConversation(),
63
+ registerActions: (actions) => el.value?.registerActions(actions),
64
+ unregisterAction: (name) => el.value?.unregisterAction(name)
58
65
  });
59
66
  return () => h("dewee-chat", { ref: el, endpoint: p.endpoint, mode: p.mode });
60
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dewee-webchat",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Embeddable chat widget for Dewee AI agents — web component, React/Vue/Astro wrappers and a secure backend handler (Workers, Next.js, Node, Bun, Deno).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,10 +0,0 @@
1
- // src/protocol.ts
2
- var HEADER_GATEWAY_URL = "x-dewee-gateway-url";
3
- var HEADER_GATEWAY_TOKEN = "x-dewee-gateway-token";
4
- var VERSION = "0.1.1";
5
-
6
- export {
7
- HEADER_GATEWAY_URL,
8
- HEADER_GATEWAY_TOKEN,
9
- VERSION
10
- };