@purpleschool/gptbot 0.7.45 → 0.7.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.
Files changed (79) hide show
  1. package/api/controllers/http/index.ts +1 -0
  2. package/api/controllers/http/writer.ts +20 -0
  3. package/build/api/controllers/http/index.js +1 -0
  4. package/build/api/controllers/http/writer.js +22 -0
  5. package/build/commands/tools/index.js +1 -0
  6. package/build/commands/tools/writer/create-writer-document.command.js +16 -0
  7. package/build/commands/tools/writer/delete-all-writer-documents.command.js +8 -0
  8. package/build/commands/tools/writer/delete-writer-document-by-uuid.command.js +11 -0
  9. package/build/commands/tools/writer/export-writer-document-as-docx.command.js +15 -0
  10. package/build/commands/tools/writer/find-writer-document-by-uuid.command.js +14 -0
  11. package/build/commands/tools/writer/find-writer-documents.command.js +18 -0
  12. package/build/commands/tools/writer/generate-writer-document-contents.command.js +14 -0
  13. package/build/commands/tools/writer/get-writer-tool-config.command.js +11 -0
  14. package/build/commands/tools/writer/index.js +31 -0
  15. package/build/commands/tools/writer/update-writer-document-contents.command.js +18 -0
  16. package/build/commands/tools/writer/update-writer-document-outline.command.js +17 -0
  17. package/build/commands/tools/writer/writer-extend-text.command.js +18 -0
  18. package/build/commands/tools/writer/writer-fix-errors.command.js +18 -0
  19. package/build/commands/tools/writer/writer-generate-text.command.js +21 -0
  20. package/build/commands/tools/writer/writer-paraphrase.command.js +18 -0
  21. package/build/commands/tools/writer/writer-shorten-text.command.js +18 -0
  22. package/build/constants/errors/errors.js +107 -32
  23. package/build/constants/index.js +1 -0
  24. package/build/constants/writer/enums/index.js +20 -0
  25. package/build/constants/writer/enums/writer-ai-action-pricing-type.enum.js +8 -0
  26. package/build/constants/writer/enums/writer-ai-action-type.enum.js +11 -0
  27. package/build/constants/writer/enums/writer-document-section-type.enum.js +9 -0
  28. package/build/constants/writer/enums/writer-document-stage.enum.js +14 -0
  29. package/build/constants/writer/index.js +17 -0
  30. package/build/helpers/index.js +1 -0
  31. package/build/helpers/writer/calculate-page-count.util.js +37 -0
  32. package/build/helpers/writer/calculate-writer-ai-action-price.util.js +16 -0
  33. package/build/helpers/writer/calculate-writer-content-generation-price.util.js +6 -0
  34. package/build/helpers/writer/index.js +19 -0
  35. package/build/models/tools/index.js +1 -0
  36. package/build/models/tools/writer/index.js +21 -0
  37. package/build/models/tools/writer/writer-ai-action.schema.js +26 -0
  38. package/build/models/tools/writer/writer-config.schema.js +11 -0
  39. package/build/models/tools/writer/writer-document-outline.schema.js +21 -0
  40. package/build/models/tools/writer/writer-document-type.schema.js +16 -0
  41. package/build/models/tools/writer/writer-document.schema.js +22 -0
  42. package/commands/tools/index.ts +1 -0
  43. package/commands/tools/writer/create-writer-document.command.ts +16 -0
  44. package/commands/tools/writer/delete-all-writer-documents.command.ts +6 -0
  45. package/commands/tools/writer/delete-writer-document-by-uuid.command.ts +11 -0
  46. package/commands/tools/writer/export-writer-document-as-docx.command.ts +15 -0
  47. package/commands/tools/writer/find-writer-document-by-uuid.command.ts +14 -0
  48. package/commands/tools/writer/find-writer-documents.command.ts +18 -0
  49. package/commands/tools/writer/generate-writer-document-contents.command.ts +14 -0
  50. package/commands/tools/writer/get-writer-tool-config.command.ts +10 -0
  51. package/commands/tools/writer/index.ts +15 -0
  52. package/commands/tools/writer/update-writer-document-contents.command.ts +20 -0
  53. package/commands/tools/writer/update-writer-document-outline.command.ts +19 -0
  54. package/commands/tools/writer/writer-extend-text.command.ts +20 -0
  55. package/commands/tools/writer/writer-fix-errors.command.ts +20 -0
  56. package/commands/tools/writer/writer-generate-text.command.ts +23 -0
  57. package/commands/tools/writer/writer-paraphrase.command.ts +20 -0
  58. package/commands/tools/writer/writer-shorten-text.command.ts +20 -0
  59. package/constants/errors/errors.ts +107 -32
  60. package/constants/index.ts +1 -0
  61. package/constants/writer/enums/index.ts +4 -0
  62. package/constants/writer/enums/writer-ai-action-pricing-type.enum.ts +4 -0
  63. package/constants/writer/enums/writer-ai-action-type.enum.ts +7 -0
  64. package/constants/writer/enums/writer-document-section-type.enum.ts +5 -0
  65. package/constants/writer/enums/writer-document-stage.enum.ts +13 -0
  66. package/constants/writer/index.ts +1 -0
  67. package/helpers/index.ts +1 -0
  68. package/helpers/writer/calculate-page-count.util.ts +46 -0
  69. package/helpers/writer/calculate-writer-ai-action-price.util.ts +20 -0
  70. package/helpers/writer/calculate-writer-content-generation-price.util.ts +3 -0
  71. package/helpers/writer/index.ts +3 -0
  72. package/models/tools/index.ts +1 -0
  73. package/models/tools/writer/index.ts +5 -0
  74. package/models/tools/writer/writer-ai-action.schema.ts +27 -0
  75. package/models/tools/writer/writer-config.schema.ts +10 -0
  76. package/models/tools/writer/writer-document-outline.schema.ts +28 -0
  77. package/models/tools/writer/writer-document-type.schema.ts +15 -0
  78. package/models/tools/writer/writer-document.schema.ts +21 -0
  79. package/package.json +1 -1
