@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,235 @@
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 Ajv from 'ajv';
9
+ import { getLogger } from './lib/logger';
10
+ import { getGenerateDoc as getGenerateAnthropicDoc, getGenerateDocStreaming as getGenerateAnthropicDocStreaming, getGenerateHtml as getGenerateAnthropicHtml, getGenerateHtmlStreaming as getGenerateAnthropicHtmlStreaming, getGenerateText as getGenerateAnthropicText, getGenerateTextStreaming as getGenerateAnthropicTextStreaming, } from './models/anthropic/generate';
11
+ import { getGenerateDoc as getGenerateGeminiDoc, getGenerateDocStreaming as getGenerateGeminiDocStreaming, getGenerateHtml as getGenerateGeminiHtml, getGenerateHtmlStreaming as getGenerateGeminiHtmlStreaming, getGenerateText as getGenerateGeminiText, getGenerateTextStreaming as getGenerateGeminiTextStreaming, } from './models/google/generate';
12
+ import { getGenerateDoc as getGenerateOpenAIDoc, getGenerateDocStreaming as getGenerateOpenAIDocStreaming, getGenerateHtml as getGenerateOpenAIHtml, getGenerateHtmlStreaming as getGenerateOpenAIHtmlStreaming, getGenerateText as getGenerateOpenAIText, getGenerateTextStreaming as getGenerateOpenAITextStreaming, } from './models/openai/generate';
13
+ import { documentSchema } from './schemas/lexical-json-schema';
14
+ import { convertToLexical } from './utils/convert-to-lexical';
15
+ const ajv = new Ajv({ allErrors: true, strict: false });
16
+ const validateLexicalDocument = ajv.compile(documentSchema);
17
+ const logger = getLogger();
18
+ const composeTextPrompt = (prompt, inputText) => {
19
+ const trimmedPrompt = prompt.trim();
20
+ const trimmedInput = inputText?.trim();
21
+ const delimiter = '\n\n---\n';
22
+ if (trimmedInput == null)
23
+ return trimmedPrompt;
24
+ return `${trimmedPrompt}${delimiter}${trimmedInput}`;
25
+ };
26
+ async function processGenerationResult(generated, options) {
27
+ const { provider, apiKey, modelName, prompt, sdk, signal } = options;
28
+ const generatedDocument = convertToLexical(generated);
29
+ const isValid = validateLexicalDocument(generatedDocument);
30
+ if (isValid) {
31
+ return {
32
+ success: true,
33
+ format: 'lexical',
34
+ editor: generatedDocument,
35
+ message: 'Task completed successfully via AI instruction (generate mode).',
36
+ };
37
+ }
38
+ const validationErrors = (validateLexicalDocument.errors ?? []).map((e) => {
39
+ const instancePath = e.instancePath ? ` at ${e.instancePath}` : '';
40
+ const message = e.message ?? 'Schema validation error';
41
+ return `${message}${instancePath}`;
42
+ });
43
+ logger.warn({ errors: validationErrors }, 'Lexical validation failed, attempting HTML fallback');
44
+ // Fallback: generate HTML when the model cannot reliably produce valid Lexical JSON.
45
+ const generateHtml = provider === 'openai'
46
+ ? getGenerateOpenAIHtml(sdk)
47
+ : provider === 'google'
48
+ ? getGenerateGeminiHtml(sdk)
49
+ : getGenerateAnthropicHtml(sdk);
50
+ try {
51
+ const html = await generateHtml({ apiKey, model: modelName, prompt, signal });
52
+ const trimmedHtml = html?.trim() ?? '';
53
+ if (trimmedHtml.length > 0) {
54
+ return {
55
+ success: true,
56
+ format: 'html',
57
+ html: trimmedHtml,
58
+ message: 'Generated HTML fallback (Lexical JSON validation failed).',
59
+ };
60
+ }
61
+ }
62
+ catch (error) {
63
+ logger.error(error, 'HTML fallback generation failed');
64
+ }
65
+ return {
66
+ success: false,
67
+ message: 'AI failed to generate a valid Lexical document (and HTML fallback was empty).',
68
+ errors: {
69
+ editor: validationErrors,
70
+ },
71
+ };
72
+ }
73
+ /**
74
+ * Generates a new Lexical document from scratch based on a user prompt.
75
+ * Uses the documentSchema to ensure the AI generates valid Lexical JSON
76
+ * with proper structure including headings, paragraphs, lists, etc.
77
+ */
78
+ export async function generateStructured(options) {
79
+ const { provider, apiKey, modelName, prompt, sdk, signal, inputText } = options;
80
+ const generateDoc = provider === 'openai'
81
+ ? getGenerateOpenAIDoc(sdk)
82
+ : provider === 'google'
83
+ ? getGenerateGeminiDoc(sdk)
84
+ : getGenerateAnthropicDoc(sdk);
85
+ const composedPrompt = composeTextPrompt(prompt, inputText);
86
+ const generated = await generateDoc({ apiKey, model: modelName, prompt: composedPrompt, signal });
87
+ return processGenerationResult(generated, options);
88
+ }
89
+ /**
90
+ * Streams a Lexical document generation.
91
+ */
92
+ export function generateStructuredStreaming(options) {
93
+ const { provider, apiKey, modelName, prompt, sdk, signal, inputText } = options;
94
+ const generateDocStreaming = provider === 'openai'
95
+ ? getGenerateOpenAIDocStreaming(sdk)
96
+ : provider === 'google'
97
+ ? getGenerateGeminiDocStreaming(sdk)
98
+ : getGenerateAnthropicDocStreaming(sdk);
99
+ const composedPrompt = composeTextPrompt(prompt, inputText);
100
+ const streamResult = generateDocStreaming({
101
+ apiKey,
102
+ model: modelName,
103
+ prompt: composedPrompt,
104
+ signal,
105
+ });
106
+ const final = (async () => {
107
+ const generated = await streamResult.final;
108
+ return processGenerationResult(generated, options);
109
+ })();
110
+ return { text: streamResult.text, final };
111
+ }
112
+ export async function generateHtml(options) {
113
+ const { provider, apiKey, modelName, prompt, sdk, signal, inputText } = options;
114
+ const generateHtml = provider === 'openai'
115
+ ? getGenerateOpenAIHtml(sdk)
116
+ : provider === 'google'
117
+ ? getGenerateGeminiHtml(sdk)
118
+ : getGenerateAnthropicHtml(sdk);
119
+ const composedPrompt = composeTextPrompt(prompt, inputText);
120
+ const html = await generateHtml({ apiKey, model: modelName, prompt: composedPrompt, signal });
121
+ const trimmed = html?.trim() ?? '';
122
+ if (trimmed.length === 0) {
123
+ return {
124
+ success: false,
125
+ message: 'AI returned empty HTML.',
126
+ errors: { prompt: ['AI returned empty HTML.'] },
127
+ };
128
+ }
129
+ return {
130
+ success: true,
131
+ format: 'html',
132
+ html: trimmed,
133
+ message: 'Generated HTML successfully.',
134
+ };
135
+ }
136
+ export function generateHtmlStreaming(options) {
137
+ const { provider, apiKey, modelName, prompt, sdk, signal, inputText } = options;
138
+ const generateHtmlStreaming = provider === 'openai'
139
+ ? getGenerateOpenAIHtmlStreaming(sdk)
140
+ : provider === 'google'
141
+ ? getGenerateGeminiHtmlStreaming(sdk)
142
+ : getGenerateAnthropicHtmlStreaming(sdk);
143
+ const composedPrompt = composeTextPrompt(prompt, inputText);
144
+ const streamResult = generateHtmlStreaming({
145
+ apiKey,
146
+ model: modelName,
147
+ prompt: composedPrompt,
148
+ signal,
149
+ });
150
+ const final = (async () => {
151
+ const html = await streamResult.final;
152
+ const trimmed = html?.trim() ?? '';
153
+ if (trimmed.length === 0) {
154
+ return {
155
+ success: false,
156
+ message: 'AI returned empty HTML.',
157
+ errors: { prompt: ['AI returned empty HTML.'] },
158
+ };
159
+ }
160
+ return {
161
+ success: true,
162
+ format: 'html',
163
+ html: trimmed,
164
+ message: 'Generated HTML successfully.',
165
+ };
166
+ })();
167
+ return { text: streamResult.text, final };
168
+ }
169
+ export async function generateText(options) {
170
+ const { provider, apiKey, modelName, prompt, sdk, signal, maxLength, inputText } = options;
171
+ const generateText = provider === 'openai'
172
+ ? getGenerateOpenAIText(sdk)
173
+ : provider === 'google'
174
+ ? getGenerateGeminiText(sdk)
175
+ : getGenerateAnthropicText(sdk);
176
+ const composedPrompt = composeTextPrompt(prompt, inputText);
177
+ // console.log('Composed Prompt:', composedPrompt)
178
+ const text = await generateText({
179
+ apiKey,
180
+ model: modelName,
181
+ prompt: composedPrompt,
182
+ maxLength,
183
+ signal,
184
+ });
185
+ const trimmed = text?.trim() ?? '';
186
+ if (trimmed.length === 0) {
187
+ return {
188
+ success: false,
189
+ message: 'AI returned empty text.',
190
+ errors: { prompt: ['AI returned empty text.'] },
191
+ };
192
+ }
193
+ return {
194
+ success: true,
195
+ format: 'text',
196
+ text: trimmed,
197
+ message: 'Generated text successfully.',
198
+ };
199
+ }
200
+ export function generateTextStreaming(options) {
201
+ const { provider, apiKey, modelName, prompt, sdk, signal, maxLength, inputText } = options;
202
+ const generateTextStreaming = provider === 'openai'
203
+ ? getGenerateOpenAITextStreaming(sdk)
204
+ : provider === 'google'
205
+ ? getGenerateGeminiTextStreaming(sdk)
206
+ : getGenerateAnthropicTextStreaming(sdk);
207
+ const composedPrompt = composeTextPrompt(prompt, inputText);
208
+ // console.log('Composed Prompt:', composedPrompt)
209
+ const streamResult = generateTextStreaming({
210
+ apiKey,
211
+ model: modelName,
212
+ prompt: composedPrompt,
213
+ maxLength,
214
+ signal,
215
+ });
216
+ const final = (async () => {
217
+ const text = await streamResult.final;
218
+ const trimmed = text?.trim() ?? '';
219
+ if (trimmed.length === 0) {
220
+ return {
221
+ success: false,
222
+ message: 'AI returned empty text.',
223
+ errors: { prompt: ['AI returned empty text.'] },
224
+ };
225
+ }
226
+ return {
227
+ success: true,
228
+ format: 'text',
229
+ text: trimmed,
230
+ message: 'Generated text successfully.',
231
+ };
232
+ })();
233
+ return { text: streamResult.text, final };
234
+ }
235
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EACL,cAAc,IAAI,uBAAuB,EACzC,uBAAuB,IAAI,gCAAgC,EAC3D,eAAe,IAAI,wBAAwB,EAC3C,wBAAwB,IAAI,iCAAiC,EAC7D,eAAe,IAAI,wBAAwB,EAC3C,wBAAwB,IAAI,iCAAiC,GAC9D,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,cAAc,IAAI,oBAAoB,EACtC,uBAAuB,IAAI,6BAA6B,EACxD,eAAe,IAAI,qBAAqB,EACxC,wBAAwB,IAAI,8BAA8B,EAC1D,eAAe,IAAI,qBAAqB,EACxC,wBAAwB,IAAI,8BAA8B,GAC3D,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,cAAc,IAAI,oBAAoB,EACtC,uBAAuB,IAAI,6BAA6B,EACxD,eAAe,IAAI,qBAAqB,EACxC,wBAAwB,IAAI,8BAA8B,EAC1D,eAAe,IAAI,qBAAqB,EACxC,wBAAwB,IAAI,8BAA8B,GAC3D,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAG7D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;AACvD,MAAM,uBAAuB,GAAG,GAAG,CAAC,OAAO,CAAC,cAAqB,CAAC,CAAA;AAClE,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AA+C1B,MAAM,iBAAiB,GA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zC,MAAM;QACN,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,cAAc;QACtB,SAAS;QACT,MAAM;KACA,CAAC,CAAA;IAET,MAAM,KAAK,GAAG,CAAC,KAAK,IAA6C,EAAE;QACjE,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,KAAK,CAAA;QACrC,MAAM,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAClC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,yBAAyB;gBAClC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,yBAAyB,CAAC,EAAE;aAChD,CAAA;QACH,CAAC;QAED,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,8BAA8B;SACxC,CAAA;IACH,CAAC,CAAC,EAAE,CAAA;IAEJ,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,CAAA;AAC3C,CAAC"}
@@ -0,0 +1,28 @@
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
+ /**
9
+ * Browser-safe public surface for `@byline/ai`.
10
+ *
11
+ * Importing this entry pulls only: type definitions, the public config
12
+ * provider, and small provider/model helpers. It does NOT pull in the
13
+ * AI execution code (which depends on pino, the Anthropic/OpenAI/Google
14
+ * SDKs, etc., and would crash in the browser).
15
+ *
16
+ * Server-only execution APIs live at `@byline/ai/server`.
17
+ */
18
+ export { INSTRUCTION_MODES } from './@types';
19
+ export { type AiPublicConfig, DEFAULT_AI_ENDPOINT, DEFAULT_MODELS, getAiPublicConfig, PROVIDER_MODELS, } from './config/ai-config';
20
+ export { AiPublicConfigContext, AiPublicConfigProvider, useAiPublicConfig, useOptionalAiPublicConfig, } from './config/ai-provider';
21
+ export type { ExecuteInstruction, ExecuteInstructionOptions, ExecuteInstructionParams, InstructionMode, InstructionState, OutputPreference, Provider, Sdk, } from './@types';
22
+ import type { Provider, Sdk } from './@types';
23
+ export declare const PROVIDERS: Array<[Provider, string]>;
24
+ export declare const SDKS: Sdk[];
25
+ export declare const isProvider: (value: string) => value is Provider;
26
+ export declare const getDefaultModel: (provider: Provider) => string;
27
+ export declare const normalizeSdk: (value: unknown) => Sdk;
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EACL,KAAK,cAAc,EACnB,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACV,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,GAAG,GACJ,MAAM,UAAU,CAAA;AAGjB,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAE7C,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAI/C,CAAA;AAED,eAAO,MAAM,IAAI,EAAE,GAAG,EAAyB,CAAA;AAE/C,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,KAAK,IAAI,QAEnD,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,UAAU,QAAQ,KAAG,MAKpD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,GAI7C,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
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
+ /**
9
+ * Browser-safe public surface for `@byline/ai`.
10
+ *
11
+ * Importing this entry pulls only: type definitions, the public config
12
+ * provider, and small provider/model helpers. It does NOT pull in the
13
+ * AI execution code (which depends on pino, the Anthropic/OpenAI/Google
14
+ * SDKs, etc., and would crash in the browser).
15
+ *
16
+ * Server-only execution APIs live at `@byline/ai/server`.
17
+ */
18
+ export { INSTRUCTION_MODES } from './@types';
19
+ export { DEFAULT_AI_ENDPOINT, DEFAULT_MODELS, getAiPublicConfig, PROVIDER_MODELS, } from './config/ai-config';
20
+ export { AiPublicConfigContext, AiPublicConfigProvider, useAiPublicConfig, useOptionalAiPublicConfig, } from './config/ai-provider';
21
+ import { DEFAULT_MODELS } from './config/ai-config';
22
+ export const PROVIDERS = [
23
+ ['openai', 'OpenAI'],
24
+ ['google', 'Google'],
25
+ ['anthropic', 'Anthropic'],
26
+ ];
27
+ export const SDKS = ['native', 'vercel'];
28
+ export const isProvider = (value) => {
29
+ return value === 'openai' || value === 'google' || value === 'anthropic';
30
+ };
31
+ export const getDefaultModel = (provider) => {
32
+ if (!isProvider(provider)) {
33
+ throw new Error(`Invalid provider: ${provider}`);
34
+ }
35
+ return DEFAULT_MODELS[provider];
36
+ };
37
+ export const normalizeSdk = (value) => {
38
+ if (typeof value !== 'string')
39
+ return 'native';
40
+ const normalized = value.trim().toLowerCase();
41
+ return normalized === 'vercel' ? 'vercel' : 'native';
42
+ };
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":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AAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;AACtD,CAAC,CAAA"}
@@ -0,0 +1,23 @@
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 { z } from 'zod';
9
+ export declare const lexicalTextEditsResponseSchema: z.ZodObject<{
10
+ edits: z.ZodArray<z.ZodObject<{
11
+ id: z.ZodNumber;
12
+ text: z.ZodString;
13
+ }, z.core.$strip>>;
14
+ }, z.core.$strip>;
15
+ export type LexicalTextEditsResponse = z.infer<typeof lexicalTextEditsResponseSchema>;
16
+ export type ExtractedTextNode = {
17
+ id: number;
18
+ path: (string | number)[];
19
+ text: string;
20
+ };
21
+ export declare function extractTextNodesFromLexicalState(state: unknown): ExtractedTextNode[];
22
+ export declare function setAtPath(root: unknown, path: (string | number)[], value: unknown): void;
23
+ //# sourceMappingURL=lexical-text-edits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexical-text-edits.d.ts","sourceRoot":"","sources":["../src/lexical-text-edits.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,8BAA8B;;;;;iBAOzC,CAAA;AAEF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAErF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAMD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,EAAE,CA+BpF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAexF"}
@@ -0,0 +1,62 @@
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 { z } from 'zod';
9
+ export const lexicalTextEditsResponseSchema = z.object({
10
+ edits: z.array(z.object({
11
+ id: z.number(),
12
+ text: z.string(),
13
+ })),
14
+ });
15
+ const isPlainObject = (value) => {
16
+ return typeof value === 'object' && value !== null && Array.isArray(value) === false;
17
+ };
18
+ export function extractTextNodesFromLexicalState(state) {
19
+ const nodes = [];
20
+ const walk = (value, path) => {
21
+ if (Array.isArray(value)) {
22
+ for (let index = 0; index < value.length; index++) {
23
+ walk(value[index], [...path, index]);
24
+ }
25
+ return;
26
+ }
27
+ if (!isPlainObject(value))
28
+ return;
29
+ const type = value.type;
30
+ const text = value.text;
31
+ if (type === 'text' && typeof text === 'string') {
32
+ nodes.push({
33
+ id: nodes.length,
34
+ path: [...path, 'text'],
35
+ text,
36
+ });
37
+ }
38
+ for (const [key, child] of Object.entries(value)) {
39
+ if (key === 'text')
40
+ continue;
41
+ walk(child, [...path, key]);
42
+ }
43
+ };
44
+ walk(state, []);
45
+ return nodes;
46
+ }
47
+ export function setAtPath(root, path, value) {
48
+ let cursor = root;
49
+ for (let i = 0; i < path.length - 1; i++) {
50
+ const key = path[i];
51
+ if (cursor == null) {
52
+ throw new Error('Invalid path: hit null/undefined');
53
+ }
54
+ cursor = cursor[key];
55
+ }
56
+ const last = path[path.length - 1];
57
+ if (cursor == null) {
58
+ throw new Error('Invalid path: hit null/undefined at leaf parent');
59
+ }
60
+ cursor[last] = value;
61
+ }
62
+ //# sourceMappingURL=lexical-text-edits.js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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 { BaseLogger } from 'pino';
9
+ export declare const getLogger: () => BaseLogger;
10
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAKtC,eAAO,MAAM,SAAS,QAAO,UAK5B,CAAA"}
@@ -0,0 +1,16 @@
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 logger from 'pino';
9
+ let cached;
10
+ export const getLogger = () => {
11
+ if (cached == null) {
12
+ cached = logger({ level: 'debug' });
13
+ }
14
+ return cached;
15
+ };
16
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,MAAM,MAAM,MAAM,CAAA;AAEzB,IAAI,MAA8B,CAAA;AAElC,MAAM,CAAC,MAAM,SAAS,GAAG,GAAe,EAAE;IACxC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,MAAM,GAAG,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,14 @@
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 type ModelInfo = {
9
+ id: string;
10
+ name: string;
11
+ created: string;
12
+ };
13
+ export declare function listAllModels(): Promise<ModelInfo[]>;
14
+ //# sourceMappingURL=anthropic-models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-models.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/anthropic-models.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAYD,wBAAsB,aAAa,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAqB1D"}
@@ -0,0 +1,41 @@
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 Anthropic from '@anthropic-ai/sdk';
9
+ import { getAiServerConfig } from '../../config/ai-config';
10
+ const isValidHttpUrl = (value) => {
11
+ if (value == null || value.trim().length === 0)
12
+ return false;
13
+ try {
14
+ const url = new URL(value);
15
+ return url.protocol === 'http:' || url.protocol === 'https:';
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ };
21
+ export async function listAllModels() {
22
+ const config = getAiServerConfig();
23
+ const baseURL = isValidHttpUrl(config.ai.anthropic.baseUrl)
24
+ ? config.ai.anthropic.baseUrl
25
+ : 'https://api.anthropic.com';
26
+ const client = new Anthropic({
27
+ apiKey: config.ai.anthropic.apiKey,
28
+ baseURL,
29
+ });
30
+ const models = [];
31
+ const modelsPager = await client.models.list();
32
+ for await (const model of modelsPager) {
33
+ models.push({
34
+ id: model.id,
35
+ name: model.display_name,
36
+ created: model.created_at,
37
+ });
38
+ }
39
+ return models;
40
+ }
41
+ //# sourceMappingURL=anthropic-models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-models.js","sourceRoot":"","sources":["../../../src/models/anthropic/anthropic-models.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAA;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAW1D,MAAM,cAAc,GAAG,CAAC,KAAyB,EAAmB,EAAE;IACpE,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC5D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;QAC1B,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAA;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,aAAa;IACjC,MAAM,MAAM,GAAG,iBAAiB,EAAE,CAAA;IAClC,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;QACzD,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO;QAC7B,CAAC,CAAC,2BAA2B,CAAA;IAE/B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM;QAClC,OAAO;KACR,CAAC,CAAA;IAEF,MAAM,MAAM,GAAgB,EAAE,CAAA;IAC9B,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC9C,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;QACtC,MAAM,CAAC,IAAI,CAAC;YACV,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,KAAK,CAAC,YAAY;YACxB,OAAO,EAAE,KAAK,CAAC,UAAU;SAC1B,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,9 @@
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 anthropic: (apiKey: string) => import("@ai-sdk/anthropic").AnthropicProvider;
9
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,kDAIpC,CAAA"}
@@ -0,0 +1,20 @@
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 { createAnthropic } from '@ai-sdk/anthropic';
9
+ const normalizeAnthropicBaseURL = (value) => {
10
+ const base = (value && value.trim().length > 0 ? value : 'https://api.anthropic.com')
11
+ .trim()
12
+ .replace(/\/+$/, '');
13
+ // The Vercel AI SDK Anthropic provider expects baseURL that includes `/v1`.
14
+ return base.endsWith('/v1') ? base : `${base}/v1`;
15
+ };
16
+ export const anthropic = (apiKey) => createAnthropic({
17
+ apiKey,
18
+ baseURL: normalizeAnthropicBaseURL(process.env.ANTHROPIC_BASE_URL),
19
+ });
20
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/models/anthropic/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,MAAM,yBAAyB,GAAG,CAAC,KAAyB,EAAE,EAAE;IAC9D,MAAM,IAAI,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,2BAA2B,CAAC;SAClF,IAAI,EAAE;SACN,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAEtB,4EAA4E;IAC5E,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,CAAA;AACnD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,EAAE,CAC1C,eAAe,CAAC;IACd,MAAM;IACN,OAAO,EAAE,yBAAyB,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;CACnE,CAAC,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/anthropic/generate-native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;CACvB,CAAA;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA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