nsarrazin HF Staff commited on
Commit
821697c
·
1 Parent(s): c99779e

feat: add setting option to disable content pasting

Browse files
scripts/populate.ts CHANGED
@@ -150,9 +150,9 @@ async function seed() {
150
  createdAt: faker.date.recent({ days: 30 }),
151
  updatedAt: faker.date.recent({ days: 30 }),
152
  disableStream: faker.datatype.boolean(0.25),
 
153
  customPrompts: {},
154
  assistants: [],
155
- disableStream: faker.datatype.boolean(0.25),
156
  };
157
  await collections.settings.updateOne(
158
  { userId: user._id },
 
150
  createdAt: faker.date.recent({ days: 30 }),
151
  updatedAt: faker.date.recent({ days: 30 }),
152
  disableStream: faker.datatype.boolean(0.25),
153
+ directPaste: faker.datatype.boolean(0.25),
154
  customPrompts: {},
155
  assistants: [],
 
156
  };
157
  await collections.settings.updateOne(
158
  { userId: user._id },
src/lib/components/chat/ChatWindow.svelte CHANGED
@@ -92,7 +92,7 @@
92
  const onPaste = (e: ClipboardEvent) => {
93
  const textContent = e.clipboardData?.getData("text");
94
 
95
- if (textContent && textContent.length > 256) {
96
  e.preventDefault();
97
  pastedLongContent = true;
98
  setTimeout(() => {
 
92
  const onPaste = (e: ClipboardEvent) => {
93
  const textContent = e.clipboardData?.getData("text");
94
 
95
+ if (!$settings.directPaste && textContent && textContent.length > 256) {
96
  e.preventDefault();
97
  pastedLongContent = true;
98
  setTimeout(() => {
src/lib/stores/settings.ts CHANGED
@@ -17,6 +17,7 @@ type SettingsStore = {
17
  assistants: Array<ObjectId | string>;
18
  tools?: Array<string>;
19
  disableStream: boolean;
 
20
  };
21
 
22
  type SettingsStoreWritable = Writable<SettingsStore> & {
 
17
  assistants: Array<ObjectId | string>;
18
  tools?: Array<string>;
19
  disableStream: boolean;
20
+ directPaste: boolean;
21
  };
22
 
23
  type SettingsStoreWritable = Writable<SettingsStore> & {
src/lib/types/Settings.ts CHANGED
@@ -23,6 +23,7 @@ export interface Settings extends Timestamps {
23
  assistants?: Assistant["_id"][];
24
  tools?: string[];
25
  disableStream: boolean;
 
26
  }
27
 
28
  export type SettingsEditable = Omit<Settings, "ethicsModalAcceptedAt" | "createdAt" | "updatedAt">;
@@ -35,4 +36,5 @@ export const DEFAULT_SETTINGS = {
35
  assistants: [],
36
  tools: [],
37
  disableStream: false,
 
38
  } satisfies SettingsEditable;
 
23
  assistants?: Assistant["_id"][];
24
  tools?: string[];
25
  disableStream: boolean;
26
+ directPaste: boolean;
27
  }
28
 
29
  export type SettingsEditable = Omit<Settings, "ethicsModalAcceptedAt" | "createdAt" | "updatedAt">;
 
36
  assistants: [],
37
  tools: [],
38
  disableStream: false,
39
+ directPaste: false,
40
  } satisfies SettingsEditable;
src/routes/+layout.server.ts CHANGED
@@ -174,6 +174,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
174
  .filter((el) => !el.isHidden && el.isOnByDefault)
175
  .map((el) => el._id.toString()),
176
  disableStream: settings?.disableStream ?? DEFAULT_SETTINGS.disableStream,
 
177
  },
178
  models: models.map((model) => ({
179
  id: model.id,
 
174
  .filter((el) => !el.isHidden && el.isOnByDefault)
175
  .map((el) => el._id.toString()),
176
  disableStream: settings?.disableStream ?? DEFAULT_SETTINGS.disableStream,
177
+ directPaste: settings?.directPaste ?? DEFAULT_SETTINGS.directPaste,
178
  },
179
  models: models.map((model) => ({
180
  id: model.id,
src/routes/settings/(nav)/+page.svelte CHANGED
@@ -25,7 +25,7 @@
25
  >
26
  </span>
27
  </div>
28
- <div class="flex h-full flex-col gap-2 max-sm:pt-0">
29
  {#if envPublic.PUBLIC_APP_DATA_SHARING === "1"}
30
  <!-- svelte-ignore a11y-label-has-associated-control -->
31
  <label class="flex items-center">
@@ -45,19 +45,34 @@
45
  <!-- svelte-ignore a11y-label-has-associated-control -->
46
  <label class="mt-6 flex items-center">
47
  <Switch name="hideEmojiOnSidebar" bind:checked={$settings.hideEmojiOnSidebar} />
48
- <div class="inline cursor-pointer select-none items-center gap-2 pl-2">
49
  Hide emoticons in conversation topics
 
 
 
50
  </div>
51
  </label>
52
 
53
  <!-- svelte-ignore a11y-label-has-associated-control -->
54
  <label class="mt-6 flex items-center">
55
  <Switch name="disableStream" bind:checked={$settings.disableStream} />
56
- <div class="inline cursor-pointer select-none items-center gap-2 pl-2">
57
  Disable streaming tokens
58
  </div>
59
  </label>
60
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  <div class="mt-12 flex flex-col gap-3">
62
  <a
63
  href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"
 
25
  >
26
  </span>
27
  </div>
28
+ <div class="flex h-full max-w-2xl flex-col gap-2 max-sm:pt-0">
29
  {#if envPublic.PUBLIC_APP_DATA_SHARING === "1"}
30
  <!-- svelte-ignore a11y-label-has-associated-control -->
31
  <label class="flex items-center">
 
45
  <!-- svelte-ignore a11y-label-has-associated-control -->
46
  <label class="mt-6 flex items-center">
47
  <Switch name="hideEmojiOnSidebar" bind:checked={$settings.hideEmojiOnSidebar} />
48
+ <div class="inline cursor-pointer select-none items-center gap-2 pl-2 font-semibold">
49
  Hide emoticons in conversation topics
50
+ <p class="text-sm font-normal text-gray-500">
51
+ Emoticons are shown in the sidebar by default, enable this to hide them.
52
+ </p>
53
  </div>
54
  </label>
55
 
56
  <!-- svelte-ignore a11y-label-has-associated-control -->
57
  <label class="mt-6 flex items-center">
58
  <Switch name="disableStream" bind:checked={$settings.disableStream} />
59
+ <div class="inline cursor-pointer select-none items-center gap-2 pl-2 font-semibold">
60
  Disable streaming tokens
61
  </div>
62
  </label>
63
 
64
+ <!-- svelte-ignore a11y-label-has-associated-control -->
65
+ <label class="mt-6 flex items-center">
66
+ <Switch name="directPaste" bind:checked={$settings.directPaste} />
67
+ <div class="inline cursor-pointer select-none items-center gap-2 pl-2 font-semibold">
68
+ Paste text directly into chat
69
+ <p class="text-sm font-normal text-gray-500">
70
+ By default, when pasting long text into the chat, we treat it as a plaintext file. Enable
71
+ this to paste directly into the chat instead.
72
+ </p>
73
+ </div>
74
+ </label>
75
+
76
  <div class="mt-12 flex flex-col gap-3">
77
  <a
78
  href="https://huggingface.co/spaces/huggingchat/chat-ui/discussions"
src/routes/settings/(nav)/+server.ts CHANGED
@@ -19,6 +19,7 @@ export async function POST({ request, locals }) {
19
  customPrompts: z.record(z.string()).default({}),
20
  tools: z.array(z.string()).optional(),
21
  disableStream: z.boolean().default(false),
 
22
  })
23
  .parse(body) satisfies SettingsEditable;
24
 
 
19
  customPrompts: z.record(z.string()).default({}),
20
  tools: z.array(z.string()).optional(),
21
  disableStream: z.boolean().default(false),
22
+ directPaste: z.boolean().default(false),
23
  })
24
  .parse(body) satisfies SettingsEditable;
25