@widgetic/chat 0.1.22 → 0.1.24

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 ADDED
@@ -0,0 +1,122 @@
1
+ Widgetic Integration License
2
+ Version 1.0
3
+
4
+ Copyright (c) Widgetic. All rights reserved.
5
+
6
+ This license covers the software package that it came with, in source and
7
+ compiled form, together with its documentation (the "Software"). By
8
+ installing, copying or using the Software you accept this license. If you do
9
+ not accept it, do not install or use the Software.
10
+
11
+ In this license, "Widgetic" is the company that publishes the Software, "you"
12
+ is the person or organization that uses it, and "Your Application" is an
13
+ application, website, product or service that you build or operate, for
14
+ yourself or for a client. "Widgetic Services" are the services that Widgetic
15
+ operates: the Widgetic API, widgets, compositions, embeds, editors, file
16
+ browser, chat and AI creator, and the other services that can be reached from
17
+ widgetic.com or its API hosts.
18
+
19
+ 1. What you may do
20
+
21
+ Widgetic grants you a worldwide, non-exclusive, non-transferable and
22
+ non-sublicensable license to use the Software, unmodified, for one purpose: to
23
+ integrate the Widgetic Services into Your Application. Within that purpose you
24
+ may:
25
+
26
+ (a) install the Software and run it in Your Application, in development,
27
+ testing and production;
28
+
29
+ (b) use it to call the Widgetic API, to show Widgetic widgets and
30
+ compositions, and to open Widgetic's editors, file browser, chat and AI
31
+ creator inside Your Application;
32
+
33
+ (c) bundle, minify and tree-shake the Software with the build tools of Your
34
+ Application, deliver the result to the people who use Your Application as a
35
+ part of it, and let them run it there;
36
+
37
+ (d) keep the copies of the Software that (a), (b) and (c) need, including
38
+ copies in your version control, your build systems and your backups.
39
+
40
+ 2. What you may not do
41
+
42
+ You may not, and may not allow anyone else to:
43
+
44
+ (a) use the Software for any purpose other than the one in section 1;
45
+
46
+ (b) use the Software to build, run or improve a service that offers what the
47
+ Widgetic Services offer, or to connect Your Application to anything other than
48
+ the Widgetic Services (a proxy of yours that forwards calls to the Widgetic
49
+ Services is fine);
50
+
51
+ (c) copy, modify, translate, adapt or make derivative works of the Software,
52
+ except as section 1(c) allows;
53
+
54
+ (d) publish, sell, rent, lease, sublicense or distribute the Software on its
55
+ own, or inside a library, SDK, template or product that others could use for
56
+ anything other than integrating the Widgetic Services, including by
57
+ publishing it, or a copy of it, to a package registry or a public CDN;
58
+
59
+ (e) reverse engineer, decompile or disassemble the Software, or try to get at
60
+ its source code, except as far as the law lets you despite this restriction;
61
+
62
+ (f) remove or change a copyright, license or attribution notice in the
63
+ Software;
64
+
65
+ (g) bypass, disable or interfere with the authentication, rate limits, quotas,
66
+ credits, plan limits or other protections of the Widgetic Services, or help
67
+ anyone else to;
68
+
69
+ (h) use the name, logo or trademarks of Widgetic, except to say truthfully
70
+ that Your Application integrates Widgetic.
71
+
72
+ 3. The Widgetic Services are separate
73
+
74
+ This license is for the Software only. It does not give you the right to use
75
+ the Widgetic Services. That right comes from your account or agreement with
76
+ Widgetic and from Widgetic's Terms of Service (https://widgetic.com/terms),
77
+ which this license does not change.
78
+
79
+ 4. Ownership
80
+
81
+ The Software is licensed to you, not sold. Widgetic and its licensors keep all
82
+ rights in it. Any right that this license does not give you in plain words is
83
+ reserved to Widgetic.
84
+
85
+ 5. Third-party software
86
+
87
+ The Software may include or depend on software from others. That software is
88
+ under its own license, which applies to it instead of this one, and nothing in
89
+ this license limits your rights under it.
90
+
91
+ 6. How long it lasts
92
+
93
+ This license lasts while you follow it and while you are entitled to use the
94
+ Widgetic Services. It ends on its own if you break it or that entitlement
95
+ ends. When it ends, you stop using the Software and delete your copies of it,
96
+ except copies that the law requires you to keep. Sections 4, 8 and 9 still
97
+ apply after it has ended.
98
+
99
+ 7. Versions
100
+
101
+ This license applies to the version of the Software that it came with and to
102
+ later versions that carry it. A version that Widgetic published under another
103
+ license stays under that license, for the copies of it that you already have.
104
+
105
+ 8. No warranty
106
+
107
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
108
+ IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
109
+ PURPOSE AND NON-INFRINGEMENT.
110
+
111
+ 9. Limit of liability
112
+
113
+ TO THE EXTENT THE LAW ALLOWS, WIDGETIC IS NOT LIABLE FOR ANY INDIRECT,
114
+ INCIDENTAL, SPECIAL, CONSEQUENTIAL OR PUNITIVE DAMAGES, OR FOR LOST PROFITS,
115
+ REVENUE, DATA OR GOODWILL, THAT ARISE FROM THE SOFTWARE OR FROM THIS LICENSE,
116
+ EVEN IF IT HAS BEEN TOLD THAT THEY ARE POSSIBLE. NOTHING IN THIS LICENSE
117
+ LIMITS A LIABILITY THAT THE LAW DOES NOT ALLOW TO BE LIMITED.
118
+
119
+ 10. Questions
120
+
121
+ If you need to do something that this license does not allow, ask first:
122
+ support@widgetic.com.
package/README.md CHANGED
@@ -225,16 +225,6 @@ const customConfig = {
225
225
  };
