@useknest/widget-core 0.0.1-alpha.9 → 0.1.0-beta.10

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @useknest/widget-core
2
+
3
+ Shared business logic for Knest chat widgets. This package provides the core functionality used by platform-specific widget packages.
4
+
5
+ ## Note
6
+
7
+ This package is primarily intended for internal use by `@useknest/widget-react` and `@useknest/widget-web`. For most use cases, install the platform-specific package instead.
8
+
9
+ ## Peer Dependencies
10
+
11
+ This package requires the following peer dependencies:
12
+
13
+ - `@supabase/supabase-js` - For anonymous authentication
14
+ - `@sentry/browser` - For error reporting
15
+ - `marked` - For markdown rendering
16
+
17
+ ## License
18
+
19
+ Proprietary - All rights reserved. This software is for use by authorized Knest customers only.
package/dist/config.d.ts CHANGED
@@ -6,9 +6,18 @@ export interface ConfigResult {
6
6
  }
7
7
  /**
8
8
  * Fetches widget configuration from the API.
9
+ * Uses localStorage caching to speed up subsequent loads.
10
+ *
11
+ * Caching strategy:
12
+ * - On first load: fetches from API, caches result
13
+ * - On subsequent loads (within TTL): returns cached config immediately,
14
+ * then refreshes in background to pick up any config changes
15
+ * - Cache includes updatedAt timestamp for staleness detection
16
+ *
9
17
  * @param publishableApiKey - The API key for authentication
10
18
  * @param baseUrl - Base URL for the API. Defaults to https://useknest.com. Pass empty string for relative paths.
19
+ * @param onConfigUpdate - Optional callback when config is updated in background
11
20
  * @returns ConfigResult with config data or error type
12
21
  */
13
- export declare function fetchWidgetConfig(publishableApiKey: string, baseUrl?: string): Promise<ConfigResult>;
22
+ export declare function fetchWidgetConfig(publishableApiKey: string, baseUrl?: string, onConfigUpdate?: (config: WidgetConfig) => void): Promise<ConfigResult>;
14
23
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAExD,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,eAAe,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACtC,iBAAiB,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,YAAY,CAAC,CA6BvB"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAExD,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,eAAe,CAAC;CACvB;AAgGD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,iBAAiB,CACtC,iBAAiB,EAAE,MAAM,EACzB,OAAO,CAAC,EAAE,MAAM,EAChB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAC7C,OAAO,CAAC,YAAY,CAAC,CAkBvB"}
@@ -1,5 +1,7 @@
1
1
  export declare const DEFAULT_BASE_URL = "https://useknest.com";
2
2
  export declare const API_PATH = "/api/v1";
3
+ export declare const PUBLIC_SUPABASE_URL = "https://lghrsugmhzpccpriqhrx.supabase.co";
4
+ export declare const PUBLIC_SUPABASE_ANON_KEY = "sb_publishable_-KUwilDA78QM849gk662FA_kEzMezNS";
3
5
  /** Builds the chat messages API URL from a base URL. */
4
6
  export declare function getChatApiUrl(baseUrl?: string): string;
5
7
  /** Builds the widget config API URL from a base URL. */
@@ -7,8 +9,9 @@ export declare function getConfigApiUrl(baseUrl?: string): string;
7
9
  export declare const FALLBACK_ERROR_MESSAGE = "Sorry, I didn't get a response.";
8
10
  export declare const DEFAULT_ERROR_MESSAGE = "Unknown error occurred";
9
11
  export declare const AUTH_ERROR_MESSAGE = "This domain is not authorized. Please add it to your allowed origins in the Knest dashboard.";
12
+ export declare const USAGE_LIMIT_MESSAGE = "This chatbot has reached its usage limit. Please contact the site owner to upgrade their plan.";
10
13
  export declare const DEFAULT_AVATAR_URL = "https://useknest.com/default-avatar.svg";
11
- export declare const DEFAULT_BRAND_COLOR = "#0d7a7f";
14
+ export declare const DEFAULT_BRAND_COLOR = "#3b82f6";
12
15
  export declare const DEFAULT_WELCOME_MESSAGE = "Hi! I'm your AI assistant. I'm trained to answer questions about your documentation. How can I help you today?";
