@sahan-sac/chat-kit 0.4.0 → 0.5.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.
Files changed (4) hide show
  1. package/CHANGELOG.md +58 -51
  2. package/LICENSE +202 -202
  3. package/README.md +100 -100
  4. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,51 +1,58 @@
1
- # @sahan-sac/chat-kit
2
-
3
- ## 0.4.0
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [1570cf6]
8
- - Updated dependencies [396e692]
9
- - @sahan-sac/ai-core@0.4.0
10
-
11
- ## 0.3.1
12
-
13
- ### Patch Changes
14
-
15
- - 5e7f3cb: The build shares modules between subpaths (code splitting) instead of copying them into each one. Before, a class imported from two subpaths was two different classes, so `instanceof` failed (for example `EmailGuardError` from `@sahan-sac/email-kit/guards` against an error thrown through `./layout`), and module-level state such as caches existed once per subpath.
16
- - Updated dependencies [5e7f3cb]
17
- - @sahan-sac/ai-core@0.3.1
18
-
19
- ## 0.3.0
20
-
21
- ### Minor Changes
22
-
23
- - f465908: Owner guidance and per-post steering. `BlogSiteProfile.guidance` and `ChatSite.guidance` add the site owner's standing guidance to every blog, SEO, helper and chatbot prompt, after the fixed rules. `BlogGenerationInput` takes optional `instructions` (up to `MAX_INSTRUCTIONS_LENGTH`, 2,000 characters) and `resources` (pasted reference text, up to `MAX_RESOURCES_LENGTH`, 12,000), both fenced as untrusted data: resources are used as facts, never as instructions, and nothing is fetched from a link.
24
-
25
- ### Patch Changes
26
-
27
- - Updated dependencies [b9d2dd6]
28
- - Updated dependencies [4fa21e3]
29
- - Updated dependencies [f465908]
30
- - @sahan-sac/ai-core@0.3.0
31
-
32
- ## 0.2.0
33
-
34
- ### Minor Changes
35
-
36
- - c2cc383: Site-specific values are now options with neutral defaults. blog-kit: `BlogAiDeps.site` (a `BlogSiteProfile`: description, allowed internal links, call-to-action paths) feeds every prompt, `realBlogDeps(env, site)` takes it, inline image tokens are `ai-image://N`, and `draftStorageKey(id, prefix)` takes a key prefix (default "admin"). chat-kit: `ChatSite` gains optional `kind`, `scope` and `linkExample` (default wording says "site"), and `CHAT_VISITOR_COOKIE` defaults to "chat_vid". media-kit: `MEDIA_CONFIG.uploadFolder` is removed; the upload folder is the app's own constant.
37
-
38
- ### Patch Changes
39
-
40
- - @sahan-sac/ai-core@0.2.0
41
-
42
- ## 0.1.0
43
-
44
- ### Minor Changes
45
-
46
- - b620f44: First release. ai-core: the free-by-default provider chain (Gemini, OpenRouter, NVIDIA, then paid Vertex) with hedging, cooldowns and deadlines, env-driven model resolution, image generation, prompt guards and the shared env schema (ENABLE_BLOG_AI, ENABLE_CHATBOT). blog-kit: full-post, SEO, draft and cover generation, AI images through an ImageSink port, and pure blog utilities. chat-kit: runChat, guarded prompts, output filtering, the knowledge builder, the ChatStore contract and the visitor rate-limit cookie. Licensed Apache-2.0.
47
-
48
- ### Patch Changes
49
-
50
- - Updated dependencies [b620f44]
51
- - @sahan-sac/ai-core@0.1.0
1
+ # @sahan-sac/chat-kit
2
+
3
+ ## 0.5.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [c0127d5]
8
+ - @sahan-sac/ai-core@0.5.0
9
+
10
+ ## 0.4.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [1570cf6]
15
+ - Updated dependencies [396e692]
16
+ - @sahan-sac/ai-core@0.4.0
17
+
18
+ ## 0.3.1
19
+
20
+ ### Patch Changes
21
+
22
+ - 5e7f3cb: The build shares modules between subpaths (code splitting) instead of copying them into each one. Before, a class imported from two subpaths was two different classes, so `instanceof` failed (for example `EmailGuardError` from `@sahan-sac/email-kit/guards` against an error thrown through `./layout`), and module-level state such as caches existed once per subpath.
23
+ - Updated dependencies [5e7f3cb]
24
+ - @sahan-sac/ai-core@0.3.1
25
+
26
+ ## 0.3.0
27
+
28
+ ### Minor Changes
29
+
30
+ - f465908: Owner guidance and per-post steering. `BlogSiteProfile.guidance` and `ChatSite.guidance` add the site owner's standing guidance to every blog, SEO, helper and chatbot prompt, after the fixed rules. `BlogGenerationInput` takes optional `instructions` (up to `MAX_INSTRUCTIONS_LENGTH`, 2,000 characters) and `resources` (pasted reference text, up to `MAX_RESOURCES_LENGTH`, 12,000), both fenced as untrusted data: resources are used as facts, never as instructions, and nothing is fetched from a link.
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [b9d2dd6]
35
+ - Updated dependencies [4fa21e3]
36
+ - Updated dependencies [f465908]
37
+ - @sahan-sac/ai-core@0.3.0
38
+
39
+ ## 0.2.0
40
+
41
+ ### Minor Changes
42
+
43
+ - c2cc383: Site-specific values are now options with neutral defaults. blog-kit: `BlogAiDeps.site` (a `BlogSiteProfile`: description, allowed internal links, call-to-action paths) feeds every prompt, `realBlogDeps(env, site)` takes it, inline image tokens are `ai-image://N`, and `draftStorageKey(id, prefix)` takes a key prefix (default "admin"). chat-kit: `ChatSite` gains optional `kind`, `scope` and `linkExample` (default wording says "site"), and `CHAT_VISITOR_COOKIE` defaults to "chat_vid". media-kit: `MEDIA_CONFIG.uploadFolder` is removed; the upload folder is the app's own constant.
44
+
45
+ ### Patch Changes
46
+
47
+ - @sahan-sac/ai-core@0.2.0
48
+
49
+ ## 0.1.0
50
+
51
+ ### Minor Changes
52
+
53
+ - b620f44: First release. ai-core: the free-by-default provider chain (Gemini, OpenRouter, NVIDIA, then paid Vertex) with hedging, cooldowns and deadlines, env-driven model resolution, image generation, prompt guards and the shared env schema (ENABLE_BLOG_AI, ENABLE_CHATBOT). blog-kit: full-post, SEO, draft and cover generation, AI images through an ImageSink port, and pure blog utilities. chat-kit: runChat, guarded prompts, output filtering, the knowledge builder, the ChatStore contract and the visitor rate-limit cookie. Licensed Apache-2.0.
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [b620f44]
58
+ - @sahan-sac/ai-core@0.1.0
package/LICENSE CHANGED
@@ -1,202 +1,202 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the
44
- purposes of this License, Derivative Works shall not include works
45
- that remain separable from, or merely link (or bind by name) to the
46
- interfaces of, the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including the
49
- original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright
52
- owner or by an individual or Legal Entity authorized to submit on
53
- behalf of the copyright owner. For the purposes of this definition,
54
- "submitted" means any form of electronic, verbal, or written
55
- communication sent to the Licensor or its representatives,
56
- including but not limited to communication on electronic mailing
57
- lists, source code control systems, and issue tracking systems
58
- that are managed by, or on behalf of, the Licensor for the purpose
59
- of discussing and improving the Work, but excluding communication
60
- that is conspicuously marked or otherwise designated in writing
61
- by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or Derivative
96
- Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing
142
- the origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright 2026 Sahan Sachintha
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the
44
+ purposes of this License, Derivative Works shall not include works
45
+ that remain separable from, or merely link (or bind by name) to the
46
+ interfaces of, the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the
49
+ original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright
52
+ owner or by an individual or Legal Entity authorized to submit on
53
+ behalf of the copyright owner. For the purposes of this definition,
54
+ "submitted" means any form of electronic, verbal, or written
55
+ communication sent to the Licensor or its representatives,
56
+ including but not limited to communication on electronic mailing
57
+ lists, source code control systems, and issue tracking systems
58
+ that are managed by, or on behalf of, the Licensor for the purpose
59
+ of discussing and improving the Work, but excluding communication
60
+ that is conspicuously marked or otherwise designated in writing
61
+ by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or Derivative
96
+ Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing
142
+ the origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Sahan Sachintha
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,100 +1,100 @@
1
- # @sahan-sac/chat-kit
2
-
3
- Headless portfolio chatbot core, built on `@sahan-sac/ai-core`. It provides:
4
-
5
- - guarded prompt building;
6
- - prompt-injection and output-link guards;
7
- - a signed anonymous-visitor cookie for rate limiting;
8
- - a knowledge-base builder;
9
- - `runChat`, one chat turn from visitor message to filtered reply.
10
-
11
- It is headless and framework-agnostic: no Prisma, no Next.js APIs, no React. The host app keeps:
12
-
13
- - the HTTP route, origin checks and rate limits;
14
- - cookie I/O and settings;
15
- - storage (through `ChatStore`) and caching;
16
- - the widget UI.
17
-
18
- ## Subpaths
19
-
20
- | Import | What |
21
- | --- | --- |
22
- | `@sahan-sac/chat-kit/types` | `ChatbotConfig`, `ChatSite` (the owner identity; optional `kind`, `scope` and `linkExample` set the wording, default "site"), `ChatTurn`, `CHAT_TONES` |
23
- | `@sahan-sac/chat-kit/handler` | `runChat(input, deps)`, `CHAT_BUDGETS` (12 s per attempt, 20 s chain, 5 s hedge, 500 tokens) |
24
- | `@sahan-sac/chat-kit/knowledge` | `buildKnowledge(sources)`, `profileSection(site)`, `trainingSection(entries)`, `knowledgeHosts(text)` |
25
- | `@sahan-sac/chat-kit/prompts` | `buildChatPrompt` (fixed system prompt, knowledge as fenced reference data) |
26
- | `@sahan-sac/chat-kit/guard` | `guardUserMessage`, `filterModelOutput` (strips HTML, secrets, `/admin` paths and links to hosts not allowed) |
27
- | `@sahan-sac/chat-kit/visitor-cookie` | `newChatVisitorId`, `signChatVisitorId`, `verifyChatVisitorCookie`, `chatVisitorCookieOptions`, `CHAT_VISITOR_COOKIE` (default name "chat_vid"; any name works) |
28
- | `@sahan-sac/chat-kit/adapter` | `ChatStore`, `ChatSessionInput`, `ChatMessageInput` |
29
- | `@sahan-sac/chat-kit/session-summaries` | `ChatSessionSummary`, `parseChatSessionListParams`, page-size limits for the admin conversations list |
30
-
31
- Only `handler` imports `server-only`. The other subpaths are pure, and `session-summaries` and `types` are safe in client components.
32
-
33
- ## Environment
34
-
35
- Uses `@sahan-sac/ai-core`'s variables; see its README for the full table. The chatbot runs only when `chatbotEnabled(env)` from `@sahan-sac/ai-core/availability` is true:
36
-
37
- - `ENABLE_CHATBOT` is on. It defaults to `true`; `false`, `0`, `no` or `off` turns it off.
38
- - At least one provider can answer chat: its key is set, it is in `AI_PROVIDER_ORDER_CHAT` (or `AI_PROVIDER_ORDER`) when one is set, and a paid one also has `AI_ALLOW_PAID=true`.
39
-
40
- The chat chain falls through providers on any failure (quota, timeout, bad key, bad output), so one provider's outage does not stop the chatbot. Set `AI_PROVIDER_ORDER_CHAT` to choose which providers answer and in what order; see `@sahan-sac/ai-core`'s README.
41
-
42
- When the chatbot is off, return 503 from the route and do not render the widget.
43
-
44
- ## Wiring
45
-
46
- ```ts
47
- import { realProviders, sharedAiHealth } from "@sahan-sac/ai-core/providers";
48
- import { runChat } from "@sahan-sac/chat-kit/handler";
49
-
50
- const result = await runChat(
51
- {
52
- message,
53
- history: await store.getRecentMessages(sessionId, 10),
54
- knowledge: await getKnowledge(), // cached by the app
55
- config: { tone: "professional" },
56
- site: { ...chatSite, guidance: ownerGuidance }, // optional: added after the fixed rules
57
- siteHostname: new URL(env.SITE_URL).hostname,
58
- extraHosts: ["wa.me", "t.me"],
59
- },
60
- { providers: realProviders(env, "chat"), health: sharedAiHealth, logger }
61
- );
62
- if (!result.ok) return new Response(null, { status: 503 });
63
- // result.text is already filtered; store it with result.tokens and result.latencyMs.
64
- ```
65
-
66
- Knowledge sources run in parallel and join in order. A source that throws is skipped and reported, so one failing source never empties the knowledge base:
67
-
68
- ```ts
69
- import { buildKnowledge, profileSection, trainingSection } from "@sahan-sac/chat-kit/knowledge";
70
-
71
- const knowledge = await buildKnowledge(
72
- [
73
- { name: "profile", load: () => profileSection(chatSite) },
74
- { name: "posts", load: async () => (await getPosts()).map((post) => `- ${post.title} (/blog/${post.slug})\n`).join("") },
75
- { name: "training", load: async () => trainingSection(await db.chatTrainingEntry.findMany({ where: { isActive: true }, take: 50 })) },
76
- ],
77
- { onError: (source, error) => logger.warn("knowledge source failed", { source, error: String(error) }) }
78
- );
79
- ```
80
-
81
- A Prisma `ChatStore`:
82
-
83
- ```ts
84
- import type { ChatStore } from "@sahan-sac/chat-kit/adapter";
85
-
86
- export const prismaChatStore: ChatStore = {
87
- upsertSession: (input) => db.chatSession.upsert({ where: { sessionId: input.sessionId }, update: {}, create: input }),
88
- addMessage: (input) =>
89
- Promise.all([
90
- db.chatSession.update({ where: { sessionId: input.sessionId }, data: { messagesCount: { increment: 1 } } }),
91
- db.chatMessage.create({ data: input }),
92
- ]),
93
- getRecentMessages: async (sessionId, limit) =>
94
- (await db.chatMessage.findMany({ where: { sessionId }, orderBy: { createdAt: "desc" }, take: limit })).reverse(),
95
- linkInquiry: (sessionId, inquiryId) => db.chatSession.update({ where: { sessionId }, data: { inquiryId, capturedLead: true } }),
96
- listSessionSummaries: async ({ limit, offset }) => /* select without message bodies */ [],
97
- };
98
- ```
99
-
100
- The visitor cookie is a rate-limit fallback for callers whose IP is unknown. It holds a random id plus an HMAC. Pass the secret in (for example `INTERNAL_SIGNING_SECRET`): nothing in this package reads `process.env`.
1
+ # @sahan-sac/chat-kit
2
+
3
+ Headless portfolio chatbot core, built on `@sahan-sac/ai-core`. It provides:
4
+
5
+ - guarded prompt building;
6
+ - prompt-injection and output-link guards;
7
+ - a signed anonymous-visitor cookie for rate limiting;
8
+ - a knowledge-base builder;
9
+ - `runChat`, one chat turn from visitor message to filtered reply.
10
+
11
+ It is headless and framework-agnostic: no Prisma, no Next.js APIs, no React. The host app keeps:
12
+
13
+ - the HTTP route, origin checks and rate limits;
14
+ - cookie I/O and settings;
15
+ - storage (through `ChatStore`) and caching;
16
+ - the widget UI.
17
+
18
+ ## Subpaths
19
+
20
+ | Import | What |
21
+ | --- | --- |
22
+ | `@sahan-sac/chat-kit/types` | `ChatbotConfig`, `ChatSite` (the owner identity; optional `kind`, `scope` and `linkExample` set the wording, default "site"), `ChatTurn`, `CHAT_TONES` |
23
+ | `@sahan-sac/chat-kit/handler` | `runChat(input, deps)`, `CHAT_BUDGETS` (12 s per attempt, 20 s chain, 5 s hedge, 500 tokens) |
24
+ | `@sahan-sac/chat-kit/knowledge` | `buildKnowledge(sources)`, `profileSection(site)`, `trainingSection(entries)`, `knowledgeHosts(text)` |
25
+ | `@sahan-sac/chat-kit/prompts` | `buildChatPrompt` (fixed system prompt, knowledge as fenced reference data) |
26
+ | `@sahan-sac/chat-kit/guard` | `guardUserMessage`, `filterModelOutput` (strips HTML, secrets, `/admin` paths and links to hosts not allowed) |
27
+ | `@sahan-sac/chat-kit/visitor-cookie` | `newChatVisitorId`, `signChatVisitorId`, `verifyChatVisitorCookie`, `chatVisitorCookieOptions`, `CHAT_VISITOR_COOKIE` (default name "chat_vid"; any name works) |
28
+ | `@sahan-sac/chat-kit/adapter` | `ChatStore`, `ChatSessionInput`, `ChatMessageInput` |
29
+ | `@sahan-sac/chat-kit/session-summaries` | `ChatSessionSummary`, `parseChatSessionListParams`, page-size limits for the admin conversations list |
30
+
31
+ Only `handler` imports `server-only`. The other subpaths are pure, and `session-summaries` and `types` are safe in client components.
32
+
33
+ ## Environment
34
+
35
+ Uses `@sahan-sac/ai-core`'s variables; see its README for the full table. The chatbot runs only when `chatbotEnabled(env)` from `@sahan-sac/ai-core/availability` is true:
36
+
37
+ - `ENABLE_CHATBOT` is on. It defaults to `true`; `false`, `0`, `no` or `off` turns it off.
38
+ - At least one provider can answer chat: its key is set, it is in `AI_PROVIDER_ORDER_CHAT` (or `AI_PROVIDER_ORDER`) when one is set, and a paid one also has `AI_ALLOW_PAID=true`.
39
+
40
+ The chat chain falls through providers on any failure (quota, timeout, bad key, bad output), so one provider's outage does not stop the chatbot. Set `AI_PROVIDER_ORDER_CHAT` to choose which providers answer and in what order; see `@sahan-sac/ai-core`'s README.
41
+
42
+ When the chatbot is off, return 503 from the route and do not render the widget.
43
+
44
+ ## Wiring
45
+
46
+ ```ts
47
+ import { realProviders, sharedAiHealth } from "@sahan-sac/ai-core/providers";
48
+ import { runChat } from "@sahan-sac/chat-kit/handler";
49
+
50
+ const result = await runChat(
51
+ {
52
+ message,
53
+ history: await store.getRecentMessages(sessionId, 10),
54
+ knowledge: await getKnowledge(), // cached by the app
55
+ config: { tone: "professional" },
56
+ site: { ...chatSite, guidance: ownerGuidance }, // optional: added after the fixed rules
57
+ siteHostname: new URL(env.SITE_URL).hostname,
58
+ extraHosts: ["wa.me", "t.me"],
59
+ },
60
+ { providers: realProviders(env, "chat"), health: sharedAiHealth, logger }
61
+ );
62
+ if (!result.ok) return new Response(null, { status: 503 });
63
+ // result.text is already filtered; store it with result.tokens and result.latencyMs.
64
+ ```
65
+
66
+ Knowledge sources run in parallel and join in order. A source that throws is skipped and reported, so one failing source never empties the knowledge base:
67
+
68
+ ```ts
69
+ import { buildKnowledge, profileSection, trainingSection } from "@sahan-sac/chat-kit/knowledge";
70
+
71
+ const knowledge = await buildKnowledge(
72
+ [
73
+ { name: "profile", load: () => profileSection(chatSite) },
74
+ { name: "posts", load: async () => (await getPosts()).map((post) => `- ${post.title} (/blog/${post.slug})\n`).join("") },
75
+ { name: "training", load: async () => trainingSection(await db.chatTrainingEntry.findMany({ where: { isActive: true }, take: 50 })) },
76
+ ],
77
+ { onError: (source, error) => logger.warn("knowledge source failed", { source, error: String(error) }) }
78
+ );
79
+ ```
80
+
81
+ A Prisma `ChatStore`:
82
+
83
+ ```ts
84
+ import type { ChatStore } from "@sahan-sac/chat-kit/adapter";
85
+
86
+ export const prismaChatStore: ChatStore = {
87
+ upsertSession: (input) => db.chatSession.upsert({ where: { sessionId: input.sessionId }, update: {}, create: input }),
88
+ addMessage: (input) =>
89
+ Promise.all([
90
+ db.chatSession.update({ where: { sessionId: input.sessionId }, data: { messagesCount: { increment: 1 } } }),
91
+ db.chatMessage.create({ data: input }),
92
+ ]),
93
+ getRecentMessages: async (sessionId, limit) =>
94
+ (await db.chatMessage.findMany({ where: { sessionId }, orderBy: { createdAt: "desc" }, take: limit })).reverse(),
95
+ linkInquiry: (sessionId, inquiryId) => db.chatSession.update({ where: { sessionId }, data: { inquiryId, capturedLead: true } }),
96
+ listSessionSummaries: async ({ limit, offset }) => /* select without message bodies */ [],
97
+ };
98
+ ```
99
+
100
+ The visitor cookie is a rate-limit fallback for callers whose IP is unknown. It holds a random id plus an HMAC. Pass the secret in (for example `INTERNAL_SIGNING_SECRET`): nothing in this package reads `process.env`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sahan-sac/chat-kit",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Headless chatbot core for the portfolio site: guarded prompt building, prompt-injection and output-link guards, an anonymous-visitor rate-limit cookie, a knowledge-base builder that tolerates a failing source, and runChat, the pure request/response path behind /api/chat. Depends on @sahan-sac/ai-core; never on @sahan-sac/blog-kit or @sahan-sac/media-kit.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -61,7 +61,7 @@
61
61
  "types": "./dist/index.d.ts",
62
62
  "main": "./dist/index.js",
63
63
  "dependencies": {
64
- "@sahan-sac/ai-core": "^0.4.0",
64
+ "@sahan-sac/ai-core": "^0.5.0",
65
65
  "server-only": "^0.0.1"
66
66
  },
67
67
  "devDependencies": {