@chaibuilder/sdk 4.0.0-beta.44 → 4.0.0-beta.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{2SSKDMRQ-BrCeJE2w.js → 2SSKDMRQ-B6pWs8Zk.js} +2 -2
- package/dist/{2SSKDMRQ-BKWkM_6d.cjs → 2SSKDMRQ-B7Va8HeK.cjs} +1 -1
- package/dist/{AP7HFJJL-CskLuLc8.js → AP7HFJJL-CNIRZpP-.js} +1 -1
- package/dist/{AP7HFJJL-vt0XlZqG.cjs → AP7HFJJL-Xv13XYXE.cjs} +1 -1
- package/dist/{IconPicker-BJ6a_dl-.js → IconPicker-CGtjTiWr.js} +1 -1
- package/dist/{WDYDFRGG-BN61b01J.js → WDYDFRGG-5Lwxhw_-.js} +2 -2
- package/dist/{WDYDFRGG-Nw-WmjVB.cjs → WDYDFRGG-zZ8jN8rF.cjs} +1 -1
- package/dist/{actions-registery-CMKfEXxX.js → actions-registery-B1VeX52Y.js} +1565 -1529
- package/dist/{actions-registery-CqhNZFV3.cjs → actions-registery-BQ31lpix.cjs} +19 -19
- package/dist/actions.cjs +1 -1
- package/dist/actions.d.ts +132 -0
- package/dist/actions.js +7 -6
- package/dist/{active-in-another-tab-DHTYNRjQ.cjs → active-in-another-tab-C8FXtXk5.cjs} +1 -1
- package/dist/{active-in-another-tab-CZHN4gdI.js → active-in-another-tab-HtM97aRN.js} +4 -4
- package/dist/{add-new-language-page-DUm56cDk.cjs → add-new-language-page-gbvPI58M.cjs} +1 -1
- package/dist/{add-new-language-page-J0FxQGri.js → add-new-language-page-x88_n8EW.js} +3 -3
- package/dist/{add-new-page-B4dH-sG6.js → add-new-page-BMSePgKl.js} +2 -2
- package/dist/{add-new-page-D0H-HGrE.cjs → add-new-page-CPB4yhqv.cjs} +1 -1
- package/dist/{ai-panel-default-lang-BHzxr8XE.cjs → ai-panel-default-lang-DKGh1pbz.cjs} +2 -2
- package/dist/{ai-panel-default-lang-DrKTSHgh.js → ai-panel-default-lang-Dav6FRUY.js} +10 -10
- package/dist/{ai-panel-other-lang-CMs97ftp.js → ai-panel-other-lang-CdFx2x23.js} +14 -14
- package/dist/{ai-panel-other-lang-B6cRPiU9.cjs → ai-panel-other-lang-DdDn2I8h.cjs} +1 -1
- package/dist/ai-prompt-input-B8SFfk6N.cjs +1 -0
- package/dist/ai-prompt-input-bleYNRnH.js +650 -0
- package/dist/{ai-translation-prompt-Ddum5Ge5.cjs → ai-translation-prompt-DGrNA2Od.cjs} +1 -1
- package/dist/{ai-translation-prompt-BfJry6ZR.js → ai-translation-prompt-DvHdOZ6t.js} +1 -1
- package/dist/{change-password-modal-C4ngPnKd.js → change-password-modal-C9afEHLW.js} +4 -4
- package/dist/{change-password-modal-UTKwQzI4.cjs → change-password-modal-bce5bF3K.cjs} +1 -1
- package/dist/{code-editor-LNL_FEZ0.js → code-editor-BfGHceIq.js} +1 -1
- package/dist/{continue-editing-in-this-client-rjJy4-cq.cjs → continue-editing-in-this-client-4bvChAL-.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-CuBlXJb6.js → continue-editing-in-this-client-BFptv8tA.js} +2 -2
- package/dist/core.js +18 -18
- package/dist/{css-import-modal-ChRsUOVa.js → css-import-modal-CEQccCmc.js} +1 -1
- package/dist/{delete-page-BegGYX7_.js → delete-page-8h4dNP7d.js} +2 -2
- package/dist/{delete-page-BaJ0oesv.cjs → delete-page-BOxoMgyl.cjs} +1 -1
- package/dist/{design-token-usage-Bgphgz_u.js → design-token-usage-CVPBTF21.js} +8 -8
- package/dist/{digital-asset-manager-BPy9RYlx.js → digital-asset-manager-83B0Y6L-.js} +3 -3
- package/dist/{digital-asset-manager-uzOuwVMR.cjs → digital-asset-manager-JtBK07Ob.cjs} +1 -1
- package/dist/{duplicate-page-n6osptll.js → duplicate-page-DIa59iDe.js} +12 -12
- package/dist/{duplicate-page-BofwxP4t.cjs → duplicate-page-DVqC24Rd.cjs} +1 -1
- package/dist/{dynamic-page-selector-6EWhAHX0.js → dynamic-page-selector-C9vYslOg.js} +12 -12
- package/dist/{dynamic-page-selector-CVI1LwdD.cjs → dynamic-page-selector-YRCRqWlz.cjs} +1 -1
- package/dist/{image-editor-D1euq0rl.js → image-editor-CzxSXo-u.js} +1 -1
- package/dist/index-DXBHjFwY.cjs +5 -0
- package/dist/{index-fxuo68Am.js → index-DlTEPwjW.js} +1344 -1289
- package/dist/{index-fThd1uce.js → index-RwAuF_BE.js} +39 -39
- package/dist/{json-diff-viewer-B2Q7bs-U.cjs → json-diff-viewer-Bpsk0toO.cjs} +1 -1
- package/dist/{json-diff-viewer-C0kg3Rss.js → json-diff-viewer-is2P3TOV.js} +6 -6
- package/dist/{lang-panel-MB00AgoJ.cjs → lang-panel-BI5OFsBY.cjs} +1 -1
- package/dist/{lang-panel-DgDlmKaN.js → lang-panel-DwiCJRs9.js} +22 -22
- package/dist/{manage-design-tokens-nTmzLQyq.js → manage-design-tokens-D2Oz-jVp.js} +2 -2
- package/dist/{manage-design-tokens-modal-ayqKkRLc.js → manage-design-tokens-modal-ZR8PuhWC.js} +2 -2
- package/dist/{mark-as-template-BARMivkY.js → mark-as-template-C0Z2P_UF.js} +2 -2
- package/dist/{mark-as-template-CProQdMy.cjs → mark-as-template-muKJE1gk.cjs} +1 -1
- package/dist/{models-D95ZYr_x.js → models-BCu-p_QK.js} +4 -4
- package/dist/{models-5gOsRC56.cjs → models-D0RH2u4C.cjs} +1 -1
- package/dist/{nested-path-selector-content-DxW18z33.js → nested-path-selector-content-Ct80kFX-.js} +1 -1
- package/dist/{no-language-page-content-CB_UK8pU.js → no-language-page-content-BekrmPc5.js} +4 -4
- package/dist/{no-language-page-content-C2Q-PlyR.cjs → no-language-page-content-zn3891M8.cjs} +1 -1
- package/dist/{no-language-page-dialog-DsZDAaRd.js → no-language-page-dialog-dHlAqLlU.js} +2 -2
- package/dist/{no-language-page-dialog-B7SNu92-.cjs → no-language-page-dialog-wEXIlBuQ.cjs} +1 -1
- package/dist/{page-creator-CulX1J10.js → page-creator-6L7ehzhL.js} +4 -4
- package/dist/page-creator-CN2phGn5.cjs +1 -0
- package/dist/{page-lock-DbH7spVl.js → page-lock-C--D8qD7.js} +2 -2
- package/dist/{page-lock-BQr6vqz-.cjs → page-lock-DllloCJE.cjs} +1 -1
- package/dist/{page-locked-dialog-BgaqVH5J.js → page-locked-dialog-BD8LHbdC.js} +15 -15
- package/dist/{page-locked-dialog-B3ZmWOt_.cjs → page-locked-dialog-DzB8p0wl.cjs} +1 -1
- package/dist/{page-manager-new-ydVnl9s6.cjs → page-manager-new-DyjhsvPx.cjs} +1 -1
- package/dist/{page-manager-new-DNBm5H5A.js → page-manager-new-uFcGaZZY.js} +29 -29
- package/dist/{page-manager-search-and-filter-jYP_ub36.js → page-manager-search-and-filter-DK883UmG.js} +26 -26
- package/dist/{page-manager-search-and-filter-BhBT7qY0.cjs → page-manager-search-and-filter-zfR5i_GU.cjs} +1 -1
- package/dist/{page-revisions-content-ZOroDtgV.cjs → page-revisions-content-Bi2ehMnj.cjs} +1 -1
- package/dist/{page-revisions-content-YGYK8pv9.js → page-revisions-content-D3rIJj9X.js} +24 -24
- package/dist/pages.cjs +1 -1
- package/dist/pages.d.ts +2 -0
- package/dist/pages.js +24 -23
- package/dist/{publish-pages-content-Du3LgWM2.cjs → publish-pages-content-BQUHNRCX.cjs} +1 -1
- package/dist/{publish-pages-content-BgdFWGKT.js → publish-pages-content-ByPf4lvE.js} +23 -23
- package/dist/{rte-widget-modal-B7wA8UGi.js → rte-widget-modal-Tj_pS3ql.js} +1 -1
- package/dist/{save-to-lib-hHRxVrjy.js → save-to-lib-CcUqS0s1.js} +62 -62
- package/dist/{save-to-lib-Dxisxuo9.cjs → save-to-lib-Cyeqcelv.cjs} +1 -1
- package/dist/{selected-block-display-5hDghITH.cjs → selected-block-display-Benbb_OW.cjs} +1 -1
- package/dist/{selected-block-display-BNX9ZuNH.js → selected-block-display-C6LxDm0H.js} +11 -11
- package/dist/{seo-panel-CBEV-Nds.js → seo-panel-1U9Q0Ato.js} +25 -25
- package/dist/{seo-panel-C1DEkfcC.cjs → seo-panel-CCuvQpwV.cjs} +1 -1
- package/dist/{shared-json-ld-4o0YbV25.js → shared-json-ld-DbzUITto.js} +46 -46
- package/dist/{shared-json-ld-DuXm_88W.cjs → shared-json-ld-bj77fq_b.cjs} +1 -1
- package/dist/{slug-input-DE-a4dMb.js → slug-input-P-CLfUrw.js} +1 -1
- package/dist/supabase-actions.cjs +1 -1
- package/dist/supabase-actions.d.ts +4 -7
- package/dist/supabase-actions.js +1 -1
- package/dist/{take-over-request-WL-btbiZ.js → take-over-request-Bwj_2nPR.js} +5 -5
- package/dist/{take-over-request-DR4RC8TT.cjs → take-over-request-R3HRgShm.cjs} +1 -1
- package/dist/{translation-warning-modal-Cef9OsyI.js → translation-warning-modal-BdkToZwn.js} +1 -1
- package/dist/{unmark-as-template-Dexn_9W7.cjs → unmark-as-template-BG882c_S.cjs} +1 -1
- package/dist/{unmark-as-template-D-5cQ61Q.js → unmark-as-template-DHDMooLZ.js} +2 -2
- package/dist/{unpublish-page-C-7RnGgj.js → unpublish-page-C4e_gIX8.js} +2 -2
- package/dist/{unpublish-page-C14PYuLT.cjs → unpublish-page-DudJ1znF.cjs} +1 -1
- package/dist/{unpublished-partials-modal-O0E8HViJ.js → unpublished-partials-modal-p_0N6V23.js} +1 -1
- package/dist/{web-preview-DOJ6E273.js → web-preview-BA08d7DN.js} +1 -1
- package/dist/{web-preview-CgKfKkdH.cjs → web-preview-MG0HZxgA.cjs} +1 -1
- package/package.json +1 -1
- package/dist/ai-panel-content-BV5Hzsso.js +0 -62
- package/dist/ai-panel-content-D0ugQDEu.cjs +0 -1
- package/dist/ai-prompt-input-MPIh7805.cjs +0 -1
- package/dist/ai-prompt-input-__vuJNRC.js +0 -652
- package/dist/index-Dh-fEHei.cjs +0 -5
- package/dist/page-creator-CnyQu1Te.cjs +0 -1
package/dist/actions.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./actions-registery-BQ31lpix.cjs"),h=s=>async o=>{const{apiKey:t,userId:u}=s;try{const i=o,{action:r,data:e}=i,n=a.getChaiAction(r);return n?n.validate(e)?(n.setContext({appId:t,userId:u}),await n.execute(e)):{error:`Validation failed: ${n.getValidationErrors(e)}`,code:"INVALID_REQUEST_DATA",status:400}:{error:`Action ${r} not found`,code:"ACTION_NOT_FOUND",status:404}}catch(i){return console.log("Error in builderApiHandler:",i),i instanceof a.ActionError?{error:i.message,code:i.code,status:i.status||400}:{error:"Something went wrong.",status:500}}},l={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"};exports.ChaiActionsRegistry=a.actionsRegistery;exports.PublishChangesAction=a.PublishChangesAction;exports.db=a.db;exports.getAskAiSystemPrompt=a.getAskAiSystemPrompt;exports.safeQuery=a.safeQuery;exports.schema=a.schema;exports.LANGUAGES=l;exports.initChaiBuilderActionHandler=h;
|
package/dist/actions.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { PgColumn } from 'drizzle-orm/pg-core';
|
|
|
2
2
|
import { PgSequence } from 'drizzle-orm/pg-core';
|
|
3
3
|
import { PgTableWithColumns } from 'drizzle-orm/pg-core';
|
|
4
4
|
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
5
|
+
import { z } from 'zod';
|
|
5
6
|
|
|
6
7
|
declare const aiLogs: PgTableWithColumns< {
|
|
7
8
|
name: "ai_logs";
|
|
@@ -2522,6 +2523,56 @@ declare class ChaiActionsRegistry_2 {
|
|
|
2522
2523
|
getAllActions(): Record<string, ChaiAction<any, any>>;
|
|
2523
2524
|
}
|
|
2524
2525
|
|
|
2526
|
+
/**
|
|
2527
|
+
* Base Action Class
|
|
2528
|
+
* Provides common functionality for all action handlers
|
|
2529
|
+
*/
|
|
2530
|
+
declare abstract class ChaiBaseAction<T = any, K = any> implements ChaiAction<T, K> {
|
|
2531
|
+
protected context: ChaiActionContext | null;
|
|
2532
|
+
/**
|
|
2533
|
+
* Abstract method to get the validation schema for the action data
|
|
2534
|
+
* Each action must implement this to define its own validation rules
|
|
2535
|
+
*/
|
|
2536
|
+
protected abstract getValidationSchema(): z.ZodType<T>;
|
|
2537
|
+
/**
|
|
2538
|
+
* Validate the action data using the schema provided by getValidationSchema
|
|
2539
|
+
* @param data The data to validate
|
|
2540
|
+
* @returns true if the data is valid, false otherwise
|
|
2541
|
+
*/
|
|
2542
|
+
validate(data: T): boolean;
|
|
2543
|
+
/**
|
|
2544
|
+
* Get validation errors for the action data
|
|
2545
|
+
* This can be useful for debugging or providing more detailed error messages
|
|
2546
|
+
* @param data The data to validate
|
|
2547
|
+
* @returns An array of validation errors or null if the data is valid
|
|
2548
|
+
*/
|
|
2549
|
+
getValidationErrors(data: T): string | null;
|
|
2550
|
+
/**
|
|
2551
|
+
* Set the action context
|
|
2552
|
+
* @param context The context to set
|
|
2553
|
+
*/
|
|
2554
|
+
setContext(context: ChaiActionContext): void;
|
|
2555
|
+
/**
|
|
2556
|
+
* Abstract method to execute the action
|
|
2557
|
+
* Each action must implement this to define its own business logic
|
|
2558
|
+
*/
|
|
2559
|
+
abstract execute(data: T): Promise<any>;
|
|
2560
|
+
/**
|
|
2561
|
+
* Verify if the user has access to the app.
|
|
2562
|
+
* Delegates to the CHECK_USER_ACCESS action from the registry so that
|
|
2563
|
+
* callers can override the default access-check by registering a custom action.
|
|
2564
|
+
* Uses a dynamic import to avoid a circular module dependency at init time.
|
|
2565
|
+
* @throws ActionError if the user does not have access
|
|
2566
|
+
*/
|
|
2567
|
+
protected verifyAccess(): Promise<void>;
|
|
2568
|
+
/**
|
|
2569
|
+
* Helper method to handle common errors in actions
|
|
2570
|
+
* @param error The error to handle
|
|
2571
|
+
* @throws ActionError with appropriate message and code
|
|
2572
|
+
*/
|
|
2573
|
+
protected handleError(error: unknown): never;
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2525
2576
|
export declare const db: PostgresJsDatabase<typeof schema>;
|
|
2526
2577
|
|
|
2527
2578
|
declare type DbResult<T> = {
|
|
@@ -3017,6 +3068,87 @@ generated: undefined;
|
|
|
3017
3068
|
dialect: "pg";
|
|
3018
3069
|
}>;
|
|
3019
3070
|
|
|
3071
|
+
/**
|
|
3072
|
+
* Action to publish changes to pages or theme
|
|
3073
|
+
*/
|
|
3074
|
+
export declare class PublishChangesAction extends ChaiBaseAction<PublishChangesActionData, PublishChangesActionResponse> {
|
|
3075
|
+
private appId;
|
|
3076
|
+
private revisionsEnabled;
|
|
3077
|
+
/**
|
|
3078
|
+
* Define the validation schema for publish changes action
|
|
3079
|
+
*/
|
|
3080
|
+
protected getValidationSchema(): z.ZodObject<{
|
|
3081
|
+
ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
3082
|
+
revisions: z.ZodOptional<z.ZodBoolean>;
|
|
3083
|
+
}, z.core.$strip>;
|
|
3084
|
+
/**
|
|
3085
|
+
* Execute the publish changes action
|
|
3086
|
+
*/
|
|
3087
|
+
execute(data: PublishChangesActionData): Promise<PublishChangesActionResponse>;
|
|
3088
|
+
/**
|
|
3089
|
+
* Validate that context is properly set
|
|
3090
|
+
*/
|
|
3091
|
+
private validateContext;
|
|
3092
|
+
/**
|
|
3093
|
+
* Publish theme changes
|
|
3094
|
+
*/
|
|
3095
|
+
private publishTheme;
|
|
3096
|
+
/**
|
|
3097
|
+
* Publish design token changes
|
|
3098
|
+
*/
|
|
3099
|
+
private publishDesignToken;
|
|
3100
|
+
/**
|
|
3101
|
+
* Remove a specific key from the app's changes array.
|
|
3102
|
+
* Sets changes to null only if the array becomes empty after removal.
|
|
3103
|
+
*/
|
|
3104
|
+
private removeFromChangesArray;
|
|
3105
|
+
/**
|
|
3106
|
+
* Clone app data from main table
|
|
3107
|
+
*/
|
|
3108
|
+
private cloneApp;
|
|
3109
|
+
/**
|
|
3110
|
+
* Clear changes flag after publishing
|
|
3111
|
+
*/
|
|
3112
|
+
private clearChanges;
|
|
3113
|
+
/**
|
|
3114
|
+
* Get pages that use a partial block
|
|
3115
|
+
*/
|
|
3116
|
+
private getPartialBlockUsage;
|
|
3117
|
+
/**
|
|
3118
|
+
* Publish a single page
|
|
3119
|
+
*/
|
|
3120
|
+
private publishPage;
|
|
3121
|
+
/**
|
|
3122
|
+
* Create a revision before publishing
|
|
3123
|
+
*/
|
|
3124
|
+
private createRevision;
|
|
3125
|
+
/**
|
|
3126
|
+
* Add page to online table
|
|
3127
|
+
*/
|
|
3128
|
+
private addOnlinePage;
|
|
3129
|
+
/**
|
|
3130
|
+
* Clone page data from main table
|
|
3131
|
+
*/
|
|
3132
|
+
private clonePage;
|
|
3133
|
+
/**
|
|
3134
|
+
* Handle execution errors with proper error transformation
|
|
3135
|
+
*/
|
|
3136
|
+
private handleExecutionError;
|
|
3137
|
+
}
|
|
3138
|
+
|
|
3139
|
+
/**
|
|
3140
|
+
* Data type for PublishChangesAction
|
|
3141
|
+
*/
|
|
3142
|
+
declare type PublishChangesActionData = {
|
|
3143
|
+
ids?: string[];
|
|
3144
|
+
revisions?: boolean;
|
|
3145
|
+
};
|
|
3146
|
+
|
|
3147
|
+
declare type PublishChangesActionResponse = {
|
|
3148
|
+
tags: string[];
|
|
3149
|
+
paths: string[];
|
|
3150
|
+
};
|
|
3151
|
+
|
|
3020
3152
|
export declare function safeQuery<T>(queryFn: () => Promise<T>): Promise<DbResult<T>>;
|
|
3021
3153
|
|
|
3022
3154
|
declare namespace schema {
|
package/dist/actions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as u, A as h } from "./actions-registery-
|
|
2
|
-
import { a as b,
|
|
1
|
+
import { g as u, A as h } from "./actions-registery-B1VeX52Y.js";
|
|
2
|
+
import { a as b, P as y, d as A, b as S, s as v, c as w } from "./actions-registery-B1VeX52Y.js";
|
|
3
3
|
const c = (r) => async (s) => {
|
|
4
4
|
const { apiKey: o, userId: t } = r;
|
|
5
5
|
try {
|
|
@@ -208,9 +208,10 @@ const c = (r) => async (s) => {
|
|
|
208
208
|
export {
|
|
209
209
|
b as ChaiActionsRegistry,
|
|
210
210
|
d as LANGUAGES,
|
|
211
|
-
y as
|
|
212
|
-
A as
|
|
211
|
+
y as PublishChangesAction,
|
|
212
|
+
A as db,
|
|
213
|
+
S as getAskAiSystemPrompt,
|
|
213
214
|
c as initChaiBuilderActionHandler,
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
v as safeQuery,
|
|
216
|
+
w as schema
|
|
216
217
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-DrzR7vXl.cjs"),s=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-DrzR7vXl.cjs"),s=require("./index-DXBHjFwY.cjs"),n=require("lucide-react"),l=require("react-i18next"),o=()=>{const r=s.useSendRealtimeEvent(),{setPageStatus:i}=s.usePageLockStatus(),{t:a}=l.useTranslation();return e.jsx(s.BlurContainer,{children:e.jsxs(t.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(t.CardHeader,{className:"space-y-1",children:e.jsxs(t.CardTitle,{className:"flex items-center gap-2 text-xl font-medium",children:[e.jsx(n.TableIcon,{className:"h-6 w-6 text-green-500"}),e.jsx("span",{children:a("Active in Another Tab")})]})}),e.jsx(t.CardContent,{className:"space-y-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:a("This page is currently being edited in another tab. You can continue editing here, which will close the editor in the other tab.")})}),e.jsx(t.CardFooter,{className:"flex justify-end gap-2",children:e.jsxs(c.Button,{variant:"default",onClick:()=>{r(s.EVENT.CONTINUE_EDITING_IN_THIS_TAB_REQUEST),i(s.PAGE_STATUS.CHECKING)},className:"gap-2",children:[e.jsx(n.Edit,{className:"h-4 w-4"}),a("Continue Editing Here")]})})]})})};exports.default=o;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as e, jsxs as t } from "react/jsx-runtime";
|
|
2
2
|
import { B as r } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { J as i, K as o, M as l, O as c, Q as d } from "./index-RwAuF_BE.js";
|
|
4
|
+
import { al as m, a as h, B as u, E as p, P as N } from "./index-DlTEPwjW.js";
|
|
5
5
|
import { TableIcon as f, Edit as T } from "lucide-react";
|
|
6
6
|
import { useTranslation as E } from "react-i18next";
|
|
7
7
|
const b = () => {
|
|
8
|
-
const s =
|
|
8
|
+
const s = m(), { setPageStatus: n } = h(), { t: a } = E();
|
|
9
9
|
return /* @__PURE__ */ e(u, { children: /* @__PURE__ */ t(i, { className: "mx-auto w-full max-w-md", children: [
|
|
10
10
|
/* @__PURE__ */ e(o, { className: "space-y-1", children: /* @__PURE__ */ t(l, { className: "flex items-center gap-2 text-xl font-medium", children: [
|
|
11
11
|
/* @__PURE__ */ e(f, { className: "h-6 w-6 text-green-500" }),
|
|
@@ -14,7 +14,7 @@ const b = () => {
|
|
|
14
14
|
/* @__PURE__ */ e(c, { className: "space-y-4", children: /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a(
|
|
15
15
|
"This page is currently being edited in another tab. You can continue editing here, which will close the editor in the other tab."
|
|
16
16
|
) }) }),
|
|
17
|
-
/* @__PURE__ */ e(
|
|
17
|
+
/* @__PURE__ */ e(d, { className: "flex justify-end gap-2", children: /* @__PURE__ */ t(
|
|
18
18
|
r,
|
|
19
19
|
{
|
|
20
20
|
variant: "default",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),k=require("./register-chai-top-bar-DyW9GPzV.cjs"),N=require("./index-DrzR7vXl.cjs"),Y=require("./slug-input-BvIplRdd.cjs"),g=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),k=require("./register-chai-top-bar-DyW9GPzV.cjs"),N=require("./index-DrzR7vXl.cjs"),Y=require("./slug-input-BvIplRdd.cjs"),g=require("./index-DXBHjFwY.cjs"),j=require("lodash-es"),ds=require("lucide-react"),v=require("react"),U=require("react-i18next"),Z=({edit:c,lang:h,languages:a,name:u,setLang:t,setName:i,primaryPageObject:o})=>{const{t:s}=U.useTranslation();return e.jsxs("div",{className:"space-y-1",children:[e.jsx(N.Label,{htmlFor:"lang",children:s("Language")}),e.jsxs("select",{value:c?"":h,disabled:c||!a.length,onChange:l=>{const x=l.target.value;t(x),!c&&(j.startsWith(u,o==null?void 0:o.name)||u.length===0)&&i(`${o==null?void 0:o.name} - ${g.LANGUAGES[x]}`)},className:"col-span-3 flex h-9 w-full rounded-md border border-border bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",children:[e.jsx("option",{value:"",disabled:!0,children:c?g.LANGUAGES[h]||h:a.length?s("Choose language"):s("All available language page is created.")}),a.map(l=>e.jsx("option",{value:l,children:g.LANGUAGES[l]||l},l))]})]})},_=({lang:c,name:h,setName:a,parentHasSelectedLanguagePage:u})=>{const{t}=U.useTranslation();return e.jsxs("div",{className:"space-y-1",children:[e.jsx(N.Label,{htmlFor:"name",children:t("Page Name")}),e.jsx(k.Input,{id:"name",value:c?h:"",onChange:i=>a(i.target.value),required:!0,placeholder:t(c?"Enter page name":"Choose language to add slug"),disabled:!u||!c})]})},cs=({dynamic:c,isNonSlugPageType:h,isRootPage:a,lang:u,useLanguagePrefix:t,setUseLanguagePrefix:i,isHomePage:o,parentSlug:s,parentHasSelectedLanguagePage:l,slug:x,setSlug:d,setIsSlugValid:S,getSlug:f})=>{const{t:r}=U.useTranslation();return h?null:e.jsxs("div",{className:"space-y-1",children:[a&&u&&e.jsxs("div",{className:"flex items-center space-x-2 pb-1",children:[e.jsx("input",{type:"checkbox",id:"useLanguagePrefix",checked:t,onChange:A=>i(A.target.checked),className:"rounded border-gray-300"}),e.jsxs(N.Label,{htmlFor:"useLanguagePrefix",className:"text-sm font-normal leading-tight",children:["Add language code (",e.jsxs("span",{className:"font-mono text-gray-900",children:["/",u]}),") as slug prefix"]})]}),e.jsx(N.Label,{htmlFor:"slug",children:r("Slug")}),c?e.jsx(k.Alert,{variant:"default",className:"p-2 text-xs font-medium italic text-muted-foreground",children:r("This page will use dynamic slug as defined in primary page")}):e.jsx(Y.SlugInput,{disabled:!u||!l,value:x,onChange:d,placeholder:r(u?o&&t?"Leave empty for home page":"Enter page slug":"Choose language to add slug"),parentSlug:s,onValidationChange:S,fullSlug:f()})]})},H=({parentHasSelectedLanguagePage:c,name:h,lang:a,slug:u,edit:t,id:i,primaryPageObject:o,pages:s,isNonSlugPageType:l,isHomePage:x,useLanguagePrefix:d,isSlugValid:S,isPending:f})=>{const{t:r}=U.useTranslation(),A=f||!h||!a||s.some(m=>(t?m.id!==i:!0)&&m.parent===(o==null?void 0:o.id)&&m.lang===a)||!l&&!(x&&d)&&(!S||!u);return e.jsx(N.DialogFooter,{children:c?e.jsxs(e.Fragment,{children:[e.jsx(k.Button,{type:"submit",disabled:A&&!o.dynamic,children:f?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"loader mr-2"}),r(t?"Updating...":"Adding...")]}):r(t?"Update":"Add new language page")}),s.some(m=>(t?m.id!==i:!0)&&m.parent===(o==null?void 0:o.id)&&m.lang===a)&&e.jsx("p",{className:"mt-2 text-xs text-red-500",children:r("A page for this language already exists.")})]}):a&&e.jsx(k.Alert,{variant:"destructive",children:e.jsxs("p",{className:"mx-auto w-5/6 text-center",children:[r("You need to create the")," ",e.jsx("span",{className:"font-medium",children:g.LANGUAGES[a]})," ",r("page in the parent to add here.")]})})})},rs=({onSubmit:c,edit:h,lang:a,languages:u,name:t,setLang:i,setName:o,primaryPageObject:s,parentHasSelectedLanguagePage:l,id:x,pages:d,isNonSlugPageType:S,isHomePage:f,useLanguagePrefix:r,slug:A,isSlugValid:m,isPending:p})=>e.jsxs("form",{onSubmit:c,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(Z,{edit:h,lang:a,languages:u,name:t,setLang:i,setName:o,primaryPageObject:s}),e.jsx(_,{lang:a,name:t,setName:o,parentHasSelectedLanguagePage:l})]}),e.jsx(H,{parentHasSelectedLanguagePage:l,name:t,lang:a,slug:A,edit:h,id:x,primaryPageObject:s,pages:d,isNonSlugPageType:S,isHomePage:f,useLanguagePrefix:r,isSlugValid:m,isPending:p})]}),hs=({loading:c,onSubmit:h,edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l,parentHasSelectedLanguagePage:x,isNonSlugPageType:d,isRootPage:S,useLanguagePrefix:f,setUseLanguagePrefix:r,isHomePage:A,parentSlug:m,slug:p,setSlug:C,isSlugValid:T,setIsSlugValid:I,getSlug:M,isPending:$,id:q,pages:L})=>c?e.jsx("div",{className:"flex h-80 items-center justify-center",children:e.jsx(ds.Loader,{className:"animate-spin"})}):d?e.jsx(rs,{onSubmit:h,edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l,parentHasSelectedLanguagePage:x,id:q,pages:L,isNonSlugPageType:d,isHomePage:A,useLanguagePrefix:f,slug:p,isSlugValid:T,isPending:$}):e.jsxs("form",{onSubmit:h,children:[e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsx(Z,{edit:a,lang:u,languages:t,name:i,setLang:o,setName:s,primaryPageObject:l}),e.jsx(_,{lang:u,name:i,setName:s,parentHasSelectedLanguagePage:x}),e.jsx(cs,{dynamic:l==null?void 0:l.dynamic,isNonSlugPageType:d,isRootPage:S,lang:u,useLanguagePrefix:f,setUseLanguagePrefix:r,isHomePage:A,parentSlug:m,parentHasSelectedLanguagePage:x,slug:p,setSlug:C,isSlugValid:T,setIsSlugValid:I,getSlug:M})]}),e.jsx(H,{parentHasSelectedLanguagePage:x,name:i,lang:u,slug:p,edit:a,id:q,primaryPageObject:l,pages:L,isNonSlugPageType:d,isHomePage:A,useLanguagePrefix:f,isSlugValid:T,isPending:$})]}),xs=({id:c,isOpen:h,onClose:a,primaryPage:u,edit:t=!1,preselectedLang:i})=>{const{data:o=[]}=g.useWebsitePrimaryPages(),s=v.useMemo(()=>o.find(n=>n.id===u),[o,u]),[l,x]=v.useState(""),[d,S]=v.useState(""),[f,r]=v.useState(""),[A,m]=v.useState(!0),[p,C]=v.useState(!0),{mutate:T,isPending:I}=g.useCreatePage(),{mutate:M,isPending:$}=g.useUpdatePage(),q=I||$,{data:L,isFetching:b}=g.useWebsiteSetting(),z=g.useFallbackLang(),{data:w,isFetching:y}=g.useLanguagePages(u),{data:F=[],isFetching:P}=g.useLanguagePages(s==null?void 0:s.parent),{data:J=[],isFetching:O}=g.usePageTypes(),{setSelectedLang:ss}=N.useLanguages(),{t:B}=U.useTranslation(),[,es]=g.useSearchParams(),[,ns]=N.useSidebarActivePanel(),ts=b||y||P||O,G=v.useMemo(()=>j.filter(L==null?void 0:L.languages,n=>!j.find(w,{lang:n})),[L,w]),W=v.useMemo(()=>J.find(n=>n.key===(s==null?void 0:s.pageType)),[J,s==null?void 0:s.pageType]),K=!(W!=null&&W.hasSlug),V=(s==null?void 0:s.slug)==="/";v.useEffect(()=>{if(!t&&s&&i&&(S(i),x(`${s.name} - ${g.LANGUAGES[i]}`)),!t||!s)return;const n=w==null?void 0:w.find(is=>is.id===c);if(!n)return;x(n.name),S(n.lang);const E=n.slug||"",{initSlug:R,prefix:us}=Y.parseSlugForEdit(E,s);r(R),C(us)},[t,c,w,s,i]),v.useEffect(()=>{if(i)S(i);else if((G==null?void 0:G.length)===1&&!t){const n=G[0];if(!n||!g.LANGUAGES[n])return;S(n),(!l||l===(s==null?void 0:s.name))&&x(`${s==null?void 0:s.name} - ${g.LANGUAGES[n]}`)}},[i,G,t,l,s]);const{parentSlug:Q,isRootPage:D}=v.useMemo(()=>{if(V||!d)return{parentSlug:void 0,isRootPage:!(s!=null&&s.parent)};if(!(s!=null&&s.parent))return{parentSlug:p?`/${d}`:void 0,isRootPage:!0};const n=F==null?void 0:F.find(E=>E.lang===d);return{parentSlug:n==null?void 0:n.slug,isRootPage:!1}},[s==null?void 0:s.parent,F,p,d,V]),os=v.useMemo(()=>D?!0:!!(F!=null&&F.some(n=>(n==null?void 0:n.lang)===d)),[d,F,D]),X=()=>{let n="";return D?n=`/${p?[d,f].filter(Boolean).join("/"):f}`:n=`${Y.removeSlugExtension(Q)}/${f}`,n.replace(/\/{2,}/g,"/").replace(/\/$/,"")},ls=n=>{const E=new URLSearchParams(window.location.search);z&&n===z?E.delete("lang"):E.set("lang",n),es(E),window.dispatchEvent(new PopStateEvent("popstate"))},as=n=>{n.preventDefault();const E={name:l,lang:d,primaryPage:s==null?void 0:s.id,slug:K?"":X(),pageType:s==null?void 0:s.pageType,...t&&{id:c}},R=()=>{!t&&d&&(ss(d),ls(d)),ns("outline"),a()};t?M(E,{onSuccess:R}):T(E,{onSuccess:R})};return e.jsx(N.Dialog,{open:h,onOpenChange:a,children:h&&e.jsxs(N.DialogContent,{className:"text-slate-600 sm:max-w-[425px]",children:[e.jsxs(N.DialogHeader,{children:[e.jsx(N.DialogTitle,{children:B(t?"Edit language":"Add new language page")}),e.jsx(N.DialogDescription,{className:"font-light",children:B("Enter the details for the language")})]}),e.jsx(hs,{id:c,pages:o,loading:ts,onSubmit:as,edit:t,lang:d,languages:G,name:l,setLang:S,setName:x,primaryPageObject:s,parentHasSelectedLanguagePage:os,isNonSlugPageType:K,isRootPage:D,useLanguagePrefix:p,setUseLanguagePrefix:C,isHomePage:V,parentSlug:Q,slug:f,setSlug:r,isSlugValid:A,setIsSlugValid:m,getSlug:X,isPending:q})]})})};exports.default=xs;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as t, jsxs as g, Fragment as hn } from "react/jsx-runtime";
|
|
2
2
|
import { z as fn, D as H, B as gn } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
|
-
import { d as mn, n as xn, D as vn, e as pn, f as Sn, g as Nn, o as Fn, p as I, q as wn } from "./index-
|
|
4
|
-
import { p as An, r as Cn, S as Dn } from "./slug-input-
|
|
5
|
-
import { e as En, f as $n, g as Ln, h as kn, i as Tn, j as Z, k as Un, c as Bn, L as A } from "./index-
|
|
3
|
+
import { d as mn, n as xn, D as vn, e as pn, f as Sn, g as Nn, o as Fn, p as I, q as wn } from "./index-RwAuF_BE.js";
|
|
4
|
+
import { p as An, r as Cn, S as Dn } from "./slug-input-P-CLfUrw.js";
|
|
5
|
+
import { e as En, f as $n, g as Ln, h as kn, i as Tn, j as Z, k as Un, c as Bn, L as A } from "./index-DlTEPwjW.js";
|
|
6
6
|
import { filter as Rn, find as Wn, startsWith as In } from "lodash-es";
|
|
7
7
|
import { Loader as qn } from "lucide-react";
|
|
8
8
|
import { useMemo as $, useState as L, useEffect as _ } from "react";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as e, jsxs as r } from "react/jsx-runtime";
|
|
2
|
-
import { D as t, e as c, f as m, g as p, o as h } from "./index-
|
|
2
|
+
import { D as t, e as c, f as m, g as p, o as h } from "./index-RwAuF_BE.js";
|
|
3
3
|
import { Suspense as f, lazy as D } from "react";
|
|
4
4
|
import { useTranslation as u } from "react-i18next";
|
|
5
|
-
const x = D(() => import("./page-creator-
|
|
5
|
+
const x = D(() => import("./page-creator-6L7ehzhL.js")), C = ({
|
|
6
6
|
addEditPage: o,
|
|
7
7
|
setAddEditPage: s,
|
|
8
8
|
closePanel: l
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DrzR7vXl.cjs"),c=require("react"),a=require("react-i18next"),u=c.lazy(()=>Promise.resolve().then(()=>require("./page-creator-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DrzR7vXl.cjs"),c=require("react"),a=require("react-i18next"),u=c.lazy(()=>Promise.resolve().then(()=>require("./page-creator-CN2phGn5.cjs"))),x=({addEditPage:n,setAddEditPage:r,closePanel:l})=>{const{t:o}=a.useTranslation(),t=!!(n!=null&&n.id),i=!!n;return e.jsx(s.Dialog,{open:i,onOpenChange:()=>r(void 0),children:i&&e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{children:[o(t?"Edit":"Add New")," "]}),e.jsx(s.DialogDescription,{children:o(t?"Update your page name":"Enter details to create a new page")})]}),e.jsx(c.Suspense,{fallback:e.jsx("div",{className:"min-h-40"}),children:e.jsx(u,{closePanel:l,addEditPage:n,close:()=>r(void 0)})})]})})};exports.default=x;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),S=require("./index-DrzR7vXl.cjs"),p=require("./selected-block-display-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),S=require("./index-DrzR7vXl.cjs"),p=require("./selected-block-display-Benbb_OW.cjs"),P=require("lucide-react"),j=require("react"),W=require("sonner"),F=require("./models-D0RH2u4C.cjs"),L=require("./apply-binding-CBSjMYSk.cjs"),O=require("@tanstack/react-query"),$=()=>{const{addPredefinedBlock:k}=S.useAddBlock(),N=S.useReplaceBlock(),y=S.useRemoveBlocks(),T=O.useQueryClient(),w=async(r,e)=>{if(!e)return;const s=L.getBlocksFromHTML(e);await k(s,r.parentId,r.position)},B=async(r,e)=>{if(!r.blockId||!e)return;const s=L.getBlocksFromHTML(e);await N(r.blockId,s)},I=async r=>{!r.ids||r.ids.length===0||await y(r.ids)};let d=null;const E=(r,e)=>{const s=document.getElementById("canvas-iframe");if(!s)return null;const u=s==null?void 0:s.contentDocument;if(!u)return null;u.querySelectorAll("[data-stream-canvas]").forEach(n=>n.remove());let o=null;if(r&&r!=="undefined"&&(o=u.querySelector(`[data-block-id="${r}"]`)),o||(o=u.body),!o)return null;if(d=u.createElement("div"),d.setAttribute("data-stream-canvas","true"),e!==void 0&&e>=0&&o.children){const n=Math.min(e,o.children.length);n<o.children.length?o.insertBefore(d,o.children[n]):o.appendChild(d)}else o.appendChild(d);return d},H=r=>{var o;const e=document.getElementById("canvas-iframe");if(!e)return null;const s=e==null?void 0:e.contentDocument;if(!s)return null;s.querySelectorAll("[data-stream-canvas]").forEach(n=>n.remove());const f=s.querySelector(`[data-block-id="${r}"]`);return f?(d=s.createElement("div"),d.setAttribute("data-stream-canvas","true"),(o=f.parentNode)==null||o.insertBefore(d,f.nextSibling),f.style.display="none",d):null},M=r=>{const e=document.getElementById("canvas-iframe");(e==null?void 0:e.contentWindow)&&r.scrollIntoView({behavior:"smooth",block:"end"})},v=(r,e,s)=>{const u=E(e,s);u&&(u.innerHTML=r,M(u))},x=(r,e)=>{const s=H(e);s&&(s.innerHTML=r,M(s))},D=r=>{const e=r.match(/^--ACTION=(.+)--$/);if(!e)return null;let u=e[1].replace(/--/g,"").split("|");const o={type:u[0]};return u.forEach(n=>{const t=n.trim();if(t.startsWith("PARENT=")){const A=t.substring(7);o.parentId=A==="undefined"?void 0:A}else t.startsWith("POS=")?o.position=parseInt(t.substring(4)):t.startsWith("ID=")?o.blockId=t.substring(3):t.startsWith("IDS=")&&(o.ids=t.substring(4).split(",").map(A=>A.trim()))}),o};return j.useCallback(async(r,e)=>{const s=new TextDecoder;let u="",f="",o=!1,n=null;const t={isInAction:!1,currentAction:null,htmlBuffer:"",isCapturingHtml:!1},A=async m=>{const i=m.trim();if(i==="--START--"){o=!0;return}if(o){if(i==="--END--"){t.currentAction&&(t.htmlBuffer||t.currentAction.type==="REMOVE")&&await C(t.currentAction,t.htmlBuffer),d&&(d.remove(),d=null);return}if(i.startsWith("--THINKING=")){const c=i.substring(11);e(l=>{const h=[...l],g=h[h.length-1];if(g&&g.role==="assistant"&&g.isReasoning)g.content=c,g.isStreaming=!1;else{const b={id:Date.now().toString(),role:"assistant",content:c,isReasoning:!0,isStreaming:!1};h.push(b)}return h});return}if(i.startsWith("--TASK=")){const c=i.substring(7),l=`task-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,h={id:l,role:"assistant",content:c.replace(/--$/,""),isTask:!0,isTaskLoading:!0,isTaskCompleted:!1};n=l,e(g=>[...g,h]);return}if(i.startsWith("--MSG=")){const c=i.substring(6),l={id:Date.now().toString(),role:"assistant",content:c.replace(/--$/g,""),isReasoning:!1,isStreaming:!1};e(h=>[...h,l]);return}if(i.startsWith("--ACTION=")){t.currentAction&&(t.htmlBuffer||t.currentAction.type==="REMOVE")&&await C(t.currentAction,t.htmlBuffer),t.currentAction=D(i),t.htmlBuffer="",t.isInAction=!0;return}if(i==="--ENDACTION--"){t.currentAction&&(t.htmlBuffer||t.currentAction.type==="REMOVE")&&await C(t.currentAction,t.htmlBuffer),n&&(e(c=>c.map(l=>l.isTask?{...l,isTaskCompleted:!0}:l)),n=null),t.currentAction=null,t.htmlBuffer="",t.isInAction=!1;return}if(i==="--HTML--"){t.isCapturingHtml=!0;return}if(i==="--ENDHTML--"){t.isCapturingHtml=!1;return}if(i.startsWith("--HTML--")&&i.includes("--ENDHTML--")){const c=i.match(/^--HTML--(.+?)--ENDHTML--$/);if(c&&t.currentAction){const l=c[1];t.htmlBuffer+=l,t.currentAction.type==="ADD"?v(t.htmlBuffer,t.currentAction.parentId,t.currentAction.position):t.currentAction.type==="EDIT"&&t.currentAction.blockId&&x(t.htmlBuffer,t.currentAction.blockId)}return}t.isCapturingHtml&&t.currentAction&&(t.htmlBuffer+=m+`
|
|
2
2
|
`,t.currentAction.type==="ADD"?v(t.htmlBuffer,t.currentAction.parentId,t.currentAction.position):t.currentAction.type==="EDIT"&&t.currentAction.blockId&&x(t.htmlBuffer,t.currentAction.blockId))}},C=async(m,i)=>{try{switch(m.type){case"ADD":await w(m,i);break;case"EDIT":await B(m,i);break;case"REMOVE":await I(m);break}e(c=>c.filter(l=>!l.isTask))}catch(c){console.log(c)}};try{for(;;){const{done:m,value:i}=await r.read();if(m)break;const c=s.decode(i,{stream:!0});u+=c,f+=c;const l=f.split(`
|
|
3
|
-
`);f=l.pop()||"";for(const h of l)await A(h)}f&&await A(f),T.invalidateQueries({queryKey:["AI_USAGE"]})}catch(m){console.log(m)}},[y])},V=j.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-
|
|
3
|
+
`);f=l.pop()||"";for(const h of l)await A(h)}f&&await A(f),T.invalidateQueries({queryKey:["AI_USAGE"]})}catch(m){console.log(m)}},[y])},V=j.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-B8SFfk6N.cjs"))),K=({t:k,fetch:N,input:y,messages:T,setInput:w,isLoading:B,setMessages:I,handleStop:d,setIsLoading:E,currentBlock:H,fallbackLang:M,setCurrentBlock:v,setAbortController:x,selectedModel:D=F.getDefaultModel().id,onModelChange:r})=>{const e=S.useSelectedBlock(),[,s]=S.useSelectedBlockIds(),u=S.useBlocksHtmlForAi(),f=$(),o=async(n,t,A,C)=>{var h;if(!n||B)return;v(e);const m=u(e?{blockId:e._id,additionalCoreBlocks:["Icon"]}:{additionalCoreBlocks:["Icon"]});if(e&&!m){W.toast.error(k("Something went wrong. Please try again."));return}const i={id:Date.now().toString(),role:"user",content:p.getUserPrompt({language:M,userInput:t||n,currentHtml:m}),userMessage:n},c={id:(Date.now()+1).toString(),role:"assistant",content:"",isReasoning:!0,isStreaming:!0};I(g=>[...g,i,c]),E(!0);const l=new AbortController;x(l);try{const g={messages:[i].map(q=>({role:q.role,content:q.content})),model:C||D};A&&(g.image=A);const b=await N({body:{action:"ASK_AI",data:g},streamResponse:!0});if(!b.ok)throw new Error(k("Failed to get AI response"));const R=(h=b.body)==null?void 0:h.getReader();if(!R)throw new Error(k("Response body is not readable"));await f(R,I)}catch(g){if(g.name!=="AbortError"){const b={id:(Date.now()+1).toString(),role:"assistant",content:k("Sorry, I encountered an error. Please try again.")};I(R=>[...R,b])}}finally{w(""),E(!1),v(null),x(null)}};return a.jsxs(a.Fragment,{children:[a.jsxs(p.Conversation,{className:"no-scrollbar",children:[a.jsxs(p.ConversationContent,{className:"gap-2 px-0",children:[T.length===0&&a.jsx(p.ConversationEmptyState,{icon:a.jsx(P.Bot,{size:48,className:"text-gray-300"}),title:"Start a conversation",description:k("Start a conversation with the AI assistant to add/edit current page")}),T.map(n=>n.role!=="system"&&a.jsx(j.Fragment,{children:n.isReasoning?a.jsxs(p.Reasoning,{isStreaming:n.isStreaming,defaultOpen:!0,children:[a.jsx(p.ReasoningTrigger,{className:"text-xs [&_p]:text-muted-foreground"}),a.jsx(p.ReasoningContent,{className:"p-0 text-xs",children:n.content})]}):n.isTask&&!n.isTaskCompleted?a.jsx(p.TaskMessage,{content:n.content,isLoading:n.isTaskLoading}):a.jsx(p.Message,{from:n.role,children:a.jsx(p.MessageContent,{className:"p-0",children:n.role==="assistant"?a.jsx(p.MessageResponse,{className:"p-0 text-xs",children:n.content}):a.jsx("div",{className:"p-0 text-xs",children:n.userMessage||n.content})})})},n.id))]}),a.jsx(p.ConversationScrollButton,{})]}),a.jsxs("div",{className:"border-gray-200 pb-2",children:[a.jsx(p.SelectedBlockDisplay,{onRemove:()=>s([]),isLoading:B}),a.jsx(j.Suspense,{fallback:a.jsx("div",{children:"Loading..."}),children:a.jsx(V,{input:y,setInput:w,onSend:o,onStop:d,isLoading:B,selectedLang:"",currentBlock:e||H,disabled:(y==null?void 0:y.length)===0,selectedModel:D,onModelChange:r})})]})]})};exports.default=K;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsxs as C, Fragment as W, jsx as d } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { C as
|
|
2
|
+
import { ab as F, ac as P, ad as O, r as $, a as q, ae as V } from "./index-RwAuF_BE.js";
|
|
3
|
+
import { C as K, a as _, b as j, R as G, c as z, d as Q, T as U, M as J, e as X, f as Y, h as Z, S as tt, i as et } from "./selected-block-display-C6LxDm0H.js";
|
|
4
4
|
import { Bot as nt } from "lucide-react";
|
|
5
5
|
import { useCallback as rt, Fragment as st, Suspense as ot, lazy as at } from "react";
|
|
6
6
|
import { toast as it } from "sonner";
|
|
7
|
-
import { g as ct } from "./models-
|
|
7
|
+
import { g as ct } from "./models-BCu-p_QK.js";
|
|
8
8
|
import { g as L } from "./apply-binding-vAuN-TGV.js";
|
|
9
9
|
import { useQueryClient as lt } from "@tanstack/react-query";
|
|
10
10
|
const ut = () => {
|
|
@@ -199,7 +199,7 @@ const ut = () => {
|
|
|
199
199
|
},
|
|
200
200
|
[k]
|
|
201
201
|
);
|
|
202
|
-
}, dt = at(() => import("./ai-prompt-input-
|
|
202
|
+
}, dt = at(() => import("./ai-prompt-input-bleYNRnH.js")), It = ({
|
|
203
203
|
t: A,
|
|
204
204
|
fetch: x,
|
|
205
205
|
input: k,
|
|
@@ -273,10 +273,10 @@ const ut = () => {
|
|
|
273
273
|
}
|
|
274
274
|
};
|
|
275
275
|
return /* @__PURE__ */ C(W, { children: [
|
|
276
|
-
/* @__PURE__ */ C(
|
|
277
|
-
/* @__PURE__ */ C(
|
|
276
|
+
/* @__PURE__ */ C(K, { className: "no-scrollbar", children: [
|
|
277
|
+
/* @__PURE__ */ C(_, { className: "gap-2 px-0", children: [
|
|
278
278
|
w.length === 0 && /* @__PURE__ */ d(
|
|
279
|
-
|
|
279
|
+
j,
|
|
280
280
|
{
|
|
281
281
|
icon: /* @__PURE__ */ d(nt, { size: 48, className: "text-gray-300" }),
|
|
282
282
|
title: "Start a conversation",
|
|
@@ -285,9 +285,9 @@ const ut = () => {
|
|
|
285
285
|
),
|
|
286
286
|
w.map(
|
|
287
287
|
(n) => n.role !== "system" && /* @__PURE__ */ d(st, { children: n.isReasoning ? /* @__PURE__ */ C(G, { isStreaming: n.isStreaming, defaultOpen: !0, children: [
|
|
288
|
-
/* @__PURE__ */ d(
|
|
289
|
-
/* @__PURE__ */ d(
|
|
290
|
-
] }) : n.isTask && !n.isTaskCompleted ? /* @__PURE__ */ d(
|
|
288
|
+
/* @__PURE__ */ d(z, { className: "text-xs [&_p]:text-muted-foreground" }),
|
|
289
|
+
/* @__PURE__ */ d(Q, { className: "p-0 text-xs", children: n.content })
|
|
290
|
+
] }) : n.isTask && !n.isTaskCompleted ? /* @__PURE__ */ d(U, { content: n.content, isLoading: n.isTaskLoading }) : /* @__PURE__ */ d(J, { from: n.role, children: /* @__PURE__ */ d(X, { className: "p-0", children: n.role === "assistant" ? /* @__PURE__ */ d(Y, { className: "p-0 text-xs", children: n.content }) : /* @__PURE__ */ d("div", { className: "p-0 text-xs", children: n.userMessage || n.content }) }) }) }, n.id)
|
|
291
291
|
)
|
|
292
292
|
] }),
|
|
293
293
|
/* @__PURE__ */ d(Z, {})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsxs as c, Fragment as $, jsx as t } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import { C as Y, a as Z, b as L, R as ee, c as te, d as ne, T as se, M as oe, e as ae, f as re, S as ie, g as ce } from "./selected-block-display-
|
|
2
|
+
import { r as G, a as H, s as Q, t as X } from "./index-RwAuF_BE.js";
|
|
3
|
+
import { C as Y, a as Z, b as L, R as ee, c as te, d as ne, T as se, M as oe, e as ae, f as re, S as ie, g as ce } from "./selected-block-display-C6LxDm0H.js";
|
|
4
4
|
import { Bot as le } from "lucide-react";
|
|
5
5
|
import { useRef as de, useEffect as ue, Suspense as B, lazy as v, Fragment as he } from "react";
|
|
6
6
|
import { useTranslation as me } from "react-i18next";
|
|
7
|
-
import { g as ge } from "./models-
|
|
8
|
-
const fe = v(() => import("./ai-translation-prompt-
|
|
7
|
+
import { g as ge } from "./models-BCu-p_QK.js";
|
|
8
|
+
const fe = v(() => import("./ai-translation-prompt-DvHdOZ6t.js")), pe = v(() => import("./ai-prompt-input-bleYNRnH.js")), xe = ({
|
|
9
9
|
fetch: A,
|
|
10
10
|
input: o,
|
|
11
11
|
messages: l,
|
|
@@ -43,7 +43,7 @@ const fe = v(() => import("./ai-translation-prompt-BfJry6ZR.js")), pe = v(() =>
|
|
|
43
43
|
blocks: S ? k() : k(r)
|
|
44
44
|
}),
|
|
45
45
|
userMessage: y || e || n("Translate the content")
|
|
46
|
-
},
|
|
46
|
+
}, q = {
|
|
47
47
|
id: (Date.now() + 1).toString(),
|
|
48
48
|
role: "assistant",
|
|
49
49
|
content: "Thinking...",
|
|
@@ -51,8 +51,8 @@ const fe = v(() => import("./ai-translation-prompt-BfJry6ZR.js")), pe = v(() =>
|
|
|
51
51
|
isStreaming: !0
|
|
52
52
|
};
|
|
53
53
|
d(!0);
|
|
54
|
-
const
|
|
55
|
-
O(
|
|
54
|
+
const z = new AbortController();
|
|
55
|
+
O(z), g((b) => [...b, w, q]), d(!0);
|
|
56
56
|
try {
|
|
57
57
|
const x = await A({ body: { action: "ASK_AI", data: {
|
|
58
58
|
messages: [w],
|
|
@@ -61,18 +61,18 @@ const fe = v(() => import("./ai-translation-prompt-BfJry6ZR.js")), pe = v(() =>
|
|
|
61
61
|
} }, streamResponse: !0 });
|
|
62
62
|
if (!x.ok)
|
|
63
63
|
throw new Error(n("Failed to get AI response"));
|
|
64
|
-
const R = (N = x.body) == null ? void 0 : N.getReader(),
|
|
64
|
+
const R = (N = x.body) == null ? void 0 : N.getReader(), U = new TextDecoder();
|
|
65
65
|
let s = "";
|
|
66
66
|
if (!R) throw new Error(n("Response body is not readable"));
|
|
67
67
|
for (; ; ) {
|
|
68
|
-
const { done:
|
|
69
|
-
if (
|
|
68
|
+
const { done: K, value: V } = await R.read();
|
|
69
|
+
if (K)
|
|
70
70
|
break;
|
|
71
|
-
const
|
|
72
|
-
s +=
|
|
71
|
+
const W = U.decode(V, { stream: !0 });
|
|
72
|
+
s += W, g((h) => (h[h.length - 1].content = s, [...h]));
|
|
73
73
|
}
|
|
74
|
-
const
|
|
75
|
-
F(
|
|
74
|
+
const J = JSON.parse(s == null ? void 0 : s.replace("```json", "").replace("```", ""));
|
|
75
|
+
F(J);
|
|
76
76
|
} catch {
|
|
77
77
|
u == null || u.abort();
|
|
78
78
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-DrzR7vXl.cjs"),s=require("./selected-block-display-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-DrzR7vXl.cjs"),s=require("./selected-block-display-Benbb_OW.cjs"),G=require("lucide-react"),o=require("react"),H=require("react-i18next"),Q=require("./models-D0RH2u4C.cjs"),X=o.lazy(()=>Promise.resolve().then(()=>require("./ai-translation-prompt-DGrNA2Od.cjs"))),Y=o.lazy(()=>Promise.resolve().then(()=>require("./ai-prompt-input-B8SFfk6N.cjs"))),Z=({fetch:v,input:a,messages:u,setInput:j,isLoading:c,handleStop:q,setMessages:y,setIsLoading:h,selectedLang:i,currentBlock:A,fallbackLang:P,abortController:x,setAbortController:E,setCurrentBlock:k,selectedModel:S=Q.getDefaultModel().id,onModelChange:M})=>{const{t:n}=H.useTranslation(),O=o.useRef(null),l=d.useSelectedBlock(),[,D]=d.useSelectedBlockIds(),T=d.useI18nBlocks(),I=d.useStreamMultipleBlocksProps(),C=()=>{var t;(t=O.current)==null||t.scrollIntoView({behavior:"smooth"})};o.useEffect(()=>{C()},[u,c]);const f=async(t,m,F)=>{var b;l&&k(l);const p=(t==null?void 0:t.toLowerCase())==="translate",R={id:Date.now().toString(),role:"user",content:s.getTranslationUserPrompt({fallbackLang:P,userInput:m||t,language:i,blocks:p?T():T(i)}),userMessage:m||t||n("Translate the content")},_={id:(Date.now()+1).toString(),role:"assistant",content:"Thinking...",isReasoning:!0,isStreaming:!0};h(!0);const z=new AbortController;E(z),y(w=>[...w,R,_]),h(!0);try{const N=await v({body:{action:"ASK_AI",data:{messages:[R],initiator:p?"TRANSLATE_CONTENT":"UPDATE_CONTENT",model:F||S}},streamResponse:!0});if(!N.ok)throw new Error(n("Failed to get AI response"));const B=(b=N.body)==null?void 0:b.getReader(),U=new TextDecoder;let r="";if(!B)throw new Error(n("Response body is not readable"));for(;;){const{done:K,value:V}=await B.read();if(K)break;const W=U.decode(V,{stream:!0});r+=W,y(g=>(g[g.length-1].content=r,[...g]))}const J=JSON.parse(r==null?void 0:r.replace("```json","").replace("```",""));I(J)}catch{x==null||x.abort()}finally{h(!1),j(""),k(null)}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(o.Suspense,{fallback:e.jsx("div",{children:n("Loading...")}),children:e.jsx(X,{isLoading:c,selectedBlock:l,selectedLang:i,onClick:f})})}),e.jsx(s.Conversation,{children:e.jsxs(s.ConversationContent,{className:"gap-4 px-0",children:[u.length===0&&e.jsx(s.ConversationEmptyState,{icon:e.jsx(G.Bot,{size:48,className:"text-gray-300"}),title:n("Start a conversation with the AI assistant to translate/edit your content"),description:n("Only content can be edited in secondary languages. To edit layout, styles and more, switch to the default language.")}),u.map(t=>t.role!=="system"&&e.jsx(o.Fragment,{children:t.isReasoning?e.jsxs(s.Reasoning,{isStreaming:t.isStreaming,defaultOpen:!0,children:[e.jsx(s.ReasoningTrigger,{className:"text-xs [&_p]:text-muted-foreground"}),e.jsx(s.ReasoningContent,{className:"p-0 text-xs",children:t.content})]}):t.isTask?e.jsx(s.TaskMessage,{content:t.content,isLoading:t.isTaskLoading}):e.jsx(s.Message,{from:t.role,children:e.jsx(s.MessageContent,{className:"p-0",children:t.role==="assistant"?e.jsx(s.MessageResponse,{className:"p-0 text-xs",children:t.content}):e.jsx("div",{className:"p-0 text-xs",children:t.userMessage||t.content})})})},t.id))]})}),e.jsxs("div",{className:"border-gray-200 pb-2",children:[e.jsx(s.SelectedBlockDisplay,{onRemove:()=>D([]),isLoading:c}),e.jsx(o.Suspense,{fallback:e.jsx("div",{children:n("Loading...")}),children:e.jsx(Y,{input:a,setInput:j,onSend:f,onStop:q,isLoading:c,selectedLang:i,currentBlock:l||A,disabled:(a==null?void 0:a.length)===0,selectedModel:S,onModelChange:M})})]})]})};exports.default=Z;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("./register-chai-top-bar-DyW9GPzV.cjs"),S=require("./index-DrzR7vXl.cjs"),W=require("class-variance-authority"),k=require("lucide-react"),te=require("nanoid"),c=require("react"),se=require("react-i18next"),L=require("./models-D0RH2u4C.cjs");function ne({className:t,...s}){return e.jsx("div",{"data-slot":"input-group",role:"group",className:b.cn("group/input-group shadow-xs relative flex w-full items-center rounded-md border border-input outline-none transition-[color,box-shadow] dark:bg-input/30","h-9 has-[>textarea]:h-auto","has-[>[data-align=inline-start]]:[&>input]:pl-2","has-[>[data-align=inline-end]]:[&>input]:pr-2","has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3","has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3","has-[[data-slot=input-group-control]:focus-visible]:ring-1 has-[[data-slot=input-group-control]:focus-visible]:ring-ring","has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",t),...s})}const re=W.cva("text-muted-foreground flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]","inline-end":"order-last pr-3 has-[>button]:mr-[-0.4rem] has-[>kbd]:mr-[-0.35rem]","block-start":"[.border-b]:pb-3 order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5","block-end":"[.border-t]:pt-3 order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5"}},defaultVariants:{align:"inline-start"}});function H({className:t,align:s="inline-start",...a}){return e.jsx("div",{role:"group","data-slot":"input-group-addon","data-align":s,className:b.cn(re({align:s}),t),onClick:l=>{var o,f;l.target.closest("button")||(f=(o=l.currentTarget.parentElement)==null?void 0:o.querySelector("input"))==null||f.focus()},...a})}const ae=W.cva("flex items-center gap-2 text-sm shadow-none",{variants:{size:{xs:"h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",sm:"h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5","icon-xs":"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0","icon-sm":"size-8 p-0 has-[>svg]:p-0"}},defaultVariants:{size:"xs"}});function K({className:t,type:s="button",variant:a="ghost",size:l="xs",...o}){return e.jsx(b.Button,{type:s,"data-size":l,variant:a,className:b.cn(ae({size:l}),t),...o})}function oe({className:t,...s}){return e.jsx(S.Textarea,{"data-slot":"input-group-control",className:b.cn("flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",t),...s})}const ie=c.createContext(null),ce=c.createContext(null),X=()=>c.useContext(ie),le=()=>c.useContext(ce),$=c.createContext(null),q=()=>{const t=le(),s=c.useContext($),a=t??s;if(!a)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return a};function ue({data:t,className:s,...a}){var u;const l=q(),o=t.filename||"",p=((u=t.mediaType)!=null&&u.startsWith("image/")&&t.url?"image":"file")==="image",x=o||(p?"Image":"Attachment");return e.jsxs(ye,{children:[e.jsx(S.HoverCardTrigger,{asChild:!0,children:e.jsxs("div",{className:b.cn("group relative flex h-8 cursor-default select-none items-center gap-1.5 rounded-md border border-border px-1.5 text-sm font-medium transition-all hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",s),...a,children:[e.jsxs("div",{className:"relative size-5 shrink-0",children:[e.jsx("div",{className:"absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",children:p?e.jsx("img",{alt:o||"attachment",className:"size-5 object-cover",height:20,src:t.url,width:20}):e.jsx("div",{className:"flex size-5 items-center justify-center text-muted-foreground",children:e.jsx(k.PaperclipIcon,{className:"size-3"})})}),e.jsxs(b.Button,{"aria-label":"Remove attachment",className:"absolute inset-0 size-5 cursor-pointer rounded p-0 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 [&>svg]:size-2.5",onClick:N=>{N.stopPropagation(),l.remove(t.id)},type:"button",variant:"ghost",children:[e.jsx(k.XIcon,{}),e.jsx("span",{className:"sr-only",children:"Remove"})]})]}),e.jsx("span",{className:"flex-1 truncate",children:x})]},t.id)}),e.jsx(Ie,{className:"w-auto p-2",children:e.jsxs("div",{className:"w-auto space-y-3",children:[p&&e.jsx("div",{className:"flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",children:e.jsx("img",{alt:o||"attachment preview",className:"max-h-full max-w-full object-contain",height:384,src:t.url,width:448})}),e.jsx("div",{className:"flex items-center gap-2.5",children:e.jsxs("div",{className:"min-w-0 flex-1 space-y-1 px-0.5",children:[e.jsx("h4",{className:"truncate text-sm font-semibold leading-none",children:o||(p?"Image":"Attachment")}),t.mediaType&&e.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:t.mediaType})]})})]})})]})}function de({children:t,className:s,...a}){const l=q();return l.files.length?e.jsx("div",{className:b.cn("flex flex-wrap items-center gap-2 p-3",s),...a,children:l.files.map(o=>e.jsx(c.Fragment,{children:t(o)},o.id))}):null}const pe=({label:t="Add photos or files",...s})=>{const a=q();return e.jsxs(S.DropdownMenuItem,{...s,onSelect:l=>{l.preventDefault(),a.openFileDialog()},children:[e.jsx(k.ImageIcon,{className:"mr-2 size-4"})," ",t]})},me=({className:t,accept:s,multiple:a,globalDrop:l,syncHiddenInput:o,maxFiles:f,maxFileSize:p,onError:x,onSubmit:u,children:N,...y})=>{const r=X(),i=!!r,g=c.useRef(null),P=c.useRef(null),I=c.useRef(null);c.useEffect(()=>{var v;const n=(v=P.current)==null?void 0:v.closest("form");n instanceof HTMLFormElement&&(I.current=n)},[]);const[D,z]=c.useState([]),h=i?r.attachments.files:D,A=c.useCallback(()=>{var n;(n=g.current)==null||n.click()},[]),M=c.useCallback(n=>!s||s.trim()===""?!0:s.includes("image/*")?n.type.startsWith("image/"):!0,[s]),U=c.useCallback(n=>{const v=Array.from(n),m=v.filter(w=>M(w));if(v.length&&m.length===0){x==null||x({code:"accept",message:"No files match the accepted types."});return}const d=w=>p?w.size<=p:!0,j=m.filter(d);if(m.length>0&&j.length===0){x==null||x({code:"max_file_size",message:"All files exceed the maximum size."});return}z(w=>{const C=typeof f=="number"?Math.max(0,f-w.length):void 0,ee=typeof C=="number"?j.slice(0,C):j;typeof C=="number"&&j.length>C&&(x==null||x({code:"max_files",message:"Too many files. Some were not added."}));const _=[];for(const E of ee)_.push({id:te.nanoid(),type:"file",url:URL.createObjectURL(E),mediaType:E.type,filename:E.name});return w.concat(_)})},[M,f,p,x]),T=i?n=>r.attachments.add(n):U,R=i?n=>r.attachments.remove(n):n=>z(v=>{const m=v.find(d=>d.id===n);return m!=null&&m.url&&URL.revokeObjectURL(m.url),v.filter(d=>d.id!==n)}),O=i?()=>r.attachments.clear():()=>z(n=>{for(const v of n)v.url&&URL.revokeObjectURL(v.url);return[]}),B=i?()=>r.attachments.openFileDialog():A;c.useEffect(()=>{i&&r.__registerFileInput(g,()=>{var n;return(n=g.current)==null?void 0:n.click()})},[i,r]),c.useEffect(()=>{o&&g.current&&h.length===0&&(g.current.value="")},[h,o]),c.useEffect(()=>{const n=I.current;if(!n)return;const v=d=>{var j,w;(w=(j=d.dataTransfer)==null?void 0:j.types)!=null&&w.includes("Files")&&d.preventDefault()},m=d=>{var j,w,C;(w=(j=d.dataTransfer)==null?void 0:j.types)!=null&&w.includes("Files")&&d.preventDefault(),(C=d.dataTransfer)!=null&&C.files&&d.dataTransfer.files.length>0&&T(d.dataTransfer.files)};return n.addEventListener("dragover",v),n.addEventListener("drop",m),()=>{n.removeEventListener("dragover",v),n.removeEventListener("drop",m)}},[T]),c.useEffect(()=>{if(!l)return;const n=m=>{var d,j;(j=(d=m.dataTransfer)==null?void 0:d.types)!=null&&j.includes("Files")&&m.preventDefault()},v=m=>{var d,j,w;(j=(d=m.dataTransfer)==null?void 0:d.types)!=null&&j.includes("Files")&&m.preventDefault(),(w=m.dataTransfer)!=null&&w.files&&m.dataTransfer.files.length>0&&T(m.dataTransfer.files)};return document.addEventListener("dragover",n),document.addEventListener("drop",v),()=>{document.removeEventListener("dragover",n),document.removeEventListener("drop",v)}},[T,l]),c.useEffect(()=>()=>{if(!i)for(const n of h)n.url&&URL.revokeObjectURL(n.url)},[i,h]);const Y=n=>{n.currentTarget.files&&T(n.currentTarget.files)},J=async n=>{const m=await(await fetch(n)).blob();return new Promise((d,j)=>{const w=new FileReader;w.onloadend=()=>d(w.result),w.onerror=j,w.readAsDataURL(m)})},Q=c.useMemo(()=>({files:h.map(n=>({...n,id:n.id})),add:T,remove:R,clear:O,openFileDialog:B,fileInputRef:g}),[h,T,R,O,B]),Z=n=>{n.preventDefault();const v=n.currentTarget,m=i?r.textInput.value:new FormData(v).get("message")||"";i||v.reset(),Promise.all(h.map(async({...d})=>d.url&&d.url.startsWith("blob:")?{...d,url:await J(d.url)}:d)).then(d=>{try{const j=u({text:m,files:d},n);j instanceof Promise?j.then(()=>{O(),i&&r.textInput.clear()}).catch(()=>{}):(O(),i&&r.textInput.clear())}catch{}})},G=e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"hidden",ref:P}),e.jsx("input",{accept:s,"aria-label":"Upload files",className:"hidden",multiple:a,onChange:Y,ref:g,title:"Upload files",type:"file"}),e.jsx("form",{className:b.cn("w-full",t),onSubmit:Z,...y,children:e.jsx(ne,{className:"overflow-hidden",children:N})})]});return i?G:e.jsx($.Provider,{value:Q,children:G})},fe=({onChange:t,className:s,placeholder:a="What would you like to know?",...l})=>{const o=X(),f=q(),[p,x]=c.useState(!1),u=r=>{if(r.key==="Enter"){if(p||r.nativeEvent.isComposing||r.shiftKey)return;r.preventDefault();const i=r.currentTarget.form,g=i==null?void 0:i.querySelector('button[type="submit"]');if(g!=null&&g.disabled)return;i==null||i.requestSubmit()}if(r.key==="Backspace"&&r.currentTarget.value===""&&f.files.length>0){r.preventDefault();const i=f.files.at(-1);i&&f.remove(i.id)}},N=r=>{var P;const i=(P=r.clipboardData)==null?void 0:P.items;if(!i)return;const g=[];for(const I of i)if(I.kind==="file"){const D=I.getAsFile();D&&g.push(D)}g.length>0&&(r.preventDefault(),f.add(g))},y=o?{value:o.textInput.value,onChange:r=>{o.textInput.setInput(r.currentTarget.value),t==null||t(r)}}:{onChange:t};return e.jsx(oe,{className:b.cn("field-sizing-content max-h-48 min-h-16",s),name:"message",onCompositionEnd:()=>x(!1),onCompositionStart:()=>x(!0),onKeyDown:u,onPaste:N,placeholder:a,...l,...y})},he=({className:t,...s})=>e.jsx(H,{align:"block-end",className:b.cn("order-first flex-wrap gap-1",t),...s}),xe=({className:t,...s})=>e.jsx(H,{align:"block-end",className:b.cn("justify-between gap-1",t),...s}),ge=({className:t,...s})=>e.jsx("div",{className:b.cn("flex items-center gap-1",t),...s}),F=({variant:t="ghost",className:s,size:a,...l})=>{const o=a??(c.Children.count(l.children)>1?"sm":"icon-sm");return e.jsx(K,{className:b.cn(s),size:o,type:"button",variant:t,...l})},ve=t=>e.jsx(S.DropdownMenu,{...t}),je=({className:t,children:s,...a})=>e.jsx(S.DropdownMenuTrigger,{asChild:!0,children:e.jsx(F,{className:t,...a,children:s??e.jsx(k.PlusIcon,{className:"size-4"})})}),be=({className:t,...s})=>e.jsx(S.DropdownMenuContent,{align:"start",className:b.cn(t),...s}),we=({className:t,variant:s="default",size:a="icon-sm",status:l,children:o,...f})=>{let p=e.jsx(k.CornerDownLeftIcon,{className:"size-4"});return l==="submitted"?p=e.jsx(k.Loader2Icon,{className:"size-4 animate-spin"}):l==="streaming"?p=e.jsx(k.SquareIcon,{className:"size-4"}):l==="error"&&(p=e.jsx(k.XIcon,{className:"size-4"})),e.jsx(K,{"aria-label":"Submit",className:b.cn(t),size:a,type:"submit",variant:s,...f,children:o??p})},Ne=({className:t,textareaRef:s,onTranscriptionChange:a,...l})=>{const[o,f]=c.useState(!1),[p,x]=c.useState(null),u=c.useRef(null);c.useEffect(()=>{if(typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)){const y=window.SpeechRecognition||window.webkitSpeechRecognition,r=new y;r.continuous=!0,r.interimResults=!0,r.lang="en-US",r.onstart=()=>{f(!0)},r.onend=()=>{f(!1)},r.onresult=i=>{var P;let g="";for(let I=i.resultIndex;I<i.results.length;I++){const D=i.results[I];D.isFinal&&(g+=((P=D[0])==null?void 0:P.transcript)??"")}if(g&&(s!=null&&s.current)){const I=s.current,D=I.value,z=D+(D?" ":"")+g;I.value=z,I.dispatchEvent(new Event("input",{bubbles:!0})),a==null||a(z)}},r.onerror=i=>{console.error("Speech recognition error:",i.error),f(!1)},u.current=r,c.startTransition(()=>x(r))}return()=>{u.current&&u.current.stop()}},[s,a]);const N=c.useCallback(()=>{p&&(o?p.stop():p.start())},[p,o]);return e.jsx(F,{className:b.cn("relative transition-all duration-200",o&&"animate-pulse bg-accent text-accent-foreground",t),disabled:!p,onClick:N,...l,children:e.jsx(k.MicIcon,{className:"size-4"})})},ye=({openDelay:t=0,closeDelay:s=0,...a})=>e.jsx(S.HoverCard,{closeDelay:s,openDelay:t,...a}),Ie=({align:t="start",...s})=>e.jsx(S.HoverCardContent,{align:t,...s}),Se=t=>e.jsx(S.Dialog,{...t}),ke=t=>e.jsx(S.DialogTrigger,{...t}),De=({className:t,children:s,title:a="Model Selector",...l})=>e.jsxs(S.DialogContent,{className:b.cn("p-0",t),...l,children:[e.jsx(S.DialogTitle,{className:"sr-only",children:a}),e.jsx(S.Command,{className:"**:data-[slot=command-input-wrapper]:h-auto",children:s})]}),Pe=t=>e.jsx(S.CommandList,{...t}),Te=t=>e.jsx(S.CommandGroup,{...t}),ze=t=>e.jsx(S.CommandItem,{...t}),Ae=({provider:t,className:s,...a})=>e.jsx("img",{...a,alt:`${t} logo`,className:b.cn("size-3 dark:invert",s),height:12,src:`https://models.dev/logos/${t}.svg`,width:12}),Ce=({className:t,...s})=>e.jsx("span",{className:b.cn("flex-1 truncate text-left",t),...s}),Re=({selectedModel:t,onModelChange:s,disabled:a=!1})=>{const[l,o]=c.useState(!1),f=L.getModelById(t)||L.getDefaultModel(),p=L.AI_MODELS.reduce((u,N)=>(u[N.provider]||(u[N.provider]=[]),u[N.provider].push(N),u),{}),x=u=>{s(u),o(!1)};return e.jsxs(Se,{open:l,onOpenChange:o,children:[e.jsx(ke,{asChild:!0,children:e.jsxs(b.Button,{variant:"outline",size:"sm",disabled:a,className:"h-8 gap-1 px-2 text-xs",children:[e.jsx(k.Cpu,{size:14}),e.jsx("span",{className:"max-w-20 truncate",children:f.name})]})}),e.jsxs(De,{className:"w-96 p-0",children:[e.jsx("h3",{className:"mt-2 px-2 py-2 font-semibold",children:"Models"}),e.jsx(Pe,{children:Object.entries(p).map(([u,N])=>e.jsx(Te,{heading:u.charAt(0).toUpperCase()+u.slice(1),children:N.map(y=>e.jsxs(ze,{value:y.id,onSelect:()=>x(y.id),className:"flex cursor-pointer items-center gap-2 p-2",children:[e.jsx(Ae,{provider:y.provider}),e.jsxs("div",{className:"flex flex-1 items-center justify-between",children:[e.jsx(Ce,{children:y.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:y.description})]}),t===y.id&&e.jsx("div",{className:"h-2 w-2 rounded-full bg-blue-500"})]},y.id))},u))})]})]})},V="chai-ai-selected-model",Le=({input:t,setInput:s,onSend:a,onStop:l,isLoading:o,disabled:f,selectedLang:p,selectedModel:x=L.getDefaultModel().id,onModelChange:u})=>{const{t:N}=se.useTranslation(),[y,r]=c.useState(x),[i,g]=c.useState(null),P=c.useRef(null),[I,D]=c.useState(!1);c.useEffect(()=>{if(!p){const h=localStorage.getItem(V);if(h)r(h),u==null||u(h);else{const A=L.getDefaultModel().id;r(A),u==null||u(A)}}},[p,u]);const z=h=>{var U;const A=h.files.find(T=>{var R;return(R=T.mediaType)==null?void 0:R.startsWith("image/")}),M=(A==null?void 0:A.url)||i;a((U=h.text)==null?void 0:U.trim(),void 0,M,y),g(null)};return e.jsx("div",{className:"relative",children:e.jsx("div",{className:"border-gray-20 rounded-lg border",children:e.jsxs(me,{onSubmit:z,accept:"image/*",className:"flex h-auto w-full flex-col",children:[e.jsx(he,{className:"p-0",children:e.jsx(de,{className:"pb-0",children:h=>e.jsx(ue,{className:"text-xs",data:h})})}),e.jsx(fe,{ref:P,value:t,onChange:h=>s(h.target.value),placeholder:N(p?"Ask to update content":"Ask me anything..."),disabled:o,className:"max-h-[200px] min-h-[60px] w-full",rows:3}),e.jsxs(xe,{children:[p?e.jsx("div",{}):e.jsxs(ge,{children:[e.jsxs(ve,{children:[e.jsx(je,{disabled:o,children:e.jsx(k.Paperclip,{size:16})}),e.jsx(be,{children:e.jsx(pe,{})})]}),e.jsx(Ne,{textareaRef:P,onTranscriptionChange:s,disabled:o}),e.jsx(Re,{selectedModel:y,onModelChange:h=>{r(h),u==null||u(h),localStorage.setItem(V,h)},disabled:o}),e.jsxs(F,{className:"hidden",size:"sm",onClick:()=>D(!I),variant:I?"default":"ghost",children:[e.jsx(k.GlobeIcon,{size:16}),e.jsx("span",{children:"Search"})]})]}),o?e.jsx("button",{onClick:l,className:"z-50 flex items-center gap-x-1 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:N("Stop generation"),children:e.jsx(k.Square,{size:16})}):e.jsx(we,{disabled:!t.trim()||f,children:e.jsx(k.Send,{size:16})})]})]})})})};exports.default=Le;
|