13
16
  export declare const DEFAULT_EXAMPLE_QUESTIONS: string[];
14
17
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,QAAQ,YAAY,CAAC;AAElC,wDAAwD;AACxD,wBAAgB,aAAa,CAAC,OAAO,GAAE,MAAyB,GAAG,MAAM,CAExE;AAED,wDAAwD;AACxD,wBAAgB,eAAe,CAAC,OAAO,GAAE,MAAyB,GAAG,MAAM,CAE1E;AAED,eAAO,MAAM,sBAAsB,oCAAoC,CAAC;AACxE,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAC9D,eAAO,MAAM,kBAAkB,iGACgE,CAAC;AAChG,eAAO,MAAM,kBAAkB,4CAA4C,CAAC;AAC5E,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,eAAO,MAAM,uBAAuB,mHAC6E,CAAC;AAClH,eAAO,MAAM,yBAAyB,UAIrC,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,QAAQ,YAAY,CAAC;AAIlC,eAAO,MAAM,mBAAmB,6CAA6C,CAAC;AAC9E,eAAO,MAAM,wBAAwB,mDAAmD,CAAC;AAEzF,wDAAwD;AACxD,wBAAgB,aAAa,CAAC,OAAO,GAAE,MAAyB,GAAG,MAAM,CAExE;AAED,wDAAwD;AACxD,wBAAgB,eAAe,CAAC,OAAO,GAAE,MAAyB,GAAG,MAAM,CAE1E;AAED,eAAO,MAAM,sBAAsB,oCAAoC,CAAC;AACxE,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAC9D,eAAO,MAAM,kBAAkB,iGACgE,CAAC;AAChG,eAAO,MAAM,mBAAmB,mGACiE,CAAC;AAClG,eAAO,MAAM,kBAAkB,4CAA4C,CAAC;AAC5E,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,eAAO,MAAM,uBAAuB,mHAC6E,CAAC;AAClH,eAAO,MAAM,yBAAyB,UAIrC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { MessageRole, Source, Message, ChatMessageRequest, ChatMessageResponse, ChatApiError, WidgetConfig, SSEEvent } from './types';
2
- export { DEFAULT_BASE_URL, API_PATH, getChatApiUrl, getConfigApiUrl, FALLBACK_ERROR_MESSAGE, DEFAULT_ERROR_MESSAGE, AUTH_ERROR_MESSAGE, DEFAULT_AVATAR_URL, DEFAULT_BRAND_COLOR, DEFAULT_WELCOME_MESSAGE, DEFAULT_EXAMPLE_QUESTIONS } from './constants';
1
+ export type { WidgetMode, MessageRole, Source, Message, ChatMessageRequest, ChatMessageResponse, ChatApiError, WidgetConfig, SSEEvent } from './types';
2
+ export { DEFAULT_BASE_URL, API_PATH, getChatApiUrl, getConfigApiUrl, FALLBACK_ERROR_MESSAGE, DEFAULT_ERROR_MESSAGE, AUTH_ERROR_MESSAGE, USAGE_LIMIT_MESSAGE, DEFAULT_AVATAR_URL, DEFAULT_BRAND_COLOR, DEFAULT_WELCOME_MESSAGE, DEFAULT_EXAMPLE_QUESTIONS, PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from './constants';
3
3
  export { fetchWidgetConfig } from './config';
4
4
  export type { ConfigResult, ConfigErrorType } from './config';
5
5
  export { streamChatMessage } from './streaming';
@@ -7,4 +7,6 @@ export type { StreamCallbacks, StreamMessageOptions } from './streaming';
7
7
  export { formatContent } from './utils';
8
8
  export { initWidgetAuth, getAccessToken, isAuthenticated, getSupabaseClient } from './auth';
9
9
  export { initWidgetSentry, captureWidgetException } from './sentry';
10
+ export { subscribeToThread } from './realtime';
11
+ export type { BroadcastMessage } from './realtime';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACX,WAAW,EACX,MAAM,EACN,OAAO,EACP,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,MAAM,SAAS,CAAC;AAGjB,OAAO,EACN,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGzE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAG5F,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CA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