@byline/ai 1.9.0 → 1.9.1

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 (126) hide show
  1. package/dist/@types.d.ts +0 -9
  2. package/dist/@types.d.ts.map +1 -1
  3. package/dist/@types.js +0 -10
  4. package/dist/@types.js.map +1 -1
  5. package/dist/execute.d.ts.map +1 -1
  6. package/dist/execute.js +13 -38
  7. package/dist/execute.js.map +1 -1
  8. package/dist/generate.d.ts +1 -2
  9. package/dist/generate.d.ts.map +1 -1
  10. package/dist/generate.js +53 -49
  11. package/dist/generate.js.map +1 -1
  12. package/dist/index.d.ts +3 -5
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +1 -8
  15. package/dist/index.js.map +1 -1
  16. package/dist/lib/logger.d.ts +2 -2
  17. package/dist/lib/logger.d.ts.map +1 -1
  18. package/dist/lib/logger.js +27 -5
  19. package/dist/lib/logger.js.map +1 -1
  20. package/dist/models/anthropic/generate.d.ts +51 -8
  21. package/dist/models/anthropic/generate.d.ts.map +1 -1
  22. package/dist/models/anthropic/generate.js +261 -18
  23. package/dist/models/anthropic/generate.js.map +1 -1
  24. package/dist/models/anthropic/generate.test.node.js +7 -56
  25. package/dist/models/anthropic/generate.test.node.js.map +1 -1
  26. package/dist/models/anthropic/patch.d.ts +25 -4
  27. package/dist/models/anthropic/patch.d.ts.map +1 -1
  28. package/dist/models/anthropic/patch.js +142 -6
  29. package/dist/models/anthropic/patch.js.map +1 -1
  30. package/dist/models/anthropic/patch.test.node.js +7 -57
  31. package/dist/models/anthropic/patch.test.node.js.map +1 -1
  32. package/dist/models/google/generate.d.ts +51 -8
  33. package/dist/models/google/generate.d.ts.map +1 -1
  34. package/dist/models/google/generate.js +235 -19
  35. package/dist/models/google/generate.js.map +1 -1
  36. package/dist/models/google/generate.test.node.js +8 -56
  37. package/dist/models/google/generate.test.node.js.map +1 -1
  38. package/dist/models/google/patch.d.ts +25 -4
  39. package/dist/models/google/patch.d.ts.map +1 -1
  40. package/dist/models/google/patch.js +154 -6
  41. package/dist/models/google/patch.js.map +1 -1
  42. package/dist/models/google/patch.test.node.js +7 -57
  43. package/dist/models/google/patch.test.node.js.map +1 -1
  44. package/dist/models/openai/generate.d.ts +57 -8
  45. package/dist/models/openai/generate.d.ts.map +1 -1
  46. package/dist/models/openai/generate.js +266 -18
  47. package/dist/models/openai/generate.js.map +1 -1
  48. package/dist/models/openai/generate.test.node.js +7 -56
  49. package/dist/models/openai/generate.test.node.js.map +1 -1
  50. package/dist/models/openai/patch.d.ts +25 -4
  51. package/dist/models/openai/patch.d.ts.map +1 -1
  52. package/dist/models/openai/patch.js +141 -6
  53. package/dist/models/openai/patch.js.map +1 -1
  54. package/dist/models/openai/patch.test.node.js +7 -57
  55. package/dist/models/openai/patch.test.node.js.map +1 -1
  56. package/dist/patch.d.ts +2 -3
  57. package/dist/patch.d.ts.map +1 -1
  58. package/dist/patch.js +18 -16
  59. package/dist/patch.js.map +1 -1
  60. package/dist/plugins/ai-plugin-base.d.ts +1 -2
  61. package/dist/plugins/ai-plugin-base.d.ts.map +1 -1
  62. package/dist/plugins/ai-plugin-base.js +5 -20
  63. package/dist/plugins/ai-plugin-base.js.map +1 -1
  64. package/dist/plugins/lexical/plugin.d.ts.map +1 -1
  65. package/dist/plugins/lexical/plugin.js +3 -5
  66. package/dist/plugins/lexical/plugin.js.map +1 -1
  67. package/dist/plugins/storage.d.ts +1 -2
  68. package/dist/plugins/storage.d.ts.map +1 -1
  69. package/dist/plugins/storage.js +2 -4
  70. package/dist/plugins/storage.js.map +1 -1
  71. package/dist/plugins/text/plugin.d.ts.map +1 -1
  72. package/dist/plugins/text/plugin.js +3 -5
  73. package/dist/plugins/text/plugin.js.map +1 -1
  74. package/package.json +4 -10
  75. package/dist/models/anthropic/anthropic.d.ts +0 -9
  76. package/dist/models/anthropic/anthropic.d.ts.map +0 -1
  77. package/dist/models/anthropic/anthropic.js +0 -20
  78. package/dist/models/anthropic/anthropic.js.map +0 -1
  79. package/dist/models/anthropic/generate-native.d.ts +0 -59
  80. package/dist/models/anthropic/generate-native.d.ts.map +0 -1
  81. package/dist/models/anthropic/generate-native.js +0 -271
  82. package/dist/models/anthropic/generate-native.js.map +0 -1
  83. package/dist/models/anthropic/generate-vercel.d.ts +0 -59
  84. package/dist/models/anthropic/generate-vercel.d.ts.map +0 -1
  85. package/dist/models/anthropic/generate-vercel.js +0 -126
  86. package/dist/models/anthropic/generate-vercel.js.map +0 -1
  87. package/dist/models/anthropic/patch-native.d.ts +0 -33
  88. package/dist/models/anthropic/patch-native.d.ts.map +0 -1
  89. package/dist/models/anthropic/patch-native.js +0 -152
  90. package/dist/models/anthropic/patch-native.js.map +0 -1
  91. package/dist/models/anthropic/patch-vercel.d.ts +0 -33
  92. package/dist/models/anthropic/patch-vercel.d.ts.map +0 -1
  93. package/dist/models/anthropic/patch-vercel.js +0 -47
  94. package/dist/models/anthropic/patch-vercel.js.map +0 -1
  95. package/dist/models/google/generate-native.d.ts +0 -59
  96. package/dist/models/google/generate-native.d.ts.map +0 -1
  97. package/dist/models/google/generate-native.js +0 -244
  98. package/dist/models/google/generate-native.js.map +0 -1
  99. package/dist/models/google/generate-vercel.d.ts +0 -59
  100. package/dist/models/google/generate-vercel.d.ts.map +0 -1
  101. package/dist/models/google/generate-vercel.js +0 -133
  102. package/dist/models/google/generate-vercel.js.map +0 -1
  103. package/dist/models/google/patch-native.d.ts +0 -33
  104. package/dist/models/google/patch-native.d.ts.map +0 -1
  105. package/dist/models/google/patch-native.js +0 -164
  106. package/dist/models/google/patch-native.js.map +0 -1
  107. package/dist/models/google/patch-vercel.d.ts +0 -33
  108. package/dist/models/google/patch-vercel.d.ts.map +0 -1
  109. package/dist/models/google/patch-vercel.js +0 -49
  110. package/dist/models/google/patch-vercel.js.map +0 -1
  111. package/dist/models/openai/generate-native.d.ts +0 -65
  112. package/dist/models/openai/generate-native.d.ts.map +0 -1
  113. package/dist/models/openai/generate-native.js +0 -276
  114. package/dist/models/openai/generate-native.js.map +0 -1
  115. package/dist/models/openai/generate-vercel.d.ts +0 -59
  116. package/dist/models/openai/generate-vercel.d.ts.map +0 -1
  117. package/dist/models/openai/generate-vercel.js +0 -132
  118. package/dist/models/openai/generate-vercel.js.map +0 -1
  119. package/dist/models/openai/patch-native.d.ts +0 -33
  120. package/dist/models/openai/patch-native.d.ts.map +0 -1
  121. package/dist/models/openai/patch-native.js +0 -151
  122. package/dist/models/openai/patch-native.js.map +0 -1
  123. package/dist/models/openai/patch-vercel.d.ts +0 -33
  124. package/dist/models/openai/patch-vercel.d.ts.map +0 -1
  125. package/dist/models/openai/patch-vercel.js +0 -49
  126. package/dist/models/openai/patch-vercel.js.map +0 -1
