diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 314d6c365..000000000 --- a/Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -FROM node:18-alpine AS base - -FROM base AS deps - -RUN apk add --no-cache libc6-compat - -WORKDIR /app - -COPY package.json yarn.lock* package-lock.json* ./ - -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - elif [ -f package-lock.json ]; then npm ci; \ - else echo "Lockfile not found." && exit 1; \ - fi - -FROM base AS builder - -RUN apk update && apk add --no-cache git - -ENV OPENAI_API_KEY="" -ENV CODE="" -ARG DOCKER=true - -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . - -RUN yarn build - -FROM base AS runner -WORKDIR /app - -ENV OPENAI_API_KEY="" -ENV CODE="" - -COPY --from=builder /app/public ./public -COPY --from=builder /app/.next/standalone ./ -COPY --from=builder /app/.next/static ./.next/static -COPY --from=builder /app/.next/server ./.next/server - -EXPOSE 3000 - -CMD ["node","server.js"] diff --git a/LICENSE b/LICENSE index 4f00efc87..f288702d2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,75 +1,674 @@ -版权所有(c)<2023> + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 -反996许可证版本1.0 + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -在符合下列条件的情况下, -特此免费向任何得到本授权作品的副本(包括源代码、文件和/或相关内容,以下统称为“授权作品” -)的个人和法人实体授权:被授权个人或法人实体有权以任何目的处置授权作品,包括但不限于使 -用、复制,修改,衍生利用、散布,发布和再许可: + Preamble + The GNU General Public License is a free, copyleft license for +software and other kinds of works. -1. 个人或法人实体必须在许可作品的每个再散布或衍生副本上包含以上版权声明和本许可证,不 - 得自行修改。 -2. 个人或法人实体必须严格遵守与个人实际所在地或个人出生地或归化地、或法人实体注册地或 - 经营地(以较严格者为准)的司法管辖区所有适用的与劳动和就业相关法律、法规、规则和 - 标准。如果该司法管辖区没有此类法律、法规、规章和标准或其法律、法规、规章和标准不可 - 执行,则个人或法人实体必须遵守国际劳工标准的核心公约。 -3. 个人或法人不得以任何方式诱导或强迫其全职或兼职员工或其独立承包人以口头或书面形式同 - 意直接或间接限制、削弱或放弃其所拥有的,受相关与劳动和就业有关的法律、法规、规则和 - 标准保护的权利或补救措施,无论该等书面或口头协议是否被该司法管辖区的法律所承认,该 - 等个人或法人实体也不得以任何方法限制其雇员或独立承包人向版权持有人或监督许可证合规 - 情况的有关当局报告或投诉上述违反许可证的行为的权利。 + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. -该授权作品是"按原样"提供,不做任何明示或暗示的保证,包括但不限于对适销性、特定用途适用 -性和非侵权性的保证。在任何情况下,无论是在合同诉讼、侵权诉讼或其他诉讼中,版权持有人均 -不承担因本软件或本软件的使用或其他交易而产生、引起或与之相关的任何索赔、损害或其他责任。 + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. -------------------------- ENGLISH ------------------------------ + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. -Copyright (c) <2023> + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. -Anti 996 License Version 1.0 (Draft) + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. -Permission is hereby granted to any individual or legal entity obtaining a copy -of this licensed work (including the source code, documentation and/or related -items, hereinafter collectively referred to as the "licensed work"), free of -charge, to deal with the licensed work for any purpose, including without -limitation, the rights to use, reproduce, modify, prepare derivative works of, -publish, distribute and sublicense the licensed work, subject to the following -conditions: + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. -1. The individual or the legal entity must conspicuously display, without - modification, this License on each redistributed or derivative copy of the - Licensed Work. + The precise terms and conditions for copying, distribution and +modification follow. -2. The individual or the legal entity must strictly comply with all applicable - laws, regulations, rules and standards of the jurisdiction relating to - labor and employment where the individual is physically located or where - the individual was born or naturalized; or where the legal entity is - registered or is operating (whichever is stricter). In case that the - jurisdiction has no such laws, regulations, rules and standards or its - laws, regulations, rules and standards are unenforceable, the individual - or the legal entity are required to comply with Core International Labor - Standards. + TERMS AND CONDITIONS -3. The individual or the legal entity shall not induce or force its - employee(s), whether full-time or part-time, or its independent - contractor(s), in any methods, to agree in oral or written form, - to directly or indirectly restrict, weaken or relinquish his or - her rights or remedies under such laws, regulations, rules and - standards relating to labor and employment as mentioned above, - no matter whether such written or oral agreement are enforceable - under the laws of the said jurisdiction, nor shall such individual - or the legal entity limit, in any methods, the rights of its employee(s) - or independent contractor(s) from reporting or complaining to the copyright - holder or relevant authorities monitoring the compliance of the license - about its violation(s) of the said license. + 0. Definitions. -THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT -HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ANY WAY CONNECTION -WITH THE LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK. \ No newline at end of file + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..04652e4a7 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +build: clean + echo "Building theme" + pnpm install + pnpm build + echo "Theme built successfully!" + echo "Collect theme dist" + mkdir dist + cp -r templates dist + cp theme.yaml settings.yaml README.md dist + +clean: + echo "Clean dist folder" + rm -rf dist diff --git a/OWNERS b/OWNERS new file mode 100644 index 000000000..aff754562 --- /dev/null +++ b/OWNERS @@ -0,0 +1,12 @@ +reviewers: +- ruibaby +- guqing +- JohnNiang +- lan-yonghui +- wangzhen-fit2cloud + +approvers: +- ruibaby +- guqing +- JohnNiang + diff --git a/README.md b/README.md index 5952aa33a..017aff066 100644 --- a/README.md +++ b/README.md @@ -1,194 +1,35 @@ -
-预览 +# Earth -

