@intlayer/ai 7.3.0-canary.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/README.md +275 -0
- package/dist/assets/auditDictionaryMetadata/PROMPT.md +73 -0
- package/dist/assets/translateJSON/PROMPT.md +45 -0
- package/dist/cjs/_virtual/_utils_asset.cjs +97 -0
- package/dist/cjs/aiSdk.cjs +93 -0
- package/dist/cjs/aiSdk.cjs.map +1 -0
- package/dist/cjs/auditDictionaryMetadata/index.cjs +37 -0
- package/dist/cjs/auditDictionaryMetadata/index.cjs.map +1 -0
- package/dist/cjs/customQuery.cjs +24 -0
- package/dist/cjs/customQuery.cjs.map +1 -0
- package/dist/cjs/index.cjs +25 -0
- package/dist/cjs/translateJSON/index.cjs +67 -0
- package/dist/cjs/translateJSON/index.cjs.map +1 -0
- package/dist/cjs/utils/extractJSON.cjs +61 -0
- package/dist/cjs/utils/extractJSON.cjs.map +1 -0
- package/dist/esm/_virtual/_utils_asset.mjs +97 -0
- package/dist/esm/aiSdk.mjs +92 -0
- package/dist/esm/aiSdk.mjs.map +1 -0
- package/dist/esm/auditDictionaryMetadata/index.mjs +36 -0
- package/dist/esm/auditDictionaryMetadata/index.mjs.map +1 -0
- package/dist/esm/customQuery.mjs +23 -0
- package/dist/esm/customQuery.mjs.map +1 -0
- package/dist/esm/index.mjs +8 -0
- package/dist/esm/translateJSON/index.mjs +66 -0
- package/dist/esm/translateJSON/index.mjs.map +1 -0
- package/dist/esm/utils/extractJSON.mjs +60 -0
- package/dist/esm/utils/extractJSON.mjs.map +1 -0
- package/dist/types/aiSdk.d.ts +61 -0
- package/dist/types/aiSdk.d.ts.map +1 -0
- package/dist/types/auditDictionaryMetadata/index.d.ts +36 -0
- package/dist/types/auditDictionaryMetadata/index.d.ts.map +1 -0
- package/dist/types/customQuery.d.ts +24 -0
- package/dist/types/customQuery.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/translateJSON/index.d.ts +43 -0
- package/dist/types/translateJSON/index.d.ts.map +1 -0
- package/dist/types/utils/extractJSON.d.ts +36 -0
- package/dist/types/utils/extractJSON.d.ts.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region src/utils/extractJSON.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extracts and parses the first valid JSON value (object or array) from a string containing arbitrary text.
|
|
4
|
+
* This is used to safely extract JSON from LLM responses that may contain additional text or markdown.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Extracts JSON object from markdown response:
|
|
8
|
+
* ```json
|
|
9
|
+
* {
|
|
10
|
+
* "title": "Test content declarations",
|
|
11
|
+
* "description": "A comprehensive test dictionary...",
|
|
12
|
+
* "tags": ["test tag"]
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Extracts JSON array:
|
|
18
|
+
* ```json
|
|
19
|
+
* ["item1", "item2", "item3"]
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Extracts JSON from markdown:
|
|
24
|
+
* Here is the response:
|
|
25
|
+
* ```json
|
|
26
|
+
* {"key": "value"}
|
|
27
|
+
* ```
|
|
28
|
+
* End of response.
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} If no valid JSON object/array is found or if parsing fails
|
|
31
|
+
* @returns {T} The parsed JSON value cast to type T
|
|
32
|
+
*/
|
|
33
|
+
const extractJson = (input) => {
|
|
34
|
+
const opening = input.match(/[{[]/);
|
|
35
|
+
if (!opening) throw new Error("No JSON start character ({ or [) found.");
|
|
36
|
+
const startIdx = opening.index;
|
|
37
|
+
const openChar = input[startIdx];
|
|
38
|
+
const closeChar = openChar === "{" ? "}" : "]";
|
|
39
|
+
let depth = 0;
|
|
40
|
+
for (let i = startIdx; i < input.length; i++) {
|
|
41
|
+
const char = input[i];
|
|
42
|
+
if (char === openChar) depth++;
|
|
43
|
+
else if (char === closeChar) {
|
|
44
|
+
depth--;
|
|
45
|
+
if (depth === 0) {
|
|
46
|
+
const jsonSubstring = input.slice(startIdx, i + 1);
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(jsonSubstring);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw new Error(`Failed to parse JSON: ${err.message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw new Error("Reached end of input without closing JSON bracket.");
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { extractJson };
|
|
60
|
+
//# sourceMappingURL=extractJSON.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractJSON.mjs","names":[],"sources":["../../../src/utils/extractJSON.ts"],"sourcesContent":["/**\n * Extracts and parses the first valid JSON value (object or array) from a string containing arbitrary text.\n * This is used to safely extract JSON from LLM responses that may contain additional text or markdown.\n *\n * @example\n * // Extracts JSON object from markdown response:\n * ```json\n * {\n * \"title\": \"Test content declarations\",\n * \"description\": \"A comprehensive test dictionary...\",\n * \"tags\": [\"test tag\"]\n * }\n * ```\n *\n * @example\n * // Extracts JSON array:\n * ```json\n * [\"item1\", \"item2\", \"item3\"]\n * ```\n *\n * @example\n * // Extracts JSON from markdown:\n * Here is the response:\n * ```json\n * {\"key\": \"value\"}\n * ```\n * End of response.\n *\n * @throws {Error} If no valid JSON object/array is found or if parsing fails\n * @returns {T} The parsed JSON value cast to type T\n */\nexport const extractJson = <T = any>(input: string): T => {\n const opening = input.match(/[{[]/);\n if (!opening) throw new Error('No JSON start character ({ or [) found.');\n\n const startIdx = opening.index!;\n const openChar = input[startIdx];\n const closeChar = openChar === '{' ? '}' : ']';\n let depth = 0;\n\n for (let i = startIdx; i < input.length; i++) {\n const char = input[i];\n if (char === openChar) depth++;\n else if (char === closeChar) {\n depth--;\n if (depth === 0) {\n const jsonSubstring = input.slice(startIdx, i + 1);\n try {\n return JSON.parse(jsonSubstring) as T;\n } catch (err) {\n throw new Error(`Failed to parse JSON: ${(err as Error).message}`);\n }\n }\n }\n }\n\n throw new Error('Reached end of input without closing JSON bracket.');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,eAAwB,UAAqB;CACxD,MAAM,UAAU,MAAM,MAAM,OAAO;AACnC,KAAI,CAAC,QAAS,OAAM,IAAI,MAAM,0CAA0C;CAExE,MAAM,WAAW,QAAQ;CACzB,MAAM,WAAW,MAAM;CACvB,MAAM,YAAY,aAAa,MAAM,MAAM;CAC3C,IAAI,QAAQ;AAEZ,MAAK,IAAI,IAAI,UAAU,IAAI,MAAM,QAAQ,KAAK;EAC5C,MAAM,OAAO,MAAM;AACnB,MAAI,SAAS,SAAU;WACd,SAAS,WAAW;AAC3B;AACA,OAAI,UAAU,GAAG;IACf,MAAM,gBAAgB,MAAM,MAAM,UAAU,IAAI,EAAE;AAClD,QAAI;AACF,YAAO,KAAK,MAAM,cAAc;aACzB,KAAK;AACZ,WAAM,IAAI,MAAM,yBAA0B,IAAc,UAAU;;;;;AAM1E,OAAM,IAAI,MAAM,qDAAqD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { anthropic } from "@ai-sdk/anthropic";
|
|
2
|
+
import { deepseek } from "@ai-sdk/deepseek";
|
|
3
|
+
import { google } from "@ai-sdk/google";
|
|
4
|
+
import { mistral } from "@ai-sdk/mistral";
|
|
5
|
+
import { openai } from "@ai-sdk/openai";
|
|
6
|
+
import { AssistantModelMessage, SystemModelMessage, ToolModelMessage, UserModelMessage, generateText } from "ai";
|
|
7
|
+
|
|
8
|
+
//#region src/aiSdk.d.ts
|
|
9
|
+
type AnthropicModel = Parameters<typeof anthropic>[0];
|
|
10
|
+
type DeepSeekModel = Parameters<typeof deepseek>[0];
|
|
11
|
+
type MistralModel = Parameters<typeof mistral>[0];
|
|
12
|
+
type OpenAIModel = Parameters<typeof openai>[0];
|
|
13
|
+
type GoogleModel = Parameters<typeof google>[0];
|
|
14
|
+
type Messages = (SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage)[];
|
|
15
|
+
/**
|
|
16
|
+
* Supported AI models
|
|
17
|
+
*/
|
|
18
|
+
type Model = AnthropicModel | DeepSeekModel | MistralModel | OpenAIModel | GoogleModel | (string & {});
|
|
19
|
+
/**
|
|
20
|
+
* Supported AI SDK providers
|
|
21
|
+
*/
|
|
22
|
+
declare enum AIProvider {
|
|
23
|
+
OPENAI = "openai",
|
|
24
|
+
ANTHROPIC = "anthropic",
|
|
25
|
+
MISTRAL = "mistral",
|
|
26
|
+
DEEPSEEK = "deepseek",
|
|
27
|
+
GEMINI = "gemini",
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Common options for all AI providers
|
|
31
|
+
*/
|
|
32
|
+
type AIOptions = {
|
|
33
|
+
provider?: AIProvider;
|
|
34
|
+
model?: Model;
|
|
35
|
+
temperature?: number;
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
applicationContext?: string;
|
|
38
|
+
};
|
|
39
|
+
type ChatCompletionRequestMessage = {
|
|
40
|
+
role: 'system' | 'user' | 'assistant';
|
|
41
|
+
content: string;
|
|
42
|
+
timestamp?: Date;
|
|
43
|
+
};
|
|
44
|
+
type AccessType = 'apiKey' | 'registered_user' | 'premium_user' | 'public';
|
|
45
|
+
type AIConfig = Omit<Parameters<typeof generateText>[0], 'prompt'>;
|
|
46
|
+
type AIConfigOptions = {
|
|
47
|
+
userOptions?: AIOptions;
|
|
48
|
+
defaultOptions?: AIOptions;
|
|
49
|
+
accessType?: AccessType[];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Get AI model configuration based on the selected provider and options
|
|
53
|
+
* This function handles the configuration for different AI providers
|
|
54
|
+
*
|
|
55
|
+
* @param options Configuration options including provider, API keys, models and temperature
|
|
56
|
+
* @returns Configured AI model ready to use with generateText
|
|
57
|
+
*/
|
|
58
|
+
declare const getAIConfig: (options: AIConfigOptions, isAuthenticated?: boolean) => Promise<AIConfig>;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { AIConfig, AIConfigOptions, AIOptions, AIProvider, ChatCompletionRequestMessage, Messages, Model, getAIConfig };
|
|
61
|
+
//# sourceMappingURL=aiSdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiSdk.d.ts","names":[],"sources":["../../src/aiSdk.ts"],"sourcesContent":[],"mappings":";;;;;;;;KAaK,cAAA,GAAiB,kBAAkB;KACnC,aAAA,GAAgB,kBAAkB;AAH3B,KAIP,YAAA,GAAe,UAFD,CAAA,OAEmB,OAFhB,CAAA,CAAA,CAAA,CAAA;AAAU,KAG3B,WAAA,GAAc,UAFD,CAAA,OAEmB,MAFhB,CAAA,CAAA,CAAA,CAAA;AAAU,KAG1B,WAAA,GAAc,UAFF,CAAqB,OAED,MAFjB,CAAA,CAAA,CAAA,CAAA;AACf,KAGO,QAAA,GAHI,CAIZ,kBAJe,GAKf,gBALyB,GAMzB,qBANyB,GAOzB,gBAPyB,CAAA,EAAA;AAAA;AAG7B;;AAEI,KAQQ,KAAA,GACR,cATA,GAUA,aAVA,GAWA,YAXA,GAYA,WAZA,GAaA,WAbA,GAAA,CAAA,MAAA,GAAA,CAAA,CAAA,CAAA;;;;AAQQ,aAWA,UAAA;EAVR,MAAA,GAAA,QAAA;EACA,SAAA,GAAA,WAAA;EACA,OAAA,GAAA,SAAA;EACA,QAAA,GAAA,UAAA;EACA,MAAA,GAAA,QAAA;;AAMJ;AAWA;AASA;AAMK,KAfO,SAAA,GAeG;EAiEH,QAAA,CAAA,EA/EC,UA+EO;EAA0B,KAAA,CAAA,EA9EpC,KA8EoC;EAAlB,WAAA,CAAA,EAAA,MAAA;EAAL,MAAA,CAAA,EAAA,MAAA;EAAI,kBAAA,CAAA,EAAA,MAAA;AAK3B,CAAA;AACgB,KA7EJ,4BAAA,GA6EI;EACG,IAAA,EAAA,QAAA,GAAA,MAAA,GAAA,WAAA;EACJ,OAAA,EAAA,MAAA;EAAU,SAAA,CAAA,EA5EX,IA4EW;AAUzB,CAAA;KAnFK,UAAA,GAoFM,QAAA,GAAA,iBAAA,GAAA,cAAA,GAAA,QAAA;AAEA,KArBC,QAAA,GAAW,IAqBZ,CArBiB,UAqBjB,CAAA,OArBmC,YAqBnC,CAAA,CAAA,CAAA,CAAA,EAAA,QAAA,CAAA;AAAR,KAhBS,eAAA,GAgBT;EAAO,WAAA,CAAA,EAfM,SAeN;mBAdS;eACJ;;;;;;;;;cAUF,uBACF,+CAER,QAAQ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AIConfig, AIOptions } from "../aiSdk.js";
|
|
2
|
+
|
|
3
|
+
//#region src/auditDictionaryMetadata/index.d.ts
|
|
4
|
+
type Tag = {
|
|
5
|
+
key: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
};
|
|
8
|
+
type AuditDictionaryMetadataOptions = {
|
|
9
|
+
fileContent: string;
|
|
10
|
+
tags?: Tag[];
|
|
11
|
+
aiConfig: AIConfig;
|
|
12
|
+
applicationContext?: string;
|
|
13
|
+
};
|
|
14
|
+
type AuditFileResultData = {
|
|
15
|
+
fileContent: {
|
|
16
|
+
title: string;
|
|
17
|
+
description: string;
|
|
18
|
+
tags: string[];
|
|
19
|
+
};
|
|
20
|
+
tokenUsed: number;
|
|
21
|
+
};
|
|
22
|
+
declare const aiDefaultOptions: AIOptions;
|
|
23
|
+
/**
|
|
24
|
+
* Audits a content declaration file by constructing a prompt for AI models.
|
|
25
|
+
* The prompt includes details about the project's locales, file paths of content declarations,
|
|
26
|
+
* and requests for identifying issues or inconsistencies.
|
|
27
|
+
*/
|
|
28
|
+
declare const auditDictionaryMetadata: ({
|
|
29
|
+
fileContent,
|
|
30
|
+
tags,
|
|
31
|
+
aiConfig,
|
|
32
|
+
applicationContext
|
|
33
|
+
}: AuditDictionaryMetadataOptions) => Promise<AuditFileResultData | undefined>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { AuditDictionaryMetadataOptions, AuditFileResultData, aiDefaultOptions, auditDictionaryMetadata };
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/auditDictionaryMetadata/index.ts"],"sourcesContent":[],"mappings":";;;KAKK,GAAA;;EAAA,WAAG,CAAA,EAAA,MAAA;AAKR,CAAA;AAOY,KAPA,8BAAA,GAOmB;EASlB,WAAA,EAAA,MAEZ;EAOY,IAAA,CAAA,EAvBJ,GAuBI,EAAA;EAAiC,QAAA,EAtBlC,QAsBkC;EAAA,kBAAA,CAAA,EAAA,MAAA;CAAA;AAAA,KAlBlC,mBAAA,GAkBkC;EAK3C,WAAA,EAAA;IACD,KAAA,EAAA,MAAA;IADkC,WAAA,EAAA,MAAA;IAAO,IAAA,EAAA,MAAA,EAAA;;;;cAd9B,kBAAkB;;;;;;cASlB;;;;;GAKV,mCAAiC,QAClC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AIConfig, AIOptions, Messages } from "./aiSdk.js";
|
|
2
|
+
|
|
3
|
+
//#region src/customQuery.d.ts
|
|
4
|
+
type CustomQueryOptions = {
|
|
5
|
+
messages: Messages;
|
|
6
|
+
aiConfig: AIConfig;
|
|
7
|
+
};
|
|
8
|
+
type CustomQueryResultData = {
|
|
9
|
+
fileContent: string;
|
|
10
|
+
tokenUsed: number;
|
|
11
|
+
};
|
|
12
|
+
declare const aiDefaultOptions: AIOptions;
|
|
13
|
+
/**
|
|
14
|
+
* CustomQuery a content declaration file by constructing a prompt for AI models.
|
|
15
|
+
* The prompt includes details about the project's locales, file paths of content declarations,
|
|
16
|
+
* and requests for identifying issues or inconsistencies.
|
|
17
|
+
*/
|
|
18
|
+
declare const customQuery: ({
|
|
19
|
+
messages,
|
|
20
|
+
aiConfig
|
|
21
|
+
}: CustomQueryOptions) => Promise<CustomQueryResultData | undefined>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { CustomQueryOptions, CustomQueryResultData, aiDefaultOptions, customQuery };
|
|
24
|
+
//# sourceMappingURL=customQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customQuery.d.ts","names":[],"sources":["../../src/customQuery.ts"],"sourcesContent":[],"mappings":";;;KAGY,kBAAA;YACA;EADA,QAAA,EAEA,QAFA;AAKZ,CAAA;AAKa,KALD,qBAAA,GAKmB;EAUlB,WAAA,EAAA,MAcZ;EAdiC,SAAA,EAAA,MAAA;CAAA;AAG/B,cAbU,gBAaV,EAb4B,SAa5B;;;;;;cAHU;;;GAGV,uBAAqB,QAAQ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AIConfig, AIConfigOptions, AIOptions, AIProvider, ChatCompletionRequestMessage, Messages, Model, getAIConfig } from "./aiSdk.js";
|
|
2
|
+
import { AuditDictionaryMetadataOptions, AuditFileResultData, auditDictionaryMetadata } from "./auditDictionaryMetadata/index.js";
|
|
3
|
+
import { CustomQueryOptions, CustomQueryResultData, customQuery } from "./customQuery.js";
|
|
4
|
+
import { TranslateJSONOptions, TranslateJSONResultData, translateJSON } from "./translateJSON/index.js";
|
|
5
|
+
import { extractJson } from "./utils/extractJSON.js";
|
|
6
|
+
import { generateText, streamText } from "ai";
|
|
7
|
+
export { AIConfig, AIConfigOptions, AIOptions, AIProvider, type AuditDictionaryMetadataOptions, type AuditFileResultData, ChatCompletionRequestMessage, type CustomQueryOptions, type CustomQueryResultData, Messages, Model, type TranslateJSONOptions, type TranslateJSONResultData, auditDictionaryMetadata, customQuery, extractJson, generateText, getAIConfig, streamText, translateJSON };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AIConfig, AIOptions } from "../aiSdk.js";
|
|
2
|
+
import { Locale } from "@intlayer/types";
|
|
3
|
+
|
|
4
|
+
//#region src/translateJSON/index.d.ts
|
|
5
|
+
type Tag = {
|
|
6
|
+
key: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
};
|
|
9
|
+
type TranslateJSONOptions = {
|
|
10
|
+
entryFileContent: JSON;
|
|
11
|
+
presetOutputContent: JSON;
|
|
12
|
+
dictionaryDescription?: string;
|
|
13
|
+
entryLocale: Locale;
|
|
14
|
+
outputLocale: Locale;
|
|
15
|
+
tags?: Tag[];
|
|
16
|
+
aiConfig: AIConfig;
|
|
17
|
+
mode: 'complete' | 'review';
|
|
18
|
+
applicationContext?: string;
|
|
19
|
+
};
|
|
20
|
+
type TranslateJSONResultData = {
|
|
21
|
+
fileContent: string;
|
|
22
|
+
tokenUsed: number;
|
|
23
|
+
};
|
|
24
|
+
declare const aiDefaultOptions: AIOptions;
|
|
25
|
+
/**
|
|
26
|
+
* TranslateJSONs a content declaration file by constructing a prompt for AI models.
|
|
27
|
+
* The prompt includes details about the project's locales, file paths of content declarations,
|
|
28
|
+
* and requests for identifying issues or inconsistencies.
|
|
29
|
+
*/
|
|
30
|
+
declare const translateJSON: ({
|
|
31
|
+
entryFileContent,
|
|
32
|
+
presetOutputContent,
|
|
33
|
+
dictionaryDescription,
|
|
34
|
+
aiConfig,
|
|
35
|
+
entryLocale,
|
|
36
|
+
outputLocale,
|
|
37
|
+
tags,
|
|
38
|
+
mode,
|
|
39
|
+
applicationContext
|
|
40
|
+
}: TranslateJSONOptions) => Promise<TranslateJSONResultData | undefined>;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { TranslateJSONOptions, TranslateJSONResultData, aiDefaultOptions, translateJSON };
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/translateJSON/index.ts"],"sourcesContent":[],"mappings":";;;;KAOK,GAAA;;EAAA,WAAG,CAAA,EAAA,MAAA;AAKR,CAAA;AACoB,KADR,oBAAA,GACQ;EACG,gBAAA,EADH,IACG;EAER,mBAAA,EAFQ,IAER;EACC,qBAAA,CAAA,EAAA,MAAA;EACP,WAAA,EAFM,MAEN;EACG,YAAA,EAFI,MAEJ;EAAQ,IAAA,CAAA,EADX,GACW,EAAA;EAKR,QAAA,EALA,QAKA;EAKC,IAAA,EAAA,UAAA,GAGZ,QAAA;EA0CY,kBA0CZ,CAAA,EAAA,MAAA;CA1CmC;AAAA,KAlDxB,uBAAA,GAkDwB;EAAA,WAAA,EAAA,MAAA;EAAA,SAAA,EAAA,MAAA;CAAA;AAAA,cA7CvB,gBA6CuB,EA7CL,SA6CK;;;;;;AAUV,cAVb,aAUa,EAAA,CAAA;EAAA,gBAAA;EAAA,mBAAA;EAAA,qBAAA;EAAA,QAAA;EAAA,WAAA;EAAA,YAAA;EAAA,IAAA;EAAA,IAAA;EAAA;AAAA,CAAA,EAAvB,oBAAuB,EAAA,GAAA,OAAA,CAAQ,uBAAR,GAAA,SAAA,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/utils/extractJSON.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Extracts and parses the first valid JSON value (object or array) from a string containing arbitrary text.
|
|
4
|
+
* This is used to safely extract JSON from LLM responses that may contain additional text or markdown.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Extracts JSON object from markdown response:
|
|
8
|
+
* ```json
|
|
9
|
+
* {
|
|
10
|
+
* "title": "Test content declarations",
|
|
11
|
+
* "description": "A comprehensive test dictionary...",
|
|
12
|
+
* "tags": ["test tag"]
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Extracts JSON array:
|
|
18
|
+
* ```json
|
|
19
|
+
* ["item1", "item2", "item3"]
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Extracts JSON from markdown:
|
|
24
|
+
* Here is the response:
|
|
25
|
+
* ```json
|
|
26
|
+
* {"key": "value"}
|
|
27
|
+
* ```
|
|
28
|
+
* End of response.
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} If no valid JSON object/array is found or if parsing fails
|
|
31
|
+
* @returns {T} The parsed JSON value cast to type T
|
|
32
|
+
*/
|
|
33
|
+
declare const extractJson: <T = any>(input: string) => T;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { extractJson };
|
|
36
|
+
//# sourceMappingURL=extractJSON.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractJSON.d.ts","names":[],"sources":["../../../src/utils/extractJSON.ts"],"sourcesContent":[],"mappings":";;AA+BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,yCAAwC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@intlayer/ai",
|
|
3
|
+
"version": "7.3.0-canary.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "SDK that provides AI capabilities for Intlayer applications",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"intlayer",
|
|
8
|
+
"application",
|
|
9
|
+
"ai",
|
|
10
|
+
"backend",
|
|
11
|
+
"i18n",
|
|
12
|
+
"internationalization"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://intlayer.org",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/aymericzip/intlayer.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Aymeric PINEAU",
|
|
25
|
+
"url": "https://github.com/aymericzip"
|
|
26
|
+
},
|
|
27
|
+
"contributors": [
|
|
28
|
+
{
|
|
29
|
+
"name": "Aymeric Pineau",
|
|
30
|
+
"email": "ay.pineau@gmail.com",
|
|
31
|
+
"url": "https://github.com/aymericzip"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/types/index.d.ts",
|
|
38
|
+
"require": "./dist/cjs/index.cjs",
|
|
39
|
+
"import": "./dist/esm/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"main": "dist/cjs/index.cjs",
|
|
44
|
+
"module": "dist/esm/index.mjs",
|
|
45
|
+
"types": "dist/types/index.d.ts",
|
|
46
|
+
"typesVersions": {
|
|
47
|
+
"*": {
|
|
48
|
+
"package.json": [
|
|
49
|
+
"./package.json"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"./dist",
|
|
55
|
+
"./package.json"
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsdown --config tsdown.config.ts",
|
|
59
|
+
"build:ci": "tsdown --config tsdown.config.ts",
|
|
60
|
+
"clean": "rimraf ./dist .turbo",
|
|
61
|
+
"dev": "tsdown --config tsdown.config.ts --watch",
|
|
62
|
+
"format": "biome format . --check",
|
|
63
|
+
"format:fix": "biome format --write .",
|
|
64
|
+
"lint": "biome lint .",
|
|
65
|
+
"lint:fix": "biome lint --write .",
|
|
66
|
+
"prepublish": "cp -f ../../../README.md ./README.md",
|
|
67
|
+
"publish": "bun publish || true",
|
|
68
|
+
"publish:canary": "bun publish --access public --tag canary || true",
|
|
69
|
+
"publish:latest": "bun publish --access public --tag latest || true",
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"test:watch": "vitest",
|
|
72
|
+
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@ai-sdk/anthropic": "2.0.45",
|
|
76
|
+
"@ai-sdk/deepseek": "1.0.29",
|
|
77
|
+
"@ai-sdk/google": "2.0.40",
|
|
78
|
+
"@ai-sdk/mistral": "2.0.24",
|
|
79
|
+
"@ai-sdk/openai": "2.0.71",
|
|
80
|
+
"@intlayer/api": "7.3.0-canary.0",
|
|
81
|
+
"@intlayer/config": "7.3.0-canary.0",
|
|
82
|
+
"@intlayer/core": "7.3.0-canary.0",
|
|
83
|
+
"@intlayer/types": "7.3.0-canary.0",
|
|
84
|
+
"ai": "5.0.98"
|
|
85
|
+
},
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"@types/node": "24.10.1",
|
|
88
|
+
"@utils/ts-config": "1.0.4",
|
|
89
|
+
"@utils/ts-config-types": "1.0.4",
|
|
90
|
+
"@utils/tsdown-config": "1.0.4",
|
|
91
|
+
"rimraf": "6.1.2",
|
|
92
|
+
"tsdown": "0.16.6",
|
|
93
|
+
"typescript": "5.9.3",
|
|
94
|
+
"vitest": "4.0.13"
|
|
95
|
+
},
|
|
96
|
+
"engines": {
|
|
97
|
+
"node": ">=14.18"
|
|
98
|
+
},
|
|
99
|
+
"bug": {
|
|
100
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
101
|
+
}
|
|
102
|
+
}
|