@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.
- package/LICENSE +21 -0
- package/README.md +4 -0
- package/dist/@types.d.ts +103 -0
- package/dist/@types.d.ts.map +1 -0
- package/dist/@types.js +68 -0
- package/dist/@types.js.map +1 -0
- package/dist/config/ai-config.d.ts +76 -0
- package/dist/config/ai-config.d.ts.map +1 -0
- package/dist/config/ai-config.js +108 -0
- package/dist/config/ai-config.js.map +1 -0
- package/dist/config/ai-config.test.node.d.ts +9 -0
- package/dist/config/ai-config.test.node.d.ts.map +1 -0
- package/dist/config/ai-config.test.node.js +31 -0
- package/dist/config/ai-config.test.node.js.map +1 -0
- package/dist/config/ai-provider.d.ts +17 -0
- package/dist/config/ai-provider.d.ts.map +1 -0
- package/dist/config/ai-provider.js +32 -0
- package/dist/config/ai-provider.js.map +1 -0
- package/dist/execute.d.ts +15 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +473 -0
- package/dist/execute.js.map +1 -0
- package/dist/generate.d.ts +64 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +235 -0
- package/dist/generate.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/lexical-text-edits.d.ts +23 -0
- package/dist/lexical-text-edits.d.ts.map +1 -0
- package/dist/lexical-text-edits.js +62 -0
- package/dist/lexical-text-edits.js.map +1 -0
- package/dist/lib/logger.d.ts +10 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +16 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/models/anthropic/anthropic-models.d.ts +14 -0
- package/dist/models/anthropic/anthropic-models.d.ts.map +1 -0
- package/dist/models/anthropic/anthropic-models.js +41 -0
- package/dist/models/anthropic/anthropic-models.js.map +1 -0
- package/dist/models/anthropic/anthropic.d.ts +9 -0
- package/dist/models/anthropic/anthropic.d.ts.map +1 -0
- package/dist/models/anthropic/anthropic.js +20 -0
- package/dist/models/anthropic/anthropic.js.map +1 -0
- package/dist/models/anthropic/generate-native.d.ts +59 -0
- package/dist/models/anthropic/generate-native.d.ts.map +1 -0
- package/dist/models/anthropic/generate-native.js +271 -0
- package/dist/models/anthropic/generate-native.js.map +1 -0
- package/dist/models/anthropic/generate-vercel.d.ts +59 -0
- package/dist/models/anthropic/generate-vercel.d.ts.map +1 -0
- package/dist/models/anthropic/generate-vercel.js +126 -0
- package/dist/models/anthropic/generate-vercel.js.map +1 -0
- package/dist/models/anthropic/generate.d.ts +16 -0
- package/dist/models/anthropic/generate.d.ts.map +1 -0
- package/dist/models/anthropic/generate.js +28 -0
- package/dist/models/anthropic/generate.js.map +1 -0
- package/dist/models/anthropic/generate.test.node.d.ts +9 -0
- package/dist/models/anthropic/generate.test.node.d.ts.map +1 -0
- package/dist/models/anthropic/generate.test.node.js +106 -0
- package/dist/models/anthropic/generate.test.node.js.map +1 -0
- package/dist/models/anthropic/patch-native.d.ts +33 -0
- package/dist/models/anthropic/patch-native.d.ts.map +1 -0
- package/dist/models/anthropic/patch-native.js +152 -0
- package/dist/models/anthropic/patch-native.js.map +1 -0
- package/dist/models/anthropic/patch-vercel.d.ts +33 -0
- package/dist/models/anthropic/patch-vercel.d.ts.map +1 -0
- package/dist/models/anthropic/patch-vercel.js +47 -0
- package/dist/models/anthropic/patch-vercel.js.map +1 -0
- package/dist/models/anthropic/patch.d.ts +12 -0
- package/dist/models/anthropic/patch.d.ts.map +1 -0
- package/dist/models/anthropic/patch.js +16 -0
- package/dist/models/anthropic/patch.js.map +1 -0
- package/dist/models/anthropic/patch.test.node.d.ts +9 -0
- package/dist/models/anthropic/patch.test.node.d.ts.map +1 -0
- package/dist/models/anthropic/patch.test.node.js +110 -0
- package/dist/models/anthropic/patch.test.node.js.map +1 -0
- package/dist/models/anthropic/schema.d.ts +212 -0
- package/dist/models/anthropic/schema.d.ts.map +1 -0
- package/dist/models/anthropic/schema.js +131 -0
- package/dist/models/anthropic/schema.js.map +1 -0
- package/dist/models/google/generate-native.d.ts +59 -0
- package/dist/models/google/generate-native.d.ts.map +1 -0
- package/dist/models/google/generate-native.js +244 -0
- package/dist/models/google/generate-native.js.map +1 -0
- package/dist/models/google/generate-vercel.d.ts +59 -0
- package/dist/models/google/generate-vercel.d.ts.map +1 -0
- package/dist/models/google/generate-vercel.js +133 -0
- package/dist/models/google/generate-vercel.js.map +1 -0
- package/dist/models/google/generate.d.ts +16 -0
- package/dist/models/google/generate.d.ts.map +1 -0
- package/dist/models/google/generate.js +28 -0
- package/dist/models/google/generate.js.map +1 -0
- package/dist/models/google/generate.test.node.d.ts +9 -0
- package/dist/models/google/generate.test.node.d.ts.map +1 -0
- package/dist/models/google/generate.test.node.js +106 -0
- package/dist/models/google/generate.test.node.js.map +1 -0
- package/dist/models/google/google-models.d.ts +14 -0
- package/dist/models/google/google-models.d.ts.map +1 -0
- package/dist/models/google/google-models.js +25 -0
- package/dist/models/google/google-models.js.map +1 -0
- package/dist/models/google/normalize-generated-doc.d.ts +10 -0
- package/dist/models/google/normalize-generated-doc.d.ts.map +1 -0
- package/dist/models/google/normalize-generated-doc.js +48 -0
- package/dist/models/google/normalize-generated-doc.js.map +1 -0
- package/dist/models/google/patch-native.d.ts +33 -0
- package/dist/models/google/patch-native.d.ts.map +1 -0
- package/dist/models/google/patch-native.js +164 -0
- package/dist/models/google/patch-native.js.map +1 -0
- package/dist/models/google/patch-vercel.d.ts +33 -0
- package/dist/models/google/patch-vercel.d.ts.map +1 -0
- package/dist/models/google/patch-vercel.js +49 -0
- package/dist/models/google/patch-vercel.js.map +1 -0
- package/dist/models/google/patch.d.ts +12 -0
- package/dist/models/google/patch.d.ts.map +1 -0
- package/dist/models/google/patch.js +16 -0
- package/dist/models/google/patch.js.map +1 -0
- package/dist/models/google/patch.test.node.d.ts +9 -0
- package/dist/models/google/patch.test.node.d.ts.map +1 -0
- package/dist/models/google/patch.test.node.js +110 -0
- package/dist/models/google/patch.test.node.js.map +1 -0
- package/dist/models/google/schema.d.ts +416 -0
- package/dist/models/google/schema.d.ts.map +1 -0
- package/dist/models/google/schema.js +254 -0
- package/dist/models/google/schema.js.map +1 -0
- package/dist/models/openai/generate-native.d.ts +65 -0
- package/dist/models/openai/generate-native.d.ts.map +1 -0
- package/dist/models/openai/generate-native.js +276 -0
- package/dist/models/openai/generate-native.js.map +1 -0
- package/dist/models/openai/generate-vercel.d.ts +59 -0
- package/dist/models/openai/generate-vercel.d.ts.map +1 -0
- package/dist/models/openai/generate-vercel.js +132 -0
- package/dist/models/openai/generate-vercel.js.map +1 -0
- package/dist/models/openai/generate.d.ts +16 -0
- package/dist/models/openai/generate.d.ts.map +1 -0
- package/dist/models/openai/generate.js +28 -0
- package/dist/models/openai/generate.js.map +1 -0
- package/dist/models/openai/generate.test.node.d.ts +9 -0
- package/dist/models/openai/generate.test.node.d.ts.map +1 -0
- package/dist/models/openai/generate.test.node.js +106 -0
- package/dist/models/openai/generate.test.node.js.map +1 -0
- package/dist/models/openai/openai-models.d.ts +14 -0
- package/dist/models/openai/openai-models.d.ts.map +1 -0
- package/dist/models/openai/openai-models.js +23 -0
- package/dist/models/openai/openai-models.js.map +1 -0
- package/dist/models/openai/patch-native.d.ts +33 -0
- package/dist/models/openai/patch-native.d.ts.map +1 -0
- package/dist/models/openai/patch-native.js +151 -0
- package/dist/models/openai/patch-native.js.map +1 -0
- package/dist/models/openai/patch-vercel.d.ts +33 -0
- package/dist/models/openai/patch-vercel.d.ts.map +1 -0
- package/dist/models/openai/patch-vercel.js +49 -0
- package/dist/models/openai/patch-vercel.js.map +1 -0
- package/dist/models/openai/patch.d.ts +12 -0
- package/dist/models/openai/patch.d.ts.map +1 -0
- package/dist/models/openai/patch.js +16 -0
- package/dist/models/openai/patch.js.map +1 -0
- package/dist/models/openai/patch.test.node.d.ts +9 -0
- package/dist/models/openai/patch.test.node.d.ts.map +1 -0
- package/dist/models/openai/patch.test.node.js +110 -0
- package/dist/models/openai/patch.test.node.js.map +1 -0
- package/dist/models/openai/schema.d.ts +460 -0
- package/dist/models/openai/schema.d.ts.map +1 -0
- package/dist/models/openai/schema.js +327 -0
- package/dist/models/openai/schema.js.map +1 -0
- package/dist/patch.d.ts +45 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +138 -0
- package/dist/patch.js.map +1 -0
- package/dist/plugins/ai-plugin-base.d.ts +40 -0
- package/dist/plugins/ai-plugin-base.d.ts.map +1 -0
- package/dist/plugins/ai-plugin-base.js +218 -0
- package/dist/plugins/ai-plugin-base.js.map +1 -0
- package/dist/plugins/ai-plugin.css +181 -0
- package/dist/plugins/lexical/create-empty-editor-state.d.ts +32 -0
- package/dist/plugins/lexical/create-empty-editor-state.d.ts.map +1 -0
- package/dist/plugins/lexical/create-empty-editor-state.js +51 -0
- package/dist/plugins/lexical/create-empty-editor-state.js.map +1 -0
- package/dist/plugins/lexical/import-html.d.ts +10 -0
- package/dist/plugins/lexical/import-html.d.ts.map +1 -0
- package/dist/plugins/lexical/import-html.js +31 -0
- package/dist/plugins/lexical/import-html.js.map +1 -0
- package/dist/plugins/lexical/index.d.ts +9 -0
- package/dist/plugins/lexical/index.d.ts.map +1 -0
- package/dist/plugins/lexical/index.js +9 -0
- package/dist/plugins/lexical/index.js.map +1 -0
- package/dist/plugins/lexical/plugin.d.ts +11 -0
- package/dist/plugins/lexical/plugin.d.ts.map +1 -0
- package/dist/plugins/lexical/plugin.js +305 -0
- package/dist/plugins/lexical/plugin.js.map +1 -0
- package/dist/plugins/storage.d.ts +18 -0
- package/dist/plugins/storage.d.ts.map +1 -0
- package/dist/plugins/storage.js +57 -0
- package/dist/plugins/storage.js.map +1 -0
- package/dist/plugins/streaming-preview.d.ts +12 -0
- package/dist/plugins/streaming-preview.d.ts.map +1 -0
- package/dist/plugins/streaming-preview.js +24 -0
- package/dist/plugins/streaming-preview.js.map +1 -0
- package/dist/plugins/text/index.d.ts +9 -0
- package/dist/plugins/text/index.d.ts.map +1 -0
- package/dist/plugins/text/index.js +9 -0
- package/dist/plugins/text/index.js.map +1 -0
- package/dist/plugins/text/plugin.d.ts +18 -0
- package/dist/plugins/text/plugin.d.ts.map +1 -0
- package/dist/plugins/text/plugin.js +261 -0
- package/dist/plugins/text/plugin.js.map +1 -0
- package/dist/prompts.d.ts +30 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +83 -0
- package/dist/prompts.js.map +1 -0
- package/dist/schemas/lexical-json-schema.d.ts +68 -0
- package/dist/schemas/lexical-json-schema.d.ts.map +1 -0
- package/dist/schemas/lexical-json-schema.js +434 -0
- package/dist/schemas/lexical-json-schema.js.map +1 -0
- package/dist/scripts/list-models.d.ts +9 -0
- package/dist/scripts/list-models.d.ts.map +1 -0
- package/dist/scripts/list-models.js +55 -0
- package/dist/scripts/list-models.js.map +1 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +22 -0
- package/dist/server.js.map +1 -0
- package/dist/utils/convert-to-lexical.d.ts +62 -0
- package/dist/utils/convert-to-lexical.d.ts.map +1 -0
- package/dist/utils/convert-to-lexical.js +210 -0
- package/dist/utils/convert-to-lexical.js.map +1 -0
- package/dist/utils/create-empty-editor-state.d.ts +32 -0
- package/dist/utils/create-empty-editor-state.d.ts.map +1 -0
- package/dist/utils/create-empty-editor-state.js +51 -0
- package/dist/utils/create-empty-editor-state.js.map +1 -0
- package/dist/utils/has-text.d.ts +10 -0
- package/dist/utils/has-text.d.ts.map +1 -0
- package/dist/utils/has-text.js +35 -0
- package/dist/utils/has-text.js.map +1 -0
- package/dist/utils/has-text.test.d.ts +9 -0
- package/dist/utils/has-text.test.d.ts.map +1 -0
- package/dist/utils/has-text.test.js +69 -0
- package/dist/utils/has-text.test.js.map +1 -0
- package/dist/utils/is-object-schema.d.ts +17 -0
- package/dist/utils/is-object-schema.d.ts.map +1 -0
- package/dist/utils/is-object-schema.js +19 -0
- package/dist/utils/is-object-schema.js.map +1 -0
- package/dist/utils/lexical-text-edits.d.ts +23 -0
- package/dist/utils/lexical-text-edits.d.ts.map +1 -0
- package/dist/utils/lexical-text-edits.js +62 -0
- package/dist/utils/lexical-text-edits.js.map +1 -0
- package/package.json +111 -0
|
@@ -0,0 +1,106 @@
|
|
|
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 { beforeEach, describe, expect, it } from 'vitest';
|
|
9
|
+
import { getAiServerConfig as getServerConfig } from '../../config/ai-config';
|
|
10
|
+
import { generateDoc as generateDocNative, generateDocStreaming as generateDocStreamingNative, } from './generate-native';
|
|
11
|
+
import { generateDocStreaming as generateDocStreamingVercel, generateDoc as generateDocVercel, } from './generate-vercel';
|
|
12
|
+
const MODEL = 'claude-sonnet-4-5-20250929';
|
|
13
|
+
describe('anthropic generate', () => {
|
|
14
|
+
beforeEach(async () => { });
|
|
15
|
+
const runReal = process.env.AI_RUN_REAL_TESTS === 'true';
|
|
16
|
+
if (runReal) {
|
|
17
|
+
/***
|
|
18
|
+
* Generates a document from Anthropic using structured outputs.
|
|
19
|
+
*/
|
|
20
|
+
it.skip('makes a real Anthropic request (manual run) from native provider', async () => {
|
|
21
|
+
const config = getServerConfig();
|
|
22
|
+
if (!config.ai.anthropic.apiKey) {
|
|
23
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
24
|
+
}
|
|
25
|
+
const result = await generateDocNative({
|
|
26
|
+
apiKey: config.ai.anthropic.apiKey,
|
|
27
|
+
model: MODEL,
|
|
28
|
+
prompt: 'Create a haiku poem about a child by the sea.',
|
|
29
|
+
});
|
|
30
|
+
// console.log(result)
|
|
31
|
+
expect(result).toBeTruthy();
|
|
32
|
+
expect(typeof result).toBe('object');
|
|
33
|
+
}, 30000);
|
|
34
|
+
/***
|
|
35
|
+
* Generates a document from Anthropic using structured outputs via streaming.
|
|
36
|
+
*/
|
|
37
|
+
it.skip('streams a real Anthropic response (manual run) from native provider', async () => {
|
|
38
|
+
const config = getServerConfig();
|
|
39
|
+
if (!config.ai.anthropic.apiKey) {
|
|
40
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
41
|
+
}
|
|
42
|
+
const streamResult = generateDocStreamingNative({
|
|
43
|
+
apiKey: config.ai.anthropic.apiKey,
|
|
44
|
+
model: MODEL,
|
|
45
|
+
prompt: 'Create a haiku poem about a child by the sea.',
|
|
46
|
+
});
|
|
47
|
+
let streamedText = '';
|
|
48
|
+
for await (const chunk of streamResult.text) {
|
|
49
|
+
streamedText += chunk;
|
|
50
|
+
console.log('STREAM CHUNK (Anthropic Native):', chunk);
|
|
51
|
+
}
|
|
52
|
+
const final = await streamResult.final;
|
|
53
|
+
console.log('FINAL RESULT (Anthropic Native):', final);
|
|
54
|
+
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
55
|
+
expect(final).toBeTruthy();
|
|
56
|
+
expect(typeof final).toBe('object');
|
|
57
|
+
}, 30000);
|
|
58
|
+
/***
|
|
59
|
+
* Generates a document from Anthropic using structured outputs.
|
|
60
|
+
*/
|
|
61
|
+
it.skip('makes a real Anthropic request (manual run) from vercel provider', async () => {
|
|
62
|
+
const config = getServerConfig();
|
|
63
|
+
if (!config.ai.anthropic.apiKey) {
|
|
64
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
65
|
+
}
|
|
66
|
+
const result = await generateDocVercel({
|
|
67
|
+
apiKey: config.ai.anthropic.apiKey,
|
|
68
|
+
model: MODEL,
|
|
69
|
+
prompt: 'Create a haiku poem about a child by the sea.',
|
|
70
|
+
});
|
|
71
|
+
// console.log(result)
|
|
72
|
+
expect(result).toBeTruthy();
|
|
73
|
+
expect(typeof result).toBe('object');
|
|
74
|
+
}, 30000);
|
|
75
|
+
/***
|
|
76
|
+
* Generates a document from Anthropic using structured outputs via streaming.
|
|
77
|
+
*/
|
|
78
|
+
it.skip('streams a real Anthropic response (manual run) from vercel provider', async () => {
|
|
79
|
+
const config = getServerConfig();
|
|
80
|
+
if (!config.ai.anthropic.apiKey) {
|
|
81
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
82
|
+
}
|
|
83
|
+
const streamResult = generateDocStreamingVercel({
|
|
84
|
+
apiKey: config.ai.anthropic.apiKey,
|
|
85
|
+
model: MODEL,
|
|
86
|
+
prompt: 'Create a haiku poem about a child by the sea.',
|
|
87
|
+
});
|
|
88
|
+
let streamedText = '';
|
|
89
|
+
for await (const chunk of streamResult.text) {
|
|
90
|
+
streamedText += chunk;
|
|
91
|
+
console.log('STREAM CHUNK (Anthropic Vercel):', chunk);
|
|
92
|
+
}
|
|
93
|
+
const final = await streamResult.final;
|
|
94
|
+
console.log('FINAL RESULT (Anthropic Vercel):', final);
|
|
95
|
+
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
96
|
+
expect(final).toBeTruthy();
|
|
97
|
+
expect(typeof final).toBe('object');
|
|
98
|
+
}, 30000);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
it.skip('skips real Anthropic tests', () => {
|
|
102
|
+
console.log('Set AI_RUN_REAL_TESTS=true to run real Anthropic tests.');
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=generate.test.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.test.node.js","sourceRoot":"","sources":["../../../src/models/anthropic/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,e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AAC;SAAM,CAAC;QACN,EAAE,CAAC,IAAI,CAAC,4BAA4B,EAAE,GAAG,EAAE;YACzC,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAA;QACxE,CAAC,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-native.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/patch-native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAoD1E,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,CAoDpC;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,CA4E1B"}
|
|
@@ -0,0 +1,152 @@
|
|
|
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 { 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 isValidHttpUrl = (value) => {
|
|
19
|
+
if (value == null || value.trim().length === 0)
|
|
20
|
+
return false;
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(value);
|
|
23
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const normalizeAnthropicBaseURLForSdk = (value) => {
|
|
30
|
+
const base = (value && value.trim().length > 0 ? value : 'https://api.anthropic.com')
|
|
31
|
+
.trim()
|
|
32
|
+
.replace(/\/+$/, '');
|
|
33
|
+
return base.endsWith('/v1') ? base.slice(0, -3) : base;
|
|
34
|
+
};
|
|
35
|
+
const anthropicPatchSchema = {
|
|
36
|
+
type: 'object',
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
properties: {
|
|
39
|
+
edits: {
|
|
40
|
+
type: 'array',
|
|
41
|
+
items: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
properties: {
|
|
45
|
+
id: { type: 'number' },
|
|
46
|
+
text: { type: 'string' },
|
|
47
|
+
},
|
|
48
|
+
required: ['id', 'text'],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
required: ['edits'],
|
|
53
|
+
};
|
|
54
|
+
export async function patchDoc(options) {
|
|
55
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
56
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
57
|
+
: 'https://api.anthropic.com';
|
|
58
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
59
|
+
const toolName = 'patch_lexical_text_nodes_v1';
|
|
60
|
+
const result = await client.messages.create({
|
|
61
|
+
model: options.model,
|
|
62
|
+
max_tokens: 4000,
|
|
63
|
+
system: buildPatchSystemPrompt(),
|
|
64
|
+
messages: [
|
|
65
|
+
{
|
|
66
|
+
role: 'user',
|
|
67
|
+
content: buildPatchUserPrompt(options.prompt, options.textNodes),
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
tools: [
|
|
71
|
+
{
|
|
72
|
+
name: toolName,
|
|
73
|
+
description: 'Patch Lexical text nodes by returning edits as JSON.',
|
|
74
|
+
input_schema: anthropicPatchSchema,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
tool_choice: { type: 'tool', name: toolName },
|
|
78
|
+
}, options.signal ? { signal: options.signal } : undefined);
|
|
79
|
+
const toolUse = (result.content ?? []).find((c) => c?.type === 'tool_use' && c?.name === toolName);
|
|
80
|
+
const parsed = toolUse?.input;
|
|
81
|
+
if (parsed && typeof parsed === 'object') {
|
|
82
|
+
return parsed;
|
|
83
|
+
}
|
|
84
|
+
const text = (result.content ?? [])
|
|
85
|
+
.filter((c) => c?.type === 'text')
|
|
86
|
+
.map((c) => c?.text)
|
|
87
|
+
.filter((t) => typeof t === 'string' && t.length > 0)
|
|
88
|
+
.join('\n');
|
|
89
|
+
throw new Error(text.length > 0
|
|
90
|
+
? `Anthropic did not return a tool payload. Text: ${text}`
|
|
91
|
+
: 'Anthropic did not return a tool payload.');
|
|
92
|
+
}
|
|
93
|
+
export function patchDocStreaming(options) {
|
|
94
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
95
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
96
|
+
: 'https://api.anthropic.com';
|
|
97
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
98
|
+
const toolName = 'patch_lexical_text_nodes_v1';
|
|
99
|
+
const stream = client.messages.stream({
|
|
100
|
+
model: options.model,
|
|
101
|
+
max_tokens: 4000,
|
|
102
|
+
system: buildPatchSystemPrompt(),
|
|
103
|
+
messages: [
|
|
104
|
+
{
|
|
105
|
+
role: 'user',
|
|
106
|
+
content: buildPatchUserPrompt(options.prompt, options.textNodes),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
tools: [
|
|
110
|
+
{
|
|
111
|
+
name: toolName,
|
|
112
|
+
description: 'Patch Lexical text nodes by returning edits as JSON.',
|
|
113
|
+
input_schema: anthropicPatchSchema,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
tool_choice: { type: 'tool', name: toolName },
|
|
117
|
+
stream: true,
|
|
118
|
+
}, options.signal ? { signal: options.signal } : undefined);
|
|
119
|
+
const text = (async function* () {
|
|
120
|
+
for await (const event of stream) {
|
|
121
|
+
if (event.type === 'content_block_delta') {
|
|
122
|
+
const deltaText = event?.delta?.text;
|
|
123
|
+
const deltaJson = event?.delta?.partial_json ??
|
|
124
|
+
event?.delta?.input_json_delta?.partial_json;
|
|
125
|
+
if (typeof deltaText === 'string' && deltaText.length > 0) {
|
|
126
|
+
yield deltaText;
|
|
127
|
+
}
|
|
128
|
+
else if (typeof deltaJson === 'string' && deltaJson.length > 0) {
|
|
129
|
+
yield deltaJson;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
})();
|
|
134
|
+
const final = (async () => {
|
|
135
|
+
const result = await stream.finalMessage();
|
|
136
|
+
const toolUse = (result.content ?? []).find((c) => c?.type === 'tool_use' && c?.name === toolName);
|
|
137
|
+
const parsed = toolUse?.input;
|
|
138
|
+
if (parsed && typeof parsed === 'object') {
|
|
139
|
+
return parsed;
|
|
140
|
+
}
|
|
141
|
+
const text = (result.content ?? [])
|
|
142
|
+
.filter((c) => c?.type === 'text')
|
|
143
|
+
.map((c) => c?.text)
|
|
144
|
+
.filter((t) => typeof t === 'string' && t.length > 0)
|
|
145
|
+
.join('\n');
|
|
146
|
+
throw new Error(text.length > 0
|
|
147
|
+
? `Anthropic did not return a tool payload. Text: ${text}`
|
|
148
|
+
: 'Anthropic did not return a tool payload.');
|
|
149
|
+
})();
|
|
150
|
+
return { text, final };
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=patch-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-native.js","sourceRoot":"","sources":["../../../src/models/anthropic/patch-native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAA;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAGlD,MAAM,oBAAoB,GAAG,CAC3B,WAAmB,EACnB,SAA8C,EAC9C,EAAE;IACF,OAAO;QACL,gBAAgB,WAAW,EAAE;QAC7B,EAAE;QACF,wBAAwB;QACxB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;KAC1B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC,CAAA;AAED,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,+BAA+B,GAAG,CAAC,KAAyB,EAAE,EAAE;IACpE,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,OA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,IAAI,KAAK,CACb,IAAI,CAAC,MAAM,GAAG,CAAC;YACb,CAAC,CAAC,kDAAkD,IAAI,EAAE;YAC1D,CAAC,CAAC,0CAA0C,CAC/C,CAAA;IACH,CAAC,CAAC,EAAE,CAAA;IAEJ,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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-vercel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-vercel.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/patch-vercel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EACL,KAAK,wBAAwB,EAE9B,MAAM,4BAA4B,CAAA;AAenC,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,CAYpC;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,CAe1B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { generateText, Output, streamText } from 'ai';
|
|
9
|
+
import { buildPatchSystemPrompt } from '../../prompts';
|
|
10
|
+
import { lexicalTextEditsResponseSchema, } from '../../utils/lexical-text-edits';
|
|
11
|
+
import { anthropic } from './anthropic';
|
|
12
|
+
const buildPatchUserPrompt = (instruction, textNodes) => {
|
|
13
|
+
return [
|
|
14
|
+
`INSTRUCTION: ${instruction}`,
|
|
15
|
+
'',
|
|
16
|
+
'INPUT_TEXT_NODES_JSON:',
|
|
17
|
+
JSON.stringify(textNodes),
|
|
18
|
+
].join('\n');
|
|
19
|
+
};
|
|
20
|
+
export async function patchDoc(options) {
|
|
21
|
+
const result = await generateText({
|
|
22
|
+
model: anthropic(options.apiKey)(options.model),
|
|
23
|
+
system: buildPatchSystemPrompt(),
|
|
24
|
+
prompt: buildPatchUserPrompt(options.prompt, options.textNodes),
|
|
25
|
+
abortSignal: options.signal,
|
|
26
|
+
output: Output.object({
|
|
27
|
+
schema: lexicalTextEditsResponseSchema,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
return result.output;
|
|
31
|
+
}
|
|
32
|
+
export function patchDocStreaming(options) {
|
|
33
|
+
const result = streamText({
|
|
34
|
+
model: anthropic(options.apiKey)(options.model),
|
|
35
|
+
system: buildPatchSystemPrompt(),
|
|
36
|
+
prompt: buildPatchUserPrompt(options.prompt, options.textNodes),
|
|
37
|
+
abortSignal: options.signal,
|
|
38
|
+
output: Output.object({
|
|
39
|
+
schema: lexicalTextEditsResponseSchema,
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
text: result.textStream,
|
|
44
|
+
final: result.output,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=patch-vercel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-vercel.js","sourceRoot":"","sources":["../../../src/models/anthropic/patch-vercel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAEL,8BAA8B,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,UAAU;QACvB,KAAK,EAAE,MAAM,CAAC,MAA2C;KAC1D,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { patchDoc as patchVercelDoc, patchDocStreaming as patchVercelDocStreaming } from './patch-vercel';
|
|
9
|
+
import type { Sdk } from '../../@types';
|
|
10
|
+
export declare const getPatchDoc: (sdk: Sdk) => typeof patchVercelDoc;
|
|
11
|
+
export declare const getPatchDocStreaming: (sdk: Sdk) => typeof patchVercelDocStreaming;
|
|
12
|
+
//# sourceMappingURL=patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/patch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,EACL,QAAQ,IAAI,cAAc,EAC1B,iBAAiB,IAAI,uBAAuB,EAC7C,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAEnC,eAAO,MAAM,WAAW,GAAI,KAAK,GAAG,0BAEnC,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,KAAK,GAAG,mCAE5C,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 { patchDoc as patchNativeDoc, patchDocStreaming as patchNativeDocStreaming, } from './patch-native';
|
|
9
|
+
import { patchDoc as patchVercelDoc, patchDocStreaming as patchVercelDocStreaming, } from './patch-vercel';
|
|
10
|
+
export const getPatchDoc = (sdk) => {
|
|
11
|
+
return sdk === 'vercel' ? patchVercelDoc : patchNativeDoc;
|
|
12
|
+
};
|
|
13
|
+
export const getPatchDocStreaming = (sdk) => {
|
|
14
|
+
return sdk === 'vercel' ? patchVercelDocStreaming : patchNativeDocStreaming;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../src/models/anthropic/patch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,QAAQ,IAAI,cAAc,EAC1B,iBAAiB,IAAI,uBAAuB,GAC7C,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,QAAQ,IAAI,cAAc,EAC1B,iBAAiB,IAAI,uBAAuB,GAC7C,MAAM,gBAAgB,CAAA;AAGvB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,EAAE;IACtC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,CAAA;AAC3D,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAQ,EAAE,EAAE;IAC/C,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,uBAAuB,CAAA;AAC7E,CAAC,CAAA"}
|
|
@@ -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 {};
|
|
9
|
+
//# sourceMappingURL=patch.test.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.test.node.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/patch.test.node.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,110 @@
|
|
|
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 { beforeEach, describe, expect, it } from 'vitest';
|
|
9
|
+
import { getAiServerConfig as getServerConfig } from '../../config/ai-config';
|
|
10
|
+
import { patchDoc as patchDocNative, patchDocStreaming as patchDocStreamingNative, } from './patch-native';
|
|
11
|
+
import { patchDocStreaming as patchDocStreamingVercel, patchDoc as patchDocVercel, } from './patch-vercel';
|
|
12
|
+
const MODEL = 'claude-sonnet-4-5-20250929';
|
|
13
|
+
describe('anthropic patch', () => {
|
|
14
|
+
beforeEach(async () => { });
|
|
15
|
+
const runReal = process.env.AI_RUN_REAL_TESTS === 'true';
|
|
16
|
+
if (runReal) {
|
|
17
|
+
/***
|
|
18
|
+
* Generates a document from Anthropic using structured outputs.
|
|
19
|
+
*/
|
|
20
|
+
it.skip('makes a real Anthropic request (manual run) from native provider', async () => {
|
|
21
|
+
const config = getServerConfig();
|
|
22
|
+
if (!config.ai.anthropic.apiKey) {
|
|
23
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
24
|
+
}
|
|
25
|
+
const result = await patchDocNative({
|
|
26
|
+
apiKey: config.ai.anthropic.apiKey,
|
|
27
|
+
model: MODEL,
|
|
28
|
+
prompt: 'Translate into French.',
|
|
29
|
+
textNodes: [{ id: 0, text: 'The sun is shining' }],
|
|
30
|
+
});
|
|
31
|
+
console.log(result);
|
|
32
|
+
expect(result).toBeTruthy();
|
|
33
|
+
expect(typeof result).toBe('object');
|
|
34
|
+
}, 30000);
|
|
35
|
+
/***
|
|
36
|
+
* Generates a document from Anthropic using structured outputs via streaming.
|
|
37
|
+
*/
|
|
38
|
+
it.skip('streams a real Anthropic response (manual run) from native provider', async () => {
|
|
39
|
+
const config = getServerConfig();
|
|
40
|
+
if (!config.ai.anthropic.apiKey) {
|
|
41
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
42
|
+
}
|
|
43
|
+
const streamResult = patchDocStreamingNative({
|
|
44
|
+
apiKey: config.ai.anthropic.apiKey,
|
|
45
|
+
model: MODEL,
|
|
46
|
+
prompt: 'Translate into French.',
|
|
47
|
+
textNodes: [{ id: 0, text: 'The sun is shining' }],
|
|
48
|
+
});
|
|
49
|
+
let streamedText = '';
|
|
50
|
+
for await (const chunk of streamResult.text) {
|
|
51
|
+
streamedText += chunk;
|
|
52
|
+
console.log('STREAM CHUNK (Anthropic Native):', chunk);
|
|
53
|
+
}
|
|
54
|
+
const final = await streamResult.final;
|
|
55
|
+
console.log('FINAL RESULT (Anthropic Native):', final);
|
|
56
|
+
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
57
|
+
expect(final).toBeTruthy();
|
|
58
|
+
expect(typeof final).toBe('object');
|
|
59
|
+
}, 30000);
|
|
60
|
+
/***
|
|
61
|
+
* Generates a document from Anthropic using structured outputs.
|
|
62
|
+
*/
|
|
63
|
+
it.skip('makes a real Anthropic request (manual run) from vercel provider', async () => {
|
|
64
|
+
const config = getServerConfig();
|
|
65
|
+
if (!config.ai.anthropic.apiKey) {
|
|
66
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
67
|
+
}
|
|
68
|
+
const result = await patchDocVercel({
|
|
69
|
+
apiKey: config.ai.anthropic.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 Anthropic using structured outputs via streaming.
|
|
80
|
+
*/
|
|
81
|
+
it.skip('streams a real Anthropic response (manual run) from vercel provider', async () => {
|
|
82
|
+
const config = getServerConfig();
|
|
83
|
+
if (!config.ai.anthropic.apiKey) {
|
|
84
|
+
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
85
|
+
}
|
|
86
|
+
const streamResult = patchDocStreamingVercel({
|
|
87
|
+
apiKey: config.ai.anthropic.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 (Anthropic Vercel):', chunk);
|
|
96
|
+
}
|
|
97
|
+
const final = await streamResult.final;
|
|
98
|
+
console.log('FINAL RESULT (Anthropic Vercel):', final);
|
|
99
|
+
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
100
|
+
expect(final).toBeTruthy();
|
|
101
|
+
expect(typeof final).toBe('object');
|
|
102
|
+
}, 30000);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
it.skip('skips real Anthropic tests', () => {
|
|
106
|
+
console.log('Set AI_RUN_REAL_TESTS=true to run real Anthropic tests.');
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=patch.test.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.test.node.js","sourceRoot":"","sources":["../../../src/models/anth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