ChatGPT Next Web

+Halo 2.0 的默认主题。 -一键免费部署你的私人 ChatGPT 网页应用。 +![Earth](./screenshot.jpg) -One-Click to deploy your own ChatGPT web UI. +## 开发 -[演示 Demo](https://chat-gpt-next-web.vercel.app/) / [反馈 Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [加入 Discord](https://discord.gg/zrhvHCr79N) / [QQ 群](https://user-images.githubusercontent.com/16968934/228190818-7dd00845-e9b9-4363-97e5-44c507ac76da.jpeg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg) / [Donate](#捐赠-donate-usdt) - -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web) - -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web) - -![主界面](./static/cover.png) - -
- -## 主要功能 - -- 在 1 分钟内使用 Vercel **免费一键部署** -- 精心设计的 UI,响应式设计,支持深色模式 -- 极快的首屏加载速度(~85kb) -- 海量的内置 prompt 列表,来自[中文](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)和[英文](https://github.com/f/awesome-chatgpt-prompts) -- 自动压缩上下文聊天记录,在节省 Token 的同时支持超长对话 -- 一键导出聊天记录,完整的 Markdown 支持 -- 拥有自己的域名?好上加好,绑定后即可在任何地方**无障碍**快速访问 - -## Features - -- **Deploy for free with one-click** on Vercel in under 1 minute -- Responsive design, and dark mode -- Fast first screen loading speed (~85kb) -- Awesome prompts powered by [awesome-chatgpt-prompts-zh](https://github.com/PlexPt/awesome-chatgpt-prompts-zh) and [awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts) -- Automatically compresses chat history to support long conversations while also saving your tokens -- One-click export all chat history with full Markdown support - -## 使用 - -1. 准备好你的 [OpenAI API Key](https://platform.openai.com/account/api-keys); -2. 点击右侧按钮开始部署: - [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web),直接使用 Github 账号登陆即可,记得在环境变量页填入 API Key; -3. 部署完毕后,即可开始使用; -4. (可选)[绑定自定义域名](https://vercel.com/docs/concepts/projects/domains/add-a-domain):Vercel 分配的域名 DNS 在某些区域被污染了,绑定自定义域名即可直连。 - -## Get Started - -1. Get [OpenAI API Key](https://platform.openai.com/account/api-keys); -2. Click - [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web); -3. Enjoy :) - -## 保持更新 Keep Updated - -如果你按照上述步骤一键部署了自己的项目,可能会发现总是提示“存在更新”的问题,这是由于 Vercel 会默认为你创建一个新项目而不是 fork 本项目,这会导致无法正确地检测更新。 -推荐你按照下列步骤重新部署: - -- 删除掉原先的 repo; -- fork 本项目; -- 前往 vercel 控制台,删除掉原先的 project,然后新建 project,选择你刚刚 fork 出来的项目重新进行部署即可; -- 在重新部署的过程中,请手动添加名为 `OPENAI_API_KEY` 的环境变量,并填入你的 api key 作为值。 - -本项目会持续更新,如果你想让代码库总是保持更新,可以查看 [Github 的文档](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) 了解如何让 fork 的项目与上游代码同步,建议定期进行同步操作以获得新功能。 - -你可以 star/watch 本项目或者 follow 作者来及时获得新功能更新通知。 - -If you have deployed your own project with just one click following the steps above, you may encounter the issue of "Updates Available" constantly showing up. This is because Vercel will create a new project for you by default instead of forking this project, resulting in the inability to detect updates correctly. - -We recommend that you follow the steps below to re-deploy: - -- Delete the original repo; -- Fork this project; -- Go to the Vercel dashboard, delete the original project, then create a new project and select the project you just forked to redeploy; -- Please manually add an environment variable named `OPENAI_API_KEY` and enter your API key as the value during the redeploy process. - -This project will be continuously maintained. If you want to keep the code repository up to date, you can check out the [Github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) to learn how to synchronize a forked project with upstream code. It is recommended to perform synchronization operations regularly. - -You can star or watch this project or follow author to get release notifictions in time. - -## 配置密码 Password - -本项目提供有限的权限控制功能,请在 Vercel 项目控制面板的环境变量页增加名为 `CODE` 的环境变量,值为用英文逗号分隔的自定义密码: - -``` -code1,code2,code3 +```bash +git clone git@github.com:halo-dev/theme-earth.git ~/halo2-dev/themes/theme-earth ``` -增加或修改该环境变量后,请**重新部署**项目使改动生效。 - -This project provides limited access control. Please add an environment variable named `CODE` on the vercel environment variables page. The value should be passwords separated by comma like this: - -``` -code1,code2,code3 +```bash +cd ~/halo2-dev/themes/theme-earth ``` -After adding or modifying this environment variable, please redeploy the project for the changes to take effect. - -## 环境变量 Environment Variables - -### `OPENAI_API_KEY` (required) - -OpanAI 密钥。 - -Your openai api key. - -### `CODE` (optional) - -访问密码,可选,可以使用逗号隔开多个密码。 - -Access passsword, separated by comma. - -### `BASE_URL` (optional) - -> Default: `api.openai.com` - -OpenAI 接口代理 URL。 - -Override openai api request base url. - -### `PROTOCOL` (optional) - -> Default: `https` - -> Values: `http` | `https` - -OpenAI 接口协议。 - -Override openai api request protocol. - -## 开发 Development - -点击下方按钮,开始二次开发: - -[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web) - -在开始写代码之前,需要在项目根目录新建一个 `.env.local` 文件,里面填入环境变量: - -Before starting development, you must create a new `.env.local` file at project root, and place your api key into it: - -``` -OPENAI_API_KEY= +```bash +pnpm install ``` -### 本地开发 Local Development - -> 如果你是中国大陆用户,不建议在本地进行开发,除非你能够独立解决 OpenAI API 本地代理问题。 - -1. 安装 nodejs 和 yarn,具体细节请询问 ChatGPT; -2. 执行 `yarn install && yarn dev` 即可。 - -### 本地部署 Local Deployment - -```shell -bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh) +```bash +pnpm dev ``` -### 容器部署 Docker Deployment +主题开发文档可查阅: -```shell -docker pull yidadaa/chatgpt-next-web +## 构建 -docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next-web +> 如果你使用的是 Windows 操作系统,请安装 `make` 命令并在 Git Bash 或 WSL 中执行。 + +```bash +make build ``` -## 截图 Screenshots - -![设置 Settings](./static/settings.png) - -![更多展示 More](./static/more.png) - - -## 捐赠 Donate USDT -> BNB Smart Chain (BEP 20) -``` -0x67cD02c7EB62641De576a1fA3EdB32eA0c3ffD89 -``` - -## 鸣谢 Special Thanks - -### 捐赠者 Sponsor - -[@mushan0x0](https://github.com/mushan0x0) -[@ClarenceDan](https://github.com/ClarenceDan) -[@zhangjia](https://github.com/zhangjia) -[@hoochanlon](https://github.com/hoochanlon) - -### 贡献者 Contributor - -[Contributors](https://github.com/Yidadaa/ChatGPT-Next-Web/graphs/contributors) - -## LICENSE - -- [Anti 996 License](https://github.com/kattgu7/Anti-996-License/blob/master/LICENSE_CN_EN) +然后将 `dist` 目录压缩成 `ZIP` 格式压缩包即可在 Halo 后台上传安装。 diff --git a/app/api/access.ts b/app/api/access.ts deleted file mode 100644 index d3e4c9cf9..000000000 --- a/app/api/access.ts +++ /dev/null @@ -1,17 +0,0 @@ -import md5 from "spark-md5"; - -export function getAccessCodes(): Set { - const code = process.env.CODE; - - try { - const codes = (code?.split(",") ?? []) - .filter((v) => !!v) - .map((v) => md5.hash(v.trim())); - return new Set(codes); - } catch (e) { - return new Set(); - } -} - -export const ACCESS_CODES = getAccessCodes(); -export const IS_IN_DOCKER = process.env.DOCKER; diff --git a/app/api/chat-stream/route.ts b/app/api/chat-stream/route.ts deleted file mode 100644 index e7bdfc5fb..000000000 --- a/app/api/chat-stream/route.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { createParser } from "eventsource-parser"; -import { NextRequest } from "next/server"; -import { requestOpenai } from "../common"; - -async function createStream(req: NextRequest) { - const encoder = new TextEncoder(); - const decoder = new TextDecoder(); - - const res = await requestOpenai(req); - - const stream = new ReadableStream({ - async start(controller) { - function onParse(event: any) { - if (event.type === "event") { - const data = event.data; - // https://beta.openai.com/docs/api-reference/completions/create#completions/create-stream - if (data === "[DONE]") { - controller.close(); - return; - } - try { - const json = JSON.parse(data); - const text = json.choices[0].delta.content; - const queue = encoder.encode(text); - controller.enqueue(queue); - } catch (e) { - controller.error(e); - } - } - } - - const parser = createParser(onParse); - for await (const chunk of res.body as any) { - parser.feed(decoder.decode(chunk)); - } - }, - }); - return stream; -} - -export async function POST(req: NextRequest) { - try { - const stream = await createStream(req); - return new Response(stream); - } catch (error) { - console.error("[Chat Stream]", error); - } -} - -export const config = { - runtime: "edge", -}; diff --git a/app/api/common.ts b/app/api/common.ts deleted file mode 100644 index 842eeacaf..000000000 --- a/app/api/common.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { NextRequest } from "next/server"; - -const OPENAI_URL = "api.openai.com"; -const DEFAULT_PROTOCOL = "https"; -const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL; -const BASE_URL = process.env.BASE_URL ?? OPENAI_URL; - -export async function requestOpenai(req: NextRequest) { - const apiKey = req.headers.get("token"); - const openaiPath = req.headers.get("path"); - - console.log("[Proxy] ", openaiPath); - - return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, { - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${apiKey}`, - }, - method: req.method, - body: req.body, - }); -} diff --git a/app/api/openai/route.ts b/app/api/openai/route.ts deleted file mode 100644 index 5bc317e55..000000000 --- a/app/api/openai/route.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { NextRequest, NextResponse } from "next/server"; -import { requestOpenai } from "../common"; - -async function makeRequest(req: NextRequest) { - try { - const res = await requestOpenai(req); - return new Response(res.body); - } catch (e) { - console.error("[OpenAI] ", req.body, e); - return NextResponse.json( - { - error: true, - msg: JSON.stringify(e), - }, - { - status: 500, - }, - ); - } -} - -export async function POST(req: NextRequest) { - return makeRequest(req); -} - -export async function GET(req: NextRequest) { - return makeRequest(req); -} diff --git a/app/api/openai/typing.ts b/app/api/openai/typing.ts deleted file mode 100644 index 8c4218467..000000000 --- a/app/api/openai/typing.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { - CreateChatCompletionRequest, - CreateChatCompletionResponse, -} from "openai"; - -export type ChatRequest = CreateChatCompletionRequest; -export type ChatReponse = CreateChatCompletionResponse; diff --git a/app/components/button.module.scss b/app/components/button.module.scss deleted file mode 100644 index b882a0c1f..000000000 --- a/app/components/button.module.scss +++ /dev/null @@ -1,60 +0,0 @@ -.icon-button { - background-color: var(--white); - border-radius: 10px; - display: flex; - align-items: center; - justify-content: center; - padding: 10px; - - box-shadow: var(--card-shadow); - cursor: pointer; - transition: all 0.3s ease; - overflow: hidden; - user-select: none; -} - -.border { - border: var(--border-in-light); -} - -.icon-button:hover { - filter: brightness(0.9); - border-color: var(--primary); -} - -.icon-button-icon { - width: 16px; - height: 16px; - display: flex; - justify-content: center; - align-items: center; -} - -@media only screen and (max-width: 600px) { - .icon-button { - padding: 16px; - } -} - -@mixin dark-button { - div:not(:global(.no-dark))>.icon-button-icon { - filter: invert(0.5); - } - - .icon-button:hover { - filter: brightness(1.2); - } -} - -:global(.dark) { - @include dark-button; -} - -@media (prefers-color-scheme: dark) { - @include dark-button; -} - -.icon-button-text { - margin-left: 5px; - font-size: 12px; -} \ No newline at end of file diff --git a/app/components/button.tsx b/app/components/button.tsx deleted file mode 100644 index 43b699b68..000000000 --- a/app/components/button.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import * as React from "react"; - -import styles from "./button.module.scss"; - -export function IconButton(props: { - onClick?: () => void; - icon: JSX.Element; - text?: string; - bordered?: boolean; - className?: string; - title?: string; -}) { - return ( -
-
{props.icon}
- {props.text && ( -
{props.text}
- )} -
- ); -} diff --git a/app/components/home.module.scss b/app/components/home.module.scss deleted file mode 100644 index 87231feee..000000000 --- a/app/components/home.module.scss +++ /dev/null @@ -1,456 +0,0 @@ -@import "./window.scss"; - -@mixin container { - background-color: var(--white); - border: var(--border-in-light); - border-radius: 20px; - box-shadow: var(--shadow); - color: var(--black); - background-color: var(--white); - min-width: 600px; - min-height: 480px; - max-width: 900px; - - display: flex; - overflow: hidden; - box-sizing: border-box; - - width: var(--window-width); - height: var(--window-height); -} - -.container { - @include container(); -} - -@media only screen and (min-width: 600px) { - .tight-container { - --window-width: 100vw; - --window-height: 100vh; - --window-content-width: calc(100% - var(--sidebar-width)); - - @include container(); - - max-width: 100vw; - max-height: 100vh; - - border-radius: 0; - } -} - -.sidebar { - top: 0; - width: var(--sidebar-width); - box-sizing: border-box; - padding: 20px; - background-color: var(--second); - display: flex; - flex-direction: column; - box-shadow: inset -2px 0px 2px 0px rgb(0, 0, 0, 0.05); -} - -.window-content { - width: var(--window-content-width); - height: 100%; - display: flex; - flex-direction: column; -} - -.mobile { - display: none; -} - -@media only screen and (max-width: 600px) { - .container { - min-height: unset; - min-width: unset; - max-height: unset; - min-width: unset; - border: 0; - border-radius: 0; - } - - .sidebar { - position: absolute; - left: -100%; - z-index: 999; - height: 100vh; - transition: all ease 0.3s; - box-shadow: none; - } - - .sidebar-show { - left: 0; - } - - .mobile { - display: block; - } -} - -.sidebar-header { - position: relative; - padding-top: 20px; - padding-bottom: 20px; -} - -.sidebar-logo { - position: absolute; - right: 0; - bottom: 18px; -} - -.sidebar-title { - font-size: 20px; - font-weight: bold; -} - -.sidebar-sub-title { - font-size: 12px; - font-weight: 400px; -} - -.sidebar-body { - flex: 1; - overflow: auto; -} - -.chat-list { -} - -.chat-item { - padding: 10px 14px; - background-color: var(--white); - border-radius: 10px; - margin-bottom: 10px; - box-shadow: var(--card-shadow); - transition: all 0.3s ease; - cursor: pointer; - user-select: none; - border: 2px solid transparent; - position: relative; - overflow: hidden; -} - -@keyframes slide-in { - from { - opacity: 0; - transform: translateY(20px); - } - - to { - opacity: 1; - transform: translateY(0px); - } -} - -.chat-item:hover { - background-color: var(--hover-color); -} - -.chat-item-selected { - border-color: var(--primary); -} - -.chat-item-title { - font-size: 14px; - font-weight: bolder; - display: block; - width: 200px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.chat-item-delete { - position: absolute; - top: 10px; - right: -20px; - transition: all ease 0.3s; - opacity: 0; -} - -.chat-item:hover > .chat-item-delete { - opacity: 0.5; - right: 10px; -} - -.chat-item:hover > .chat-item-delete:hover { - opacity: 1; -} - -.chat-item-info { - display: flex; - justify-content: space-between; - color: rgb(166, 166, 166); - font-size: 12px; - margin-top: 8px; -} - -.chat-item-count { -} - -.chat-item-date { -} - -.sidebar-tail { - display: flex; - justify-content: space-between; - padding-top: 20px; -} - -.sidebar-actions { - display: inline-flex; -} - -.sidebar-action:not(:last-child) { - margin-right: 15px; -} - -.chat { - display: flex; - flex-direction: column; - position: relative; - height: 100%; -} - -.chat-body { - flex: 1; - overflow: auto; - padding: 20px; - margin-bottom: 100px; -} - -.chat-body-title { - cursor: pointer; - - &:hover { - text-decoration: underline; - } -} - -.chat-message { - display: flex; - flex-direction: row; -} - -.chat-message-user { - display: flex; - flex-direction: row-reverse; -} - -.chat-message-container { - max-width: var(--message-max-width); - display: flex; - flex-direction: column; - align-items: flex-start; - animation: slide-in ease 0.3s; - - &:hover { - .chat-message-top-actions { - opacity: 1; - right: 10px; - pointer-events: all; - } - } -} - -.chat-message-user > .chat-message-container { - align-items: flex-end; -} - -.chat-message-avatar { - margin-top: 20px; -} - -.chat-message-status { - font-size: 12px; - color: #aaa; - line-height: 1.5; - margin-top: 5px; -} - -.user-avtar { - height: 30px; - width: 30px; - display: flex; - align-items: center; - justify-content: center; - border: var(--border-in-light); - box-shadow: var(--card-shadow); - border-radius: 10px; -} - -.chat-message-item { - box-sizing: border-box; - max-width: 100%; - margin-top: 10px; - border-radius: 10px; - background-color: rgba(0, 0, 0, 0.05); - padding: 10px; - font-size: 14px; - user-select: text; - word-break: break-word; - border: var(--border-in-light); - position: relative; -} - -.chat-message-top-actions { - font-size: 12px; - position: absolute; - right: 20px; - top: -26px; - left: 100px; - transition: all ease 0.3s; - opacity: 0; - pointer-events: none; - - display: flex; - flex-direction: row-reverse; - - .chat-message-top-action { - opacity: 0.5; - color: var(--black); - white-space: nowrap; - cursor: pointer; - - &:hover { - opacity: 1; - } - - &:not(:first-child) { - margin-right: 10px; - } - } -} - -.chat-message-user > .chat-message-container > .chat-message-item { - background-color: var(--second); -} - -.chat-message-actions { - display: flex; - flex-direction: row-reverse; - width: 100%; - padding-top: 5px; - box-sizing: border-box; - font-size: 12px; -} - -.chat-message-action-date { - color: #aaa; -} - -.chat-input-panel { - position: absolute; - bottom: 0px; - display: flex; - width: 100%; - padding: 20px; - box-sizing: border-box; - flex-direction: column; -} - -@mixin single-line { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} - -.prompt-hints { - min-height: 20px; - width: 100%; - max-height: 50vh; - overflow: auto; - display: flex; - flex-direction: column-reverse; - - background-color: var(--white); - border: var(--border-in-light); - border-radius: 10px; - margin-bottom: 10px; - box-shadow: var(--shadow); - - .prompt-hint { - color: var(--black); - padding: 6px 10px; - animation: slide-in ease 0.3s; - cursor: pointer; - transition: all ease 0.3s; - border: transparent 1px solid; - margin: 4px; - border-radius: 8px; - - &:not(:last-child) { - margin-top: 0; - } - - .hint-title { - font-size: 12px; - font-weight: bolder; - - @include single-line(); - } - .hint-content { - font-size: 12px; - - @include single-line(); - } - - &-selected, - &:hover { - border-color: var(--primary); - } - } -} - -.chat-input-panel-inner { - display: flex; - flex: 1; -} - -.chat-input { - height: 100%; - width: 100%; - border-radius: 10px; - border: var(--border-in-light); - box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.03); - background-color: var(--white); - color: var(--black); - font-family: inherit; - padding: 10px 14px 50px; - resize: none; - outline: none; -} - -@media only screen and (max-width: 600px) { - .chat-input { - font-size: 16px; - } -} - -.chat-input:focus { - border: 1px solid var(--primary); -} - -.chat-input-send { - background-color: var(--primary); - color: white; - - position: absolute; - right: 30px; - bottom: 30px; -} - -.export-content { - white-space: break-spaces; -} - -.loading-content { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - height: 100%; - width: 100%; -} diff --git a/app/components/home.tsx b/app/components/home.tsx deleted file mode 100644 index 10f58ebe8..000000000 --- a/app/components/home.tsx +++ /dev/null @@ -1,690 +0,0 @@ -"use client"; - -import { useState, useRef, useEffect, useLayoutEffect } from "react"; -import { useDebouncedCallback } from "use-debounce"; - -import { IconButton } from "./button"; -import styles from "./home.module.scss"; - -import SettingsIcon from "../icons/settings.svg"; -import GithubIcon from "../icons/github.svg"; -import ChatGptIcon from "../icons/chatgpt.svg"; -import SendWhiteIcon from "../icons/send-white.svg"; -import BrainIcon from "../icons/brain.svg"; -import ExportIcon from "../icons/export.svg"; -import BotIcon from "../icons/bot.svg"; -import AddIcon from "../icons/add.svg"; -import DeleteIcon from "../icons/delete.svg"; -import LoadingIcon from "../icons/three-dots.svg"; -import MenuIcon from "../icons/menu.svg"; -import CloseIcon from "../icons/close.svg"; -import CopyIcon from "../icons/copy.svg"; -import DownloadIcon from "../icons/download.svg"; - -import { Message, SubmitKey, useChatStore, ChatSession } from "../store"; -import { showModal, showToast } from "./ui-lib"; -import { copyToClipboard, downloadAs, isIOS, selectOrCopy } from "../utils"; -import Locale from "../locales"; - -import dynamic from "next/dynamic"; -import { REPO_URL } from "../constant"; -import { ControllerPool } from "../requests"; -import { Prompt, usePromptStore } from "../store/prompt"; - -export function Loading(props: { noLogo?: boolean }) { - return ( -
- {!props.noLogo && } - -
- ); -} - -const Markdown = dynamic(async () => (await import("./markdown")).Markdown, { - loading: () => , -}); - -const Settings = dynamic(async () => (await import("./settings")).Settings, { - loading: () => , -}); - -const Emoji = dynamic(async () => (await import("emoji-picker-react")).Emoji, { - loading: () => , -}); - -export function Avatar(props: { role: Message["role"] }) { - const config = useChatStore((state) => state.config); - - if (props.role === "assistant") { - return ; - } - - return ( -
- -
- ); -} - -export function ChatItem(props: { - onClick?: () => void; - onDelete?: () => void; - title: string; - count: number; - time: string; - selected: boolean; -}) { - return ( -
-
{props.title}
-
-
- {Locale.ChatItem.ChatItemCount(props.count)} -
-
{props.time}
-
-
- -
-
- ); -} - -export function ChatList() { - const [sessions, selectedIndex, selectSession, removeSession] = useChatStore( - (state) => [ - state.sessions, - state.currentSessionIndex, - state.selectSession, - state.removeSession, - ] - ); - - return ( -
- {sessions.map((item, i) => ( - selectSession(i)} - onDelete={() => removeSession(i)} - /> - ))} -
- ); -} - -function useSubmitHandler() { - const config = useChatStore((state) => state.config); - const submitKey = config.submitKey; - - const shouldSubmit = (e: KeyboardEvent) => { - if (e.key !== "Enter") return false; - - return ( - (config.submitKey === SubmitKey.AltEnter && e.altKey) || - (config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) || - (config.submitKey === SubmitKey.ShiftEnter && e.shiftKey) || - (config.submitKey === SubmitKey.MetaEnter && e.metaKey) || - (config.submitKey === SubmitKey.Enter && - !e.altKey && - !e.ctrlKey && - !e.shiftKey && - !e.metaKey) - ); - }; - - return { - submitKey, - shouldSubmit, - }; -} - -export function PromptHints(props: { - prompts: Prompt[]; - onPromptSelect: (prompt: Prompt) => void; -}) { - if (props.prompts.length === 0) return null; - - return ( -
- {props.prompts.map((prompt, i) => ( -
props.onPromptSelect(prompt)} - > -
{prompt.title}
-
{prompt.content}
-
- ))} -
- ); -} - -export function Chat(props: { - showSideBar?: () => void; - sideBarShowing?: boolean; -}) { - type RenderMessage = Message & { preview?: boolean }; - - const chatStore = useChatStore(); - const [session, sessionIndex] = useChatStore((state) => [ - state.currentSession(), - state.currentSessionIndex, - ]); - const fontSize = useChatStore((state) => state.config.fontSize); - - const inputRef = useRef(null); - const [userInput, setUserInput] = useState(""); - const [isLoading, setIsLoading] = useState(false); - const { submitKey, shouldSubmit } = useSubmitHandler(); - - // prompt hints - const promptStore = usePromptStore(); - const [promptHints, setPromptHints] = useState([]); - const onSearch = useDebouncedCallback( - (text: string) => { - setPromptHints(promptStore.search(text)); - }, - 100, - { leading: true, trailing: true } - ); - - const onPromptSelect = (prompt: Prompt) => { - setUserInput(prompt.content); - setPromptHints([]); - inputRef.current?.focus(); - }; - - const scrollInput = () => { - const dom = inputRef.current; - if (!dom) return; - const paddingBottomNum: number = parseInt( - window.getComputedStyle(dom).paddingBottom, - 10 - ); - dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum; - }; - - // only search prompts when user input is short - const SEARCH_TEXT_LIMIT = 30; - const onInput = (text: string) => { - scrollInput(); - setUserInput(text); - const n = text.trim().length; - - // clear search results - if (n === 0) { - setPromptHints([]); - } else if (!chatStore.config.disablePromptHint && n < SEARCH_TEXT_LIMIT) { - // check if need to trigger auto completion - if (text.startsWith("/") && text.length > 1) { - onSearch(text.slice(1)); - } - } - }; - - // submit user input - const onUserSubmit = () => { - if (userInput.length <= 0) return; - setIsLoading(true); - chatStore.onUserInput(userInput).then(() => setIsLoading(false)); - setUserInput(""); - setPromptHints([]); - inputRef.current?.focus(); - }; - - // stop response - const onUserStop = (messageIndex: number) => { - console.log(ControllerPool, sessionIndex, messageIndex); - ControllerPool.stop(sessionIndex, messageIndex); - }; - - // check if should send message - const onInputKeyDown = (e: KeyboardEvent) => { - if (shouldSubmit(e)) { - onUserSubmit(); - e.preventDefault(); - } - }; - const onRightClick = (e: any, message: Message) => { - // auto fill user input - if (message.role === "user") { - setUserInput(message.content); - } - - // copy to clipboard - if (selectOrCopy(e.currentTarget, message.content)) { - e.preventDefault(); - } - }; - - const onResend = (botIndex: number) => { - // find last user input message and resend - for (let i = botIndex; i >= 0; i -= 1) { - if (messages[i].role === "user") { - setIsLoading(true); - chatStore - .onUserInput(messages[i].content) - .then(() => setIsLoading(false)); - inputRef.current?.focus(); - return; - } - } - }; - - // for auto-scroll - const latestMessageRef = useRef(null); - - // wont scroll while hovering messages - const [autoScroll, setAutoScroll] = useState(false); - - // preview messages - const messages = (session.messages as RenderMessage[]) - .concat( - isLoading - ? [ - { - role: "assistant", - content: "……", - date: new Date().toLocaleString(), - preview: true, - }, - ] - : [] - ) - .concat( - userInput.length > 0 - ? [ - { - role: "user", - content: userInput, - date: new Date().toLocaleString(), - preview: true, - }, - ] - : [] - ); - - // auto scroll - useLayoutEffect(() => { - setTimeout(() => { - const dom = latestMessageRef.current; - if (dom && !isIOS() && autoScroll) { - dom.scrollIntoView({ - block: "end", - }); - } - }, 500); - }); - - return ( -
-
-
-
{ - const newTopic = prompt(Locale.Chat.Rename, session.topic); - if (newTopic && newTopic !== session.topic) { - chatStore.updateCurrentSession( - (session) => (session.topic = newTopic!) - ); - } - }} - > - {session.topic} -
-
- {Locale.Chat.SubTitle(session.messages.length)} -
-
-
-
- } - bordered - title={Locale.Chat.Actions.ChatList} - onClick={props?.showSideBar} - /> -
-
- } - bordered - title={Locale.Chat.Actions.CompressedHistory} - onClick={() => { - showMemoryPrompt(session); - }} - /> -
-
- } - bordered - title={Locale.Chat.Actions.Export} - onClick={() => { - exportMessages(session.messages, session.topic); - }} - /> -
-
-
- -
- {messages.map((message, i) => { - const isUser = message.role === "user"; - - return ( -
-
-
- -
- {(message.preview || message.streaming) && ( -
- {Locale.Chat.Typing} -
- )} -
- {!isUser && - !(message.preview || message.content.length === 0) && ( -
- {message.streaming ? ( -
onUserStop(i)} - > - {Locale.Chat.Actions.Stop} -
- ) : ( -
onResend(i)} - > - {Locale.Chat.Actions.Retry} -
- )} - -
copyToClipboard(message.content)} - > - {Locale.Chat.Actions.Copy} -
-
- )} - {(message.preview || message.content.length === 0) && - !isUser ? ( - - ) : ( -
onRightClick(e, message)} - > - -
- )} -
- {!isUser && !message.preview && ( -
-
- {message.date.toLocaleString()} -
-
- )} -
-
- ); - })} -
- - -
-
- -
- -
-