@byline/ai 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -0
  3. package/dist/@types.d.ts +103 -0
  4. package/dist/@types.d.ts.map +1 -0
  5. package/dist/@types.js +68 -0
  6. package/dist/@types.js.map +1 -0
  7. package/dist/config/ai-config.d.ts +76 -0
  8. package/dist/config/ai-config.d.ts.map +1 -0
  9. package/dist/config/ai-config.js +108 -0
  10. package/dist/config/ai-config.js.map +1 -0
  11. package/dist/config/ai-config.test.node.d.ts +9 -0
  12. package/dist/config/ai-config.test.node.d.ts.map +1 -0
  13. package/dist/config/ai-config.test.node.js +31 -0
  14. package/dist/config/ai-config.test.node.js.map +1 -0
  15. package/dist/config/ai-provider.d.ts +17 -0
  16. package/dist/config/ai-provider.d.ts.map +1 -0
  17. package/dist/config/ai-provider.js +32 -0
  18. package/dist/config/ai-provider.js.map +1 -0
  19. package/dist/execute.d.ts +15 -0
  20. package/dist/execute.d.ts.map +1 -0
  21. package/dist/execute.js +473 -0
  22. package/dist/execute.js.map +1 -0
  23. package/dist/generate.d.ts +64 -0
  24. package/dist/generate.d.ts.map +1 -0
  25. package/dist/generate.js +235 -0
  26. package/dist/generate.js.map +1 -0
  27. package/dist/index.d.ts +28 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +43 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/lexical-text-edits.d.ts +23 -0
  32. package/dist/lexical-text-edits.d.ts.map +1 -0
  33. package/dist/lexical-text-edits.js +62 -0
  34. package/dist/lexical-text-edits.js.map +1 -0
  35. package/dist/lib/logger.d.ts +10 -0
  36. package/dist/lib/logger.d.ts.map +1 -0
  37. package/dist/lib/logger.js +16 -0
  38. package/dist/lib/logger.js.map +1 -0
  39. package/dist/models/anthropic/anthropic-models.d.ts +14 -0
  40. package/dist/models/anthropic/anthropic-models.d.ts.map +1 -0
  41. package/dist/models/anthropic/anthropic-models.js +41 -0
  42. package/dist/models/anthropic/anthropic-models.js.map +1 -0
  43. package/dist/models/anthropic/anthropic.d.ts +9 -0
  44. package/dist/models/anthropic/anthropic.d.ts.map +1 -0
  45. package/dist/models/anthropic/anthropic.js +20 -0
  46. package/dist/models/anthropic/anthropic.js.map +1 -0
  47. package/dist/models/anthropic/generate-native.d.ts +59 -0
  48. package/dist/models/anthropic/generate-native.d.ts.map +1 -0
  49. package/dist/models/anthropic/generate-native.js +271 -0
  50. package/dist/models/anthropic/generate-native.js.map +1 -0
  51. package/dist/models/anthropic/generate-vercel.d.ts +59 -0
  52. package/dist/models/anthropic/generate-vercel.d.ts.map +1 -0
  53. package/dist/models/anthropic/generate-vercel.js +126 -0
  54. package/dist/models/anthropic/generate-vercel.js.map +1 -0
  55. package/dist/models/anthropic/generate.d.ts +16 -0
  56. package/dist/models/anthropic/generate.d.ts.map +1 -0
  57. package/dist/models/anthropic/generate.js +28 -0
  58. package/dist/models/anthropic/generate.js.map +1 -0
  59. package/dist/models/anthropic/generate.test.node.d.ts +9 -0
  60. package/dist/models/anthropic/generate.test.node.d.ts.map +1 -0
  61. package/dist/models/anthropic/generate.test.node.js +106 -0
  62. package/dist/models/anthropic/generate.test.node.js.map +1 -0
  63. package/dist/models/anthropic/patch-native.d.ts +33 -0
  64. package/dist/models/anthropic/patch-native.d.ts.map +1 -0
  65. package/dist/models/anthropic/patch-native.js +152 -0
  66. package/dist/models/anthropic/patch-native.js.map +1 -0
  67. package/dist/models/anthropic/patch-vercel.d.ts +33 -0
  68. package/dist/models/anthropic/patch-vercel.d.ts.map +1 -0
  69. package/dist/models/anthropic/patch-vercel.js +47 -0
  70. package/dist/models/anthropic/patch-vercel.js.map +1 -0
  71. package/dist/models/anthropic/patch.d.ts +12 -0
  72. package/dist/models/anthropic/patch.d.ts.map +1 -0
  73. package/dist/models/anthropic/patch.js +16 -0
  74. package/dist/models/anthropic/patch.js.map +1 -0
  75. package/dist/models/anthropic/patch.test.node.d.ts +9 -0
  76. package/dist/models/anthropic/patch.test.node.d.ts.map +1 -0
  77. package/dist/models/anthropic/patch.test.node.js +110 -0
  78. package/dist/models/anthropic/patch.test.node.js.map +1 -0
  79. package/dist/models/anthropic/schema.d.ts +212 -0
  80. package/dist/models/anthropic/schema.d.ts.map +1 -0
  81. package/dist/models/anthropic/schema.js +131 -0
  82. package/dist/models/anthropic/schema.js.map +1 -0
  83. package/dist/models/google/generate-native.d.ts +59 -0
  84. package/dist/models/google/generate-native.d.ts.map +1 -0
  85. package/dist/models/google/generate-native.js +244 -0
  86. package/dist/models/google/generate-native.js.map +1 -0
  87. package/dist/models/google/generate-vercel.d.ts +59 -0
  88. package/dist/models/google/generate-vercel.d.ts.map +1 -0
  89. package/dist/models/google/generate-vercel.js +133 -0
  90. package/dist/models/google/generate-vercel.js.map +1 -0
  91. package/dist/models/google/generate.d.ts +16 -0
  92. package/dist/models/google/generate.d.ts.map +1 -0
  93. package/dist/models/google/generate.js +28 -0
  94. package/dist/models/google/generate.js.map +1 -0
  95. package/dist/models/google/generate.test.node.d.ts +9 -0
  96. package/dist/models/google/generate.test.node.d.ts.map +1 -0
  97. package/dist/models/google/generate.test.node.js +106 -0
  98. package/dist/models/google/generate.test.node.js.map +1 -0
  99. package/dist/models/google/google-models.d.ts +14 -0
  100. package/dist/models/google/google-models.d.ts.map +1 -0
  101. package/dist/models/google/google-models.js +25 -0
  102. package/dist/models/google/google-models.js.map +1 -0
  103. package/dist/models/google/normalize-generated-doc.d.ts +10 -0
  104. package/dist/models/google/normalize-generated-doc.d.ts.map +1 -0
  105. package/dist/models/google/normalize-generated-doc.js +48 -0
  106. package/dist/models/google/normalize-generated-doc.js.map +1 -0
  107. package/dist/models/google/patch-native.d.ts +33 -0
  108. package/dist/models/google/patch-native.d.ts.map +1 -0
  109. package/dist/models/google/patch-native.js +164 -0
  110. package/dist/models/google/patch-native.js.map +1 -0
  111. package/dist/models/google/patch-vercel.d.ts +33 -0
  112. package/dist/models/google/patch-vercel.d.ts.map +1 -0
  113. package/dist/models/google/patch-vercel.js +49 -0
  114. package/dist/models/google/patch-vercel.js.map +1 -0
  115. package/dist/models/google/patch.d.ts +12 -0
  116. package/dist/models/google/patch.d.ts.map +1 -0
  117. package/dist/models/google/patch.js +16 -0
  118. package/dist/models/google/patch.js.map +1 -0
  119. package/dist/models/google/patch.test.node.d.ts +9 -0
  120. package/dist/models/google/patch.test.node.d.ts.map +1 -0
  121. package/dist/models/google/patch.test.node.js +110 -0
  122. package/dist/models/google/patch.test.node.js.map +1 -0
  123. package/dist/models/google/schema.d.ts +416 -0
  124. package/dist/models/google/schema.d.ts.map +1 -0
  125. package/dist/models/google/schema.js +254 -0
  126. package/dist/models/google/schema.js.map +1 -0
  127. package/dist/models/openai/generate-native.d.ts +65 -0
  128. package/dist/models/openai/generate-native.d.ts.map +1 -0
  129. package/dist/models/openai/generate-native.js +276 -0
  130. package/dist/models/openai/generate-native.js.map +1 -0
  131. package/dist/models/openai/generate-vercel.d.ts +59 -0
  132. package/dist/models/openai/generate-vercel.d.ts.map +1 -0
  133. package/dist/models/openai/generate-vercel.js +132 -0
  134. package/dist/models/openai/generate-vercel.js.map +1 -0
  135. package/dist/models/openai/generate.d.ts +16 -0
  136. package/dist/models/openai/generate.d.ts.map +1 -0
  137. package/dist/models/openai/generate.js +28 -0
  138. package/dist/models/openai/generate.js.map +1 -0
  139. package/dist/models/openai/generate.test.node.d.ts +9 -0
  140. package/dist/models/openai/generate.test.node.d.ts.map +1 -0
  141. package/dist/models/openai/generate.test.node.js +106 -0
  142. package/dist/models/openai/generate.test.node.js.map +1 -0
  143. package/dist/models/openai/openai-models.d.ts +14 -0
  144. package/dist/models/openai/openai-models.d.ts.map +1 -0
  145. package/dist/models/openai/openai-models.js +23 -0
  146. package/dist/models/openai/openai-models.js.map +1 -0
  147. package/dist/models/openai/patch-native.d.ts +33 -0
  148. package/dist/models/openai/patch-native.d.ts.map +1 -0
  149. package/dist/models/openai/patch-native.js +151 -0
  150. package/dist/models/openai/patch-native.js.map +1 -0
  151. package/dist/models/openai/patch-vercel.d.ts +33 -0
  152. package/dist/models/openai/patch-vercel.d.ts.map +1 -0
  153. package/dist/models/openai/patch-vercel.js +49 -0
  154. package/dist/models/openai/patch-vercel.js.map +1 -0
  155. package/dist/models/openai/patch.d.ts +12 -0
  156. package/dist/models/openai/patch.d.ts.map +1 -0
  157. package/dist/models/openai/patch.js +16 -0
  158. package/dist/models/openai/patch.js.map +1 -0
  159. package/dist/models/openai/patch.test.node.d.ts +9 -0
  160. package/dist/models/openai/patch.test.node.d.ts.map +1 -0
  161. package/dist/models/openai/patch.test.node.js +110 -0
  162. package/dist/models/openai/patch.test.node.js.map +1 -0
  163. package/dist/models/openai/schema.d.ts +460 -0
  164. package/dist/models/openai/schema.d.ts.map +1 -0
  165. package/dist/models/openai/schema.js +327 -0
  166. package/dist/models/openai/schema.js.map +1 -0
  167. package/dist/patch.d.ts +45 -0
  168. package/dist/patch.d.ts.map +1 -0
  169. package/dist/patch.js +138 -0
  170. package/dist/patch.js.map +1 -0
  171. package/dist/plugins/ai-plugin-base.d.ts +40 -0
  172. package/dist/plugins/ai-plugin-base.d.ts.map +1 -0
  173. package/dist/plugins/ai-plugin-base.js +218 -0
  174. package/dist/plugins/ai-plugin-base.js.map +1 -0
  175. package/dist/plugins/ai-plugin.css +181 -0
  176. package/dist/plugins/lexical/create-empty-editor-state.d.ts +32 -0
  177. package/dist/plugins/lexical/create-empty-editor-state.d.ts.map +1 -0
  178. package/dist/plugins/lexical/create-empty-editor-state.js +51 -0
  179. package/dist/plugins/lexical/create-empty-editor-state.js.map +1 -0
  180. package/dist/plugins/lexical/import-html.d.ts +10 -0
  181. package/dist/plugins/lexical/import-html.d.ts.map +1 -0
  182. package/dist/plugins/lexical/import-html.js +31 -0
  183. package/dist/plugins/lexical/import-html.js.map +1 -0
  184. package/dist/plugins/lexical/index.d.ts +9 -0
  185. package/dist/plugins/lexical/index.d.ts.map +1 -0
  186. package/dist/plugins/lexical/index.js +9 -0
  187. package/dist/plugins/lexical/index.js.map +1 -0
  188. package/dist/plugins/lexical/plugin.d.ts +11 -0
  189. package/dist/plugins/lexical/plugin.d.ts.map +1 -0
  190. package/dist/plugins/lexical/plugin.js +305 -0
  191. package/dist/plugins/lexical/plugin.js.map +1 -0
  192. package/dist/plugins/storage.d.ts +18 -0
  193. package/dist/plugins/storage.d.ts.map +1 -0
  194. package/dist/plugins/storage.js +57 -0
  195. package/dist/plugins/storage.js.map +1 -0
  196. package/dist/plugins/streaming-preview.d.ts +12 -0
  197. package/dist/plugins/streaming-preview.d.ts.map +1 -0
  198. package/dist/plugins/streaming-preview.js +24 -0
  199. package/dist/plugins/streaming-preview.js.map +1 -0
  200. package/dist/plugins/text/index.d.ts +9 -0
  201. package/dist/plugins/text/index.d.ts.map +1 -0
  202. package/dist/plugins/text/index.js +9 -0
  203. package/dist/plugins/text/index.js.map +1 -0
  204. package/dist/plugins/text/plugin.d.ts +18 -0
  205. package/dist/plugins/text/plugin.d.ts.map +1 -0
  206. package/dist/plugins/text/plugin.js +261 -0
  207. package/dist/plugins/text/plugin.js.map +1 -0
  208. package/dist/prompts.d.ts +30 -0
  209. package/dist/prompts.d.ts.map +1 -0
  210. package/dist/prompts.js +83 -0
  211. package/dist/prompts.js.map +1 -0
  212. package/dist/schemas/lexical-json-schema.d.ts +68 -0
  213. package/dist/schemas/lexical-json-schema.d.ts.map +1 -0
  214. package/dist/schemas/lexical-json-schema.js +434 -0
  215. package/dist/schemas/lexical-json-schema.js.map +1 -0
  216. package/dist/scripts/list-models.d.ts +9 -0
  217. package/dist/scripts/list-models.d.ts.map +1 -0
  218. package/dist/scripts/list-models.js +55 -0
  219. package/dist/scripts/list-models.js.map +1 -0
  220. package/dist/server.d.ts +25 -0
  221. package/dist/server.d.ts.map +1 -0
  222. package/dist/server.js +22 -0
  223. package/dist/server.js.map +1 -0
  224. package/dist/utils/convert-to-lexical.d.ts +62 -0
  225. package/dist/utils/convert-to-lexical.d.ts.map +1 -0
  226. package/dist/utils/convert-to-lexical.js +210 -0
  227. package/dist/utils/convert-to-lexical.js.map +1 -0
  228. package/dist/utils/create-empty-editor-state.d.ts +32 -0
  229. package/dist/utils/create-empty-editor-state.d.ts.map +1 -0
  230. package/dist/utils/create-empty-editor-state.js +51 -0
  231. package/dist/utils/create-empty-editor-state.js.map +1 -0
  232. package/dist/utils/has-text.d.ts +10 -0
  233. package/dist/utils/has-text.d.ts.map +1 -0
  234. package/dist/utils/has-text.js +35 -0
  235. package/dist/utils/has-text.js.map +1 -0
  236. package/dist/utils/has-text.test.d.ts +9 -0
  237. package/dist/utils/has-text.test.d.ts.map +1 -0
  238. package/dist/utils/has-text.test.js +69 -0
  239. package/dist/utils/has-text.test.js.map +1 -0
  240. package/dist/utils/is-object-schema.d.ts +17 -0
  241. package/dist/utils/is-object-schema.d.ts.map +1 -0
  242. package/dist/utils/is-object-schema.js +19 -0
  243. package/dist/utils/is-object-schema.js.map +1 -0
  244. package/dist/utils/lexical-text-edits.d.ts +23 -0
  245. package/dist/utils/lexical-text-edits.d.ts.map +1 -0
  246. package/dist/utils/lexical-text-edits.js +62 -0
  247. package/dist/utils/lexical-text-edits.js.map +1 -0
  248. package/package.json +111 -0