@@ -1747,79 +1747,119 @@ export const ERRORS = {
1747
1747
  message: 'Ошибка при обновлении ежедневного стрика',
1748
1748
  httpCode: 500,
1749
1749
  },
1750
- ACCOUNT_DELETE_ERROR: {
1750
+ WRITER_CONFIG_ERROR: {
1751
1751
  code: 'A362',
1752
+ message: 'Произошла ошибка при получении конфигурации Writer',
1753
+ httpCode: 500,
1754
+ },
1755
+ WRITER_CREATE_DOCUMENT_ERROR: {
1756
+ code: 'A363',
1757
+ message: 'Произошла ошибка при создании документа',
1758
+ httpCode: 500,
1759
+ },
1760
+ WRITER_DOCUMENT_FIND_ERROR: {
1761
+ code: 'A364',
1762
+ message: 'Произошла ошибка при поиске документа',
1763
+ httpCode: 500,
1764
+ },
1765
+ WRITER_DOCUMENTS_FIND_ERROR: {
1766
+ code: 'A365',
1767
+ message: 'Произошла ошибка при поиске документов',
1768
+ httpCode: 500,
1769
+ },
1770
+ WRITER_DELETE_DOCUMENT_ERROR: {
1771
+ code: 'A366',
1772
+ message: 'Произошла ошибка при удалении документа',
1773
+ httpCode: 500,
1774
+ },
1775
+ WRITER_DELETE_ALL_DOCUMENTS_ERROR: {
1776
+ code: 'A367',
1777
+ message: 'Произошла ошибка при удалении всех документов пользователя',
1778
+ httpCode: 500,
1779
+ },
1780
+ WRITER_UPDATE_DOCUMENT_OUTLINE_ERROR: {
1781
+ code: 'A368',
1782
+ message: 'Произошла ошибка при обновлении структуры документа',
1783
+ httpCode: 500,
1784
+ },
1785
+ WRITER_GENERATE_DOCUMENT_CONTENTS_ERROR: {
1786
+ code: 'A369',
1787
+ message: 'Произошла ошибка при генерации содержимого документа',
1788
+ httpCode: 500,
1789
+ },
1790
+ ACCOUNT_DELETE_ERROR: {
1791
+ code: 'A370',
1752
1792
  message: 'Аккаунт не был удалён',
1753
1793
  httpCode: 500,
1754
1794
  },
1755
1795
  ACCOUNT_DELETED: {
1756
- code: 'A363',
1796
+ code: 'A371',
1757
1797
  message: 'Операция невозможна, аккаунт был удалён',
1758
1798
  httpCode: 400,
1759
1799
  },
1760
1800
  TELEGRAM_PROFILE_DELETE_ERROR: {
1761
- code: 'A364',
1801
+ code: 'A372',
1762
1802
  message: 'Произошла ошибка при удалении Telegram профиля',
1763
1803
  httpCode: 500,
1764
1804
  },
1765
1805
  TOOL_NOT_FOUND_ERROR: {
1766
- code: 'A365',
1806
+ code: 'A373',
1767
1807
  message: 'Инструмент не найден',
1768
1808
  httpCode: 404,
1769
1809
  },
1770
1810
  ORDER_CHECK_FIRST_PURCHASE_ERROR: {
1771
- code: 'A366',
1811
+ code: 'A374',
1772
1812
  message: 'Произошла ошибка при проверке первой покупки',
1773
1813
  httpCode: 500,
1774
1814
  },
1775
1815
  ORDER_CURRENT_ORDER_NOT_FOUND_ERROR: {
1776
- code: 'A367',
1816
+ code: 'A375',
1777
1817
  message: 'Текущий заказ не найден',
1778
1818
  httpCode: 404,
1779
1819
  },
1780
1820
  ORDER_GET_USER_ORDERS_ERROR: {
1781
- code: 'A368',
1821
+ code: 'A376',
1782
1822
  message: 'Произошла ошибка при получении заказов пользователя',
1783
1823
  httpCode: 500,
1784
1824
  },
1785
1825
  ORDER_NO_SUBSCRIPTION_ID_OR_PRODUCT_ID_PROVIDED_ERROR: {
1786
- code: 'A369',
1826
+ code: 'A377',
1787
1827
  message: 'Не указан subscriptionId или productId',
1788
1828
  httpCode: 400,
1789
1829
  },
1790
1830
  FILE_TO_MD_FORMAT_ERROR: {
1791
- code: 'A370',
1831
+ code: 'A378',
1792
1832
  message: 'Неверный формат файла, варианты: .xlsx, .docx, .pdf',
1793
1833
  httpCode: 400,
1794
1834
  },
1795
1835
  FILE_TO_MD_ERROR: {
1796
- code: 'A371',
1836
+ code: 'A379',
1797
1837
  message: 'Произошла ошибка при конвертации файла в markdown',
1798
1838
  httpCode: 500,
1799
1839
  },
1800
1840
  FILE_TO_MD_CONVERT_ERROR: {
1801
- code: 'A372',
1841
+ code: 'A380',
1802
1842
  message:
1803
1843
  'Не получилось конвертировать файл в markdown, возможно файл пуст, поврежден или невалиден',
1804
1844
  httpCode: 400,
1805
1845
  },
1806
1846
  IMAGE_EDITOR_MODEL_INACTIVE: {
1807
- code: 'A373',
1847
+ code: 'A381',
1808
1848
  message: 'Модель редактирования картинок архивирована и недоступна для пользования',
1809
1849
  httpCode: 403,
1810
1850
  },
1811
1851
  TTS_MODEL_INACTIVE: {
1812
- code: 'A374',
1852
+ code: 'A382',
1813
1853
  message: 'Модель генерации текста в голос архивирована и недоступна для пользования',
1814
1854
  httpCode: 403,
1815
1855
  },
1816
1856
  STT_MODEL_INACTIVE: {
1817
- code: 'A375',
1857
+ code: 'A383',
1818
1858
  message: 'Модель генерации голоса в текст архивирована и недоступна для пользования',
1819
1859
  httpCode: 403,
1820
1860
  },
1821
1861
  VIDEO_MODEL_INACTIVE: {
1822
- code: 'A376',
1862
+ code: 'A384',
1823
1863
  message: 'Модель генерации видео архивирована и недоступна для пользования',
1824
1864
  httpCode: 403,
1825
1865
  },
@@ -1829,17 +1869,17 @@ export const ERRORS = {
1829
1869
  httpCode: 500,
1830
1870
  },
1831
1871
  VK_GET_ACCESS_TOKEN_ERROR: {
1832
- code: 'A377',
1872
+ code: 'A385',
1833
1873
  message: 'Ошибка при получении кода доступа от ВК',
1834
1874
  httpCode: 500,
1835
1875
  },
1836
1876
  VK_GET_USER_INFO_ERROR: {
1837
- code: 'A378',
1877
+ code: 'A386',
1838
1878
  message: 'Ошибка при получении данных об юзере из ВК',
1839
1879
  httpCode: 500,
1840
1880
  },
1841
1881
  USER_NOT_VK_ID: {
1842
- code: 'A379',
1882
+ code: 'A387',
1843
1883
  message: 'Произошла ошибка при поиске пользователя по vkId',
1844
1884
  httpCode: 500,
1845
1885
  },
@@ -1849,12 +1889,12 @@ export const ERRORS = {
1849
1889
  httpCode: 409,
1850
1890
  },
1851
1891
  YANDEX_GET_USER_INFO_ERROR: {
1852
- code: 'A380',
1892
+ code: 'A388',
1853
1893
  message: 'Ошибка при получении данных об юзере из Яндекса',
1854
1894
  httpCode: 500,
1855
1895
  },
1856
1896
  USER_NOT_YANDEX_ID: {
1857
- code: 'A381',
1897
+ code: 'A389',
1858
1898
  message: 'Произошла ошибка при поиске пользователя по yandexId',
1859
1899
  httpCode: 500,
1860
1900
  },
@@ -1864,63 +1904,98 @@ export const ERRORS = {
1864
1904
  httpCode: 409,
1865
1905
  },
1866
1906
  PDF_TO_MD_CONVERT_ERROR: {
1867
- code: 'A382',
1907
+ code: 'A390',
1868
1908
  message:
1869
1909
  'Не получилось конвертировать pdf в markdown, возможно вы прикрепили скан или картинку, не имеющую текста',
1870
1910
  httpCode: 400,
1871
1911
  },
1872
1912
  SUBSCRIPTION_DOWNGRADE_INVALID: {
1873
- code: 'A383',
1913
+ code: 'A391',
1874
1914
  message: 'Невозможно понизить подписку до указанного уровня',
1875
1915
  httpCode: 400,
1876
1916
  },
1877
1917
  SUBSCRIPTION_DOWNGRADE_ERROR: {
1878
- code: 'A384',
1918
+ code: 'A392',
1879
1919
  message: 'Не удалось понизить подписку',
1880
1920
  httpCode: 500,
1881
1921
  },
1882
1922
  SUBSCRIPTIONS_GET_DOWNGRADE_ERROR: {
1883
- code: 'A385',
1923
+ code: 'A393',
1884
1924
  message: 'Не удалось получить список возможных понижений для подписок',
1885
1925
  httpCode: 500,
1886
1926
  },
1927
+ WRITER_PARAPHRASE_ERROR: {
1928
+ code: 'A394',
1929
+ message: 'Произошла ошибка при перефразировании текста',
1930
+ httpCode: 500,
1931
+ },
1932
+ WRITER_EXTEND_TEXT_ERROR: {
1933
+ code: 'A395',
1934
+ message: 'Произошла ошибка при расширении текста',
1935
+ httpCode: 500,
1936
+ },
1937
+ WRITER_SHORTEN_TEXT_ERROR: {
1938
+ code: 'A396',
1939
+ message: 'Произошла ошибка при сокращении текста',
1940
+ httpCode: 500,
1941
+ },
1942
+ WRITER_FIX_ERRORS_ERROR: {
1943
+ code: 'A397',
1944
+ message: 'Произошла ошибка при исправлении ошибок в тексте',
1945
+ httpCode: 500,
1946
+ },
1947
+ WRITER_UPDATE_DOCUMENT_CONTENTS_ERROR: {
1948
+ code: 'A398',
1949
+ message: 'Произошла ошибка при обновлении содержимого документа',
1950
+ httpCode: 500,
1951
+ },
1952
+ WRITER_GENERATE_TEXT_ERROR: {
1953
+ code: 'A399',
1954
+ message: 'Произошла ошибка при генерации текста',
1955
+ httpCode: 500,
1956
+ },
1957
+ WRITER_EXPORT_DOCX_ERROR: {
1958
+ code: 'A400',
1959
+ message: 'Произошла ошибка при экспорте документа в DOCX',
1960
+ httpCode: 500,
1961
+ },
1887
1962
  AI_MODEL_SUGGESTIONS_INVALID_PROMPT_LENGTH: {
1888
- code: 'A386',
1963
+ code: 'A401',
1889
1964
  message: 'Промпт не подходит для генерации предложений',
1890
1965
  httpCode: 400,
1891
1966
  },
1892
1967
  AI_MODEL_SUGGESTIONS_GENERATION_ERROR: {
1893
- code: 'A387',
1968
+ code: 'A402',
1894
1969
  message: 'Ошибка генерации предложения',
1895
1970
  httpCode: 500,
1896
1971
  },
1897
1972
  VK_STATE_ERROR: {
1898
- code: 'A388',
1973
+ code: 'A403',
1899
1974
  message: 'Получен неверный state в ответе от API ВК',
1900
1975
  httpCode: 400,
1901
1976
  },
1902
1977
  YANDEX_GET_ACCESS_TOKEN_ERROR: {
1903
- code: 'A389',
1978
+ code: 'A404',
1904
1979
  message: 'Ошибка при получении кода доступа от Яндекса',
1905
1980
  httpCode: 500,
1906
1981
  },
1907
1982
  KIE_MIDJOURNEY_TASK_ERROR: {
1908
- code: 'A390',
1983
+ code: 'A405',
1909
1984
  message: 'Произошла ошибка при получении задачи Midjourney',
1910
1985
  httpCode: 500,
1911
1986
  },
1912
1987
  KIE_MIDJOURNEY_GENERATION_ERROR: {
1913
- code: 'A391',
1988
+ code: 'A406',
1914
1989
  message: 'Произошла ошибка при генерации видео от Midjourney',
1915
1990
  httpCode: 500,
1916
1991
  },
1917
1992
  KIE_MIDJOURNEY_NO_RESPONSE: {
1918
- code: 'A392',
1993
+ code: 'A407',
1919
1994
  message: 'Нет ответа от Midjourney, попробуйте позже',
1920
1995
  httpCode: 503,
1921
1996
  },
1922
1997
  KIE_CONTENT_POLICY_VIOLATION: {
1923
- code: 'A393',
1998
+ code: 'A408',
1924
1999
  message: 'Запрос был отклонен, т.к. может не соответствовать политике безопасности сервиса',
1925
2000
  httpCode: 400,
1926
2001
  },
@@ -31,6 +31,7 @@ export * from './promocode';
31
31
  export * from './ui-notification';
32
32
  export * from './review';
33
33
  export * from './tool-video';
34
+ export * from './writer';
34
35
  export * from './tool-image-editor';
35
36
  export * from './feedback';
36
37
  export * from './daily-streak';
@@ -0,0 +1,4 @@
1
+ export * from './writer-document-section-type.enum';
2
+ export * from './writer-document-stage.enum';
3
+ export * from './writer-ai-action-pricing-type.enum';
4
+ export * from './writer-ai-action-type.enum';
@@ -0,0 +1,4 @@
1
+ export enum WRITER_AI_ACTION_PRICING_TYPE {
2
+ PER_CHARACTER = 'PER_CHARACTER',
3
+ FLAT = 'FLAT',
4
+ }
@@ -0,0 +1,7 @@
1
+ export enum WRITER_AI_ACTION_TYPE {
2
+ PARAPHRASE = 'PARAPHRASE',
3
+ EXTEND_TEXT = 'EXTEND_TEXT',
4
+ SHORTEN_TEXT = 'SHORTEN_TEXT',
5
+ GENERATE_TEXT = 'GENERATE_TEXT',
6
+ FIX_ERRORS = 'FIX_ERRORS',
7
+ }
@@ -0,0 +1,5 @@
1
+ export enum WRITER_DOCUMENT_SECTION_TYPE {
2
+ INTRODUCTION = 'introduction',
3
+ CONCLUSION = 'conclusion',
4
+ SECTION = 'section',
5
+ }
@@ -0,0 +1,13 @@
1
+ export enum WRITER_DOCUMENT_STAGE {
2
+ CREATED = 'CREATED',
3
+
4
+ GENERATING_OUTLINE = 'GENERATING_OUTLINE',
5
+ OUTLINE_GENERATED = 'OUTLINE_GENERATED',
6
+ OUTLINE_GENERATION_FAILED = 'OUTLINE_GENERATION_FAILED',
7
+
8
+ GENERATING_CONTENT = 'GENERATING_CONTENT',
9
+ CONTENT_GENERATED = 'CONTENT_GENERATED',
10
+ CONTENT_GENERATION_FAILED = 'CONTENT_GENERATION_FAILED',
11
+
12
+ DELETED = 'DELETED',
13
+ }
@@ -0,0 +1 @@
1
+ export * from './enums';
package/helpers/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from './stt';
3
3
  export * from './subscription';
4
4
  export * from './tts';
5
5
  export * from './video';
6
+ export * from './writer';
@@ -0,0 +1,46 @@
1
+ const WORD_FONT_SIZE_PT = 14;
2
+ const WORD_LINE_SPACING = 1.5;
3
+
4
+ const A4_WIDTH_MM = 210;
5
+ const A4_HEIGHT_MM = 297;
6
+
7
+ const MARGIN_TOP_MM = 20;
8
+ const MARGIN_BOTTOM_MM = 20;
9
+ const MARGIN_LEFT_MM = 30;
10
+ const MARGIN_RIGHT_MM = 10;
11
+
12
+ const FIRST_LINE_INDENT_MM = 12.5;
13
+
14
+ const MM_PER_POINT = 0.3527777778;
15
+
16
+ const TEXT_WIDTH_MM = A4_WIDTH_MM - MARGIN_LEFT_MM - MARGIN_RIGHT_MM;
17
+ const TEXT_HEIGHT_MM = A4_HEIGHT_MM - MARGIN_TOP_MM - MARGIN_BOTTOM_MM;
18
+
19
+ const LINE_HEIGHT_MM = WORD_FONT_SIZE_PT * WORD_LINE_SPACING * MM_PER_POINT;
20
+ const LINES_PER_PAGE = Math.floor(TEXT_HEIGHT_MM / LINE_HEIGHT_MM);
21
+
22
+ const AVG_CHAR_WIDTH_EM = 0.58;
23
+ const AVG_CHAR_WIDTH_MM = WORD_FONT_SIZE_PT * AVG_CHAR_WIDTH_EM * MM_PER_POINT;
24
+
25
+ const CHARS_PER_LINE = Math.floor(TEXT_WIDTH_MM / AVG_CHAR_WIDTH_MM);
26
+ const AVG_PARAGRAPHS_PER_PAGE = 4; // average paragraph count across typical student papers
27
+ const INDENT_CHARS_LOSS = Math.round(
28
+ (FIRST_LINE_INDENT_MM / AVG_CHAR_WIDTH_MM) * AVG_PARAGRAPHS_PER_PAGE,
29
+ );
30
+
31
+ const LAYOUT_FUDGE_FACTOR = 0.96;
32
+
33
+ export const CHARACTERS_PER_PAGE = Math.round(
34
+ (LINES_PER_PAGE * CHARS_PER_LINE - INDENT_CHARS_LOSS) * LAYOUT_FUDGE_FACTOR,
35
+ );
36
+
37
+ export function pagesToCharacters(pages: number): number {
38
+ if (!Number.isFinite(pages) || pages <= 0) return 0;
39
+ return Math.max(0, Math.round(pages * CHARACTERS_PER_PAGE));
40
+ }
41
+
42
+ export function charactersToPages(characters: number): number {
43
+ if (!Number.isFinite(characters) || characters <= 0) return 0;
44
+ const raw = characters / CHARACTERS_PER_PAGE;
45
+ return Math.max(0, Math.ceil(raw));
46
+ }
@@ -0,0 +1,20 @@
1
+ import { WRITER_AI_ACTION_PRICING_TYPE } from '../../constants';
2
+ import { WriterAiActionPricingRules } from '../../models';
3
+
4
+ export function calculateWriterAiActionPrice(
5
+ pricingRules: WriterAiActionPricingRules,
6
+ selectionText: string,
7
+ ): number {
8
+ switch (pricingRules.type) {
9
+ case WRITER_AI_ACTION_PRICING_TYPE.PER_CHARACTER:
10
+ const characterCount = selectionText.length;
11
+ const price = characterCount * pricingRules.price;
12
+ return Math.max(1, Math.ceil(price));
13
+
14
+ case WRITER_AI_ACTION_PRICING_TYPE.FLAT:
15
+ return Math.max(1, Math.ceil(pricingRules.price));
16
+
17
+ default:
18
+ throw new Error(`Unknown pricing type`);
19
+ }
20
+ }
@@ -0,0 +1,3 @@
1
+ export function calculateWriterContentGenerationPrice(pages: number): number {
2
+ return Math.max(1, pages);
3
+ }
@@ -0,0 +1,3 @@
1
+ export * from './calculate-writer-ai-action-price.util';
2
+ export * from './calculate-writer-content-generation-price.util';
3
+ export * from './calculate-page-count.util';
@@ -3,4 +3,5 @@ export * from './paraphrase';
3
3
  export * from './stt';
4
4
  export * from './tts';
5
5
  export * from './video';
6
+ export * from './writer';
6
7
  export * from './image-editor';
@@ -0,0 +1,5 @@
1
+ export * from './writer-config.schema';
2
+ export * from './writer-ai-action.schema';
3
+ export * from './writer-document-outline.schema';
4
+ export * from './writer-document.schema';
5
+ export * from './writer-document-type.schema';
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import { WRITER_AI_ACTION_PRICING_TYPE, WRITER_AI_ACTION_TYPE } from '../../../constants';
3
+
4
+ export const WriterAiActionPricingRulesSchema = z.discriminatedUnion('type', [
5
+ z.object({
6
+ type: z.literal(WRITER_AI_ACTION_PRICING_TYPE.PER_CHARACTER),
7
+ price: z.number(),
8
+ }),
9
+ z.object({
10
+ type: z.literal(WRITER_AI_ACTION_PRICING_TYPE.FLAT),
11
+ price: z.number(),
12
+ }),
13
+ ]);
14
+ export type WriterAiActionPricingRules = z.infer<typeof WriterAiActionPricingRulesSchema>;
15
+
16
+ export const WriterAiActionSchema = z.object({
17
+ uuid: z.string(),
18
+ type: z.nativeEnum(WRITER_AI_ACTION_TYPE),
19
+ pricingRules: WriterAiActionPricingRulesSchema,
20
+ maxPromptLength: z.number(),
21
+ title: z.string(),
22
+ icon: z.string(),
23
+ order: z.number(),
24
+ createdAt: z.date(),
25
+ updatedAt: z.date(),
26
+ });
27
+ export type WriterAiAction = z.infer<typeof WriterAiActionSchema>;
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod';
2
+ import { WriterDocumentTypeSchema } from './writer-document-type.schema';
3
+ import { WriterAiActionSchema } from './writer-ai-action.schema';
4
+
5
+ export const WriterConfigSchema = z.object({
6
+ maxPromptLength: z.number(),
7
+ documentTypes: z.array(WriterDocumentTypeSchema),
8
+ aiActions: z.array(WriterAiActionSchema),
9
+ });
10
+ export type WriterConfig = z.infer<typeof WriterConfigSchema>;
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ import { WRITER_DOCUMENT_SECTION_TYPE } from '../../../constants';
3
+
4
+ export const WriterDocumentOutlineSubsectionSchema = z.object({
5
+ title: z
6
+ .string()
7
+ .min(3)
8
+ .max(120)
9
+ .describe(
10
+ `Concise title of the subsection. Meant to elaborate on its parent section's title.`,
11
+ ),
12
+ });
13
+ export type WriterDocumentOutlineSubsection = z.infer<typeof WriterDocumentOutlineSubsectionSchema>;
14
+
15
+ export const WriterDocumentOutlineSectionSchema = z.object({
16
+ title: z.string().min(3).max(120).describe(`Concise title of the paper section.`),
17
+ type: z.nativeEnum(WRITER_DOCUMENT_SECTION_TYPE),
18
+ subsections: z
19
+ .array(WriterDocumentOutlineSubsectionSchema)
20
+ .optional()
21
+ .describe(
22
+ `Subsections of the paper section. Each subsection is a single idea that is a part of the parent section.`,
23
+ ),
24
+ });
25
+
26
+ export const WriterDocumentOutlineSchema = z.array(WriterDocumentOutlineSectionSchema);
27
+
28
+ export type WriterDocumentOutline = z.infer<typeof WriterDocumentOutlineSchema>;
@@ -0,0 +1,15 @@
1
+ import { z } from 'zod';
2
+ import { IconVariantsSchema } from '../../icon-variants.schema';
3
+
4
+ export const WriterDocumentTypeSchema = z.object({
5
+ uuid: z.string().uuid(),
6
+ title: z.string(),
7
+ icons: IconVariantsSchema,
8
+ order: z.number(),
9
+ minPages: z.number(),
10
+ maxPages: z.number(),
11
+ pageRange: z.array(z.number()),
12
+ createdAt: z.date(),
13
+ updatedAt: z.date(),
14
+ });
15
+ export type WriterDocumentType = z.infer<typeof WriterDocumentTypeSchema>;
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ import { WriterDocumentOutlineSchema } from './writer-document-outline.schema';
3
+ import { WRITER_DOCUMENT_STAGE } from '../../../constants';
4
+
5
+ export const WriterDocumentSchema = z.object({
6
+ uuid: z.string().uuid(),
7
+ prompt: z.string(),
8
+ topic: z.string(),
9
+ typeId: z.string(),
10
+ stage: z.nativeEnum(WRITER_DOCUMENT_STAGE),
11
+ outline: WriterDocumentOutlineSchema,
12
+ sourceMd: z.string().nullable(),
13
+ finalMd: z.string().nullable(),
14
+ userId: z.string().nullable(),
15
+ unregisteredUserId: z.string().nullable(),
16
+ pages: z.number(),
17
+ createdAt: z.date(),
18
+ updatedAt: z.date(),
19
+ completedAt: z.date().nullable(),
20
+ });
21
+ export type WriterDocument = z.infer<typeof WriterDocumentSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.7.45",
3
+ "version": "0.7.46",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",