@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.
- package/dist/@types.d.ts +0 -9
- package/dist/@types.d.ts.map +1 -1
- package/dist/@types.js +0 -10
- package/dist/@types.js.map +1 -1
- package/dist/execute.d.ts.map +1 -1
- package/dist/execute.js +13 -38
- package/dist/execute.js.map +1 -1
- package/dist/generate.d.ts +1 -2
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +53 -49
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -8
- package/dist/index.js.map +1 -1
- package/dist/lib/logger.d.ts +2 -2
- package/dist/lib/logger.d.ts.map +1 -1
- package/dist/lib/logger.js +27 -5
- package/dist/lib/logger.js.map +1 -1
- package/dist/models/anthropic/generate.d.ts +51 -8
- package/dist/models/anthropic/generate.d.ts.map +1 -1
- package/dist/models/anthropic/generate.js +261 -18
- package/dist/models/anthropic/generate.js.map +1 -1
- package/dist/models/anthropic/generate.test.node.js +7 -56
- package/dist/models/anthropic/generate.test.node.js.map +1 -1
- package/dist/models/anthropic/patch.d.ts +25 -4
- package/dist/models/anthropic/patch.d.ts.map +1 -1
- package/dist/models/anthropic/patch.js +142 -6
- package/dist/models/anthropic/patch.js.map +1 -1
- package/dist/models/anthropic/patch.test.node.js +7 -57
- package/dist/models/anthropic/patch.test.node.js.map +1 -1
- package/dist/models/google/generate.d.ts +51 -8
- package/dist/models/google/generate.d.ts.map +1 -1
- package/dist/models/google/generate.js +235 -19
- package/dist/models/google/generate.js.map +1 -1
- package/dist/models/google/generate.test.node.js +8 -56
- package/dist/models/google/generate.test.node.js.map +1 -1
- package/dist/models/google/patch.d.ts +25 -4
- package/dist/models/google/patch.d.ts.map +1 -1
- package/dist/models/google/patch.js +154 -6
- package/dist/models/google/patch.js.map +1 -1
- package/dist/models/google/patch.test.node.js +7 -57
- package/dist/models/google/patch.test.node.js.map +1 -1
- package/dist/models/openai/generate.d.ts +57 -8
- package/dist/models/openai/generate.d.ts.map +1 -1
- package/dist/models/openai/generate.js +266 -18
- package/dist/models/openai/generate.js.map +1 -1
- package/dist/models/openai/generate.test.node.js +7 -56
- package/dist/models/openai/generate.test.node.js.map +1 -1
- package/dist/models/openai/patch.d.ts +25 -4
- package/dist/models/openai/patch.d.ts.map +1 -1
- package/dist/models/openai/patch.js +141 -6
- package/dist/models/openai/patch.js.map +1 -1
- package/dist/models/openai/patch.test.node.js +7 -57
- package/dist/models/openai/patch.test.node.js.map +1 -1
- package/dist/patch.d.ts +2 -3
- package/dist/patch.d.ts.map +1 -1
- package/dist/patch.js +18 -16
- package/dist/patch.js.map +1 -1
- package/dist/plugins/ai-plugin-base.d.ts +1 -2
- package/dist/plugins/ai-plugin-base.d.ts.map +1 -1
- package/dist/plugins/ai-plugin-base.js +5 -20
- package/dist/plugins/ai-plugin-base.js.map +1 -1
- package/dist/plugins/lexical/plugin.d.ts.map +1 -1
- package/dist/plugins/lexical/plugin.js +3 -5
- package/dist/plugins/lexical/plugin.js.map +1 -1
- package/dist/plugins/storage.d.ts +1 -2
- package/dist/plugins/storage.d.ts.map +1 -1
- package/dist/plugins/storage.js +2 -4
- package/dist/plugins/storage.js.map +1 -1
- package/dist/plugins/text/plugin.d.ts.map +1 -1
- package/dist/plugins/text/plugin.js +3 -5
- package/dist/plugins/text/plugin.js.map +1 -1
- package/package.json +4 -10
- package/dist/models/anthropic/anthropic.d.ts +0 -9
- package/dist/models/anthropic/anthropic.d.ts.map +0 -1
- package/dist/models/anthropic/anthropic.js +0 -20
- package/dist/models/anthropic/anthropic.js.map +0 -1
- package/dist/models/anthropic/generate-native.d.ts +0 -59
- package/dist/models/anthropic/generate-native.d.ts.map +0 -1
- package/dist/models/anthropic/generate-native.js +0 -271
- package/dist/models/anthropic/generate-native.js.map +0 -1
- package/dist/models/anthropic/generate-vercel.d.ts +0 -59
- package/dist/models/anthropic/generate-vercel.d.ts.map +0 -1
- package/dist/models/anthropic/generate-vercel.js +0 -126
- package/dist/models/anthropic/generate-vercel.js.map +0 -1
- package/dist/models/anthropic/patch-native.d.ts +0 -33
- package/dist/models/anthropic/patch-native.d.ts.map +0 -1
- package/dist/models/anthropic/patch-native.js +0 -152
- package/dist/models/anthropic/patch-native.js.map +0 -1
- package/dist/models/anthropic/patch-vercel.d.ts +0 -33
- package/dist/models/anthropic/patch-vercel.d.ts.map +0 -1
- package/dist/models/anthropic/patch-vercel.js +0 -47
- package/dist/models/anthropic/patch-vercel.js.map +0 -1
- package/dist/models/google/generate-native.d.ts +0 -59
- package/dist/models/google/generate-native.d.ts.map +0 -1
- package/dist/models/google/generate-native.js +0 -244
- package/dist/models/google/generate-native.js.map +0 -1
- package/dist/models/google/generate-vercel.d.ts +0 -59
- package/dist/models/google/generate-vercel.d.ts.map +0 -1
- package/dist/models/google/generate-vercel.js +0 -133
- package/dist/models/google/generate-vercel.js.map +0 -1
- package/dist/models/google/patch-native.d.ts +0 -33
- package/dist/models/google/patch-native.d.ts.map +0 -1
- package/dist/models/google/patch-native.js +0 -164
- package/dist/models/google/patch-native.js.map +0 -1
- package/dist/models/google/patch-vercel.d.ts +0 -33
- package/dist/models/google/patch-vercel.d.ts.map +0 -1
- package/dist/models/google/patch-vercel.js +0 -49
- package/dist/models/google/patch-vercel.js.map +0 -1
- package/dist/models/openai/generate-native.d.ts +0 -65
- package/dist/models/openai/generate-native.d.ts.map +0 -1
- package/dist/models/openai/generate-native.js +0 -276
- package/dist/models/openai/generate-native.js.map +0 -1
- package/dist/models/openai/generate-vercel.d.ts +0 -59
- package/dist/models/openai/generate-vercel.d.ts.map +0 -1
- package/dist/models/openai/generate-vercel.js +0 -132
- package/dist/models/openai/generate-vercel.js.map +0 -1
- package/dist/models/openai/patch-native.d.ts +0 -33
- package/dist/models/openai/patch-native.d.ts.map +0 -1
- package/dist/models/openai/patch-native.js +0 -151
- package/dist/models/openai/patch-native.js.map +0 -1
- package/dist/models/openai/patch-vercel.d.ts +0 -33
- package/dist/models/openai/patch-vercel.d.ts.map +0 -1
- package/dist/models/openai/patch-vercel.js +0 -49
- package/dist/models/openai/patch-vercel.js.map +0 -1
|
@@ -7,39 +7,32 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
9
9
|
import { getAiServerConfig as getServerConfig } from '../../config/ai-config';
|
|
10
|
-
import { generateDoc
|
|
11
|
-
import { generateDocStreaming as generateDocStreamingVercel, generateDoc as generateDocVercel, } from './generate-vercel';
|
|
10
|
+
import { generateDoc, generateDocStreaming } from './generate';
|
|
12
11
|
const MODEL = 'gemini-2.5-flash';
|
|
13
12
|
describe('google generate', () => {
|
|
14
13
|
beforeEach(async () => { });
|
|
15
14
|
const runReal = true; // = process.env.AI_RUN_REAL_TESTS === 'true'
|
|
16
15
|
if (runReal) {
|
|
17
|
-
|
|
18
|
-
* Generates a document from Google using structured outputs.
|
|
19
|
-
*/
|
|
20
|
-
it('makes a real Google request (manual run) from native provider', async () => {
|
|
16
|
+
it('makes a real Google request (manual run)', async () => {
|
|
21
17
|
const config = getServerConfig();
|
|
22
18
|
if (!config.ai.google.apiKey) {
|
|
23
19
|
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
24
20
|
}
|
|
25
|
-
const result = await
|
|
21
|
+
const result = await generateDoc({
|
|
26
22
|
apiKey: config.ai.google.apiKey,
|
|
27
23
|
model: MODEL,
|
|
28
24
|
prompt: 'Write a short description of the solar system..',
|
|
29
25
|
});
|
|
30
|
-
console.log('RESULT (Google
|
|
26
|
+
console.log('RESULT (Google):', result);
|
|
31
27
|
expect(result).toBeTruthy();
|
|
32
28
|
expect(typeof result).toBe('object');
|
|
33
29
|
}, 30000);
|
|
34
|
-
|
|
35
|
-
* Generates a document from Google using structured outputs via streaming.
|
|
36
|
-
*/
|
|
37
|
-
it.skip('streams a real Google response (manual run) from native provider', async () => {
|
|
30
|
+
it.skip('streams a real Google response (manual run)', async () => {
|
|
38
31
|
const config = getServerConfig();
|
|
39
32
|
if (!config.ai.google.apiKey) {
|
|
40
33
|
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
41
34
|
}
|
|
42
|
-
const streamResult =
|
|
35
|
+
const streamResult = generateDocStreaming({
|
|
43
36
|
apiKey: config.ai.google.apiKey,
|
|
44
37
|
model: MODEL,
|
|
45
38
|
prompt: 'Write a short description of the solar system..',
|
|
@@ -47,51 +40,10 @@ describe('google generate', () => {
|
|
|
47
40
|
let streamedText = '';
|
|
48
41
|
for await (const chunk of streamResult.text) {
|
|
49
42
|
streamedText += chunk;
|
|
50
|
-
console.log('STREAM CHUNK (Google
|
|
43
|
+
console.log('STREAM CHUNK (Google):', chunk);
|
|
51
44
|
}
|
|
52
45
|
const final = await streamResult.final;
|
|
53
|
-
console.log('FINAL RESULT (Google
|
|
54
|
-
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
55
|
-
expect(final).toBeTruthy();
|
|
56
|
-
expect(typeof final).toBe('object');
|
|
57
|
-
}, 30000);
|
|
58
|
-
/***
|
|
59
|
-
* Generates a document from Google using structured outputs.
|
|
60
|
-
*/
|
|
61
|
-
it('makes a real Google request (manual run) from vercel provider', async () => {
|
|
62
|
-
const config = getServerConfig();
|
|
63
|
-
if (!config.ai.google.apiKey) {
|
|
64
|
-
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
65
|
-
}
|
|
66
|
-
const result = await generateDocVercel({
|
|
67
|
-
apiKey: config.ai.google.apiKey,
|
|
68
|
-
model: MODEL,
|
|
69
|
-
prompt: 'Write a short description of the solar system..',
|
|
70
|
-
});
|
|
71
|
-
console.log('RESULT (Google Vercel):', result);
|
|
72
|
-
expect(result).toBeTruthy();
|
|
73
|
-
expect(typeof result).toBe('object');
|
|
74
|
-
}, 30000);
|
|
75
|
-
/***
|
|
76
|
-
* Generates a document from Google using structured outputs via streaming.
|
|
77
|
-
*/
|
|
78
|
-
it.skip('streams a real Google response (manual run) from vercel provider', async () => {
|
|
79
|
-
const config = getServerConfig();
|
|
80
|
-
if (!config.ai.google.apiKey) {
|
|
81
|
-
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
82
|
-
}
|
|
83
|
-
const streamResult = generateDocStreamingVercel({
|
|
84
|
-
apiKey: config.ai.google.apiKey,
|
|
85
|
-
model: MODEL,
|
|
86
|
-
prompt: 'Write a short description of the solar system..',
|
|
87
|
-
});
|
|
88
|
-
let streamedText = '';
|
|
89
|
-
for await (const chunk of streamResult.text) {
|
|
90
|
-
streamedText += chunk;
|
|
91
|
-
console.log('STREAM CHUNK (Google Vercel):', chunk);
|
|
92
|
-
}
|
|
93
|
-
const final = await streamResult.final;
|
|
94
|
-
console.log('FINAL RESULT (Google Vercel):', final);
|
|
46
|
+
console.log('FINAL RESULT (Google):', final);
|
|
95
47
|
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
96
48
|
expect(final).toBeTruthy();
|
|
97
49
|
expect(typeof final).toBe('object');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.test.node.js","sourceRoot":"","sources":["../../../src/models/google/generate.test.node.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEzD,OAAO,EAAE,iBAAiB,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7E,OAAO,
|
|
1
|
+
{"version":3,"file":"generate.test.node.js","sourceRoot":"","sources":["../../../src/models/google/generate.test.node.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEzD,OAAO,EAAE,iBAAiB,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,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AE,KAAK;gBACZ,MAAM,EAAE,iDAAiD;aAC1D,CAAC,CAAA;YAEF,IAAI,YAAY,GAAG,EAAE,CAAA;YACrB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;gBAC5C,YAAY,IAAI,KAAK,CAAA;gBACrB,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;YAC9C,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,KAAK,CAAA;YACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAA;YAE5C,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAA;YACrD,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,CAAA;YAC1B,MAAM,CAAC,OAAO,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACrC,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC;SAAM,CAAC;QACN,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE;YACtC,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAA;QACrE,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -5,8 +5,29 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Infonomic Company Limited
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
33
|
//# sourceMappingURL=patch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../../src/models/google/patch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../../src/models/google/patch.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"}
|
|
@@ -5,12 +5,160 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Infonomic Company Limited
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
return
|
|
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');
|
|
12
17
|
};
|
|
13
|
-
|
|
14
|
-
|
|
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);
|
|
15
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
|
+
}
|
|
16
164
|
//# sourceMappingURL=patch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../src/models/google/patch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../src/models/google/patch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAGlD,MAA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;QACb,CAAC;IACH,CAAC,CAAC,EAAE,CAAA;IAEJ,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACxB,CAAC"}
|
|
@@ -7,22 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
9
9
|
import { getAiServerConfig as getServerConfig } from '../../config/ai-config';
|
|
10
|
-
import { patchDoc
|
|
11
|
-
import { patchDocStreaming as patchDocStreamingVercel, patchDoc as patchDocVercel, } from './patch-vercel';
|
|
10
|
+
import { patchDoc, patchDocStreaming } from './patch';
|
|
12
11
|
const MODEL = 'gemini-2.5-flash';
|
|
13
12
|
describe('google patch', () => {
|
|
14
13
|
beforeEach(async () => { });
|
|
15
14
|
const runReal = process.env.AI_RUN_REAL_TESTS === 'true';
|
|
16
15
|
if (runReal) {
|
|
17
|
-
|
|
18
|
-
* Generates a document from Google using structured outputs.
|
|
19
|
-
*/
|
|
20
|
-
it.skip('makes a real Google request (manual run) from native provider', async () => {
|
|
16
|
+
it.skip('makes a real Google request (manual run)', async () => {
|
|
21
17
|
const config = getServerConfig();
|
|
22
18
|
if (!config.ai.google.apiKey) {
|
|
23
19
|
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
24
20
|
}
|
|
25
|
-
const result = await
|
|
21
|
+
const result = await patchDoc({
|
|
26
22
|
apiKey: config.ai.google.apiKey,
|
|
27
23
|
model: MODEL,
|
|
28
24
|
prompt: 'Translate into French.',
|
|
@@ -32,15 +28,12 @@ describe('google patch', () => {
|
|
|
32
28
|
expect(result).toBeTruthy();
|
|
33
29
|
expect(typeof result).toBe('object');
|
|
34
30
|
}, 30000);
|
|
35
|
-
|
|
36
|
-
* Generates a document from Google using structured outputs via streaming.
|
|
37
|
-
*/
|
|
38
|
-
it.skip('streams a real Google response (manual run) from native provider', async () => {
|
|
31
|
+
it.skip('streams a real Google response (manual run)', async () => {
|
|
39
32
|
const config = getServerConfig();
|
|
40
33
|
if (!config.ai.google.apiKey) {
|
|
41
34
|
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
42
35
|
}
|
|
43
|
-
const streamResult =
|
|
36
|
+
const streamResult = patchDocStreaming({
|
|
44
37
|
apiKey: config.ai.google.apiKey,
|
|
45
38
|
model: MODEL,
|
|
46
39
|
prompt: 'Translate into French.',
|
|
@@ -49,53 +42,10 @@ describe('google patch', () => {
|
|
|
49
42
|
let streamedText = '';
|
|
50
43
|
for await (const chunk of streamResult.text) {
|
|
51
44
|
streamedText += chunk;
|
|
52
|
-
console.log('STREAM CHUNK (Google
|
|
45
|
+
console.log('STREAM CHUNK (Google):', chunk);
|
|
53
46
|
}
|
|
54
47
|
const final = await streamResult.final;
|
|
55
|
-
console.log('FINAL RESULT (Google
|
|
56
|
-
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
57
|
-
expect(final).toBeTruthy();
|
|
58
|
-
expect(typeof final).toBe('object');
|
|
59
|
-
}, 30000);
|
|
60
|
-
/***
|
|
61
|
-
* Generates a document from Google using structured outputs.
|
|
62
|
-
*/
|
|
63
|
-
it.skip('makes a real Google request (manual run) from vercel provider', async () => {
|
|
64
|
-
const config = getServerConfig();
|
|
65
|
-
if (!config.ai.google.apiKey) {
|
|
66
|
-
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
67
|
-
}
|
|
68
|
-
const result = await patchDocVercel({
|
|
69
|
-
apiKey: config.ai.google.apiKey,
|
|
70
|
-
model: MODEL,
|
|
71
|
-
prompt: 'Translate into French.',
|
|
72
|
-
textNodes: [{ id: 0, text: 'The sun is shining' }],
|
|
73
|
-
});
|
|
74
|
-
console.log(result);
|
|
75
|
-
expect(result).toBeTruthy();
|
|
76
|
-
expect(typeof result).toBe('object');
|
|
77
|
-
}, 30000);
|
|
78
|
-
/***
|
|
79
|
-
* Generates a document from Google using structured outputs via streaming.
|
|
80
|
-
*/
|
|
81
|
-
it.skip('streams a real Google response (manual run) from vercel provider', async () => {
|
|
82
|
-
const config = getServerConfig();
|
|
83
|
-
if (!config.ai.google.apiKey) {
|
|
84
|
-
throw new Error('GOOGLE_API_KEY is required for real Google tests.');
|
|
85
|
-
}
|
|
86
|
-
const streamResult = patchDocStreamingVercel({
|
|
87
|
-
apiKey: config.ai.google.apiKey,
|
|
88
|
-
model: MODEL,
|
|
89
|
-
prompt: 'Translate into French.',
|
|
90
|
-
textNodes: [{ id: 0, text: 'The sun is shining' }],
|
|
91
|
-
});
|
|
92
|
-
let streamedText = '';
|
|
93
|
-
for await (const chunk of streamResult.text) {
|
|
94
|
-
streamedText += chunk;
|
|
95
|
-
console.log('STREAM CHUNK (Google Vercel):', chunk);
|
|
96
|
-
}
|
|
97
|
-
const final = await streamResult.final;
|
|
98
|
-
console.log('FINAL RESULT (Google Vercel):', final);
|
|
48
|
+
console.log('FINAL RESULT (Google):', final);
|
|
99
49
|
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
100
50
|
expect(final).toBeTruthy();
|
|
101
51
|
expect(typeof final).toBe('object');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.test.node.js","sourceRoot":"","sources":["../../../src/models/google/patch.test.node.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEzD,OAAO,EAAE,iBAAiB,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7E,OAAO,
|
|
1
|
+
{"version":3,"file":"patch.test.node.js","sourceRoot":"","sources":["../../../src/models/google/patch.test.node.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEzD,OAAO,EAAE,iBAAiB,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,SA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edDoc } from '../../utils/convert-to-lexical';
|
|
9
|
+
export type GenerateDocStreamingResult = {
|
|
10
|
+
text: AsyncIterable<string>;
|
|
11
|
+
final: Promise<GeneratedDoc>;
|
|
12
|
+
};
|
|
13
|
+
export type GenerateTextStreamingResult = {
|
|
14
|
+
text: AsyncIterable<string>;
|
|
15
|
+
final: Promise<string>;
|
|
16
|
+
};
|
|
17
|
+
export type GenerateHtmlStreamingResult = {
|
|
18
|
+
text: AsyncIterable<string>;
|
|
19
|
+
final: Promise<string>;
|
|
20
|
+
};
|
|
21
|
+
export declare function generateHtml(options: {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
model: string;
|
|
24
|
+
prompt: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
export declare function generateHtmlStreaming(options: {
|
|
28
|
+
apiKey: string;
|
|
29
|
+
model: string;
|
|
30
|
+
prompt: string;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
}): GenerateHtmlStreamingResult;
|
|
33
|
+
export declare function generateText(options: {
|
|
34
|
+
apiKey: string;
|
|
35
|
+
model: string;
|
|
36
|
+
prompt: string;
|
|
37
|
+
maxLength?: number;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): Promise<string>;
|
|
40
|
+
export declare function generateTextStreaming(options: {
|
|
41
|
+
apiKey: string;
|
|
42
|
+
model: string;
|
|
43
|
+
prompt: string;
|
|
44
|
+
maxLength?: number;
|
|
45
|
+
signal?: AbortSignal;
|
|
46
|
+
}): GenerateTextStreamingResult;
|
|
47
|
+
/***
|
|
48
|
+
* Generates a document from OpenAI using structured outputs.
|
|
49
|
+
*/
|
|
50
|
+
export declare function generateDoc(options: {
|
|
51
|
+
apiKey: string;
|
|
52
|
+
model: string;
|
|
53
|
+
prompt: string;
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}): Promise<GeneratedDoc>;
|
|
56
|
+
/***
|
|
57
|
+
* Streams a document generation from OpenAI using structured outputs.
|
|
58
|
+
*/
|
|
59
|
+
export declare function generateDocStreaming(options: {
|
|
60
|
+
apiKey: string;
|
|
61
|
+
model: string;
|
|
62
|
+
prompt: string;
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
}): GenerateDocStreamingResult;
|
|
16
65
|
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/models/openai/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/models/openai/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;CAC7B,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,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;IACd,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CA8BlB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EA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