@@ -0,0 +1,212 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+ export declare const anthropicGenerationSchema: {
9
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
10
+ readonly type: "object";
11
+ readonly additionalProperties: false;
12
+ readonly required: readonly ["title", "blocks"];
13
+ readonly properties: {
14
+ readonly title: {
15
+ readonly type: readonly ["string", "null"];
16
+ };
17
+ readonly blocks: {
18
+ readonly type: "array";
19
+ readonly items: {
20
+ readonly $ref: "#/$defs/Block";
21
+ };
22
+ };
23
+ };
24
+ readonly $defs: {
25
+ readonly Marks: {
26
+ readonly type: "object";
27
+ readonly additionalProperties: false;
28
+ readonly required: readonly ["bold", "italic", "underline", "code"];
29
+ readonly properties: {
30
+ readonly bold: {
31
+ readonly type: "boolean";
32
+ };
33
+ readonly italic: {
34
+ readonly type: "boolean";
35
+ };
36
+ readonly underline: {
37
+ readonly type: "boolean";
38
+ };
39
+ readonly code: {
40
+ readonly type: "boolean";
41
+ };
42
+ };
43
+ };
44
+ readonly InlineText: {
45
+ readonly type: "object";
46
+ readonly additionalProperties: false;
47
+ readonly required: readonly ["kind", "text", "marks"];
48
+ readonly properties: {
49
+ readonly kind: {
50
+ readonly const: "text";
51
+ };
52
+ readonly text: {
53
+ readonly type: "string";
54
+ };
55
+ readonly marks: {
56
+ readonly $ref: "#/$defs/Marks";
57
+ };
58
+ };
59
+ };
60
+ readonly InlineLink: {
61
+ readonly type: "object";
62
+ readonly additionalProperties: false;
63
+ readonly required: readonly ["kind", "url", "text", "marks"];
64
+ readonly properties: {
65
+ readonly kind: {
66
+ readonly const: "link";
67
+ };
68
+ readonly url: {
69
+ readonly type: "string";
70
+ };
71
+ readonly text: {
72
+ readonly type: "string";
73
+ };
74
+ readonly marks: {
75
+ readonly $ref: "#/$defs/Marks";
76
+ };
77
+ };
78
+ };
79
+ readonly InlineBr: {
80
+ readonly type: "object";
81
+ readonly additionalProperties: false;
82
+ readonly required: readonly ["kind"];
83
+ readonly properties: {
84
+ readonly kind: {
85
+ readonly const: "br";
86
+ };
87
+ };
88
+ };
89
+ readonly Inline: {
90
+ readonly anyOf: readonly [{
91
+ readonly $ref: "#/$defs/InlineText";
92
+ }, {
93
+ readonly $ref: "#/$defs/InlineLink";
94
+ }, {
95
+ readonly $ref: "#/$defs/InlineBr";
96
+ }];
97
+ };
98
+ readonly Paragraph: {
99
+ readonly type: "object";
100
+ readonly additionalProperties: false;
101
+ readonly required: readonly ["kind", "align", "inlines"];
102
+ readonly properties: {
103
+ readonly kind: {
104
+ readonly const: "paragraph";
105
+ };
106
+ readonly align: {
107
+ readonly enum: readonly ["start", "center", "right"];
108
+ };
109
+ readonly inlines: {
110
+ readonly type: "array";
111
+ readonly items: {
112
+ readonly $ref: "#/$defs/Inline";
113
+ };
114
+ };
115
+ };
116
+ };
117
+ readonly Heading: {
118
+ readonly type: "object";
119
+ readonly additionalProperties: false;
120
+ readonly required: readonly ["kind", "level", "inlines"];
121
+ readonly properties: {
122
+ readonly kind: {
123
+ readonly const: "heading";
124
+ };
125
+ readonly level: {
126
+ readonly enum: readonly [1, 2, 3];
127
+ };
128
+ readonly inlines: {
129
+ readonly type: "array";
130
+ readonly items: {
131
+ readonly $ref: "#/$defs/Inline";
132
+ };
133
+ };
134
+ };
135
+ };
136
+ readonly Quote: {
137
+ readonly type: "object";
138
+ readonly additionalProperties: false;
139
+ readonly required: readonly ["kind", "blocks"];
140
+ readonly properties: {
141
+ readonly kind: {
142
+ readonly const: "quote";
143
+ };
144
+ readonly blocks: {
145
+ readonly type: "array";
146
+ readonly items: {
147
+ readonly $ref: "#/$defs/Paragraph";
148
+ };
149
+ };
150
+ };
151
+ };
152
+ readonly Hr: {
153
+ readonly type: "object";
154
+ readonly additionalProperties: false;
155
+ readonly required: readonly ["kind"];
156
+ readonly properties: {
157
+ readonly kind: {
158
+ readonly const: "hr";
159
+ };
160
+ };
161
+ };
162
+ readonly ListItem: {
163
+ readonly type: "object";
164
+ readonly additionalProperties: false;
165
+ readonly required: readonly ["indent", "blocks"];
166
+ readonly properties: {
167
+ readonly indent: {
168
+ readonly enum: readonly [0, 1];
169
+ };
170
+ readonly blocks: {
171
+ readonly type: "array";
172
+ readonly items: {
173
+ readonly $ref: "#/$defs/Paragraph";
174
+ };
175
+ };
176
+ };
177
+ };
178
+ readonly List: {
179
+ readonly type: "object";
180
+ readonly additionalProperties: false;
181
+ readonly required: readonly ["kind", "listType", "items"];
182
+ readonly properties: {
183
+ readonly kind: {
184
+ readonly const: "list";
185
+ };
186
+ readonly listType: {
187
+ readonly enum: readonly ["bullet", "number"];
188
+ };
189
+ readonly items: {
190
+ readonly type: "array";
191
+ readonly items: {
192
+ readonly $ref: "#/$defs/ListItem";
193
+ };
194
+ };
195
+ };
196
+ };
197
+ readonly Block: {
198
+ readonly anyOf: readonly [{
199
+ readonly $ref: "#/$defs/Heading";
200
+ }, {
201
+ readonly $ref: "#/$defs/Paragraph";
202
+ }, {
203
+ readonly $ref: "#/$defs/List";
204
+ }, {
205
+ readonly $ref: "#/$defs/Quote";
206
+ }, {
207
+ readonly $ref: "#/$defs/Hr";
208
+ }];
209
+ };
210
+ };
211
+ };
212
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0H5B,CAAA"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+ export const anthropicGenerationSchema = {
9
+ $schema: 'http://json-schema.org/draft-07/schema#',
10
+ type: 'object',
11
+ additionalProperties: false,
12
+ required: ['title', 'blocks'],
13
+ properties: {
14
+ title: { type: ['string', 'null'] },
15
+ blocks: {
16
+ type: 'array',
17
+ items: { $ref: '#/$defs/Block' },
18
+ },
19
+ },
20
+ $defs: {
21
+ Marks: {
22
+ type: 'object',
23
+ additionalProperties: false,
24
+ required: ['bold', 'italic', 'underline', 'code'],
25
+ properties: {
26
+ bold: { type: 'boolean' },
27
+ italic: { type: 'boolean' },
28
+ underline: { type: 'boolean' },
29
+ code: { type: 'boolean' },
30
+ },
31
+ },
32
+ InlineText: {
33
+ type: 'object',
34
+ additionalProperties: false,
35
+ required: ['kind', 'text', 'marks'],
36
+ properties: {
37
+ kind: { const: 'text' },
38
+ text: { type: 'string' },
39
+ marks: { $ref: '#/$defs/Marks' },
40
+ },
41
+ },
42
+ InlineLink: {
43
+ type: 'object',
44
+ additionalProperties: false,
45
+ required: ['kind', 'url', 'text', 'marks'],
46
+ properties: {
47
+ kind: { const: 'link' },
48
+ url: { type: 'string' },
49
+ text: { type: 'string' },
50
+ marks: { $ref: '#/$defs/Marks' },
51
+ },
52
+ },
53
+ InlineBr: {
54
+ type: 'object',
55
+ additionalProperties: false,
56
+ required: ['kind'],
57
+ properties: { kind: { const: 'br' } },
58
+ },
59
+ Inline: {
60
+ anyOf: [
61
+ { $ref: '#/$defs/InlineText' },
62
+ { $ref: '#/$defs/InlineLink' },
63
+ { $ref: '#/$defs/InlineBr' },
64
+ ],
65
+ },
66
+ Paragraph: {
67
+ type: 'object',
68
+ additionalProperties: false,
69
+ required: ['kind', 'align', 'inlines'],
70
+ properties: {
71
+ kind: { const: 'paragraph' },
72
+ align: { enum: ['start', 'center', 'right'] },
73
+ inlines: { type: 'array', items: { $ref: '#/$defs/Inline' } },
74
+ },
75
+ },
76
+ Heading: {
77
+ type: 'object',
78
+ additionalProperties: false,
79
+ required: ['kind', 'level', 'inlines'],
80
+ properties: {
81
+ kind: { const: 'heading' },
82
+ level: { enum: [1, 2, 3] },
83
+ inlines: { type: 'array', items: { $ref: '#/$defs/Inline' } },
84
+ },
85
+ },
86
+ Quote: {
87
+ type: 'object',
88
+ additionalProperties: false,
89
+ required: ['kind', 'blocks'],
90
+ properties: {
91
+ kind: { const: 'quote' },
92
+ blocks: { type: 'array', items: { $ref: '#/$defs/Paragraph' } },
93
+ },
94
+ },
95
+ Hr: {
96
+ type: 'object',
97
+ additionalProperties: false,
98
+ required: ['kind'],
99
+ properties: { kind: { const: 'hr' } },
100
+ },
101
+ ListItem: {
102
+ type: 'object',
103
+ additionalProperties: false,
104
+ required: ['indent', 'blocks'],
105
+ properties: {
106
+ indent: { enum: [0, 1] },
107
+ blocks: { type: 'array', items: { $ref: '#/$defs/Paragraph' } },
108
+ },
109
+ },
110
+ List: {
111
+ type: 'object',
112
+ additionalProperties: false,
113
+ required: ['kind', 'listType', 'items'],
114
+ properties: {
115
+ kind: { const: 'list' },
116
+ listType: { enum: ['bullet', 'number'] },
117
+ items: { type: 'array', items: { $ref: '#/$defs/ListItem' } },
118
+ },
119
+ },
120
+ Block: {
121
+ anyOf: [
122
+ { $ref: '#/$defs/Heading' },
123
+ { $ref: '#/$defs/Paragraph' },
124
+ { $ref: '#/$defs/List' },
125
+ { $ref: '#/$defs/Quote' },
126
+ { $ref: '#/$defs/Hr' },
127
+ ],
128
+ },
129
+ },
130
+ };
131
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/models/anthropic/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,OAAO,EAAE,yCAAyC;IAClD,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC7B,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnC,MAAM,EAAE;YACN,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;SACjC;KACF;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YACL,IAAI,EAAE,QAAQ;YACd,oBAAoB,EAAE,KAAK;YA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oB,EAAE,KAAK;YAC3B,QAAQ,EAAE,CAAC,MAAM,CAAC;YAClB,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;SACtC;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAAQ;YACd,oBAAoB,EAAE,KAAK;YAC3B,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;YAC9B,UAAU,EAAE;gBACV,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;gBACxB,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE;aAChE;SACF;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,oBAAoB,EAAE,KAAK;YAC3B,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC;YACvC,UAAU,EAAE;gBACV,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;gBACvB,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE;gBACxC,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,EAAE;aAC9D;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE;gBACL,EAAE,IAAI,EAAE,iBAAiB,EAAE;gBAC3B,EAAE,IAAI,EAAE,mBAAmB,EAAE;gBAC7B,EAAE,IAAI,EAAE,cAAc,EAAE;gBACxB,EAAE,IAAI,EAAE,eAAe,EAAE;gBACzB,EAAE,IAAI,EAAE,YAAY,EAAE;aACvB;SACF;KACF;CACO,CAAA"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+ import type { GeneratedDoc } from '../../utils/convert-to-lexical';
9
+ export type GenerateTextStreamingResult = {
10
+ text: AsyncIterable<string>;
11
+ final: Promise<string>;
12
+ };
13
+ export type GenerateHtmlStreamingResult = {
14
+ text: AsyncIterable<string>;
15
+ final: Promise<string>;
16
+ };
17
+ export declare function generateHtml(options: {
18
+ apiKey: string;
19
+ model: string;
20
+ prompt: string;
21
+ signal?: AbortSignal;
22
+ }): Promise<string>;
23
+ export declare function generateHtmlStreaming(options: {
24
+ apiKey: string;
25
+ model: string;
26
+ prompt: string;
27
+ signal?: AbortSignal;
28
+ }): GenerateHtmlStreamingResult;
29
+ export declare function generateText(options: {
30
+ apiKey: string;
31
+ model: string;
32
+ prompt: string;
33
+ maxLength?: number;
34
+ signal?: AbortSignal;
35
+ }): Promise<string>;
36
+ export declare function generateTextStreaming(options: {
37
+ apiKey: string;
38
+ model: string;
39
+ prompt: string;
40
+ maxLength?: number;
41
+ signal?: AbortSignal;
42
+ }): GenerateTextStreamingResult;
43
+ export declare function generateDoc(options: {
44
+ apiKey: string;
45
+ model: string;
46
+ prompt: string;
47
+ signal?: AbortSignal;
48
+ }): Promise<GeneratedDoc>;
49
+ export type GenerateDocStreamingResult = {
50
+ text: AsyncIterable<string>;
51
+ final: Promise<GeneratedDoc>;
52
+ };
53
+ export declare function generateDocStreaming(options: {
54
+ apiKey: string;
55
+ model: string;
56
+ prompt: string;
57
+ signal?: AbortSignal;
58
+ }): GenerateDocStreamingResult;
59
+ //# sourceMappingURL=generate-native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-native.d.ts","sourceRoot":"","sources":["../../../src/models/google/generate-native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,aAAa,CAAC,MAAM,C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,CAAA;CACrB,GAAG,OAAO,CAAC,YAAY,CAAC,CAyBxB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;CAC7B,CAAA;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GAAG,0BAA0B,CA6D7B"}
@@ -0,0 +1,244 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+ import { GoogleGenAI } from '@google/genai';
9
+ import { buildGenerateHtmlSystemPrompt, buildGenerateHtmlUserPrompt, buildGenerateSystemPrompt, buildGenerateTextSystemPrompt, buildGenerateTextUserPrompt, } from '../../prompts';
10
+ import { normalizeGeneratedDoc } from './normalize-generated-doc';
11
+ import { geminiGenerationSchema2 } from './schema';
12
+ export async function generateHtml(options) {
13
+ const google = new GoogleGenAI({ apiKey: options.apiKey });
14
+ const response = await google.models.generateContent({
15
+ model: options.model,
16
+ config: { systemInstruction: buildGenerateHtmlSystemPrompt() },
17
+ contents: [
18
+ {
19
+ role: 'user',
20
+ parts: [{ text: buildGenerateHtmlUserPrompt(options.prompt) }],
21
+ },
22
+ ],
23
+ });
24
+ return response.text?.trim() ?? '';
25
+ }
26
+ export function generateHtmlStreaming(options) {
27
+ const ai = new GoogleGenAI({ apiKey: options.apiKey });
28
+ const streamPromise = ai.models.generateContentStream({
29
+ model: options.model,
30
+ config: {
31
+ systemInstruction: buildGenerateHtmlSystemPrompt(),
32
+ abortSignal: options.signal,
33
+ },
34
+ contents: [
35
+ {
36
+ role: 'user',
37
+ parts: [{ text: buildGenerateHtmlUserPrompt(options.prompt) }],
38
+ },
39
+ ],
40
+ });
41
+ let resolveFinal;
42
+ let rejectFinal;
43
+ const final = new Promise((resolve, reject) => {
44
+ resolveFinal = resolve;
45
+ rejectFinal = reject;
46
+ });
47
+ const text = (async function* () {
48
+ let buffered = '';
49
+ try {
50
+ const stream = await streamPromise;
51
+ for await (const chunk of stream) {
52
+ const chunkText = typeof chunk?.text === 'function' ? chunk.text() : chunk?.text;
53
+ if (typeof chunkText === 'string' && chunkText.length > 0) {
54
+ buffered += chunkText;
55
+ yield chunkText;
56
+ }
57
+ }
58
+ resolveFinal(buffered.trim());
59
+ }
60
+ catch (error) {
61
+ rejectFinal(error);
62
+ throw error;
63
+ }
64
+ })();
65
+ return { text, final };
66
+ }
67
+ export async function generateText(options) {
68
+ const ai = new GoogleGenAI({ apiKey: options.apiKey });
69
+ const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
70
+ ? Math.floor(options.maxLength)
71
+ : undefined;
72
+ const promptWithLength = typeof maxLength === 'number' && maxLength > 0
73
+ ? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
74
+ : options.prompt;
75
+ const response = await ai.models.generateContent({
76
+ model: options.model,
77
+ config: {
78
+ systemInstruction: buildGenerateTextSystemPrompt(),
79
+ abortSignal: options.signal,
80
+ },
81
+ contents: [
82
+ {
83
+ role: 'user',
84
+ parts: [{ text: buildGenerateTextUserPrompt(promptWithLength) }],
85
+ },
86
+ ],
87
+ });
88
+ const normalized = response.text?.trim() ?? '';
89
+ if (typeof maxLength === 'number' && maxLength > 0) {
90
+ return normalized.length > maxLength ? normalized.slice(0, maxLength).trimEnd() : normalized;
91
+ }
92
+ return normalized;
93
+ }
94
+ export function generateTextStreaming(options) {
95
+ const ai = new GoogleGenAI({ apiKey: options.apiKey });
96
+ const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
97
+ ? Math.floor(options.maxLength)
98
+ : undefined;
99
+ const promptWithLength = typeof maxLength === 'number' && maxLength > 0
100
+ ? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
101
+ : options.prompt;
102
+ const streamPromise = ai.models.generateContentStream({
103
+ model: options.model,
104
+ config: {
105
+ systemInstruction: buildGenerateTextSystemPrompt(),
106
+ abortSignal: options.signal,
107
+ },
108
+ contents: [
109
+ {
110
+ role: 'user',
111
+ parts: [{ text: buildGenerateTextUserPrompt(promptWithLength) }],
112
+ },
113
+ ],
114
+ });
115
+ let resolveFinal;
116
+ let rejectFinal;
117
+ const final = new Promise((resolve, reject) => {
118
+ resolveFinal = resolve;
119
+ rejectFinal = reject;
120
+ });
121
+ const text = (async function* () {
122
+ let buffered = '';
123
+ let remaining = typeof maxLength === 'number' && maxLength > 0 ? maxLength : undefined;
124
+ try {
125
+ const stream = await streamPromise;
126
+ for await (const chunk of stream) {
127
+ const chunkText = typeof chunk?.text === 'function' ? chunk.text() : chunk?.text;
128
+ if (typeof chunkText !== 'string' || chunkText.length === 0) {
129
+ continue;
130
+ }
131
+ buffered += chunkText;
132
+ if (typeof remaining === 'number') {
133
+ if (remaining <= 0) {
134
+ continue;
135
+ }
136
+ const sliced = chunkText.slice(0, remaining);
137
+ remaining -= sliced.length;
138
+ if (sliced.length > 0) {
139
+ yield sliced;
140
+ }
141
+ continue;
142
+ }
143
+ yield chunkText;
144
+ }
145
+ const normalized = buffered.trim();
146
+ if (typeof maxLength === 'number' && maxLength > 0) {
147
+ resolveFinal(normalized.length > maxLength ? normalized.slice(0, maxLength).trimEnd() : normalized);
148
+ }
149
+ else {
150
+ resolveFinal(normalized);
151
+ }
152
+ }
153
+ catch (error) {
154
+ rejectFinal(error);
155
+ throw error;
156
+ }
157
+ })();
158
+ return { text, final };
159
+ }
160
+ const tryParseJson = (text) => {
161
+ const trimmed = text.trim();
162
+ if (trimmed.length === 0)
163
+ return undefined;
164
+ // Defensive: sometimes models wrap JSON in code fences.
165
+ const fenced = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i);
166
+ const candidate = fenced?.[1]?.trim() ?? trimmed;
167
+ return JSON.parse(candidate);
168
+ };
169
+ export async function generateDoc(options) {
170
+ const ai = new GoogleGenAI({ apiKey: options.apiKey });
171
+ const response = await ai.models.generateContent({
172
+ model: options.model,
173
+ contents: options.prompt,
174
+ config: {
175
+ systemInstruction: buildGenerateSystemPrompt(),
176
+ responseMimeType: 'application/json',
177
+ responseJsonSchema: geminiGenerationSchema2,
178
+ abortSignal: options.signal,
179
+ },
180
+ });
181
+ const text = response.text?.trim() ?? '';
182
+ if (text.length === 0) {
183
+ throw new Error('Google model returned an empty response.');
184
+ }
185
+ const parsed = tryParseJson(text);
186
+ if (parsed && typeof parsed === 'object') {
187
+ return normalizeGeneratedDoc(parsed);
188
+ }
189
+ throw new Error('Google structured output did not return a JSON object.');
190
+ }
191
+ export function generateDocStreaming(options) {
192
+ const ai = new GoogleGenAI({ apiKey: options.apiKey });
193
+ // const responseJsonSchema = {
194
+ // ...(geminiGenerationSchema as any),
195
+ // $schema: undefined,
196
+ // }
197
+ // const normalizedResponseJsonSchema = normalizeJsonSchemaForGemini(responseJsonSchema)
198
+ const streamPromise = ai.models.generateContentStream({
199
+ model: options.model,
200
+ contents: options.prompt,
201
+ config: {
202
+ systemInstruction: buildGenerateSystemPrompt(),
203
+ responseMimeType: 'application/json',
204
+ // responseJsonSchema: normalizedResponseJsonSchema,
205
+ responseJsonSchema: geminiGenerationSchema2,
206
+ abortSignal: options.signal,
207
+ },
208
+ });
209
+ let resolveFinal;
210
+ let rejectFinal;
211
+ const final = new Promise((resolve, reject) => {
212
+ resolveFinal = resolve;
213
+ rejectFinal = reject;
214
+ });
215
+ const text = (async function* () {
216
+ let buffered = '';
217
+ try {
218
+ const stream = await streamPromise;
219
+ for await (const chunk of stream) {
220
+ const chunkText = typeof chunk?.text === 'function' ? chunk.text() : chunk?.text;
221
+ if (typeof chunkText === 'string' && chunkText.length > 0) {
222
+ buffered += chunkText;
223
+ yield chunkText;
224
+ }
225
+ }
226
+ const trimmed = buffered.trim();
227
+ if (trimmed.length === 0) {
228
+ throw new Error('Google model returned an empty response.');
229
+ }
230
+ const parsed = tryParseJson(trimmed);
231
+ if (parsed && typeof parsed === 'object') {
232
+ resolveFinal(normalizeGeneratedDoc(parsed));
233
+ return;
234
+ }
235
+ throw new Error('Google structured output did not return a JSON object.');
236
+ }
237
+ catch (error) {
238
+ rejectFinal(error);
239
+ throw error;
240
+ }
241
+ })();
242
+ return { text, final };
243
+ }
244
+ //# sourceMappingURL=generate-native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-native.js","sourceRoot":"","sources":["../../../src/models/google/generate-native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EACL,6BAA6B,EAC7B,2BAA2B,EAC3B,yBAAyB,EACzB,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAalD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAKlC;IACC,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAE1D,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;QACnD,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,EAAE;QAC9D,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,2BAA2B,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;aAC/D;SACF;KACF,CAAC,CAAA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