@@ -1,244 +0,0 @@
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
@@ -1 +0,0 @@
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;IAEF,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAKrC;IACC,MAAM,EAAE,GAAG,IAAI,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAEtD,MAAM,aAAa,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;QAC3B,IAAI,QAAQ,GAAG,EAAE,CAAA;QACjB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,aAAa,CAAA;YAClC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBACjC,MAAM,SAAS,GACb,OAAQ,KAAa,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC,CAAE,KAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAE,KAAa,EAAE,IAAI,CAAA;gBAC3F,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC1D,QAAQ,IAAI,SAAS,CAAA;oBACrB,MAAM,SAAS,CAAA;gBACjB,CAAC;YACH,CAAC;YAED,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;YAC/B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;YAC7D,CAAC;YAED,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;YACpC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzC,YAAY,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAA;gBAC3C,OAAM;YACR,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;QAC3E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,KAAK,CAAC,CAAA;YAClB,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,CAAC,EAAE,CAAA;IAEJ,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACxB,CAAC"}
@@ -1,59 +0,0 @@
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-vercel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-vercel.d.ts","sourceRoot":"","sources":["../../../src/models/google/generate-vercel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,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,CAA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AAM,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,CAsB7B"}
@@ -1,133 +0,0 @@
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 { createGoogleGenerativeAI } from '@ai-sdk/google';
9
- import { generateText as generateTextAi, jsonSchema, Output, streamText as streamTextAi } from 'ai';
10
- import { buildGenerateHtmlSystemPrompt, buildGenerateHtmlUserPrompt, buildGenerateSystemPrompt, buildGenerateTextSystemPrompt, buildGenerateTextUserPrompt, } from '../../prompts';
11
- import { normalizeGeneratedDoc } from './normalize-generated-doc';
12
- import { geminiGenerationSchema, geminiGenerationSchema2 } from './schema';
13
- export async function generateHtml(options) {
14
- const google = createGoogleGenerativeAI({ apiKey: options.apiKey });
15
- const result = await generateTextAi({
16
- model: google(options.model),
17
- system: buildGenerateHtmlSystemPrompt(),
18
- prompt: buildGenerateHtmlUserPrompt(options.prompt),
19
- abortSignal: options.signal,
20
- });
21
- return result.text;
22
- }
23
- export function generateHtmlStreaming(options) {
24
- const google = createGoogleGenerativeAI({ apiKey: options.apiKey });
25
- const result = streamTextAi({
26
- model: google(options.model),
27
- system: buildGenerateHtmlSystemPrompt(),
28
- prompt: buildGenerateHtmlUserPrompt(options.prompt),
29
- abortSignal: options.signal,
30
- });
31
- return {
32
- text: result.textStream,
33
- final: result.text,
34
- };
35
- }
36
- export async function generateText(options) {
37
- const google = createGoogleGenerativeAI({ apiKey: options.apiKey });
38
- const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
39
- ? Math.floor(options.maxLength)
40
- : undefined;
41
- const promptWithLength = typeof maxLength === 'number' && maxLength > 0
42
- ? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
43
- : options.prompt;
44
- const result = await generateTextAi({
45
- model: google(options.model),
46
- system: buildGenerateTextSystemPrompt(),
47
- prompt: buildGenerateTextUserPrompt(promptWithLength),
48
- abortSignal: options.signal,
49
- });
50
- const normalized = result.text.trim();
51
- if (typeof maxLength === 'number' && maxLength > 0) {
52
- return normalized.length > maxLength ? normalized.slice(0, maxLength).trimEnd() : normalized;
53
- }
54
- return normalized;
55
- }
56
- export function generateTextStreaming(options) {
57
- const google = createGoogleGenerativeAI({ apiKey: options.apiKey });
58
- const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
59
- ? Math.floor(options.maxLength)
60
- : undefined;
61
- const promptWithLength = typeof maxLength === 'number' && maxLength > 0
62
- ? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
63
- : options.prompt;
64
- const result = streamTextAi({
65
- model: google(options.model),
66
- system: buildGenerateTextSystemPrompt(),
67
- prompt: buildGenerateTextUserPrompt(promptWithLength),
68
- abortSignal: options.signal,
69
- });
70
- const text = (async function* () {
71
- let remaining = typeof maxLength === 'number' && maxLength > 0 ? maxLength : undefined;
72
- for await (const delta of result.textStream) {
73
- if (typeof remaining === 'number') {
74
- if (remaining <= 0) {
75
- continue;
76
- }
77
- const chunk = delta.slice(0, remaining);
78
- remaining -= chunk.length;
79
- if (chunk.length > 0) {
80
- yield chunk;
81
- }
82
- continue;
83
- }
84
- yield delta;
85
- }
86
- })();
87
- const final = result.text.then((t) => {
88
- const normalized = (t ?? '').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
- return { text, final };
95
- }
96
- export async function generateDoc(options) {
97
- const google = createGoogleGenerativeAI({ apiKey: options.apiKey });
98
- const schema = jsonSchema({
99
- ...geminiGenerationSchema2,
100
- $schema: undefined,
101
- });
102
- const result = await generateTextAi({
103
- model: google(options.model),
104
- system: buildGenerateSystemPrompt(),
105
- prompt: options.prompt,
106
- abortSignal: options.signal,
107
- output: Output.object({
108
- schema,
109
- }),
110
- });
111
- return normalizeGeneratedDoc(result.output);
112
- }
113
- export function generateDocStreaming(options) {
114
- const google = createGoogleGenerativeAI({ apiKey: options.apiKey });
115
- const schema = jsonSchema({
116
- ...geminiGenerationSchema,
117
- $schema: undefined,
118
- });
119
- const result = streamTextAi({
120
- model: google(options.model),
121
- system: buildGenerateSystemPrompt(),
122
- prompt: options.prompt,
123
- abortSignal: options.signal,
124
- output: Output.object({
125
- schema,
126
- }),
127
- });
128
- return {
129
- text: result.textStream,
130
- final: result.output.then(normalizeGeneratedDoc),
131
- };
132
- }
133
- //# sourceMappingURL=generate-vercel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-vercel.js","sourceRoot":"","sources":["../../../src/models/google/generate-vercel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,IAAI,CAAA;AAEnG,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,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAa1E,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAKlC;IACC,MAAM,MAAM,GA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EAAE,MAAM,CAAC,MAAM,CAAC;YACpB,MAAM;SACP,CAAC;KACH,CAAC,CAAA;IAEF,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,UAAU;QACvB,KAAK,EAAG,MAAM,CAAC,MAA2B,CAAC,IAAI,CAAC,qBAAqB,CAAC;KACvE,CAAA;AACH,CAAC"}
@@ -1,33 +0,0 @@
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 { LexicalTextEditsResponse } from '../../utils/lexical-text-edits';
9
- export declare function patchDoc(options: {
10
- apiKey: string;
11
- model: string;
12
- prompt: string;
13
- textNodes: Array<{
14
- id: number;
15
- text: string;
16
- }>;
17
- signal?: AbortSignal;
18
- }): Promise<LexicalTextEditsResponse>;
19
- export type PatchDocStreamingResult = {
20
- text: AsyncIterable<string>;
21
- final: Promise<LexicalTextEditsResponse>;
22
- };
23
- export declare function patchDocStreaming(options: {
24
- apiKey: string;
25
- model: string;
26
- prompt: string;
27
- textNodes: Array<{
28
- id: number;
29
- text: string;
30
- }>;
31
- signal?: AbortSignal;
32
- }): PatchDocStreamingResult;
33
- //# sourceMappingURL=patch-native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"patch-native.d.ts","sourceRoot":"","sources":["../../../src/models/google/patch-native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAqG1E,wBAAsB,QAAQ,CAAC,OAAO,EAAE;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC9C,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CA2BpC;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,wBAAwB,CAAC,CAAA;CACzC,CAAA;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC9C,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GAAG,uBAAuB,CAuD1B"}
@@ -1,164 +0,0 @@
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 { buildPatchSystemPrompt } from '../../prompts';
10
- const buildPatchUserPrompt = (instruction, textNodes) => {
11
- return [
12
- `INSTRUCTION: ${instruction}`,
13
- '',
14
- 'INPUT_TEXT_NODES_JSON:',
15
- JSON.stringify(textNodes),
16
- ].join('\n');
17
- };
18
- const tryParseJson = (text) => {
19
- const trimmed = text.trim();
20
- if (trimmed.length === 0)
21
- return undefined;
22
- const fenced = trimmed.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i);
23
- const candidate = fenced?.[1]?.trim() ?? trimmed;
24
- return JSON.parse(candidate);
25
- };
26
- const normalizeJsonSchemaForGemini = (schema) => {
27
- if (schema == null)
28
- return schema;
29
- if (Array.isArray(schema))
30
- return schema.map(normalizeJsonSchemaForGemini);
31
- if (typeof schema !== 'object')
32
- return schema;
33
- const obj = schema;
34
- const next = {};
35
- for (const [key, value] of Object.entries(obj)) {
36
- if (key === 'const') {
37
- next.enum = [value];
38
- continue;
39
- }
40
- if (key === 'type' && Array.isArray(value)) {
41
- next.anyOf = value.map((t) => ({ type: t }));
42
- continue;
43
- }
44
- next[key] = normalizeJsonSchemaForGemini(value);
45
- }
46
- return next;
47
- };
48
- const normalizePatchResponse = (value) => {
49
- const maybeObj = value;
50
- // Allow the model to return the edits array directly.
51
- const editsCandidate = Array.isArray(maybeObj)
52
- ? maybeObj
53
- : Array.isArray(maybeObj?.edits)
54
- ? maybeObj.edits
55
- : Array.isArray(maybeObj?.output)
56
- ? maybeObj.output
57
- : undefined;
58
- if (!Array.isArray(editsCandidate)) {
59
- throw new Error('Google patch response is missing an edits array.');
60
- }
61
- const edits = editsCandidate
62
- .map((e) => {
63
- const idRaw = e?.id;
64
- const textRaw = e?.text;
65
- const id = typeof idRaw === 'number' ? idRaw : typeof idRaw === 'string' ? Number(idRaw) : NaN;
66
- const text = typeof textRaw === 'string' ? textRaw : textRaw == null ? '' : String(textRaw);
67
- if (!Number.isFinite(id))
68
- return undefined;
69
- return { id, text };
70
- })
71
- .filter(Boolean);
72
- return { edits };
73
- };
74
- const googlePatchSchema = {
75
- type: 'object',
76
- additionalProperties: false,
77
- properties: {
78
- edits: {
79
- type: 'array',
80
- items: {
81
- type: 'object',
82
- additionalProperties: false,
83
- properties: {
84
- id: { type: 'number' },
85
- text: { type: 'string' },
86
- },
87
- required: ['id', 'text'],
88
- },
89
- },
90
- },
91
- required: ['edits'],
92
- };
93
- export async function patchDoc(options) {
94
- const ai = new GoogleGenAI({ apiKey: options.apiKey });
95
- const normalizedResponseJsonSchema = normalizeJsonSchemaForGemini(googlePatchSchema);
96
- const response = await ai.models.generateContent({
97
- model: options.model,
98
- contents: buildPatchUserPrompt(options.prompt, options.textNodes),
99
- config: {
100
- systemInstruction: buildPatchSystemPrompt(),
101
- responseMimeType: 'application/json',
102
- responseJsonSchema: normalizedResponseJsonSchema,
103
- abortSignal: options.signal,
104
- },
105
- });
106
- const text = response.text?.trim() ?? '';
107
- if (text.length === 0) {
108
- throw new Error('Google model returned an empty response.');
109
- }
110
- const parsed = tryParseJson(text);
111
- if (parsed && typeof parsed === 'object') {
112
- return normalizePatchResponse(parsed);
113
- }
114
- throw new Error('Google structured output did not return a JSON object.');
115
- }
116
- export function patchDocStreaming(options) {
117
- const ai = new GoogleGenAI({ apiKey: options.apiKey });
118
- const normalizedResponseJsonSchema = normalizeJsonSchemaForGemini(googlePatchSchema);
119
- const streamPromise = ai.models.generateContentStream({
120
- model: options.model,
121
- contents: buildPatchUserPrompt(options.prompt, options.textNodes),
122
- config: {
123
- systemInstruction: buildPatchSystemPrompt(),
124
- responseMimeType: 'application/json',
125
- responseJsonSchema: normalizedResponseJsonSchema,
126
- abortSignal: options.signal,
127
- },
128
- });
129
- let resolveFinal;
130
- let rejectFinal;
131
- const final = new Promise((resolve, reject) => {
132
- resolveFinal = resolve;
133
- rejectFinal = reject;
134
- });
135
- const text = (async function* () {
136
- let buffered = '';
137
- try {
138
- const stream = await streamPromise;
139
- for await (const chunk of stream) {
140
- const chunkText = typeof chunk?.text === 'function' ? chunk.text() : chunk?.text;
141
- if (typeof chunkText === 'string' && chunkText.length > 0) {
142
- buffered += chunkText;
143
- yield chunkText;
144
- }
145
- }
146
- const trimmed = buffered.trim();
147
- if (trimmed.length === 0) {
148
- throw new Error('Google model returned an empty response.');
149
- }
150
- const parsed = tryParseJson(trimmed);
151
- if (parsed && typeof parsed === 'object') {
152
- resolveFinal(normalizePatchResponse(parsed));
153
- return;
154
- }
155
- throw new Error('Google structured output did not return a JSON object.');
156
- }
157
- catch (error) {
158
- rejectFinal(error);
159
- throw error;
160
- }
161
- })();
162
- return { text, final };
163
- }
164
- //# sourceMappingURL=patch-native.js.map