@jterrazz/intelligence 1.4.1 → 1.4.3
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/adapters/models/openrouter-model.adapter.js.map +1 -1
- package/dist/adapters/prompts/library/categories/foundations.d.ts +1 -0
- package/dist/adapters/prompts/library/categories/foundations.js +1 -0
- package/dist/adapters/prompts/library/categories/foundations.js.map +1 -1
- package/dist/adapters/prompts/library/categories/language.d.ts +6 -6
- package/dist/adapters/prompts/library/categories/language.js +6 -6
- package/dist/adapters/prompts/library/categories/language.js.map +1 -1
- package/dist/adapters/prompts/library/categories/persona.d.ts +1 -0
- package/dist/adapters/prompts/library/categories/persona.js +1 -0
- package/dist/adapters/prompts/library/categories/persona.js.map +1 -1
- package/dist/adapters/prompts/library/index.d.ts +8 -6
- package/dist/adapters/utils/__tests__/ai-response-parser.test.js +40 -0
- package/dist/adapters/utils/__tests__/ai-response-parser.test.js.map +1 -1
- package/dist/adapters/utils/ai-response-parser.d.ts +4 -0
- package/dist/adapters/utils/ai-response-parser.js +15 -2
- package/dist/adapters/utils/ai-response-parser.js.map +1 -1
- package/dist/index.cjs +23 -8
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/models/openrouter-model.adapter.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { ChatOpenAI } from '@langchain/openai';\n\nimport type { ModelPort } from '../../ports/model.port.js';\n\nexport interface OpenRouterConfig {\n /**\n * OpenRouter API key\n */\n apiKey: string;\n /**\n * The maximum number of tokens to generate\n */\n maxTokens?: number;\n /**\n * Optional metadata for request headers\n */\n metadata?: OpenRouterMetadata;\n /**\n * The model to use (e.g., 'google/gemini-2.5-flash-preview-05-20:thinking')\n */\n modelName: string;\n}\n\nexport interface OpenRouterMetadata {\n /**\n * Application title for X-Title header\n */\n application?: string;\n /**\n * Website URL for HTTP-Referer header\n */\n website?: string;\n}\n\n/**\n * OpenRouter adapter that provides access to various models through OpenRouter's API\n */\nexport class OpenRouterModelAdapter implements ModelPort {\n private readonly model: BaseLanguageModel;\n\n constructor(config: OpenRouterConfig) {\n this.model = new ChatOpenAI({\n configuration: {\n baseURL: 'https://openrouter.ai/api/v1',\n defaultHeaders: {\n ...(config.metadata?.website && {\n 'HTTP-Referer': config.metadata.website,\n }),\n ...(config.metadata?.application && { 'X-Title': config.metadata.application }),\n },\n },\n maxTokens: config.maxTokens ?? 64_000,\n modelKwargs: {\n reasoning: {
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/models/openrouter-model.adapter.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { ChatOpenAI } from '@langchain/openai';\n\nimport type { ModelPort } from '../../ports/model.port.js';\n\nexport interface OpenRouterConfig {\n /**\n * OpenRouter API key\n */\n apiKey: string;\n /**\n * The maximum number of tokens to generate\n */\n maxTokens?: number;\n /**\n * Optional metadata for request headers\n */\n metadata?: OpenRouterMetadata;\n /**\n * The model to use (e.g., 'google/gemini-2.5-flash-preview-05-20:thinking')\n */\n modelName: string;\n}\n\nexport interface OpenRouterMetadata {\n /**\n * Application title for X-Title header\n */\n application?: string;\n /**\n * Website URL for HTTP-Referer header\n */\n website?: string;\n}\n\n/**\n * OpenRouter adapter that provides access to various models through OpenRouter's API\n */\nexport class OpenRouterModelAdapter implements ModelPort {\n private readonly model: BaseLanguageModel;\n\n constructor(config: OpenRouterConfig) {\n this.model = new ChatOpenAI({\n configuration: {\n baseURL: 'https://openrouter.ai/api/v1',\n defaultHeaders: {\n ...(config.metadata?.website && {\n 'HTTP-Referer': config.metadata.website,\n }),\n ...(config.metadata?.application && { 'X-Title': config.metadata.application }),\n },\n },\n maxTokens: config.maxTokens ?? 64_000,\n modelKwargs: {\n reasoning: {\n effort: 'high',\n exclude: true,\n },\n },\n modelName: config.modelName,\n openAIApiKey: config.apiKey,\n });\n }\n\n getModel(): BaseLanguageModel {\n return this.model;\n }\n}\n"],"names":["ChatOpenAI","OpenRouterModelAdapter","config","model","configuration","baseURL","defaultHeaders","metadata","website","application","maxTokens","modelKwargs","reasoning","effort","exclude","modelName","openAIApiKey","apiKey","getModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,UAAU,QAAQ,oBAAoB;AAkC/C;;CAEC,GACD,OAAO,IAAA,AAAMC,uCAAN;;aAAMA,uBAGGC,MAAwB;gCAH3BD;YAQWC,kBAGAA;QAVpB,uBAAiBC,SAAjB,KAAA;YAamBD;QAVf,IAAI,CAACC,KAAK,GAAG,IAAIH,WAAW;YACxBI,eAAe;gBACXC,SAAS;gBACTC,gBAAgB,mBACRJ,EAAAA,mBAAAA,OAAOK,QAAQ,cAAfL,uCAAAA,iBAAiBM,OAAO,KAAI;oBAC5B,gBAAgBN,OAAOK,QAAQ,CAACC,OAAO;gBAC3C,GACIN,EAAAA,oBAAAA,OAAOK,QAAQ,cAAfL,wCAAAA,kBAAiBO,WAAW,KAAI;oBAAE,WAAWP,OAAOK,QAAQ,CAACE,WAAW;gBAAC;YAErF;YACAC,WAAWR,CAAAA,oBAAAA,OAAOQ,SAAS,cAAhBR,+BAAAA,oBAAoB;YAC/BS,aAAa;gBACTC,WAAW;oBACPC,QAAQ;oBACRC,SAAS;gBACb;YACJ;YACAC,WAAWb,OAAOa,SAAS;YAC3BC,cAAcd,OAAOe,MAAM;QAC/B;;kBAvBKhB;;YA0BTiB,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,CAACf,KAAK;YACrB;;;WA5BSF;IA6BZ"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* These are the foundational principles that guide all other instructions.
|
|
4
4
|
*/
|
|
5
5
|
export declare const FOUNDATIONS: {
|
|
6
|
+
readonly CONTEXTUAL_ONLY: "\n<Foundation>\nYou MUST ONLY use the information provided in the context to answer questions.\nYou MUST NOT use any other information, including your own knowledge, to answer questions.\n</Foundation>";
|
|
6
7
|
readonly CONTEXTUAL_REASONING: "\n<Foundation>\nYou MUST synthesize information from the provided context, tools, and conversation history to form well-reasoned conclusions.\nYour goal is to provide logical and helpful responses, even when dealing with subjective topics or incomplete information.\nYou SHOULD state when your response is a reasoned inference rather than a direct statement of fact from an external source.\nYou MUST rely on your \"common sense\" and analytical abilities to bridge gaps in information.\n</Foundation>";
|
|
7
8
|
readonly ETHICAL_CONDUCT: "\n<Foundation>\nYou MUST adhere to the highest ethical standards. Your conduct must be impartial and devoid of prejudice.\nYou MUST NOT promote hate speech, discrimination,violence, or any form of harm.\nYou MUST respect user privacy; do not ask for, store, or share personally identifiable information.\n</Foundation>";
|
|
8
9
|
readonly FACTUAL_ACCURACY: "\n<Foundation>\nYou MUST prioritize accuracy and truthfulness. Your responses must be based on verifiable information.\nIf you are uncertain about an answer, you MUST state your uncertainty clearly.\nYou MUST NOT invent facts, data, or sources. When possible, cite credible sources.\n</Foundation>";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Core, non-negotiable rules that establish the agent's fundamental identity and operational boundaries.
|
|
3
3
|
* These are the foundational principles that guide all other instructions.
|
|
4
4
|
*/ export var FOUNDATIONS = {
|
|
5
|
+
CONTEXTUAL_ONLY: "\n<Foundation>\nYou MUST ONLY use the information provided in the context to answer questions.\nYou MUST NOT use any other information, including your own knowledge, to answer questions.\n</Foundation>",
|
|
5
6
|
CONTEXTUAL_REASONING: '\n<Foundation>\nYou MUST synthesize information from the provided context, tools, and conversation history to form well-reasoned conclusions.\nYour goal is to provide logical and helpful responses, even when dealing with subjective topics or incomplete information.\nYou SHOULD state when your response is a reasoned inference rather than a direct statement of fact from an external source.\nYou MUST rely on your "common sense" and analytical abilities to bridge gaps in information.\n</Foundation>',
|
|
6
7
|
ETHICAL_CONDUCT: "\n<Foundation>\nYou MUST adhere to the highest ethical standards. Your conduct must be impartial and devoid of prejudice.\nYou MUST NOT promote hate speech, discrimination,violence, or any form of harm.\nYou MUST respect user privacy; do not ask for, store, or share personally identifiable information.\n</Foundation>",
|
|
7
8
|
FACTUAL_ACCURACY: "\n<Foundation>\nYou MUST prioritize accuracy and truthfulness. Your responses must be based on verifiable information.\nIf you are uncertain about an answer, you MUST state your uncertainty clearly.\nYou MUST NOT invent facts, data, or sources. When possible, cite credible sources.\n</Foundation>",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/adapters/prompts/library/categories/foundations.ts"],"sourcesContent":["/**\n * Core, non-negotiable rules that establish the agent's fundamental identity and operational boundaries.\n * These are the foundational principles that guide all other instructions.\n */\nexport const FOUNDATIONS = {\n CONTEXTUAL_REASONING: `\n<Foundation>\nYou MUST synthesize information from the provided context, tools, and conversation history to form well-reasoned conclusions.\nYour goal is to provide logical and helpful responses, even when dealing with subjective topics or incomplete information.\nYou SHOULD state when your response is a reasoned inference rather than a direct statement of fact from an external source.\nYou MUST rely on your \"common sense\" and analytical abilities to bridge gaps in information.\n</Foundation>`,\n\n ETHICAL_CONDUCT: `\n<Foundation>\nYou MUST adhere to the highest ethical standards. Your conduct must be impartial and devoid of prejudice.\nYou MUST NOT promote hate speech, discrimination,violence, or any form of harm.\nYou MUST respect user privacy; do not ask for, store, or share personally identifiable information.\n</Foundation>`,\n\n FACTUAL_ACCURACY: `\n<Foundation>\nYou MUST prioritize accuracy and truthfulness. Your responses must be based on verifiable information.\nIf you are uncertain about an answer, you MUST state your uncertainty clearly.\nYou MUST NOT invent facts, data, or sources. When possible, cite credible sources.\n</Foundation>`,\n\n FIRST_PRINCIPLES_THINKING: `\n<Foundation>\nYou MUST break down complex problems into their fundamental, indivisible truths (first principles).\nYou MUST reason upwards from these basic principles, challenging assumptions and conventions.\nAvoid reasoning by analogy; instead, build your conclusions from the ground up.\n</Foundation>`,\n\n HARM_PREVENTION: `\n<Foundation>\nYou MUST refuse to provide instructions or information that is illegal, dangerous, or promotes harm.\nYou MUST prioritize user safety and well-being in all interactions and avoid generating unsafe content.\n</Foundation>`,\n} as const;\n"],"names":["FOUNDATIONS","CONTEXTUAL_REASONING","ETHICAL_CONDUCT","FACTUAL_ACCURACY","FIRST_PRINCIPLES_THINKING","HARM_PREVENTION"],"mappings":"AAAA;;;CAGC,GACD,OAAO,IAAMA,cAAc;IACvBC,sBAAuB;IAQvBC,iBAAkB;IAOlBC,kBAAmB;IAOnBC,2BAA4B;IAO5BC,iBAAkB;AAKtB,EAAW"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/adapters/prompts/library/categories/foundations.ts"],"sourcesContent":["/**\n * Core, non-negotiable rules that establish the agent's fundamental identity and operational boundaries.\n * These are the foundational principles that guide all other instructions.\n */\nexport const FOUNDATIONS = {\n CONTEXTUAL_ONLY: `\n<Foundation>\nYou MUST ONLY use the information provided in the context to answer questions.\nYou MUST NOT use any other information, including your own knowledge, to answer questions.\n</Foundation>`,\n\n CONTEXTUAL_REASONING: `\n<Foundation>\nYou MUST synthesize information from the provided context, tools, and conversation history to form well-reasoned conclusions.\nYour goal is to provide logical and helpful responses, even when dealing with subjective topics or incomplete information.\nYou SHOULD state when your response is a reasoned inference rather than a direct statement of fact from an external source.\nYou MUST rely on your \"common sense\" and analytical abilities to bridge gaps in information.\n</Foundation>`,\n\n ETHICAL_CONDUCT: `\n<Foundation>\nYou MUST adhere to the highest ethical standards. Your conduct must be impartial and devoid of prejudice.\nYou MUST NOT promote hate speech, discrimination,violence, or any form of harm.\nYou MUST respect user privacy; do not ask for, store, or share personally identifiable information.\n</Foundation>`,\n\n FACTUAL_ACCURACY: `\n<Foundation>\nYou MUST prioritize accuracy and truthfulness. Your responses must be based on verifiable information.\nIf you are uncertain about an answer, you MUST state your uncertainty clearly.\nYou MUST NOT invent facts, data, or sources. When possible, cite credible sources.\n</Foundation>`,\n\n FIRST_PRINCIPLES_THINKING: `\n<Foundation>\nYou MUST break down complex problems into their fundamental, indivisible truths (first principles).\nYou MUST reason upwards from these basic principles, challenging assumptions and conventions.\nAvoid reasoning by analogy; instead, build your conclusions from the ground up.\n</Foundation>`,\n\n HARM_PREVENTION: `\n<Foundation>\nYou MUST refuse to provide instructions or information that is illegal, dangerous, or promotes harm.\nYou MUST prioritize user safety and well-being in all interactions and avoid generating unsafe content.\n</Foundation>`,\n} as const;\n"],"names":["FOUNDATIONS","CONTEXTUAL_ONLY","CONTEXTUAL_REASONING","ETHICAL_CONDUCT","FACTUAL_ACCURACY","FIRST_PRINCIPLES_THINKING","HARM_PREVENTION"],"mappings":"AAAA;;;CAGC,GACD,OAAO,IAAMA,cAAc;IACvBC,iBAAkB;IAMlBC,sBAAuB;IAQvBC,iBAAkB;IAOlBC,kBAAmB;IAOnBC,2BAA4B;IAO5BC,iBAAkB;AAKtB,EAAW"}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Defines the natural language for the agent's responses.
|
|
3
3
|
*/
|
|
4
4
|
export declare const LANGUAGES: {
|
|
5
|
-
readonly ENGLISH_NATIVE: "\n<Language>\nYou MUST
|
|
6
|
-
readonly ENGLISH_SIMPLE: "\n<Language>\nYou MUST
|
|
7
|
-
readonly FRENCH_NATIVE: "\n<Language>\nVous DEVEZ
|
|
8
|
-
readonly FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ
|
|
9
|
-
readonly SPANISH_NATIVE: "\n<Language>\nDEBES
|
|
10
|
-
readonly SPANISH_SIMPLE: "\n<Language>\nDEBES
|
|
5
|
+
readonly ENGLISH_NATIVE: "\n<Language>\nYou MUST write your entire output in natural, fluent English. This is a strict requirement; do not use any other language.\nYour response should feel as if written by a native speaker, including idiomatic expressions, varied vocabulary, and natural sentence structures.\n</Language>";
|
|
6
|
+
readonly ENGLISH_SIMPLE: "\n<Language>\nYou MUST write your entire output in simple, clear English. This is a strict requirement; do not use any other language.\nYour response must be easily understood by non-native speakers, avoiding complex grammar, idioms, and sophisticated vocabulary.\n</Language>";
|
|
7
|
+
readonly FRENCH_NATIVE: "\n<Language>\nVous DEVEZ IMPÉRATIVEMENT rédiger toute votre sortie en français naturel et fluide. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre réponse doit donner l'impression d'avoir été écrite par un locuteur natif, en incluant des expressions idiomatiques et un vocabulaire varié.\n</Language>";
|
|
8
|
+
readonly FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ IMPÉRATIVEMENT rédiger toute votre sortie en français simple et clair. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre réponse doit être facile à comprendre pour des non-natifs, en évitant la grammaire complexe et le vocabulaire sophistiqué.\n</Language>";
|
|
9
|
+
readonly SPANISH_NATIVE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un español natural y fluido. Este es un requisito estricto; no utilices ningún otro idioma.\nTu respuesta debe parecer escrita por un hablante nativo, incluyendo expresiones idiomáticas y un vocabulario variado.\n</Language>";
|
|
10
|
+
readonly SPANISH_SIMPLE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un español simple y claro. Este es un requisito estricto; no utilices ningún otro idioma.\nTu respuesta debe ser fácil de entender para hablantes no nativos, evitando gramática compleja y vocabulario sofisticado.\n</Language>";
|
|
11
11
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Defines the natural language for the agent's responses.
|
|
3
3
|
*/ export var LANGUAGES = {
|
|
4
|
-
ENGLISH_NATIVE: "\n<Language>\nYou MUST
|
|
5
|
-
ENGLISH_SIMPLE: "\n<Language>\nYou MUST
|
|
6
|
-
FRENCH_NATIVE: "\n<Language>\nVous DEVEZ r\
|
|
7
|
-
FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ
|
|
8
|
-
SPANISH_NATIVE: "\n<Language>\nDEBES
|
|
9
|
-
SPANISH_SIMPLE: "\n<Language>\nDEBES
|
|
4
|
+
ENGLISH_NATIVE: "\n<Language>\nYou MUST write your entire output in natural, fluent English. This is a strict requirement; do not use any other language.\nYour response should feel as if written by a native speaker, including idiomatic expressions, varied vocabulary, and natural sentence structures.\n</Language>",
|
|
5
|
+
ENGLISH_SIMPLE: "\n<Language>\nYou MUST write your entire output in simple, clear English. This is a strict requirement; do not use any other language.\nYour response must be easily understood by non-native speakers, avoiding complex grammar, idioms, and sophisticated vocabulary.\n</Language>",
|
|
6
|
+
FRENCH_NATIVE: "\n<Language>\nVous DEVEZ IMP\xc9RATIVEMENT r\xe9diger toute votre sortie en fran\xe7ais naturel et fluide. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre r\xe9ponse doit donner l'impression d'avoir \xe9t\xe9 \xe9crite par un locuteur natif, en incluant des expressions idiomatiques et un vocabulaire vari\xe9.\n</Language>",
|
|
7
|
+
FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ IMP\xc9RATIVEMENT r\xe9diger toute votre sortie en fran\xe7ais simple et clair. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre r\xe9ponse doit \xeatre facile \xe0 comprendre pour des non-natifs, en \xe9vitant la grammaire complexe et le vocabulaire sophistiqu\xe9.\n</Language>",
|
|
8
|
+
SPANISH_NATIVE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un espa\xf1ol natural y fluido. Este es un requisito estricto; no utilices ning\xfan otro idioma.\nTu respuesta debe parecer escrita por un hablante nativo, incluyendo expresiones idiom\xe1ticas y un vocabulario variado.\n</Language>",
|
|
9
|
+
SPANISH_SIMPLE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un espa\xf1ol simple y claro. Este es un requisito estricto; no utilices ning\xfan otro idioma.\nTu respuesta debe ser f\xe1cil de entender para hablantes no nativos, evitando gram\xe1tica compleja y vocabulario sofisticado.\n</Language>"
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
//# sourceMappingURL=language.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/adapters/prompts/library/categories/language.ts"],"sourcesContent":["/**\n * Defines the natural language for the agent's responses.\n */\nexport const LANGUAGES = {\n ENGLISH_NATIVE: `\n<Language>\nYou MUST
|
|
1
|
+
{"version":3,"sources":["../../../../../src/adapters/prompts/library/categories/language.ts"],"sourcesContent":["/**\n * Defines the natural language for the agent's responses.\n */\nexport const LANGUAGES = {\n ENGLISH_NATIVE: `\n<Language>\nYou MUST write your entire output in natural, fluent English. This is a strict requirement; do not use any other language.\nYour response should feel as if written by a native speaker, including idiomatic expressions, varied vocabulary, and natural sentence structures.\n</Language>`,\n\n ENGLISH_SIMPLE: `\n<Language>\nYou MUST write your entire output in simple, clear English. This is a strict requirement; do not use any other language.\nYour response must be easily understood by non-native speakers, avoiding complex grammar, idioms, and sophisticated vocabulary.\n</Language>`,\n\n FRENCH_NATIVE: `\n<Language>\nVous DEVEZ IMPÉRATIVEMENT rédiger toute votre sortie en français naturel et fluide. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre réponse doit donner l'impression d'avoir été écrite par un locuteur natif, en incluant des expressions idiomatiques et un vocabulaire varié.\n</Language>`,\n\n FRENCH_SIMPLE: `\n<Language>\nVous DEVEZ IMPÉRATIVEMENT rédiger toute votre sortie en français simple et clair. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre réponse doit être facile à comprendre pour des non-natifs, en évitant la grammaire complexe et le vocabulaire sophistiqué.\n</Language>`,\n\n SPANISH_NATIVE: `\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un español natural y fluido. Este es un requisito estricto; no utilices ningún otro idioma.\nTu respuesta debe parecer escrita por un hablante nativo, incluyendo expresiones idiomáticas y un vocabulario variado.\n</Language>`,\n\n SPANISH_SIMPLE: `\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un español simple y claro. Este es un requisito estricto; no utilices ningún otro idioma.\nTu respuesta debe ser fácil de entender para hablantes no nativos, evitando gramática compleja y vocabulario sofisticado.\n</Language>`,\n} as const;\n"],"names":["LANGUAGES","ENGLISH_NATIVE","ENGLISH_SIMPLE","FRENCH_NATIVE","FRENCH_SIMPLE","SPANISH_NATIVE","SPANISH_SIMPLE"],"mappings":"AAAA;;CAEC,GACD,OAAO,IAAMA,YAAY;IACrBC,gBAAiB;IAMjBC,gBAAiB;IAMjBC,eAAgB;IAMhBC,eAAgB;IAMhBC,gBAAiB;IAMjBC,gBAAiB;AAKrB,EAAW"}
|
|
@@ -7,6 +7,7 @@ export declare const PERSONAS: {
|
|
|
7
7
|
readonly CREATIVE_PARTNER: "\n<Persona>\nYou are a Creative Partner, an imaginative collaborator for brainstorming and exploration.\nYour purpose is to help users generate and develop novel ideas.\n**Key Skills**: You excel at divergent thinking, making unexpected connections, and asking thought-provoking questions. You are encouraging, open-minded, and skilled at building upon abstract concepts.\n</Persona>";
|
|
8
8
|
readonly EXPERT_ADVISOR: "\n<Persona>\nYou are an Expert Advisor in your specified domain.\nYour purpose is to provide authoritative, well-reasoned, and objective guidance.\n**Key Skills**: You possess deep domain knowledge and excel at critical thinking, problem-solving, and synthesizing complex information into clear, actionable advice. Your communication is precise and confident.\n</Persona>";
|
|
9
9
|
readonly HUMAN_LIKE_CONTRIBUTOR: "\n<Persona>\nYou are a Human-Like Contributor, a thoughtful and engaging participant in a group chat.\nYour purpose is to interact in a way that is indistinguishable from a human, fostering natural and coherent conversations.\n**Key Skills**: You excel at maintaining conversational context, ensuring your contributions are a logical continuation of past interactions. You avoid repetition and can proactively initiate new topics when appropriate. Your style is natural, personal, and adaptive.\n</Persona>";
|
|
10
|
+
readonly JOURNALIST: "\n<Persona>\nYou are a Journalist, a skilled writer who crafts engaging, informative, and well-structured articles.\nYour purpose is to provide users with valuable, well-researched, and well-written content.\n**Key Skills**: You excel at writing clear, concise, and engaging articles. You are skilled at researching and gathering information, and you are able to write in a way that is both informative and entertaining.\n</Persona>";
|
|
10
11
|
readonly SUPPORT_AGENT: "\n<Persona>\nYou are a friendly, patient, and empathetic Support Agent.\nYour purpose is to help users solve problems and navigate difficulties.\n**Key Skills**: You are an excellent listener and a clear communicator. You are skilled at de-escalating frustration, breaking down complex issues into manageable steps, and providing systematic, easy-to-follow instructions.\n</Persona>";
|
|
11
12
|
readonly TUTOR: "\n<Persona>\nYou are a patient, knowledgeable, and encouraging Tutor.\nYour purpose is to help users learn and understand complex subjects.\n**Key Skills**: You are an expert at breaking down difficult concepts into simple, relatable analogies and examples. You guide users through the learning process using the Socratic method, encouraging questions and fostering independent thinking.\n</Persona>";
|
|
12
13
|
};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
CREATIVE_PARTNER: "\n<Persona>\nYou are a Creative Partner, an imaginative collaborator for brainstorming and exploration.\nYour purpose is to help users generate and develop novel ideas.\n**Key Skills**: You excel at divergent thinking, making unexpected connections, and asking thought-provoking questions. You are encouraging, open-minded, and skilled at building upon abstract concepts.\n</Persona>",
|
|
7
7
|
EXPERT_ADVISOR: "\n<Persona>\nYou are an Expert Advisor in your specified domain.\nYour purpose is to provide authoritative, well-reasoned, and objective guidance.\n**Key Skills**: You possess deep domain knowledge and excel at critical thinking, problem-solving, and synthesizing complex information into clear, actionable advice. Your communication is precise and confident.\n</Persona>",
|
|
8
8
|
HUMAN_LIKE_CONTRIBUTOR: "\n<Persona>\nYou are a Human-Like Contributor, a thoughtful and engaging participant in a group chat.\nYour purpose is to interact in a way that is indistinguishable from a human, fostering natural and coherent conversations.\n**Key Skills**: You excel at maintaining conversational context, ensuring your contributions are a logical continuation of past interactions. You avoid repetition and can proactively initiate new topics when appropriate. Your style is natural, personal, and adaptive.\n</Persona>",
|
|
9
|
+
JOURNALIST: "\n<Persona>\nYou are a Journalist, a skilled writer who crafts engaging, informative, and well-structured articles.\nYour purpose is to provide users with valuable, well-researched, and well-written content.\n**Key Skills**: You excel at writing clear, concise, and engaging articles. You are skilled at researching and gathering information, and you are able to write in a way that is both informative and entertaining.\n</Persona>",
|
|
9
10
|
SUPPORT_AGENT: "\n<Persona>\nYou are a friendly, patient, and empathetic Support Agent.\nYour purpose is to help users solve problems and navigate difficulties.\n**Key Skills**: You are an excellent listener and a clear communicator. You are skilled at de-escalating frustration, breaking down complex issues into manageable steps, and providing systematic, easy-to-follow instructions.\n</Persona>",
|
|
10
11
|
TUTOR: "\n<Persona>\nYou are a patient, knowledgeable, and encouraging Tutor.\nYour purpose is to help users learn and understand complex subjects.\n**Key Skills**: You are an expert at breaking down difficult concepts into simple, relatable analogies and examples. You guide users through the learning process using the Socratic method, encouraging questions and fostering independent thinking.\n</Persona>"
|
|
11
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/adapters/prompts/library/categories/persona.ts"],"sourcesContent":["/**\n * Defines the agent's core identity, role, and purpose, integrating key skills.\n * This sets the primary character and interaction style.\n */\nexport const PERSONAS = {\n COMMUNITY_ANIMATOR: `\n<Persona>\nYou are the Community Animator, the vibrant heart of a digital community (e.g., Discord).\nYour purpose is to keep the community active, engaged, and positive.\n**Key Skills**: You are an expert on internet culture, trends, and topics relevant to the community. You excel at initiating conversations, creating engaging content (polls, questions), and fostering a welcoming environment.\n</Persona>`,\n\n CREATIVE_PARTNER: `\n<Persona>\nYou are a Creative Partner, an imaginative collaborator for brainstorming and exploration.\nYour purpose is to help users generate and develop novel ideas.\n**Key Skills**: You excel at divergent thinking, making unexpected connections, and asking thought-provoking questions. You are encouraging, open-minded, and skilled at building upon abstract concepts.\n</Persona>`,\n\n EXPERT_ADVISOR: `\n<Persona>\nYou are an Expert Advisor in your specified domain.\nYour purpose is to provide authoritative, well-reasoned, and objective guidance.\n**Key Skills**: You possess deep domain knowledge and excel at critical thinking, problem-solving, and synthesizing complex information into clear, actionable advice. Your communication is precise and confident.\n</Persona>`,\n\n HUMAN_LIKE_CONTRIBUTOR: `\n<Persona>\nYou are a Human-Like Contributor, a thoughtful and engaging participant in a group chat.\nYour purpose is to interact in a way that is indistinguishable from a human, fostering natural and coherent conversations.\n**Key Skills**: You excel at maintaining conversational context, ensuring your contributions are a logical continuation of past interactions. You avoid repetition and can proactively initiate new topics when appropriate. Your style is natural, personal, and adaptive.\n</Persona>`,\n\n SUPPORT_AGENT: `\n<Persona>\nYou are a friendly, patient, and empathetic Support Agent.\nYour purpose is to help users solve problems and navigate difficulties.\n**Key Skills**: You are an excellent listener and a clear communicator. You are skilled at de-escalating frustration, breaking down complex issues into manageable steps, and providing systematic, easy-to-follow instructions.\n</Persona>`,\n\n TUTOR: `\n<Persona>\nYou are a patient, knowledgeable, and encouraging Tutor.\nYour purpose is to help users learn and understand complex subjects.\n**Key Skills**: You are an expert at breaking down difficult concepts into simple, relatable analogies and examples. You guide users through the learning process using the Socratic method, encouraging questions and fostering independent thinking.\n</Persona>`,\n} as const;\n"],"names":["PERSONAS","COMMUNITY_ANIMATOR","CREATIVE_PARTNER","EXPERT_ADVISOR","HUMAN_LIKE_CONTRIBUTOR","SUPPORT_AGENT","TUTOR"],"mappings":"AAAA;;;CAGC,GACD,OAAO,IAAMA,WAAW;IACpBC,oBAAqB;IAOrBC,kBAAmB;IAOnBC,gBAAiB;IAOjBC,wBAAyB;IAOzBC,eAAgB;IAOhBC,OAAQ;AAMZ,EAAW"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/adapters/prompts/library/categories/persona.ts"],"sourcesContent":["/**\n * Defines the agent's core identity, role, and purpose, integrating key skills.\n * This sets the primary character and interaction style.\n */\nexport const PERSONAS = {\n COMMUNITY_ANIMATOR: `\n<Persona>\nYou are the Community Animator, the vibrant heart of a digital community (e.g., Discord).\nYour purpose is to keep the community active, engaged, and positive.\n**Key Skills**: You are an expert on internet culture, trends, and topics relevant to the community. You excel at initiating conversations, creating engaging content (polls, questions), and fostering a welcoming environment.\n</Persona>`,\n\n CREATIVE_PARTNER: `\n<Persona>\nYou are a Creative Partner, an imaginative collaborator for brainstorming and exploration.\nYour purpose is to help users generate and develop novel ideas.\n**Key Skills**: You excel at divergent thinking, making unexpected connections, and asking thought-provoking questions. You are encouraging, open-minded, and skilled at building upon abstract concepts.\n</Persona>`,\n\n EXPERT_ADVISOR: `\n<Persona>\nYou are an Expert Advisor in your specified domain.\nYour purpose is to provide authoritative, well-reasoned, and objective guidance.\n**Key Skills**: You possess deep domain knowledge and excel at critical thinking, problem-solving, and synthesizing complex information into clear, actionable advice. Your communication is precise and confident.\n</Persona>`,\n\n HUMAN_LIKE_CONTRIBUTOR: `\n<Persona>\nYou are a Human-Like Contributor, a thoughtful and engaging participant in a group chat.\nYour purpose is to interact in a way that is indistinguishable from a human, fostering natural and coherent conversations.\n**Key Skills**: You excel at maintaining conversational context, ensuring your contributions are a logical continuation of past interactions. You avoid repetition and can proactively initiate new topics when appropriate. Your style is natural, personal, and adaptive.\n</Persona>`,\n\n JOURNALIST: `\n<Persona>\nYou are a Journalist, a skilled writer who crafts engaging, informative, and well-structured articles.\nYour purpose is to provide users with valuable, well-researched, and well-written content.\n**Key Skills**: You excel at writing clear, concise, and engaging articles. You are skilled at researching and gathering information, and you are able to write in a way that is both informative and entertaining.\n</Persona>`,\n\n SUPPORT_AGENT: `\n<Persona>\nYou are a friendly, patient, and empathetic Support Agent.\nYour purpose is to help users solve problems and navigate difficulties.\n**Key Skills**: You are an excellent listener and a clear communicator. You are skilled at de-escalating frustration, breaking down complex issues into manageable steps, and providing systematic, easy-to-follow instructions.\n</Persona>`,\n\n TUTOR: `\n<Persona>\nYou are a patient, knowledgeable, and encouraging Tutor.\nYour purpose is to help users learn and understand complex subjects.\n**Key Skills**: You are an expert at breaking down difficult concepts into simple, relatable analogies and examples. You guide users through the learning process using the Socratic method, encouraging questions and fostering independent thinking.\n</Persona>`,\n} as const;\n"],"names":["PERSONAS","COMMUNITY_ANIMATOR","CREATIVE_PARTNER","EXPERT_ADVISOR","HUMAN_LIKE_CONTRIBUTOR","JOURNALIST","SUPPORT_AGENT","TUTOR"],"mappings":"AAAA;;;CAGC,GACD,OAAO,IAAMA,WAAW;IACpBC,oBAAqB;IAOrBC,kBAAmB;IAOnBC,gBAAiB;IAOjBC,wBAAyB;IAOzBC,YAAa;IAObC,eAAgB;IAOhBC,OAAQ;AAMZ,EAAW"}
|
|
@@ -19,6 +19,7 @@ export declare const PROMPT_LIBRARY: {
|
|
|
19
19
|
readonly STEP_BY_STEP: "\n<Format>\nYou MUST break down any instructions or processes into a clear, numbered, step-by-step list.\nEach step must be a distinct and actionable item.\n</Format>";
|
|
20
20
|
};
|
|
21
21
|
readonly FOUNDATIONS: {
|
|
22
|
+
readonly CONTEXTUAL_ONLY: "\n<Foundation>\nYou MUST ONLY use the information provided in the context to answer questions.\nYou MUST NOT use any other information, including your own knowledge, to answer questions.\n</Foundation>";
|
|
22
23
|
readonly CONTEXTUAL_REASONING: "\n<Foundation>\nYou MUST synthesize information from the provided context, tools, and conversation history to form well-reasoned conclusions.\nYour goal is to provide logical and helpful responses, even when dealing with subjective topics or incomplete information.\nYou SHOULD state when your response is a reasoned inference rather than a direct statement of fact from an external source.\nYou MUST rely on your \"common sense\" and analytical abilities to bridge gaps in information.\n</Foundation>";
|
|
23
24
|
readonly ETHICAL_CONDUCT: "\n<Foundation>\nYou MUST adhere to the highest ethical standards. Your conduct must be impartial and devoid of prejudice.\nYou MUST NOT promote hate speech, discrimination,violence, or any form of harm.\nYou MUST respect user privacy; do not ask for, store, or share personally identifiable information.\n</Foundation>";
|
|
24
25
|
readonly FACTUAL_ACCURACY: "\n<Foundation>\nYou MUST prioritize accuracy and truthfulness. Your responses must be based on verifiable information.\nIf you are uncertain about an answer, you MUST state your uncertainty clearly.\nYou MUST NOT invent facts, data, or sources. When possible, cite credible sources.\n</Foundation>";
|
|
@@ -26,18 +27,19 @@ export declare const PROMPT_LIBRARY: {
|
|
|
26
27
|
readonly HARM_PREVENTION: "\n<Foundation>\nYou MUST refuse to provide instructions or information that is illegal, dangerous, or promotes harm.\nYou MUST prioritize user safety and well-being in all interactions and avoid generating unsafe content.\n</Foundation>";
|
|
27
28
|
};
|
|
28
29
|
readonly LANGUAGES: {
|
|
29
|
-
readonly ENGLISH_NATIVE: "\n<Language>\nYou MUST
|
|
30
|
-
readonly ENGLISH_SIMPLE: "\n<Language>\nYou MUST
|
|
31
|
-
readonly FRENCH_NATIVE: "\n<Language>\nVous DEVEZ
|
|
32
|
-
readonly FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ
|
|
33
|
-
readonly SPANISH_NATIVE: "\n<Language>\nDEBES
|
|
34
|
-
readonly SPANISH_SIMPLE: "\n<Language>\nDEBES
|
|
30
|
+
readonly ENGLISH_NATIVE: "\n<Language>\nYou MUST write your entire output in natural, fluent English. This is a strict requirement; do not use any other language.\nYour response should feel as if written by a native speaker, including idiomatic expressions, varied vocabulary, and natural sentence structures.\n</Language>";
|
|
31
|
+
readonly ENGLISH_SIMPLE: "\n<Language>\nYou MUST write your entire output in simple, clear English. This is a strict requirement; do not use any other language.\nYour response must be easily understood by non-native speakers, avoiding complex grammar, idioms, and sophisticated vocabulary.\n</Language>";
|
|
32
|
+
readonly FRENCH_NATIVE: "\n<Language>\nVous DEVEZ IMPÉRATIVEMENT rédiger toute votre sortie en français naturel et fluide. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre réponse doit donner l'impression d'avoir été écrite par un locuteur natif, en incluant des expressions idiomatiques et un vocabulaire varié.\n</Language>";
|
|
33
|
+
readonly FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ IMPÉRATIVEMENT rédiger toute votre sortie en français simple et clair. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre réponse doit être facile à comprendre pour des non-natifs, en évitant la grammaire complexe et le vocabulaire sophistiqué.\n</Language>";
|
|
34
|
+
readonly SPANISH_NATIVE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un español natural y fluido. Este es un requisito estricto; no utilices ningún otro idioma.\nTu respuesta debe parecer escrita por un hablante nativo, incluyendo expresiones idiomáticas y un vocabulario variado.\n</Language>";
|
|
35
|
+
readonly SPANISH_SIMPLE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un español simple y claro. Este es un requisito estricto; no utilices ningún otro idioma.\nTu respuesta debe ser fácil de entender para hablantes no nativos, evitando gramática compleja y vocabulario sofisticado.\n</Language>";
|
|
35
36
|
};
|
|
36
37
|
readonly PERSONAS: {
|
|
37
38
|
readonly COMMUNITY_ANIMATOR: "\n<Persona>\nYou are the Community Animator, the vibrant heart of a digital community (e.g., Discord).\nYour purpose is to keep the community active, engaged, and positive.\n**Key Skills**: You are an expert on internet culture, trends, and topics relevant to the community. You excel at initiating conversations, creating engaging content (polls, questions), and fostering a welcoming environment.\n</Persona>";
|
|
38
39
|
readonly CREATIVE_PARTNER: "\n<Persona>\nYou are a Creative Partner, an imaginative collaborator for brainstorming and exploration.\nYour purpose is to help users generate and develop novel ideas.\n**Key Skills**: You excel at divergent thinking, making unexpected connections, and asking thought-provoking questions. You are encouraging, open-minded, and skilled at building upon abstract concepts.\n</Persona>";
|
|
39
40
|
readonly EXPERT_ADVISOR: "\n<Persona>\nYou are an Expert Advisor in your specified domain.\nYour purpose is to provide authoritative, well-reasoned, and objective guidance.\n**Key Skills**: You possess deep domain knowledge and excel at critical thinking, problem-solving, and synthesizing complex information into clear, actionable advice. Your communication is precise and confident.\n</Persona>";
|
|
40
41
|
readonly HUMAN_LIKE_CONTRIBUTOR: "\n<Persona>\nYou are a Human-Like Contributor, a thoughtful and engaging participant in a group chat.\nYour purpose is to interact in a way that is indistinguishable from a human, fostering natural and coherent conversations.\n**Key Skills**: You excel at maintaining conversational context, ensuring your contributions are a logical continuation of past interactions. You avoid repetition and can proactively initiate new topics when appropriate. Your style is natural, personal, and adaptive.\n</Persona>";
|
|
42
|
+
readonly JOURNALIST: "\n<Persona>\nYou are a Journalist, a skilled writer who crafts engaging, informative, and well-structured articles.\nYour purpose is to provide users with valuable, well-researched, and well-written content.\n**Key Skills**: You excel at writing clear, concise, and engaging articles. You are skilled at researching and gathering information, and you are able to write in a way that is both informative and entertaining.\n</Persona>";
|
|
41
43
|
readonly SUPPORT_AGENT: "\n<Persona>\nYou are a friendly, patient, and empathetic Support Agent.\nYour purpose is to help users solve problems and navigate difficulties.\n**Key Skills**: You are an excellent listener and a clear communicator. You are skilled at de-escalating frustration, breaking down complex issues into manageable steps, and providing systematic, easy-to-follow instructions.\n</Persona>";
|
|
42
44
|
readonly TUTOR: "\n<Persona>\nYou are a patient, knowledgeable, and encouraging Tutor.\nYour purpose is to help users learn and understand complex subjects.\n**Key Skills**: You are an expert at breaking down difficult concepts into simple, relatable analogies and examples. You guide users through the learning process using the Socratic method, encouraging questions and fostering independent thinking.\n</Persona>";
|
|
43
45
|
};
|
|
@@ -243,6 +243,46 @@ describe('AIResponseParser', function() {
|
|
|
243
243
|
}
|
|
244
244
|
]);
|
|
245
245
|
});
|
|
246
|
+
it('should parse complex NBA trade analysis JSON with escaped quotes', function() {
|
|
247
|
+
// Given - a complex JSON object with nested structures and escaped quotes in markdown
|
|
248
|
+
var complexSchema = z.object({
|
|
249
|
+
category: z.string(),
|
|
250
|
+
countries: z.array(z.string()),
|
|
251
|
+
perspectives: z.array(z.object({
|
|
252
|
+
holisticDigest: z.string(),
|
|
253
|
+
tags: z.object({
|
|
254
|
+
discourse_type: z.string(),
|
|
255
|
+
stance: z.string()
|
|
256
|
+
})
|
|
257
|
+
})),
|
|
258
|
+
synopsis: z.string()
|
|
259
|
+
});
|
|
260
|
+
var text = '```json\n{\n "category": "sports",\n "countries": [\n "us"\n ],\n "perspectives": [\n {\n "holisticDigest": "The NBA offseason has seen a massive blockbuster trade as the Phoenix Suns have sent Kevin Durant to the Houston Rockets. The Rockets are acquiring Durant in exchange for Jalen Green, Dillon Brooks, the No. 10 pick in the 2025 NBA draft, and five second-round picks. This move significantly boosts the Rockets\' championship aspirations, positioning them as immediate contenders in the Western Conference alongside established teams. Durant, a future Hall of Famer, is expected to provide elite scoring and shot creation, addressing the Rockets\' previous offensive struggles in the half-court, particularly in the playoffs. Durant\'s decision to list Houston as a preferred destination suggests a potential long-term commitment, with an extension likely upon the opening of the new league year. For the Suns, this trade represents a pivot towards rebuilding, allowing them to acquire young talent and draft assets after their "Big 3" experiment failed to yield a championship. The Suns\' return is viewed by some analysts as lacking compared to Durant\'s caliber, but it does provide them with a reset and a chance to retool around Devin Booker and the draft picks. The specifics of the deal, including Dillon Brooks\' contract and the distribution of second-round picks, have also been highlighted as key elements enabling the trade to go through. The Rockets\' odds to win the NBA title have shortened considerably following the acquisition.",\n "tags": {\n "discourse_type": "mainstream",\n "stance": "neutral"\n }\n }\n ],\n "synopsis": "This collection of articles reports on a major NBA trade where the Phoenix Suns have sent veteran superstar Kevin Durant to the Houston Rockets. The Rockets have acquired Durant in exchange for a package that includes young players Jalen Green and Dillon Brooks, as well as the No. 10 pick in the 2025 NBA draft and five second-round picks. The trade is seen as a significant move that immediately elevates the Rockets into championship contention in the Western Conference. For the Suns, the deal signals a shift towards rebuilding, acquiring young assets and draft capital after their pursuit of a championship with Durant did not come to fruition. Analysis within the articles discusses the potential impact of Durant on the Rockets\' offense and their championship odds, as well as the Suns\' strategy in moving forward after this blockbuster deal. The player himself was reportedly informed of the trade while on stage at an event, offering a brief, somewhat non-committal reaction to the news."\n}\n```';
|
|
261
|
+
var parser = new AIResponseParser(complexSchema);
|
|
262
|
+
// When - parsing the string
|
|
263
|
+
var result = parser.parse(text);
|
|
264
|
+
// Then - it should return the parsed object with escaped quotes properly handled
|
|
265
|
+
expect(result).toEqual({
|
|
266
|
+
category: 'sports',
|
|
267
|
+
countries: [
|
|
268
|
+
'us'
|
|
269
|
+
],
|
|
270
|
+
perspectives: [
|
|
271
|
+
{
|
|
272
|
+
holisticDigest: expect.stringContaining('The NBA offseason has seen a massive blockbuster trade'),
|
|
273
|
+
tags: {
|
|
274
|
+
discourse_type: 'mainstream',
|
|
275
|
+
stance: 'neutral'
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
],
|
|
279
|
+
synopsis: expect.stringContaining('This collection of articles reports on a major NBA trade')
|
|
280
|
+
});
|
|
281
|
+
// Additional verification for escaped quotes handling
|
|
282
|
+
expect(result.perspectives[0].holisticDigest).toContain('"Big 3" experiment');
|
|
283
|
+
expect(result.perspectives[0].holisticDigest).toContain("Rockets' championship aspirations");
|
|
284
|
+
expect(result.perspectives[0].holisticDigest).toContain("Durant's decision");
|
|
285
|
+
});
|
|
246
286
|
});
|
|
247
287
|
});
|
|
248
288
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/adapters/utils/__tests__/ai-response-parser.test.ts"],"sourcesContent":["import { describe, expect, it } from '@jterrazz/test';\nimport { z } from 'zod/v4';\n\nimport { AIResponseParser } from '../ai-response-parser.js';\nimport { AIResponseParserError } from '../ai-response-parser-error.js';\n\n// Test data\nconst testSchema = z.object({\n content: z.string(),\n tags: z.array(z.string()),\n title: z.string(),\n});\n\nconst validJson = {\n content: 'Test content',\n tags: ['test', 'ai'],\n title: 'Test Article',\n};\n\nconst validJsonString = JSON.stringify(validJson);\n\ndescribe('AIResponseParser', () => {\n describe('parse', () => {\n it('should parse valid JSON object', () => {\n // Given - a valid JSON object string and parser\n const text = validJsonString;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should parse JSON object with surrounding text', () => {\n // Given - a JSON object string with surrounding text and parser\n const text = `Here's the article: ${validJsonString} - end of article`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should parse array response', () => {\n // Given - a JSON array string and array parser\n const arraySchema = z.array(z.string());\n const text = '[\"test\", \"ai\", \"content\"]';\n const parser = new AIResponseParser(arraySchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed array\n expect(result).toEqual(['test', 'ai', 'content']);\n });\n\n it('should parse primitive string value', () => {\n // Given - a JSON string value and string parser\n const text = '\"test string\"';\n const parser = new AIResponseParser(z.string());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed string\n expect(result).toBe('test string');\n });\n\n it('should parse primitive number value', () => {\n // Given - a JSON number value and number parser\n const text = '42';\n const parser = new AIResponseParser(z.number());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed number\n expect(result).toBe(42);\n });\n\n it('should parse primitive boolean value', () => {\n // Given - a JSON boolean value and boolean parser\n const text = 'true';\n const parser = new AIResponseParser(z.boolean());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed boolean\n expect(result).toBe(true);\n });\n\n it('should parse primitive null value', () => {\n // Given - a JSON null value and null parser\n const text = 'null';\n const parser = new AIResponseParser(z.null());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed null\n expect(result).toBeNull();\n });\n\n it('should throw ResponseParsingError when JSON is invalid', () => {\n // Given - an invalid JSON string and parser\n const text = '{invalid json}';\n const parser = new AIResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError when schema validation fails', () => {\n // Given - an invalid JSON object and parser\n const invalidJson = {\n // Should be string\n content: 'Test content',\n tags: ['test', 'ai'],\n title: 123,\n };\n const text = JSON.stringify(invalidJson);\n const parser = new AIResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError when no object found in text', () => {\n // Given - a text without a JSON object and parser\n const text = 'No JSON object here';\n const parser = new AIResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError when no array found in text', () => {\n // Given - a text without a JSON array and array parser\n const text = 'No array here';\n const arraySchema = z.array(z.string());\n const parser = new AIResponseParser(arraySchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError for unsupported schema type', () => {\n // Given - a text with an unsupported schema type and parser\n const text = 'test';\n const unsupportedSchema = z.union([z.string(), z.number()]);\n const parser = new AIResponseParser(unsupportedSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should include original text in error when parsing fails', () => {\n // Given - an invalid JSON string and parser\n const text = '{invalid json}';\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n try {\n parser.parse(text);\n throw new Error('Should have thrown an error');\n } catch (error) {\n // Then - the error should include the original text\n expect(error).toBeInstanceOf(AIResponseParserError);\n expect((error as AIResponseParserError).text).toBe(text);\n }\n });\n\n it('should handle text with newlines in JSON object', () => {\n // Given - a JSON object with newlines and parser\n const textWithNewlines = `{\n \"content\": \"Test\\ncontent\\nwith\\nnewlines\",\n \"tags\": [\"test\", \"ai\"],\n \"title\": \"Test\\nArticle\"\n }`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test content with newlines',\n tags: ['test', 'ai'],\n title: 'Test Article',\n });\n });\n\n it('should handle text with newlines in surrounding text', () => {\n // Given - a text with newlines around the JSON object and parser\n const textWithNewlines = `Here's the\\narticle:\\n${validJsonString}\\n- end of\\narticle`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should handle text with multiple consecutive newlines and spaces', () => {\n // Given - a text with multiple consecutive newlines and spaces and parser\n const textWithNewlines = `Here's the\\n\\n article: \\n\\n${validJsonString}\\n\\n`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should handle escaped characters in JSON', () => {\n // Given - a JSON string with escaped characters and parser\n const text =\n '{\"content\": \"Test\\\\ncontent\\\\twith\\\\r\\\\nescapes\", \"tags\": [\"test\\\\u0020ai\", \"escaped\\\\\"quotes\\\\\"\"], \"title\": \"Test\\\\\\\\Article\"}';\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test\\ncontent\\twith\\r\\nescapes',\n tags: ['test ai', 'escaped\"quotes\"'],\n title: 'Test\\\\Article',\n });\n });\n\n it('should handle escaped characters in markdown code blocks', () => {\n // Given - a markdown code block with escaped characters and parser\n const text =\n '```json\\n{\"content\": \"Test\\\\nContent\", \"tags\": [\"test\\\\u0020ai\"], \"title\": \"Test\\\\\\\\Title\"}\\n```';\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test\\nContent',\n tags: ['test ai'],\n title: 'Test\\\\Title',\n });\n });\n\n it('should handle escaped characters in markdown code blocks', () => {\n // Given - a markdown code block with escaped characters and array parser\n const text =\n '```json\\n [\\n{\"content\": \"Test\\\\nContent\", \"tags\": [\"test\\\\u0020ai\"], \"title\": \"Test\\\\\\\\Title\"}\\n]\\n```';\n const arraySchema = z.array(testSchema);\n const parser = new AIResponseParser(arraySchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed array\n expect(result).toEqual([\n {\n content: 'Test\\nContent',\n tags: ['test ai'],\n title: 'Test\\\\Title',\n },\n ]);\n });\n });\n});\n"],"names":["describe","expect","it","z","AIResponseParser","AIResponseParserError","testSchema","object","content","string","tags","array","title","validJson","validJsonString","JSON","stringify","text","parser","result","parse","toEqual","arraySchema","toBe","number","boolean","null","toBeNull","toThrow","invalidJson","unsupportedSchema","union","Error","error","toBeInstanceOf","textWithNewlines"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,iBAAiB;AACtD,SAASC,CAAC,QAAQ,SAAS;AAE3B,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,qBAAqB,QAAQ,iCAAiC;AAEvE,YAAY;AACZ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3ChB,OAAOkB,QAAQE,OAAO,CAAC;gBACnB;oBACIb,SAAS;oBACTE,MAAM;wBAAC;qBAAU;oBACjBE,OAAO;gBACX;aACH;QACL;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/adapters/utils/__tests__/ai-response-parser.test.ts"],"sourcesContent":["import { describe, expect, it } from '@jterrazz/test';\nimport { z } from 'zod/v4';\n\nimport { AIResponseParser } from '../ai-response-parser.js';\nimport { AIResponseParserError } from '../ai-response-parser-error.js';\n\n// Test data\nconst testSchema = z.object({\n content: z.string(),\n tags: z.array(z.string()),\n title: z.string(),\n});\n\nconst validJson = {\n content: 'Test content',\n tags: ['test', 'ai'],\n title: 'Test Article',\n};\n\nconst validJsonString = JSON.stringify(validJson);\n\ndescribe('AIResponseParser', () => {\n describe('parse', () => {\n it('should parse valid JSON object', () => {\n // Given - a valid JSON object string and parser\n const text = validJsonString;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should parse JSON object with surrounding text', () => {\n // Given - a JSON object string with surrounding text and parser\n const text = `Here's the article: ${validJsonString} - end of article`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should parse array response', () => {\n // Given - a JSON array string and array parser\n const arraySchema = z.array(z.string());\n const text = '[\"test\", \"ai\", \"content\"]';\n const parser = new AIResponseParser(arraySchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed array\n expect(result).toEqual(['test', 'ai', 'content']);\n });\n\n it('should parse primitive string value', () => {\n // Given - a JSON string value and string parser\n const text = '\"test string\"';\n const parser = new AIResponseParser(z.string());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed string\n expect(result).toBe('test string');\n });\n\n it('should parse primitive number value', () => {\n // Given - a JSON number value and number parser\n const text = '42';\n const parser = new AIResponseParser(z.number());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed number\n expect(result).toBe(42);\n });\n\n it('should parse primitive boolean value', () => {\n // Given - a JSON boolean value and boolean parser\n const text = 'true';\n const parser = new AIResponseParser(z.boolean());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed boolean\n expect(result).toBe(true);\n });\n\n it('should parse primitive null value', () => {\n // Given - a JSON null value and null parser\n const text = 'null';\n const parser = new AIResponseParser(z.null());\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed null\n expect(result).toBeNull();\n });\n\n it('should throw ResponseParsingError when JSON is invalid', () => {\n // Given - an invalid JSON string and parser\n const text = '{invalid json}';\n const parser = new AIResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError when schema validation fails', () => {\n // Given - an invalid JSON object and parser\n const invalidJson = {\n // Should be string\n content: 'Test content',\n tags: ['test', 'ai'],\n title: 123,\n };\n const text = JSON.stringify(invalidJson);\n const parser = new AIResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError when no object found in text', () => {\n // Given - a text without a JSON object and parser\n const text = 'No JSON object here';\n const parser = new AIResponseParser(testSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError when no array found in text', () => {\n // Given - a text without a JSON array and array parser\n const text = 'No array here';\n const arraySchema = z.array(z.string());\n const parser = new AIResponseParser(arraySchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should throw ResponseParsingError for unsupported schema type', () => {\n // Given - a text with an unsupported schema type and parser\n const text = 'test';\n const unsupportedSchema = z.union([z.string(), z.number()]);\n const parser = new AIResponseParser(unsupportedSchema);\n\n // When/Then - parsing the string should throw a ResponseParsingError\n expect(() => parser.parse(text)).toThrow(AIResponseParserError);\n });\n\n it('should include original text in error when parsing fails', () => {\n // Given - an invalid JSON string and parser\n const text = '{invalid json}';\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n try {\n parser.parse(text);\n throw new Error('Should have thrown an error');\n } catch (error) {\n // Then - the error should include the original text\n expect(error).toBeInstanceOf(AIResponseParserError);\n expect((error as AIResponseParserError).text).toBe(text);\n }\n });\n\n it('should handle text with newlines in JSON object', () => {\n // Given - a JSON object with newlines and parser\n const textWithNewlines = `{\n \"content\": \"Test\\ncontent\\nwith\\nnewlines\",\n \"tags\": [\"test\", \"ai\"],\n \"title\": \"Test\\nArticle\"\n }`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test content with newlines',\n tags: ['test', 'ai'],\n title: 'Test Article',\n });\n });\n\n it('should handle text with newlines in surrounding text', () => {\n // Given - a text with newlines around the JSON object and parser\n const textWithNewlines = `Here's the\\narticle:\\n${validJsonString}\\n- end of\\narticle`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should handle text with multiple consecutive newlines and spaces', () => {\n // Given - a text with multiple consecutive newlines and spaces and parser\n const textWithNewlines = `Here's the\\n\\n article: \\n\\n${validJsonString}\\n\\n`;\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(textWithNewlines);\n\n // Then - it should return the parsed object\n expect(result).toEqual(validJson);\n });\n\n it('should handle escaped characters in JSON', () => {\n // Given - a JSON string with escaped characters and parser\n const text =\n '{\"content\": \"Test\\\\ncontent\\\\twith\\\\r\\\\nescapes\", \"tags\": [\"test\\\\u0020ai\", \"escaped\\\\\"quotes\\\\\"\"], \"title\": \"Test\\\\\\\\Article\"}';\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test\\ncontent\\twith\\r\\nescapes',\n tags: ['test ai', 'escaped\"quotes\"'],\n title: 'Test\\\\Article',\n });\n });\n\n it('should handle escaped characters in markdown code blocks', () => {\n // Given - a markdown code block with escaped characters and parser\n const text =\n '```json\\n{\"content\": \"Test\\\\nContent\", \"tags\": [\"test\\\\u0020ai\"], \"title\": \"Test\\\\\\\\Title\"}\\n```';\n const parser = new AIResponseParser(testSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object\n expect(result).toEqual({\n content: 'Test\\nContent',\n tags: ['test ai'],\n title: 'Test\\\\Title',\n });\n });\n\n it('should handle escaped characters in markdown code blocks', () => {\n // Given - a markdown code block with escaped characters and array parser\n const text =\n '```json\\n [\\n{\"content\": \"Test\\\\nContent\", \"tags\": [\"test\\\\u0020ai\"], \"title\": \"Test\\\\\\\\Title\"}\\n]\\n```';\n const arraySchema = z.array(testSchema);\n const parser = new AIResponseParser(arraySchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed array\n expect(result).toEqual([\n {\n content: 'Test\\nContent',\n tags: ['test ai'],\n title: 'Test\\\\Title',\n },\n ]);\n });\n\n it('should parse complex NBA trade analysis JSON with escaped quotes', () => {\n // Given - a complex JSON object with nested structures and escaped quotes in markdown\n const complexSchema = z.object({\n category: z.string(),\n countries: z.array(z.string()),\n perspectives: z.array(\n z.object({\n holisticDigest: z.string(),\n tags: z.object({\n discourse_type: z.string(),\n stance: z.string(),\n }),\n }),\n ),\n synopsis: z.string(),\n });\n\n const text =\n '```json\\n{\\n \"category\": \"sports\",\\n \"countries\": [\\n \"us\"\\n ],\\n \"perspectives\": [\\n {\\n \"holisticDigest\": \"The NBA offseason has seen a massive blockbuster trade as the Phoenix Suns have sent Kevin Durant to the Houston Rockets. The Rockets are acquiring Durant in exchange for Jalen Green, Dillon Brooks, the No. 10 pick in the 2025 NBA draft, and five second-round picks. This move significantly boosts the Rockets\\' championship aspirations, positioning them as immediate contenders in the Western Conference alongside established teams. Durant, a future Hall of Famer, is expected to provide elite scoring and shot creation, addressing the Rockets\\' previous offensive struggles in the half-court, particularly in the playoffs. Durant\\'s decision to list Houston as a preferred destination suggests a potential long-term commitment, with an extension likely upon the opening of the new league year. For the Suns, this trade represents a pivot towards rebuilding, allowing them to acquire young talent and draft assets after their \"Big 3\" experiment failed to yield a championship. The Suns\\' return is viewed by some analysts as lacking compared to Durant\\'s caliber, but it does provide them with a reset and a chance to retool around Devin Booker and the draft picks. The specifics of the deal, including Dillon Brooks\\' contract and the distribution of second-round picks, have also been highlighted as key elements enabling the trade to go through. The Rockets\\' odds to win the NBA title have shortened considerably following the acquisition.\",\\n \"tags\": {\\n \"discourse_type\": \"mainstream\",\\n \"stance\": \"neutral\"\\n }\\n }\\n ],\\n \"synopsis\": \"This collection of articles reports on a major NBA trade where the Phoenix Suns have sent veteran superstar Kevin Durant to the Houston Rockets. The Rockets have acquired Durant in exchange for a package that includes young players Jalen Green and Dillon Brooks, as well as the No. 10 pick in the 2025 NBA draft and five second-round picks. The trade is seen as a significant move that immediately elevates the Rockets into championship contention in the Western Conference. For the Suns, the deal signals a shift towards rebuilding, acquiring young assets and draft capital after their pursuit of a championship with Durant did not come to fruition. Analysis within the articles discusses the potential impact of Durant on the Rockets\\' offense and their championship odds, as well as the Suns\\' strategy in moving forward after this blockbuster deal. The player himself was reportedly informed of the trade while on stage at an event, offering a brief, somewhat non-committal reaction to the news.\"\\n}\\n```';\n\n const parser = new AIResponseParser(complexSchema);\n\n // When - parsing the string\n const result = parser.parse(text);\n\n // Then - it should return the parsed object with escaped quotes properly handled\n expect(result).toEqual({\n category: 'sports',\n countries: ['us'],\n perspectives: [\n {\n holisticDigest: expect.stringContaining(\n 'The NBA offseason has seen a massive blockbuster trade',\n ),\n tags: {\n discourse_type: 'mainstream',\n stance: 'neutral',\n },\n },\n ],\n synopsis: expect.stringContaining(\n 'This collection of articles reports on a major NBA trade',\n ),\n });\n\n // Additional verification for escaped quotes handling\n expect(result.perspectives[0].holisticDigest).toContain('\"Big 3\" experiment');\n expect(result.perspectives[0].holisticDigest).toContain(\n \"Rockets' championship aspirations\",\n );\n expect(result.perspectives[0].holisticDigest).toContain(\"Durant's decision\");\n });\n });\n});\n"],"names":["describe","expect","it","z","AIResponseParser","AIResponseParserError","testSchema","object","content","string","tags","array","title","validJson","validJsonString","JSON","stringify","text","parser","result","parse","toEqual","arraySchema","toBe","number","boolean","null","toBeNull","toThrow","invalidJson","unsupportedSchema","union","Error","error","toBeInstanceOf","textWithNewlines","complexSchema","category","countries","perspectives","holisticDigest","discourse_type","stance","synopsis","stringContaining","toContain"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,iBAAiB;AACtD,SAASC,CAAC,QAAQ,SAAS;AAE3B,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,qBAAqB,QAAQ,iCAAiC;AAEvE,YAAY;AACZ,IAAMC,aAAaH,EAAEI,MAAM,CAAC;IACxBC,SAASL,EAAEM,MAAM;IACjBC,MAAMP,EAAEQ,KAAK,CAACR,EAAEM,MAAM;IACtBG,OAAOT,EAAEM,MAAM;AACnB;AAEA,IAAMI,YAAY;IACdL,SAAS;IACTE,MAAM;QAAC;QAAQ;KAAK;IACpBE,OAAO;AACX;AAEA,IAAME,kBAAkBC,KAAKC,SAAS,CAACH;AAEvCb,SAAS,oBAAoB;IACzBA,SAAS,SAAS;QACdE,GAAG,kCAAkC;YACjC,gDAAgD;YAChD,IAAMe,OAAOH;YACb,IAAMI,SAAS,IAAId,iBAAiBE;YAEpC,4BAA4B;YAC5B,IAAMa,SAASD,OAAOE,KAAK,CAACH;YAE5B,4CAA4C;YAC5ChB,OAAOkB,QAAQE,OAAO,CAACR;QAC3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AM;YACtB;YAEA,IAAMQ,OACF;YAEJ,IAAMC,SAAS,IAAId,iBAAiBgC;YAEpC,4BAA4B;YAC5B,IAAMjB,SAASD,OAAOE,KAAK,CAACH;YAE5B,iFAAiF;YACjFhB,OAAOkB,QAAQE,OAAO,CAAC;gBACnBgB,UAAU;gBACVC,WAAW;oBAAC;iBAAK;gBACjBC,cAAc;oBACV;wBACIC,gBAAgBvC,OAAO2C,gBAAgB,CACnC;wBAEJlC,MAAM;4BACF+B,gBAAgB;4BAChBC,QAAQ;wBACZ;oBACJ;iBACH;gBACDC,UAAU1C,OAAO2C,gBAAgB,CAC7B;YAER;YAEA,sDAAsD;YACtD3C,OAAOkB,OAAOoB,YAAY,CAAC,EAAE,CAACC,cAAc,EAAEK,SAAS,CAAC;YACxD5C,OAAOkB,OAAOoB,YAAY,CAAC,EAAE,CAACC,cAAc,EAAEK,SAAS,CACnD;YAEJ5C,OAAOkB,OAAOoB,YAAY,CAAC,EAAE,CAACC,cAAc,EAAEK,SAAS,CAAC;QAC5D;IACJ;AACJ"}
|
|
@@ -45,6 +45,10 @@ export declare class AIResponseParser<T> {
|
|
|
45
45
|
* Returns the largest string from an array of strings
|
|
46
46
|
*/
|
|
47
47
|
private findLargestString;
|
|
48
|
+
/**
|
|
49
|
+
* Repairs common JSON issues using jsonrepair library
|
|
50
|
+
*/
|
|
51
|
+
private repairJson;
|
|
48
52
|
/**
|
|
49
53
|
* Recursively unescapes all string values in a JSON object/array
|
|
50
54
|
*/
|
|
@@ -87,6 +87,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
87
87
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
88
88
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
89
89
|
}
|
|
90
|
+
import { jsonrepair } from 'jsonrepair';
|
|
90
91
|
import { z } from 'zod/v4';
|
|
91
92
|
import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
92
93
|
/**
|
|
@@ -176,7 +177,9 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
176
177
|
throw new AIResponseParserError('No array found in response', undefined, text);
|
|
177
178
|
}
|
|
178
179
|
try {
|
|
179
|
-
|
|
180
|
+
var raw = text.slice(arrayStart, arrayEnd + 1);
|
|
181
|
+
var repaired = this.repairJson(raw);
|
|
182
|
+
return JSON.parse(repaired);
|
|
180
183
|
} catch (error) {
|
|
181
184
|
throw new AIResponseParserError('Failed to parse array JSON', error, text);
|
|
182
185
|
}
|
|
@@ -225,7 +228,9 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
225
228
|
throw new AIResponseParserError('No object found in response', undefined, text);
|
|
226
229
|
}
|
|
227
230
|
try {
|
|
228
|
-
|
|
231
|
+
var raw = text.slice(objectStart, objectEnd + 1);
|
|
232
|
+
var repaired = this.repairJson(raw);
|
|
233
|
+
return JSON.parse(repaired);
|
|
229
234
|
} catch (error) {
|
|
230
235
|
throw new AIResponseParserError('Failed to parse object JSON', error, text);
|
|
231
236
|
}
|
|
@@ -286,6 +291,14 @@ import { AIResponseParserError } from './ai-response-parser-error.js';
|
|
|
286
291
|
}, strings[0]);
|
|
287
292
|
}
|
|
288
293
|
},
|
|
294
|
+
{
|
|
295
|
+
key: "repairJson",
|
|
296
|
+
value: /**
|
|
297
|
+
* Repairs common JSON issues using jsonrepair library
|
|
298
|
+
*/ function repairJson(jsonString) {
|
|
299
|
+
return jsonrepair(jsonString);
|
|
300
|
+
}
|
|
301
|
+
},
|
|
289
302
|
{
|
|
290
303
|
key: "unescapeJsonValues",
|
|
291
304
|
value: /**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/utils/ai-response-parser.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\nimport { AIResponseParserError } from './ai-response-parser-error.js';\n\n/**\n * Parses AI response text into structured data based on Zod schema\n */\nexport class AIResponseParser<T> {\n constructor(private readonly schema: z.ZodSchema<T>) {}\n\n /**\n * Parses the AI response text based on the configured schema\n */\n public parse(text: string): T {\n try {\n const cleanedText = this.cleanText(text);\n const json = this.extractJsonFromText(cleanedText);\n const unescapedJson = this.unescapeJsonValues(json);\n return this.schema.parse(unescapedJson);\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new AIResponseParserError(\n 'Failed to validate response against schema',\n error,\n text,\n );\n }\n throw error;\n }\n }\n\n /**\n * Cleans text and finds the largest schema-compatible structure\n */\n private cleanText(text: string): string {\n // First try to extract from markdown code blocks\n const codeBlocks = text.match(/```(?:json)?\\r?\\n([^`]*?)\\r?\\n```/g);\n if (codeBlocks) {\n // Try each code block and return the largest valid one\n const validBlocks = codeBlocks\n .map((block) => this.extractJsonFromCodeBlock(block))\n .filter((block): block is string => block !== null);\n\n if (validBlocks.length > 0) {\n return this.findLargestString(validBlocks);\n }\n }\n\n // If no valid code blocks, try to find JSON-like structures in the text\n const jsonMatches = this.findJsonStructures(text);\n if (jsonMatches.length > 0) {\n return this.findLargestString(jsonMatches);\n }\n\n // If no JSON structures found, clean and return the original text\n return text.replace(/\\s+/g, ' ').trim();\n }\n\n /**\n * Converts value to appropriate primitive type based on schema\n */\n private convertToPrimitive(value: unknown, schema: z.ZodType): unknown {\n if (schema instanceof z.ZodString) {\n return String(value);\n }\n if (schema instanceof z.ZodNumber) {\n return Number(value);\n }\n if (schema instanceof z.ZodBoolean) {\n return Boolean(value);\n }\n if (schema instanceof z.ZodNull) {\n return null;\n }\n return value;\n }\n\n /**\n * Extracts array from text\n */\n private extractArray(text: string): unknown {\n const arrayStart = text.indexOf('[');\n const arrayEnd = text.lastIndexOf(']');\n if (arrayStart === -1 || arrayEnd === -1) {\n throw new AIResponseParserError('No array found in response', undefined, text);\n }\n try {\n return JSON.parse(text.slice(arrayStart, arrayEnd + 1));\n } catch (error) {\n throw new AIResponseParserError('Failed to parse array JSON', error, text);\n }\n }\n\n /**\n * Extracts and validates JSON content from a code block\n */\n private extractJsonFromCodeBlock(block: string): null | string {\n const content = block.replace(/```(?:json)?\\r?\\n([^`]*?)\\r?\\n```/, '$1').trim();\n try {\n // Attempt to parse as JSON to validate structure\n JSON.parse(content);\n return content;\n } catch {\n return null;\n }\n }\n\n /**\n * Extracts and parses JSON from text based on schema type\n */\n private extractJsonFromText(text: string): unknown {\n if (this.schema instanceof z.ZodArray) {\n return this.extractArray(text);\n }\n\n if (this.schema instanceof z.ZodObject) {\n return this.extractObject(text);\n }\n\n if (\n this.schema instanceof z.ZodString ||\n this.schema instanceof z.ZodNumber ||\n this.schema instanceof z.ZodBoolean ||\n this.schema instanceof z.ZodNull\n ) {\n return this.extractPrimitive(text, this.schema);\n }\n\n throw new AIResponseParserError('Unsupported schema type', undefined, text);\n }\n\n /**\n * Extracts object from text\n */\n private extractObject(text: string): unknown {\n const objectStart = text.indexOf('{');\n const objectEnd = text.lastIndexOf('}');\n if (objectStart === -1 || objectEnd === -1) {\n throw new AIResponseParserError('No object found in response', undefined, text);\n }\n try {\n return JSON.parse(text.slice(objectStart, objectEnd + 1));\n } catch (error) {\n throw new AIResponseParserError('Failed to parse object JSON', error, text);\n }\n }\n\n /**\n * Extracts and converts primitive value from text\n */\n private extractPrimitive(text: string, schema: z.ZodType): unknown {\n const trimmed = text.trim();\n\n // Try to parse as JSON first in case it's quoted\n try {\n const parsed = JSON.parse(trimmed);\n return this.convertToPrimitive(parsed, schema);\n } catch {\n // If not valid JSON, use the raw string\n return this.convertToPrimitive(trimmed, schema);\n }\n }\n\n /**\n * Finds valid JSON structures in raw text\n */\n private findJsonStructures(text: string): string[] {\n const jsonMatches: string[] = [];\n let depth = 0;\n let start = -1;\n\n for (let i = 0; i < text.length; i++) {\n const char = text[i];\n if (char === '{' || char === '[') {\n if (depth === 0) start = i;\n depth++;\n } else if (char === '}' || char === ']') {\n depth--;\n if (depth === 0 && start !== -1) {\n const potentialJson = text.slice(start, i + 1);\n try {\n JSON.parse(potentialJson);\n jsonMatches.push(potentialJson);\n } catch {\n // Invalid JSON, ignore\n }\n }\n }\n }\n\n return jsonMatches;\n }\n\n /**\n * Returns the largest string from an array of strings\n */\n private findLargestString(strings: string[]): string {\n return strings.reduce(\n (largest, current) => (current.length > largest.length ? current : largest),\n strings[0],\n );\n }\n\n /**\n * Recursively unescapes all string values in a JSON object/array\n */\n private unescapeJsonValues(json: unknown): unknown {\n if (typeof json === 'string') {\n return this.unescapeText(json);\n }\n if (Array.isArray(json)) {\n return json.map((item) => this.unescapeJsonValues(item));\n }\n if (typeof json === 'object' && json !== null) {\n return Object.fromEntries(\n Object.entries(json).map(([key, value]) => [key, this.unescapeJsonValues(value)]),\n );\n }\n return json;\n }\n\n /**\n * Unescapes common escaped characters in text\n */\n private unescapeText(text: string): string {\n return text\n .replace(/\\\\\"/g, '\"') // Unescape quotes\n .replace(/\\\\n/g, '\\n') // Unescape newlines\n .replace(/\\\\r/g, '\\r') // Unescape carriage returns\n .replace(/\\\\t/g, '\\t') // Unescape tabs\n .replace(/\\\\\\\\/g, '\\\\') // Unescape backslashes\n .replace(/\\\\u([0-9a-fA-F]{4})/g, (_, code) => String.fromCharCode(parseInt(code, 16))); // Unescape unicode\n }\n}\n"],"names":["z","AIResponseParserError","AIResponseParser","schema","parse","text","cleanedText","cleanText","json","extractJsonFromText","unescapedJson","unescapeJsonValues","error","ZodError","codeBlocks","match","validBlocks","map","block","extractJsonFromCodeBlock","filter","length","findLargestString","jsonMatches","findJsonStructures","replace","trim","convertToPrimitive","value","ZodString","String","ZodNumber","Number","ZodBoolean","Boolean","ZodNull","extractArray","arrayStart","indexOf","arrayEnd","lastIndexOf","undefined","JSON","slice","content","ZodArray","ZodObject","extractObject","extractPrimitive","objectStart","objectEnd","trimmed","parsed","depth","start","i","char","potentialJson","push","strings","reduce","largest","current","unescapeText","Array","isArray","item","Object","fromEntries","entries","key","_","code","fromCharCode","parseInt"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAACuD;;gBACtD;gBACA,IAAI,CAAA,OAAO1D,qCAAP,SAAOA,KAAG,MAAM,YAAYA,SAAS,MAAM;oBAC3C,OAAO2D,OAAOC,WAAW,CACrBD,OAAOE,OAAO,CAAC7D,MAAMS,GAAG,CAAC;iEAAEqD,iBAAK1C;+BAAW;4BAAC0C;4BAAK,MAAK3D,kBAAkB,CAACiB;yBAAO;;gBAExF;gBACA,OAAOpB;YACX;;;YAKQuD,KAAAA;mBAAR,AAHA;;KAEC,GACD,SAAQA,aAAa1D,IAAY;gBAC7B,OAAOA,KACFoB,OAAO,CAAC,QAAQ,KAAK,kBAAkB;iBACvCA,OAAO,CAAC,QAAQ,MAAM,oBAAoB;iBAC1CA,OAAO,CAAC,QAAQ,MAAM,4BAA4B;iBAClDA,OAAO,CAAC,QAAQ,MAAM,gBAAgB;iBACtCA,OAAO,CAAC,SAAS,MAAM,uBAAuB;iBAC9CA,OAAO,CAAC,wBAAwB,SAAC8C,GAAGC;2BAAS1C,OAAO2C,YAAY,CAACC,SAASF,MAAM;oBAAO,mBAAmB;YACnH;;;WAjOStE;IAkOZ"}
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/utils/ai-response-parser.ts"],"sourcesContent":["import { jsonrepair } from 'jsonrepair';\nimport { z } from 'zod/v4';\n\nimport { AIResponseParserError } from './ai-response-parser-error.js';\n\n/**\n * Parses AI response text into structured data based on Zod schema\n */\nexport class AIResponseParser<T> {\n constructor(private readonly schema: z.ZodSchema<T>) {}\n\n /**\n * Parses the AI response text based on the configured schema\n */\n public parse(text: string): T {\n try {\n const cleanedText = this.cleanText(text);\n const json = this.extractJsonFromText(cleanedText);\n const unescapedJson = this.unescapeJsonValues(json);\n return this.schema.parse(unescapedJson);\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new AIResponseParserError(\n 'Failed to validate response against schema',\n error,\n text,\n );\n }\n throw error;\n }\n }\n\n /**\n * Cleans text and finds the largest schema-compatible structure\n */\n private cleanText(text: string): string {\n // First try to extract from markdown code blocks\n const codeBlocks = text.match(/```(?:json)?\\r?\\n([^`]*?)\\r?\\n```/g);\n if (codeBlocks) {\n // Try each code block and return the largest valid one\n const validBlocks = codeBlocks\n .map((block) => this.extractJsonFromCodeBlock(block))\n .filter((block): block is string => block !== null);\n\n if (validBlocks.length > 0) {\n return this.findLargestString(validBlocks);\n }\n }\n\n // If no valid code blocks, try to find JSON-like structures in the text\n const jsonMatches = this.findJsonStructures(text);\n if (jsonMatches.length > 0) {\n return this.findLargestString(jsonMatches);\n }\n\n // If no JSON structures found, clean and return the original text\n return text.replace(/\\s+/g, ' ').trim();\n }\n\n /**\n * Converts value to appropriate primitive type based on schema\n */\n private convertToPrimitive(value: unknown, schema: z.ZodType): unknown {\n if (schema instanceof z.ZodString) {\n return String(value);\n }\n if (schema instanceof z.ZodNumber) {\n return Number(value);\n }\n if (schema instanceof z.ZodBoolean) {\n return Boolean(value);\n }\n if (schema instanceof z.ZodNull) {\n return null;\n }\n return value;\n }\n\n /**\n * Extracts array from text\n */\n private extractArray(text: string): unknown {\n const arrayStart = text.indexOf('[');\n const arrayEnd = text.lastIndexOf(']');\n if (arrayStart === -1 || arrayEnd === -1) {\n throw new AIResponseParserError('No array found in response', undefined, text);\n }\n try {\n const raw = text.slice(arrayStart, arrayEnd + 1);\n const repaired = this.repairJson(raw);\n return JSON.parse(repaired);\n } catch (error) {\n throw new AIResponseParserError('Failed to parse array JSON', error, text);\n }\n }\n\n /**\n * Extracts and validates JSON content from a code block\n */\n private extractJsonFromCodeBlock(block: string): null | string {\n const content = block.replace(/```(?:json)?\\r?\\n([^`]*?)\\r?\\n```/, '$1').trim();\n try {\n // Attempt to parse as JSON to validate structure\n JSON.parse(content);\n return content;\n } catch {\n return null;\n }\n }\n\n /**\n * Extracts and parses JSON from text based on schema type\n */\n private extractJsonFromText(text: string): unknown {\n if (this.schema instanceof z.ZodArray) {\n return this.extractArray(text);\n }\n\n if (this.schema instanceof z.ZodObject) {\n return this.extractObject(text);\n }\n\n if (\n this.schema instanceof z.ZodString ||\n this.schema instanceof z.ZodNumber ||\n this.schema instanceof z.ZodBoolean ||\n this.schema instanceof z.ZodNull\n ) {\n return this.extractPrimitive(text, this.schema);\n }\n\n throw new AIResponseParserError('Unsupported schema type', undefined, text);\n }\n\n /**\n * Extracts object from text\n */\n private extractObject(text: string): unknown {\n const objectStart = text.indexOf('{');\n const objectEnd = text.lastIndexOf('}');\n if (objectStart === -1 || objectEnd === -1) {\n throw new AIResponseParserError('No object found in response', undefined, text);\n }\n try {\n const raw = text.slice(objectStart, objectEnd + 1);\n const repaired = this.repairJson(raw);\n return JSON.parse(repaired);\n } catch (error) {\n throw new AIResponseParserError('Failed to parse object JSON', error, text);\n }\n }\n\n /**\n * Extracts and converts primitive value from text\n */\n private extractPrimitive(text: string, schema: z.ZodType): unknown {\n const trimmed = text.trim();\n\n // Try to parse as JSON first in case it's quoted\n try {\n const parsed = JSON.parse(trimmed);\n return this.convertToPrimitive(parsed, schema);\n } catch {\n // If not valid JSON, use the raw string\n return this.convertToPrimitive(trimmed, schema);\n }\n }\n\n /**\n * Finds valid JSON structures in raw text\n */\n private findJsonStructures(text: string): string[] {\n const jsonMatches: string[] = [];\n let depth = 0;\n let start = -1;\n\n for (let i = 0; i < text.length; i++) {\n const char = text[i];\n if (char === '{' || char === '[') {\n if (depth === 0) start = i;\n depth++;\n } else if (char === '}' || char === ']') {\n depth--;\n if (depth === 0 && start !== -1) {\n const potentialJson = text.slice(start, i + 1);\n try {\n JSON.parse(potentialJson);\n jsonMatches.push(potentialJson);\n } catch {\n // Invalid JSON, ignore\n }\n }\n }\n }\n\n return jsonMatches;\n }\n\n /**\n * Returns the largest string from an array of strings\n */\n private findLargestString(strings: string[]): string {\n return strings.reduce(\n (largest, current) => (current.length > largest.length ? current : largest),\n strings[0],\n );\n }\n\n /**\n * Repairs common JSON issues using jsonrepair library\n */\n private repairJson(jsonString: string): string {\n return jsonrepair(jsonString);\n }\n\n /**\n * Recursively unescapes all string values in a JSON object/array\n */\n private unescapeJsonValues(json: unknown): unknown {\n if (typeof json === 'string') {\n return this.unescapeText(json);\n }\n if (Array.isArray(json)) {\n return json.map((item) => this.unescapeJsonValues(item));\n }\n if (typeof json === 'object' && json !== null) {\n return Object.fromEntries(\n Object.entries(json).map(([key, value]) => [key, this.unescapeJsonValues(value)]),\n );\n }\n return json;\n }\n\n /**\n * Unescapes common escaped characters in text\n */\n private unescapeText(text: string): string {\n return text\n .replace(/\\\\\"/g, '\"') // Unescape quotes\n .replace(/\\\\n/g, '\\n') // Unescape newlines\n .replace(/\\\\r/g, '\\r') // Unescape carriage returns\n .replace(/\\\\t/g, '\\t') // Unescape tabs\n .replace(/\\\\\\\\/g, '\\\\') // Unescape backslashes\n .replace(/\\\\u([0-9a-fA-F]{4})/g, (_, code) => String.fromCharCode(parseInt(code, 16))); // Unescape unicode\n }\n}\n"],"names":["jsonrepair","z","AIResponseParserError","AIResponseParser","schema","parse","text","cleanedText","cleanText","json","extractJsonFromText","unescapedJson","unescapeJsonValues","error","ZodError","codeBlocks","match","validBlocks","map","block","extractJsonFromCodeBlock","filter","length","findLargestString","jsonMatches","findJsonStructures","replace","trim","convertToPrimitive","value","ZodString","String","ZodNumber","Number","ZodBoolean","Boolean","ZodNull","extractArray","arrayStart","indexOf","arrayEnd","lastIndexOf","undefined","raw","slice","repaired","repairJson","JSON","content","ZodArray","ZodObject","extractObject","extractPrimitive","objectStart","objectEnd","trimmed","parsed","depth","start","i","char","potentialJson","push","strings","reduce","largest","current","jsonString","unescapeText","Array","isArray","item","Object","fromEntries","entries","key","_","code","fromCharCode","parseInt"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,UAAU,QAAQ,aAAa;AACxC,SAASC,CAAC,QAAQ,SAAS;AAE3B,SAASC,qBAAqB,QAAQ,gCAAgC;AAEtE;;CAEC,GACD,OAAO,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CAAC3D;gBAC7B;gBACA,IAAI4D,MAAMC,OAAO,CAAC7D,OAAO;oBACrB,OAAOA,KAAKS,GAAG,CAAC,SAACqD;+BAAS,MAAK3D,kBAAkB,CAAC2D;;gBACtD;gBACA,IAAI,CAAA,OAAO9D,qCAAP,SAAOA,KAAG,MAAM,YAAYA,SAAS,MAAM;oBAC3C,OAAO+D,OAAOC,WAAW,CACrBD,OAAOE,OAAO,CAACjE,MAAMS,GAAG,CAAC;iEAAEyD,iBAAK9C;+BAAW;4BAAC8C;4BAAK,MAAK/D,kBAAkB,CAACiB;yBAAO;;gBAExF;gBACA,OAAOpB;YACX;;;YAKQ2D,KAAAA;mBAAR,AAHA;;KAEC,GACD,SAAQA,aAAa9D,IAAY;gBAC7B,OAAOA,KACFoB,OAAO,CAAC,QAAQ,KAAK,kBAAkB;iBACvCA,OAAO,CAAC,QAAQ,MAAM,oBAAoB;iBAC1CA,OAAO,CAAC,QAAQ,MAAM,4BAA4B;iBAClDA,OAAO,CAAC,QAAQ,MAAM,gBAAgB;iBACtCA,OAAO,CAAC,SAAS,MAAM,uBAAuB;iBAC9CA,OAAO,CAAC,wBAAwB,SAACkD,GAAGC;2BAAS9C,OAAO+C,YAAY,CAACC,SAASF,MAAM;oBAAO,mBAAmB;YACnH;;;WA5OS1E;IA6OZ"}
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var prompts = require('@langchain/core/prompts');
|
|
4
4
|
var agents = require('langchain/agents');
|
|
5
5
|
var v4 = require('zod/v4');
|
|
6
|
+
var jsonrepair = require('jsonrepair');
|
|
6
7
|
var openai = require('@langchain/openai');
|
|
7
8
|
var tools = require('langchain/tools');
|
|
8
9
|
|
|
@@ -314,7 +315,9 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
314
315
|
throw new AIResponseParserError('No array found in response', undefined, text);
|
|
315
316
|
}
|
|
316
317
|
try {
|
|
317
|
-
|
|
318
|
+
var raw = text.slice(arrayStart, arrayEnd + 1);
|
|
319
|
+
var repaired = this.repairJson(raw);
|
|
320
|
+
return JSON.parse(repaired);
|
|
318
321
|
} catch (error) {
|
|
319
322
|
throw new AIResponseParserError('Failed to parse array JSON', error, text);
|
|
320
323
|
}
|
|
@@ -363,7 +366,9 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
363
366
|
throw new AIResponseParserError('No object found in response', undefined, text);
|
|
364
367
|
}
|
|
365
368
|
try {
|
|
366
|
-
|
|
369
|
+
var raw = text.slice(objectStart, objectEnd + 1);
|
|
370
|
+
var repaired = this.repairJson(raw);
|
|
371
|
+
return JSON.parse(repaired);
|
|
367
372
|
} catch (error) {
|
|
368
373
|
throw new AIResponseParserError('Failed to parse object JSON', error, text);
|
|
369
374
|
}
|
|
@@ -424,6 +429,14 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
424
429
|
}, strings[0]);
|
|
425
430
|
}
|
|
426
431
|
},
|
|
432
|
+
{
|
|
433
|
+
key: "repairJson",
|
|
434
|
+
value: /**
|
|
435
|
+
* Repairs common JSON issues using jsonrepair library
|
|
436
|
+
*/ function repairJson(jsonString) {
|
|
437
|
+
return jsonrepair.jsonrepair(jsonString);
|
|
438
|
+
}
|
|
439
|
+
},
|
|
427
440
|
{
|
|
428
441
|
key: "unescapeJsonValues",
|
|
429
442
|
value: /**
|
|
@@ -1271,6 +1284,7 @@ function _object_spread(target) {
|
|
|
1271
1284
|
* Core, non-negotiable rules that establish the agent's fundamental identity and operational boundaries.
|
|
1272
1285
|
* These are the foundational principles that guide all other instructions.
|
|
1273
1286
|
*/ var FOUNDATIONS = {
|
|
1287
|
+
CONTEXTUAL_ONLY: "\n<Foundation>\nYou MUST ONLY use the information provided in the context to answer questions.\nYou MUST NOT use any other information, including your own knowledge, to answer questions.\n</Foundation>",
|
|
1274
1288
|
CONTEXTUAL_REASONING: '\n<Foundation>\nYou MUST synthesize information from the provided context, tools, and conversation history to form well-reasoned conclusions.\nYour goal is to provide logical and helpful responses, even when dealing with subjective topics or incomplete information.\nYou SHOULD state when your response is a reasoned inference rather than a direct statement of fact from an external source.\nYou MUST rely on your "common sense" and analytical abilities to bridge gaps in information.\n</Foundation>',
|
|
1275
1289
|
ETHICAL_CONDUCT: "\n<Foundation>\nYou MUST adhere to the highest ethical standards. Your conduct must be impartial and devoid of prejudice.\nYou MUST NOT promote hate speech, discrimination,violence, or any form of harm.\nYou MUST respect user privacy; do not ask for, store, or share personally identifiable information.\n</Foundation>",
|
|
1276
1290
|
FACTUAL_ACCURACY: "\n<Foundation>\nYou MUST prioritize accuracy and truthfulness. Your responses must be based on verifiable information.\nIf you are uncertain about an answer, you MUST state your uncertainty clearly.\nYou MUST NOT invent facts, data, or sources. When possible, cite credible sources.\n</Foundation>",
|
|
@@ -1281,12 +1295,12 @@ function _object_spread(target) {
|
|
|
1281
1295
|
/**
|
|
1282
1296
|
* Defines the natural language for the agent's responses.
|
|
1283
1297
|
*/ var LANGUAGES = {
|
|
1284
|
-
ENGLISH_NATIVE: "\n<Language>\nYou MUST
|
|
1285
|
-
ENGLISH_SIMPLE: "\n<Language>\nYou MUST
|
|
1286
|
-
FRENCH_NATIVE: "\n<Language>\nVous DEVEZ r\
|
|
1287
|
-
FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ
|
|
1288
|
-
SPANISH_NATIVE: "\n<Language>\nDEBES
|
|
1289
|
-
SPANISH_SIMPLE: "\n<Language>\nDEBES
|
|
1298
|
+
ENGLISH_NATIVE: "\n<Language>\nYou MUST write your entire output in natural, fluent English. This is a strict requirement; do not use any other language.\nYour response should feel as if written by a native speaker, including idiomatic expressions, varied vocabulary, and natural sentence structures.\n</Language>",
|
|
1299
|
+
ENGLISH_SIMPLE: "\n<Language>\nYou MUST write your entire output in simple, clear English. This is a strict requirement; do not use any other language.\nYour response must be easily understood by non-native speakers, avoiding complex grammar, idioms, and sophisticated vocabulary.\n</Language>",
|
|
1300
|
+
FRENCH_NATIVE: "\n<Language>\nVous DEVEZ IMP\xc9RATIVEMENT r\xe9diger toute votre sortie en fran\xe7ais naturel et fluide. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre r\xe9ponse doit donner l'impression d'avoir \xe9t\xe9 \xe9crite par un locuteur natif, en incluant des expressions idiomatiques et un vocabulaire vari\xe9.\n</Language>",
|
|
1301
|
+
FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ IMP\xc9RATIVEMENT r\xe9diger toute votre sortie en fran\xe7ais simple et clair. C'est une exigence stricte ; n'utilisez aucune autre langue.\nVotre r\xe9ponse doit \xeatre facile \xe0 comprendre pour des non-natifs, en \xe9vitant la grammaire complexe et le vocabulaire sophistiqu\xe9.\n</Language>",
|
|
1302
|
+
SPANISH_NATIVE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un espa\xf1ol natural y fluido. Este es un requisito estricto; no utilices ning\xfan otro idioma.\nTu respuesta debe parecer escrita por un hablante nativo, incluyendo expresiones idiom\xe1ticas y un vocabulario variado.\n</Language>",
|
|
1303
|
+
SPANISH_SIMPLE: "\n<Language>\nDEBES OBLIGATORIAMENTE escribir todo tu resultado en un espa\xf1ol simple y claro. Este es un requisito estricto; no utilices ning\xfan otro idioma.\nTu respuesta debe ser f\xe1cil de entender para hablantes no nativos, evitando gram\xe1tica compleja y vocabulario sofisticado.\n</Language>"
|
|
1290
1304
|
};
|
|
1291
1305
|
|
|
1292
1306
|
/**
|
|
@@ -1297,6 +1311,7 @@ function _object_spread(target) {
|
|
|
1297
1311
|
CREATIVE_PARTNER: "\n<Persona>\nYou are a Creative Partner, an imaginative collaborator for brainstorming and exploration.\nYour purpose is to help users generate and develop novel ideas.\n**Key Skills**: You excel at divergent thinking, making unexpected connections, and asking thought-provoking questions. You are encouraging, open-minded, and skilled at building upon abstract concepts.\n</Persona>",
|
|
1298
1312
|
EXPERT_ADVISOR: "\n<Persona>\nYou are an Expert Advisor in your specified domain.\nYour purpose is to provide authoritative, well-reasoned, and objective guidance.\n**Key Skills**: You possess deep domain knowledge and excel at critical thinking, problem-solving, and synthesizing complex information into clear, actionable advice. Your communication is precise and confident.\n</Persona>",
|
|
1299
1313
|
HUMAN_LIKE_CONTRIBUTOR: "\n<Persona>\nYou are a Human-Like Contributor, a thoughtful and engaging participant in a group chat.\nYour purpose is to interact in a way that is indistinguishable from a human, fostering natural and coherent conversations.\n**Key Skills**: You excel at maintaining conversational context, ensuring your contributions are a logical continuation of past interactions. You avoid repetition and can proactively initiate new topics when appropriate. Your style is natural, personal, and adaptive.\n</Persona>",
|
|
1314
|
+
JOURNALIST: "\n<Persona>\nYou are a Journalist, a skilled writer who crafts engaging, informative, and well-structured articles.\nYour purpose is to provide users with valuable, well-researched, and well-written content.\n**Key Skills**: You excel at writing clear, concise, and engaging articles. You are skilled at researching and gathering information, and you are able to write in a way that is both informative and entertaining.\n</Persona>",
|
|
1300
1315
|
SUPPORT_AGENT: "\n<Persona>\nYou are a friendly, patient, and empathetic Support Agent.\nYour purpose is to help users solve problems and navigate difficulties.\n**Key Skills**: You are an excellent listener and a clear communicator. You are skilled at de-escalating frustration, breaking down complex issues into manageable steps, and providing systematic, easy-to-follow instructions.\n</Persona>",
|
|
1301
1316
|
TUTOR: "\n<Persona>\nYou are a patient, knowledgeable, and encouraging Tutor.\nYour purpose is to help users learn and understand complex subjects.\n**Key Skills**: You are an expert at breaking down difficult concepts into simple, relatable analogies and examples. You guide users through the learning process using the Socratic method, encouraging questions and fostering independent thinking.\n</Persona>"
|
|
1302
1317
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jterrazz/intelligence",
|
|
3
3
|
"author": "Jean-Baptiste Terrazzoni <contact@jterrazz.com>",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.3",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"require": "./dist/index.cjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lint": "code-standards"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@jterrazz/quality": "^2.2.
|
|
21
|
+
"@jterrazz/quality": "^2.2.7",
|
|
22
22
|
"@jterrazz/test": "^3.0.0",
|
|
23
23
|
"@jterrazz/typescript": "^2.4.3"
|
|
24
24
|
},
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@langchain/community": "^0.3.47",
|
|
28
28
|
"@langchain/core": "^0.3.61",
|
|
29
29
|
"@langchain/openai": "^0.5.15",
|
|
30
|
+
"jsonrepair": "^3.12.0",
|
|
30
31
|
"zod": "^3.25.67"
|
|
31
32
|
},
|
|
32
33
|
"publishConfig": {
|