226
226
  ```
227
227
 
228
- ### Environment for local development
229
-
230
- The demo app in this repo reads its settings from a `.env` file. The file is not committed, because every `PUBLIC_*` value ends up in the JavaScript that browsers download. Copy the template and fill it in:
231
-
232
- ```bash
233
- cp .env.example .env
234
- ```
235
-
236
- Use an ordinary API key for `PUBLIC_API_KEY`. Never put an internal service key (`wgt_srv_...`) in any `PUBLIC_*` variable.
237
-
238
228
  ## Languages
239
229
 
240
230
  The chat shows English until it is told otherwise. Two props of `Chat` change that, and both can change while the chat
@@ -628,7 +618,7 @@ npm run package:watch
628
618
 
629
619
  ## License
630
620
 
631
- MIT
621
+ This package is licensed under the Widgetic Integration License (see the `LICENSE` file in the package): you may use it to integrate Widgetic into your own application, and for nothing else. It is not open source. For any other use, write to support@widgetic.com.
632
622
 
633
623
  ## Contributing
634
624
 
@@ -119,7 +119,7 @@
119
119
  onMessagesDrag?: (totalDy: number) => void;
120
120
  onMessagesDragEnd?: () => void;
121
121
  /** Messages older than the ones on screen. Empty, or `hasOlder: false`, means the top is the start. */
122
- onLoadOlderMessages?: (conversationId: string) => Promise<Array<{ id?: string; hasOlder?: boolean }>>;
122
+ onLoadOlderMessages?: (conversationId: string) => Promise<any[]>;
123
123
  /**
124
124
  * Widget Git HEAD from the host (panel lastCommitId). Used so Head / Restore chrome
125
125
  * still appears when assistant commit bubbles were never persisted.
@@ -161,10 +161,7 @@ interface Props {
161
161
  onMessagesDrag?: (totalDy: number) => void;
162
162
  onMessagesDragEnd?: () => void;
163
163
  /** Messages older than the ones on screen. Empty, or `hasOlder: false`, means the top is the start. */
164
- onLoadOlderMessages?: (conversationId: string) => Promise<Array<{
165
- id?: string;
166
- hasOlder?: boolean;
167
- }>>;
164
+ onLoadOlderMessages?: (conversationId: string) => Promise<any[]>;
168
165
  /**
169
166
  * Widget Git HEAD from the host (panel lastCommitId). Used so Head / Restore chrome
170
167
  * still appears when assistant commit bubbles were never persisted.
@@ -812,11 +812,19 @@
812
812
  window.location.assign('/workspaces/personal/settings/billing');
813
813
  }
814
814
 
815
+ function turnIsDesignCardOnly(turn: ChatTurn): boolean {
816
+ const hasCard = turn.replies.some((reply) => !!reply.designControls);
817
+ return hasCard && !getTurnCommitReply(turn);
818
+ }
819
+
815
820
  function turnNeedsRetry(turn: ChatTurn, turnIndex: number): boolean {
816
821
  // Never show Retry while a send/codegen is still running.
817
822
  if (isLoading || isGenerating) return false;
818
823
  const userMsg = turn.user;
819
824
  if (!userMsg?.messageContent?.trim()) return false;
825
+ // A design card already applied the change. Retry would send it to the model,
826
+ // add another bubble, and leave the card on the old one.
827
+ if (turnIsDesignCardOnly(turn)) return false;
820
828
  // The earlier copy of a prompt that was already run again stays without Retry.
821
829
  if (promptWasRetriedLater(turn, turnIndex)) return false;
822
830
  return true;
@@ -850,13 +858,29 @@
850
858
  * up). Disconnected on destroy.
851
859
  */
852
860
  let containerResizeObserver: ResizeObserver | null = null;
861
+ let contentGrowthObserver: MutationObserver | null = null;
853
862
 
854
- function scrollToBottomInstant(): void {
863
+ function scrollMessagesToEnd(): void {
855
864
  if (!messagesContainer) return;
856
- messagesContainer.scrollTo({
857
- top: messagesContainer.scrollHeight,
858
- behavior: 'instant',
859
- });
865
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
866
+ }
867
+
868
+ // The last bubble grows after the first scroll (text wrap, the card under it).
869
+ // One assignment lands short of the end, which is the clipped last message.
870
+ function settleMessagesToEnd(): void {
871
+ let frames = 0;
872
+ const step = () => {
873
+ if (!messagesContainer || pendingOlderScroll || isLoading) return;
874
+ const gap = messagesContainer.scrollHeight - messagesContainer.clientHeight - messagesContainer.scrollTop;
875
+ if (shouldPinChatToBottom() || !initialBottomPinned) scrollMessagesToEnd();
876
+ frames += 1;
877
+ if (frames < 12 && gap > 1) {
878
+ requestAnimationFrame(step);
879
+ return;
880
+ }
881
+ initialBottomPinned = true;
882
+ };
883
+ requestAnimationFrame(step);
860
884
  }
861
885
 
862
886
  // Auto-scroll to bottom when new messages arrive or on initial load.
@@ -869,20 +893,12 @@
869
893
  const pinToBottom = shouldPinChatToBottom();
870
894
  const messageCount = visibleMessages.length;
871
895
  if (!initialBottomPinned && messagesContainer && messageCount > 0 && !pendingOlderScroll) {
872
- void tick().then(() => {
873
- requestAnimationFrame(() => {
874
- if (!messagesContainer || pendingOlderScroll || isLoading) return;
875
- if (shouldPinChatToBottom()) {
876
- messagesContainer.scrollTop = messagesContainer.scrollHeight;
877
- }
878
- initialBottomPinned = true;
879
- });
880
- });
896
+ void tick().then(() => settleMessagesToEnd());
881
897
  }
882
898
  if (messagesContainer && pinToBottom && messageCount > 0 && !pendingOlderScroll && initialBottomPinned) {
883
899
  tick().then(() => {
884
900
  if (!messagesContainer || pendingOlderScroll || !shouldPinChatToBottom()) return;
885
- messagesContainer.scrollTop = messagesContainer.scrollHeight;
901
+ scrollMessagesToEnd();
886
902
  });
887
903
  }
888
904
  });
@@ -891,24 +907,32 @@
891
907
  onMount(() => {
892
908
  tick().then(() => {
893
909
  if (messagesContainer && visibleMessages.length > 0 && !isLoading && shouldPinChatToBottom()) {
894
- scrollToBottomInstant();
895
- initialBottomPinned = true;
910
+ settleMessagesToEnd();
896
911
  }
897
912
  // Re-pin after late container resizes (panel open animation, parent
898
913
  // layout settling, height restored from prefs).
899
914
  if (messagesContainer && typeof ResizeObserver !== 'undefined') {
900
915
  containerResizeObserver = new ResizeObserver(() => {
901
916
  if (pendingOlderScroll || !initialBottomPinned) return;
902
- if (shouldPinChatToBottom()) scrollToBottomInstant();
917
+ if (shouldPinChatToBottom()) scrollMessagesToEnd();
903
918
  });
904
919
  containerResizeObserver.observe(messagesContainer);
905
920
  }
921
+ if (messagesContainer && typeof MutationObserver !== 'undefined') {
922
+ contentGrowthObserver = new MutationObserver(() => {
923
+ if (pendingOlderScroll || !initialBottomPinned) return;
924
+ if (shouldPinChatToBottom()) scrollMessagesToEnd();
925
+ });
926
+ contentGrowthObserver.observe(messagesContainer, { childList: true, subtree: true });
927
+ }
906
928
  });
907
929
  });
908
930
 
909
931
  onDestroy(() => {
910
932
  containerResizeObserver?.disconnect();
911
933
  containerResizeObserver = null;
934
+ contentGrowthObserver?.disconnect();
935
+ contentGrowthObserver = null;
912
936
  });
913
937
 
914
938
  let olderRequestInFlight = false;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
+ "license": "SEE LICENSE IN LICENSE",
4
5
  "type": "module",
5
6
  "main": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
package/dist/config.d.ts DELETED
@@ -1,43 +0,0 @@
1
- /**
2
- * SDK Configuration Management
3
- *
4
- * Centralizes all SDK configuration including:
5
- * - Environment variables
6
- * - API configuration
7
- * - SDK settings
8
- * - Configuration validation
9
- * - Helper functions
10
- */
11
- import { Configuration } from '@widgetic/api-sdk';
12
- interface Config {
13
- NODE_ENV: string;
14
- API_URL: string;
15
- API_VERSION: string;
16
- INTERNAL_KEY?: string;
17
- API_KEY?: string;
18
- CLIENT_URL: string;
19
- PRODUCTION_URL: string;
20
- }
21
- export declare const config: Config;
22
- /**
23
- * Creates SDK configuration for API clients
24
- * Used by core and modules
25
- * Priority: passed apiKey > env API_KEY > env INTERNAL_KEY
26
- */
27
- export declare function createSdkConfig(options?: {
28
- apiKey?: string;
29
- basePath?: string;
30
- }): Configuration;
31
- /**
32
- * Gets the full API URL for the current environment
33
- */
34
- export declare function getApiUrl(): string;
35
- /**
36
- * Environment-specific settings
37
- */
38
- export declare const environment: {
39
- readonly isProduction: boolean;
40
- readonly apiUrl: string;
41
- readonly apiKey: string | undefined;
42
- };
43
- export {};
package/dist/config.js DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * SDK Configuration Management
3
- *
4
- * Centralizes all SDK configuration including:
5
- * - Environment variables
6
- * - API configuration
7
- * - SDK settings
8
- * - Configuration validation
9
- * - Helper functions
10
- */
11
- import { env } from "$env/dynamic/public";
12
- import { Configuration } from '@widgetic/api-sdk';
13
- // Validate that at least one key type is present
14
- if (!env.PUBLIC_INTERNAL_KEY && !env.PUBLIC_API_KEY) {
15
- throw new Error('Either PUBLIC_INTERNAL_KEY or PUBLIC_API_KEY must be set');
16
- }
17
- if (!env.PUBLIC_API_URL) {
18
- throw new Error('PUBLIC_API_URL environment variable is not set');
19
- }
20
- if (!env.PUBLIC_API_VERSION) {
21
- throw new Error('PUBLIC_API_VERSION environment variable is not set');
22
- }
23
- if (!env.PUBLIC_CLIENT_URL) {
24
- throw new Error('PUBLIC_CLIENT_URL environment variable is not set');
25
- }
26
- if (!env.PUBLIC_PRODUCTION_URL) {
27
- throw new Error('PUBLIC_PRODUCTION_URL environment variable is not set');
28
- }
29
- // Create and export the config object with proper typing
30
- export const config = {
31
- API_URL: env.PUBLIC_API_URL,
32
- API_VERSION: env.PUBLIC_API_VERSION,
33
- INTERNAL_KEY: env.PUBLIC_INTERNAL_KEY,
34
- API_KEY: env.PUBLIC_API_KEY,
35
- CLIENT_URL: env.PUBLIC_CLIENT_URL,
36
- PRODUCTION_URL: env.PUBLIC_PRODUCTION_URL,
37
- NODE_ENV: env.PUBLIC_NODE_ENV
38
- };
39
- /**
40
- * Creates SDK configuration for API clients
41
- * Used by core and modules
42
- * Priority: passed apiKey > env API_KEY > env INTERNAL_KEY
43
- */
44
- export function createSdkConfig(options) {
45
- return new Configuration({
46
- apiKey: (name) => options?.apiKey || config.API_KEY || config.INTERNAL_KEY || '',
47
- basePath: options?.basePath || getApiUrl()
48
- });
49
- }
50
- /**
51
- * Gets the full API URL for the current environment
52
- */
53
- export function getApiUrl() {
54
- const baseUrl = config.NODE_ENV === 'production'
55
- ? config.PRODUCTION_URL
56
- : config.API_URL;
57
- return `${baseUrl}${config.API_VERSION}`;
58
- }
59
- /**
60
- * Environment-specific settings
61
- */
62
- export const environment = {
63
- isProduction: config.NODE_ENV === 'production',
64
- apiUrl: getApiUrl(),
65
- // Use API_KEY if available, fall back to INTERNAL_KEY
66
- apiKey: config.API_KEY || config.INTERNAL_KEY
67
- };