@byline/ai 1.9.0 → 1.10.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/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/dist/{models/anthropic/anthropic.d.ts → utils/has-text.test.node.d.ts} +2 -2
- package/dist/utils/has-text.test.node.d.ts.map +1 -0
- package/dist/utils/has-text.test.node.js +70 -0
- package/dist/utils/has-text.test.node.js.map +1 -0
- package/package.json +6 -14
- 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
|
@@ -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/anthropic/generate-vercel.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,aAAa,CAAC,MAAM,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,O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|
|
@@ -1,126 +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 { generateText as generateTextAi, jsonSchema, Output, streamText as streamTextAi } from 'ai';
|
|
9
|
-
import { buildGenerateHtmlSystemPrompt, buildGenerateHtmlUserPrompt, buildGenerateSystemPrompt, buildGenerateTextSystemPrompt, buildGenerateTextUserPrompt, } from '../../prompts';
|
|
10
|
-
import { anthropic } from './anthropic';
|
|
11
|
-
import { anthropicGenerationSchema } from './schema';
|
|
12
|
-
export async function generateHtml(options) {
|
|
13
|
-
const result = await generateTextAi({
|
|
14
|
-
model: anthropic(options.apiKey)(options.model),
|
|
15
|
-
system: buildGenerateHtmlSystemPrompt(),
|
|
16
|
-
prompt: buildGenerateHtmlUserPrompt(options.prompt),
|
|
17
|
-
abortSignal: options.signal,
|
|
18
|
-
});
|
|
19
|
-
return result.text;
|
|
20
|
-
}
|
|
21
|
-
export function generateHtmlStreaming(options) {
|
|
22
|
-
const result = streamTextAi({
|
|
23
|
-
model: anthropic(options.apiKey)(options.model),
|
|
24
|
-
system: buildGenerateHtmlSystemPrompt(),
|
|
25
|
-
prompt: buildGenerateHtmlUserPrompt(options.prompt),
|
|
26
|
-
abortSignal: options.signal,
|
|
27
|
-
});
|
|
28
|
-
return {
|
|
29
|
-
text: result.textStream,
|
|
30
|
-
final: result.text,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export async function generateText(options) {
|
|
34
|
-
const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
|
|
35
|
-
? Math.floor(options.maxLength)
|
|
36
|
-
: undefined;
|
|
37
|
-
const promptWithLength = typeof maxLength === 'number' && maxLength > 0
|
|
38
|
-
? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
|
|
39
|
-
: options.prompt;
|
|
40
|
-
const result = await generateTextAi({
|
|
41
|
-
model: anthropic(options.apiKey)(options.model),
|
|
42
|
-
system: buildGenerateTextSystemPrompt(),
|
|
43
|
-
prompt: buildGenerateTextUserPrompt(promptWithLength),
|
|
44
|
-
abortSignal: options.signal,
|
|
45
|
-
});
|
|
46
|
-
const normalized = result.text.trim();
|
|
47
|
-
if (typeof maxLength === 'number' && maxLength > 0) {
|
|
48
|
-
return normalized.length > maxLength ? normalized.slice(0, maxLength).trimEnd() : normalized;
|
|
49
|
-
}
|
|
50
|
-
return normalized;
|
|
51
|
-
}
|
|
52
|
-
export function generateTextStreaming(options) {
|
|
53
|
-
const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
|
|
54
|
-
? Math.floor(options.maxLength)
|
|
55
|
-
: undefined;
|
|
56
|
-
const promptWithLength = typeof maxLength === 'number' && maxLength > 0
|
|
57
|
-
? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
|
|
58
|
-
: options.prompt;
|
|
59
|
-
const result = streamTextAi({
|
|
60
|
-
model: anthropic(options.apiKey)(options.model),
|
|
61
|
-
system: buildGenerateTextSystemPrompt(),
|
|
62
|
-
prompt: buildGenerateTextUserPrompt(promptWithLength),
|
|
63
|
-
abortSignal: options.signal,
|
|
64
|
-
});
|
|
65
|
-
const text = (async function* () {
|
|
66
|
-
let remaining = typeof maxLength === 'number' && maxLength > 0 ? maxLength : undefined;
|
|
67
|
-
for await (const delta of result.textStream) {
|
|
68
|
-
if (typeof remaining === 'number') {
|
|
69
|
-
if (remaining <= 0) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
const chunk = delta.slice(0, remaining);
|
|
73
|
-
remaining -= chunk.length;
|
|
74
|
-
if (chunk.length > 0) {
|
|
75
|
-
yield chunk;
|
|
76
|
-
}
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
yield delta;
|
|
80
|
-
}
|
|
81
|
-
})();
|
|
82
|
-
const final = result.text.then((t) => {
|
|
83
|
-
const normalized = (t ?? '').trim();
|
|
84
|
-
if (typeof maxLength === 'number' && maxLength > 0) {
|
|
85
|
-
return normalized.length > maxLength ? normalized.slice(0, maxLength).trimEnd() : normalized;
|
|
86
|
-
}
|
|
87
|
-
return normalized;
|
|
88
|
-
});
|
|
89
|
-
return { text, final };
|
|
90
|
-
}
|
|
91
|
-
export async function generateDoc(options) {
|
|
92
|
-
const schema = jsonSchema({
|
|
93
|
-
...anthropicGenerationSchema,
|
|
94
|
-
$schema: undefined,
|
|
95
|
-
});
|
|
96
|
-
const result = await generateTextAi({
|
|
97
|
-
model: anthropic(options.apiKey)(options.model),
|
|
98
|
-
system: buildGenerateSystemPrompt(),
|
|
99
|
-
prompt: options.prompt,
|
|
100
|
-
abortSignal: options.signal,
|
|
101
|
-
output: Output.object({
|
|
102
|
-
schema,
|
|
103
|
-
}),
|
|
104
|
-
});
|
|
105
|
-
return result.output;
|
|
106
|
-
}
|
|
107
|
-
export function generateDocStreaming(options) {
|
|
108
|
-
const schema = jsonSchema({
|
|
109
|
-
...anthropicGenerationSchema,
|
|
110
|
-
$schema: undefined,
|
|
111
|
-
});
|
|
112
|
-
const result = streamTextAi({
|
|
113
|
-
model: anthropic(options.apiKey)(options.model),
|
|
114
|
-
system: buildGenerateSystemPrompt(),
|
|
115
|
-
prompt: options.prompt,
|
|
116
|
-
abortSignal: options.signal,
|
|
117
|
-
output: Output.object({
|
|
118
|
-
schema,
|
|
119
|
-
}),
|
|
120
|
-
});
|
|
121
|
-
return {
|
|
122
|
-
text: result.textStream,
|
|
123
|
-
final: result.output,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=generate-vercel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-vercel.js","sourceRoot":"","sources":["../../../src/models/anthropic/generate-vercel.ts"],"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M;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACpB,MAAM;SACP,CAAC;KACH,CAAC,CAAA;IAEF,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,UAAU;QACvB,KAAK,EAAE,MAAM,CAAC,MAA+B;KAC9C,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/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"}
|
|
@@ -1,152 +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 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
|
|
@@ -1 +0,0 @@
|
|
|
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,CAA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;QAEb,MAAM,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"}
|
|
@@ -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-vercel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,47 +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 { 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
|
|
@@ -1 +0,0 @@
|
|
|
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,EA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,MAAM,CAAC,UAAU;QACvB,KAAK,EAAE,MAAM,CAAC,MAA2C;KAC1D,CAAA;AACH,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-native.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-native.d.ts","sourceRoot":"","sources":["../../../src/models/google/generate-native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,aAAa,CAAC,MAAM,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,CAelB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,E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