@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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAEL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAEL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAW7B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAGnD,MAAM,CAAC,MAAM,SAAS,GAA8B;IAClD,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACpB,CAAC,WAAW,EAAE,WAAW,CAAC;CAC3B,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAa,EAAqB,EAAE;IAC7D,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,WAAW,CAAA;AAC1E,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAkB,EAAU,EAAE;IAC5D,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAA;IAClD,CAAC;IACD,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAA;AACjC,CAAC,CAAA"}
|
package/dist/lib/logger.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Infonomic Company Limited
|
|
7
7
|
*/
|
|
8
|
-
import type
|
|
9
|
-
export declare const getLogger: () =>
|
|
8
|
+
import { type BylineLogger } from '@byline/core';
|
|
9
|
+
export declare const getLogger: () => BylineLogger;
|
|
10
10
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/lib/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,YAAY,EAA8B,MAAM,cAAc,CAAA;AAwB5E,eAAO,MAAM,SAAS,QAAO,YAM5B,CAAA"}
|
package/dist/lib/logger.js
CHANGED
|
@@ -5,12 +5,34 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Infonomic Company Limited
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
|
|
8
|
+
import { getLogger as getCoreLogger } from '@byline/core';
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a logger for `@byline/ai` in priority order:
|
|
11
|
+
* 1. `getLogger()` from `@byline/core` if `initBylineCore()` registered one
|
|
12
|
+
* 2. silent no-op fallback
|
|
13
|
+
*
|
|
14
|
+
* The silent fallback mirrors `@byline/client`: AI execution can be invoked
|
|
15
|
+
* from one-off scripts and tests that don't run `initBylineCore()`, and we
|
|
16
|
+
* don't want those contexts to throw or noisily warn just because a logger
|
|
17
|
+
* isn't wired up. Fully-wired runtimes still get the real logger via step 1.
|
|
18
|
+
*/
|
|
19
|
+
const noop = () => { };
|
|
20
|
+
const silentLogger = {
|
|
21
|
+
log: noop,
|
|
22
|
+
fatal: noop,
|
|
23
|
+
error: noop,
|
|
24
|
+
warn: noop,
|
|
25
|
+
info: noop,
|
|
26
|
+
debug: noop,
|
|
27
|
+
trace: noop,
|
|
28
|
+
silent: noop,
|
|
29
|
+
};
|
|
10
30
|
export const getLogger = () => {
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
try {
|
|
32
|
+
return getCoreLogger();
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return silentLogger;
|
|
13
36
|
}
|
|
14
|
-
return cached;
|
|
15
37
|
};
|
|
16
38
|
//# sourceMappingURL=logger.js.map
|
package/dist/lib/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAqB,SAAS,IAAI,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5E;;;;;;;;;GASG;AACH,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AACrB,MAAM,YAAY,GAAiB;IACjC,GAAG,EAAE,IAAI;IACT,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;CACb,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,GAAiB,EAAE;IAC1C,IAAI,CAAC;QACH,OAAO,aAAa,EAAE,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,YAAY,CAAA;IACrB,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -5,12 +5,55 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Infonomic Company Limited
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
59
|
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;CACvB,CAAA;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBlB;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|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) Infonomic Company Limited
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
9
|
+
import { buildGenerateHtmlSystemPrompt, buildGenerateHtmlUserPrompt, buildGenerateSystemPrompt, buildGenerateTextSystemPrompt, buildGenerateTextUserPrompt, } from '../../prompts';
|
|
10
|
+
import { anthropicGenerationSchema } from './schema';
|
|
11
|
+
export async function generateHtml(options) {
|
|
12
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
13
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
14
|
+
: 'https://api.anthropic.com';
|
|
15
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
16
|
+
const message = await client.messages.create({
|
|
17
|
+
model: options.model,
|
|
18
|
+
max_tokens: 4096,
|
|
19
|
+
system: buildGenerateHtmlSystemPrompt(),
|
|
20
|
+
messages: [{ role: 'user', content: buildGenerateHtmlUserPrompt(options.prompt) }],
|
|
21
|
+
}, { signal: options.signal });
|
|
22
|
+
const textBlock = message.content.find((b) => b.type === 'text');
|
|
23
|
+
return textBlock?.text ?? '';
|
|
24
|
+
}
|
|
25
|
+
export function generateHtmlStreaming(options) {
|
|
26
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
27
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
28
|
+
: 'https://api.anthropic.com';
|
|
29
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
30
|
+
const stream = client.messages.stream({
|
|
31
|
+
model: options.model,
|
|
32
|
+
max_tokens: 4096,
|
|
33
|
+
system: buildGenerateHtmlSystemPrompt(),
|
|
34
|
+
messages: [{ role: 'user', content: buildGenerateHtmlUserPrompt(options.prompt) }],
|
|
35
|
+
stream: true,
|
|
36
|
+
}, options.signal ? { signal: options.signal } : undefined);
|
|
37
|
+
const text = (async function* () {
|
|
38
|
+
for await (const event of stream) {
|
|
39
|
+
if (event.type === 'content_block_delta') {
|
|
40
|
+
const deltaText = event?.delta?.text;
|
|
41
|
+
if (typeof deltaText === 'string' && deltaText.length > 0) {
|
|
42
|
+
yield deltaText;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
const final = (async () => {
|
|
48
|
+
const message = await stream.finalMessage();
|
|
49
|
+
const html = (message.content ?? [])
|
|
50
|
+
.filter((b) => b?.type === 'text')
|
|
51
|
+
.map((b) => b?.text)
|
|
52
|
+
.filter((t) => typeof t === 'string' && t.length > 0)
|
|
53
|
+
.join('');
|
|
54
|
+
return html.trim();
|
|
55
|
+
})();
|
|
56
|
+
return { text, final };
|
|
57
|
+
}
|
|
58
|
+
export async function generateText(options) {
|
|
59
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
60
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
61
|
+
: 'https://api.anthropic.com';
|
|
62
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
63
|
+
const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
|
|
64
|
+
? Math.floor(options.maxLength)
|
|
65
|
+
: undefined;
|
|
66
|
+
const promptWithLength = typeof maxLength === 'number' && maxLength > 0
|
|
67
|
+
? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
|
|
68
|
+
: options.prompt;
|
|
69
|
+
const message = await client.messages.create({
|
|
70
|
+
model: options.model,
|
|
71
|
+
max_tokens: 4096,
|
|
72
|
+
system: buildGenerateTextSystemPrompt(),
|
|
73
|
+
messages: [{ role: 'user', content: buildGenerateTextUserPrompt(promptWithLength) }],
|
|
74
|
+
}, options.signal ? { signal: options.signal } : undefined);
|
|
75
|
+
const text = (message.content ?? [])
|
|
76
|
+
.filter((b) => b?.type === 'text')
|
|
77
|
+
.map((b) => b?.text)
|
|
78
|
+
.filter((t) => typeof t === 'string' && t.length > 0)
|
|
79
|
+
.join('')
|
|
80
|
+
.trim();
|
|
81
|
+
if (typeof maxLength === 'number' && maxLength > 0) {
|
|
82
|
+
return text.length > maxLength ? text.slice(0, maxLength).trimEnd() : text;
|
|
83
|
+
}
|
|
84
|
+
return text;
|
|
85
|
+
}
|
|
86
|
+
export function generateTextStreaming(options) {
|
|
87
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
88
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
89
|
+
: 'https://api.anthropic.com';
|
|
90
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
91
|
+
const maxLength = typeof options.maxLength === 'number' && Number.isFinite(options.maxLength)
|
|
92
|
+
? Math.floor(options.maxLength)
|
|
93
|
+
: undefined;
|
|
94
|
+
const promptWithLength = typeof maxLength === 'number' && maxLength > 0
|
|
95
|
+
? `${options.prompt}\n\nConstraints:\n- Maximum length: ${maxLength} characters.`
|
|
96
|
+
: options.prompt;
|
|
97
|
+
const stream = client.messages.stream({
|
|
98
|
+
model: options.model,
|
|
99
|
+
max_tokens: 4096,
|
|
100
|
+
system: buildGenerateTextSystemPrompt(),
|
|
101
|
+
messages: [{ role: 'user', content: buildGenerateTextUserPrompt(promptWithLength) }],
|
|
102
|
+
stream: true,
|
|
103
|
+
}, options.signal ? { signal: options.signal } : undefined);
|
|
104
|
+
const text = (async function* () {
|
|
105
|
+
let remaining = typeof maxLength === 'number' && maxLength > 0 ? maxLength : undefined;
|
|
106
|
+
for await (const event of stream) {
|
|
107
|
+
if (event.type !== 'content_block_delta') {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const deltaText = event?.delta?.text;
|
|
111
|
+
if (typeof deltaText !== 'string' || deltaText.length === 0) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (typeof remaining === 'number') {
|
|
115
|
+
if (remaining <= 0) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const chunk = deltaText.slice(0, remaining);
|
|
119
|
+
remaining -= chunk.length;
|
|
120
|
+
if (chunk.length > 0) {
|
|
121
|
+
yield chunk;
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
yield deltaText;
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
const final = (async () => {
|
|
129
|
+
const message = await stream.finalMessage();
|
|
130
|
+
const combined = (message.content ?? [])
|
|
131
|
+
.filter((b) => b?.type === 'text')
|
|
132
|
+
.map((b) => b?.text)
|
|
133
|
+
.filter((t) => typeof t === 'string' && t.length > 0)
|
|
134
|
+
.join('')
|
|
135
|
+
.trim();
|
|
136
|
+
if (typeof maxLength === 'number' && maxLength > 0) {
|
|
137
|
+
return combined.length > maxLength ? combined.slice(0, maxLength).trimEnd() : combined;
|
|
138
|
+
}
|
|
139
|
+
return combined;
|
|
140
|
+
})();
|
|
141
|
+
return { text, final };
|
|
142
|
+
}
|
|
143
|
+
const isValidHttpUrl = (value) => {
|
|
144
|
+
if (value == null || value.trim().length === 0)
|
|
145
|
+
return false;
|
|
146
|
+
try {
|
|
147
|
+
const url = new URL(value);
|
|
148
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
12
153
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return sdk === 'vercel' ? generateVercelHtmlStreaming : generateNativeHtmlStreaming;
|
|
21
|
-
};
|
|
22
|
-
export const getGenerateText = (sdk) => {
|
|
23
|
-
return sdk === 'vercel' ? generateVercelText : generateNativeText;
|
|
24
|
-
};
|
|
25
|
-
export const getGenerateTextStreaming = (sdk) => {
|
|
26
|
-
return sdk === 'vercel' ? generateVercelTextStreaming : generateNativeTextStreaming;
|
|
154
|
+
// The official Anthropic SDK expects a base URL like https://api.anthropic.com
|
|
155
|
+
// (it will handle the /v1 path internally). We defensively normalize env input.
|
|
156
|
+
const normalizeAnthropicBaseURLForSdk = (value) => {
|
|
157
|
+
const base = (value && value.trim().length > 0 ? value : 'https://api.anthropic.com')
|
|
158
|
+
.trim()
|
|
159
|
+
.replace(/\/+$/, '');
|
|
160
|
+
return base.endsWith('/v1') ? base.slice(0, -3) : base;
|
|
27
161
|
};
|
|
162
|
+
export async function generateDoc(options) {
|
|
163
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
164
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
165
|
+
: 'https://api.anthropic.com';
|
|
166
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
167
|
+
// Anthropic-native structured outputs: force a tool call and parse the tool input.
|
|
168
|
+
const toolName = 'generate_lexical_doc_blocks_v1';
|
|
169
|
+
// Anthropic does not need the draft-07 $schema keyword.
|
|
170
|
+
const input_schema = {
|
|
171
|
+
...anthropicGenerationSchema,
|
|
172
|
+
$schema: undefined,
|
|
173
|
+
};
|
|
174
|
+
const result = await client.messages.create({
|
|
175
|
+
model: options.model,
|
|
176
|
+
max_tokens: 4000,
|
|
177
|
+
system: buildGenerateSystemPrompt(),
|
|
178
|
+
messages: [
|
|
179
|
+
{
|
|
180
|
+
role: 'user',
|
|
181
|
+
content: options.prompt,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
tools: [
|
|
185
|
+
{
|
|
186
|
+
name: toolName,
|
|
187
|
+
description: 'Generate a document in the GeneratedDoc (blocks) JSON format.',
|
|
188
|
+
input_schema,
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
tool_choice: { type: 'tool', name: toolName },
|
|
192
|
+
}, options.signal ? { signal: options.signal } : undefined);
|
|
193
|
+
// Find the tool call content and return its JSON input.
|
|
194
|
+
const toolUse = (result.content ?? []).find((c) => c?.type === 'tool_use' && c?.name === toolName);
|
|
195
|
+
const parsed = toolUse?.input;
|
|
196
|
+
if (parsed && typeof parsed === 'object') {
|
|
197
|
+
return parsed;
|
|
198
|
+
}
|
|
199
|
+
const text = (result.content ?? [])
|
|
200
|
+
.filter((c) => c?.type === 'text')
|
|
201
|
+
.map((c) => c?.text)
|
|
202
|
+
.filter((t) => typeof t === 'string' && t.length > 0)
|
|
203
|
+
.join('\n');
|
|
204
|
+
throw new Error(text.length > 0
|
|
205
|
+
? `Anthropic did not return a tool payload. Text: ${text}`
|
|
206
|
+
: 'Anthropic did not return a tool payload.');
|
|
207
|
+
}
|
|
208
|
+
export function generateDocStreaming(options) {
|
|
209
|
+
const baseURL = isValidHttpUrl(process.env.ANTHROPIC_BASE_URL)
|
|
210
|
+
? normalizeAnthropicBaseURLForSdk(process.env.ANTHROPIC_BASE_URL)
|
|
211
|
+
: 'https://api.anthropic.com';
|
|
212
|
+
const client = new Anthropic({ apiKey: options.apiKey, baseURL });
|
|
213
|
+
const toolName = 'generate_lexical_doc_blocks_v1';
|
|
214
|
+
const input_schema = {
|
|
215
|
+
...anthropicGenerationSchema,
|
|
216
|
+
$schema: undefined,
|
|
217
|
+
};
|
|
218
|
+
const stream = client.messages.stream({
|
|
219
|
+
model: options.model,
|
|
220
|
+
max_tokens: 4000,
|
|
221
|
+
system: buildGenerateSystemPrompt(),
|
|
222
|
+
messages: [
|
|
223
|
+
{
|
|
224
|
+
role: 'user',
|
|
225
|
+
content: options.prompt,
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
tools: [
|
|
229
|
+
{
|
|
230
|
+
name: toolName,
|
|
231
|
+
description: 'Generate a document in the GeneratedDoc (blocks) JSON format.',
|
|
232
|
+
input_schema,
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
tool_choice: { type: 'tool', name: toolName },
|
|
236
|
+
stream: true,
|
|
237
|
+
}, options.signal ? { signal: options.signal } : undefined);
|
|
238
|
+
const text = (async function* () {
|
|
239
|
+
for await (const event of stream) {
|
|
240
|
+
if (event.type === 'content_block_delta') {
|
|
241
|
+
const deltaText = event?.delta?.text;
|
|
242
|
+
const deltaJson = event?.delta?.partial_json ??
|
|
243
|
+
event?.delta?.input_json_delta?.partial_json;
|
|
244
|
+
if (typeof deltaText === 'string' && deltaText.length > 0) {
|
|
245
|
+
yield deltaText;
|
|
246
|
+
}
|
|
247
|
+
else if (typeof deltaJson === 'string' && deltaJson.length > 0) {
|
|
248
|
+
yield deltaJson;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
})();
|
|
253
|
+
const final = (async () => {
|
|
254
|
+
const result = await stream.finalMessage();
|
|
255
|
+
const toolUse = (result.content ?? []).find((c) => c?.type === 'tool_use' && c?.name === toolName);
|
|
256
|
+
const parsed = toolUse?.input;
|
|
257
|
+
if (parsed && typeof parsed === 'object') {
|
|
258
|
+
return parsed;
|
|
259
|
+
}
|
|
260
|
+
const text = (result.content ?? [])
|
|
261
|
+
.filter((c) => c?.type === 'text')
|
|
262
|
+
.map((c) => c?.text)
|
|
263
|
+
.filter((t) => typeof t === 'string' && t.length > 0)
|
|
264
|
+
.join('\n');
|
|
265
|
+
throw new Error(text.length > 0
|
|
266
|
+
? `Anthropic did not return a tool payload. Text: ${text}`
|
|
267
|
+
: 'Anthropic did not return a tool payload.');
|
|
268
|
+
})();
|
|
269
|
+
return { text, final };
|
|
270
|
+
}
|
|
28
271
|
//# sourceMappingURL=generate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/models/anthropic/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,WAAW,IAAI,iBAAiB,EAChC,oBAAoB,IAAI,0BAA0B,EAClD,YAAY,IAAI,kBAAkB,EAClC,qBAAqB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AAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,CACzC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,UAAU,IAAI,CAAC,EAAE,IAAI,KAAK,QAAQ,CACpD,CAAA;QAER,MAAM,MAAM,GAAG,OAAO,EAAE,KAAiC,CAAA;QACzD,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YACzC,OAAO,MAAM,CAAA;QACf,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;aAChC,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,MAAM,CAAC;aACtC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC;aACxB,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;aACzD,IAAI,CAAC,IAAI,CAAC,CAAA;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"}
|
|
@@ -7,39 +7,31 @@
|
|
|
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 = 'claude-sonnet-4-5-20250929';
|
|
13
12
|
describe('anthropic generate', () => {
|
|
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 Anthropic using structured outputs.
|
|
19
|
-
*/
|
|
20
|
-
it.skip('makes a real Anthropic request (manual run) from native provider', async () => {
|
|
16
|
+
it.skip('makes a real Anthropic request (manual run)', async () => {
|
|
21
17
|
const config = getServerConfig();
|
|
22
18
|
if (!config.ai.anthropic.apiKey) {
|
|
23
19
|
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
24
20
|
}
|
|
25
|
-
const result = await
|
|
21
|
+
const result = await generateDoc({
|
|
26
22
|
apiKey: config.ai.anthropic.apiKey,
|
|
27
23
|
model: MODEL,
|
|
28
24
|
prompt: 'Create a haiku poem about a child by the sea.',
|
|
29
25
|
});
|
|
30
|
-
// console.log(result)
|
|
31
26
|
expect(result).toBeTruthy();
|
|
32
27
|
expect(typeof result).toBe('object');
|
|
33
28
|
}, 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 () => {
|
|
29
|
+
it.skip('streams a real Anthropic response (manual run)', async () => {
|
|
38
30
|
const config = getServerConfig();
|
|
39
31
|
if (!config.ai.anthropic.apiKey) {
|
|
40
32
|
throw new Error('ANTHROPIC_API_KEY is required for real Anthropic tests.');
|
|
41
33
|
}
|
|
42
|
-
const streamResult =
|
|
34
|
+
const streamResult = generateDocStreaming({
|
|
43
35
|
apiKey: config.ai.anthropic.apiKey,
|
|
44
36
|
model: MODEL,
|
|
45
37
|
prompt: 'Create a haiku poem about a child by the sea.',
|
|
@@ -47,51 +39,10 @@ describe('anthropic generate', () => {
|
|
|
47
39
|
let streamedText = '';
|
|
48
40
|
for await (const chunk of streamResult.text) {
|
|
49
41
|
streamedText += chunk;
|
|
50
|
-
console.log('STREAM CHUNK (Anthropic
|
|
42
|
+
console.log('STREAM CHUNK (Anthropic):', chunk);
|
|
51
43
|
}
|
|
52
44
|
const final = await streamResult.final;
|
|
53
|
-
console.log('FINAL RESULT (Anthropic
|
|
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);
|
|
45
|
+
console.log('FINAL RESULT (Anthropic):', final);
|
|
95
46
|
expect(streamedText.length).toBeGreaterThanOrEqual(0);
|
|
96
47
|
expect(final).toBeTruthy();
|
|
97
48
|
expect(typeof final).toBe('object');
|
|
@@ -1 +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,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7E,OAAO,
|
|
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,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAE9D,MAAM,KAAK,GAAG,4BAA4B,CAAA;AAE1C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,UAAU,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAA;IAE1B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,MAAM,CAAA;IAExD,IAAI,OAAO,EAAE,CAAC;QACZ,EAAE,CAAC,IAAI,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;YAChE,MAAM,MAA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,CAAC,CAAA;YAC/C,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,4BAA4B,EAAE,GAAG,EAAE;YACzC,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAA;QACxE,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/anthropic/patch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../../src/models/anthropic/patch.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"}
|