@jterrazz/intelligence 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +229 -0
- package/dist/adapters/agents/chat-agent.adapter.d.ts +35 -0
- package/dist/adapters/agents/chat-agent.adapter.js +388 -0
- package/dist/adapters/agents/chat-agent.adapter.js.map +1 -0
- package/dist/adapters/models/openrouter-model.adapter.d.ts +28 -0
- package/dist/adapters/models/openrouter-model.adapter.js +80 -0
- package/dist/adapters/models/openrouter-model.adapter.js.map +1 -0
- package/dist/adapters/prompts/__tests__/__snapshots__/presets.test.ts.snap +150 -0
- package/dist/adapters/prompts/__tests__/presets.test.d.ts +1 -0
- package/dist/adapters/prompts/__tests__/presets.test.js +31 -0
- package/dist/adapters/prompts/__tests__/presets.test.js.map +1 -0
- package/dist/adapters/prompts/library/categories/agent-logic.d.ts +8 -0
- package/dist/adapters/prompts/library/categories/agent-logic.js +9 -0
- package/dist/adapters/prompts/library/categories/agent-logic.js.map +1 -0
- package/dist/adapters/prompts/library/categories/agent-skills.d.ts +8 -0
- package/dist/adapters/prompts/library/categories/agent-skills.js +9 -0
- package/dist/adapters/prompts/library/categories/agent-skills.js.map +1 -0
- package/dist/adapters/prompts/library/categories/directives.d.ts +9 -0
- package/dist/adapters/prompts/library/categories/directives.js +10 -0
- package/dist/adapters/prompts/library/categories/directives.js.map +1 -0
- package/dist/adapters/prompts/library/categories/domain.d.ts +11 -0
- package/dist/adapters/prompts/library/categories/domain.js +12 -0
- package/dist/adapters/prompts/library/categories/domain.js.map +1 -0
- package/dist/adapters/prompts/library/categories/format.d.ts +9 -0
- package/dist/adapters/prompts/library/categories/format.js +10 -0
- package/dist/adapters/prompts/library/categories/format.js.map +1 -0
- package/dist/adapters/prompts/library/categories/language.d.ts +11 -0
- package/dist/adapters/prompts/library/categories/language.js +12 -0
- package/dist/adapters/prompts/library/categories/language.js.map +1 -0
- package/dist/adapters/prompts/library/categories/persona.d.ts +11 -0
- package/dist/adapters/prompts/library/categories/persona.js +12 -0
- package/dist/adapters/prompts/library/categories/persona.js.map +1 -0
- package/dist/adapters/prompts/library/categories/tone.d.ts +9 -0
- package/dist/adapters/prompts/library/categories/tone.js +10 -0
- package/dist/adapters/prompts/library/categories/tone.js.map +1 -0
- package/dist/adapters/prompts/library/categories/verbosity.d.ts +8 -0
- package/dist/adapters/prompts/library/categories/verbosity.js +9 -0
- package/dist/adapters/prompts/library/categories/verbosity.js.map +1 -0
- package/dist/adapters/prompts/library/index.d.ts +66 -0
- package/dist/adapters/prompts/library/index.js +28 -0
- package/dist/adapters/prompts/library/index.js.map +1 -0
- package/dist/adapters/prompts/library/presets.d.ts +17 -0
- package/dist/adapters/prompts/library/presets.js +51 -0
- package/dist/adapters/prompts/library/presets.js.map +1 -0
- package/dist/adapters/prompts/system-prompt.adapter.d.ts +9 -0
- package/dist/adapters/prompts/system-prompt.adapter.js +57 -0
- package/dist/adapters/prompts/system-prompt.adapter.js.map +1 -0
- package/dist/adapters/prompts/user-prompt.adapter.d.ts +9 -0
- package/dist/adapters/prompts/user-prompt.adapter.js +57 -0
- package/dist/adapters/prompts/user-prompt.adapter.js.map +1 -0
- package/dist/adapters/tools/safe-tool.adapter.d.ts +27 -0
- package/dist/adapters/tools/safe-tool.adapter.js +283 -0
- package/dist/adapters/tools/safe-tool.adapter.js.map +1 -0
- package/dist/adapters/utils/__tests__/ai-response-parser.test.d.ts +1 -0
- package/dist/adapters/utils/__tests__/ai-response-parser.test.js +249 -0
- package/dist/adapters/utils/__tests__/ai-response-parser.test.js.map +1 -0
- package/dist/adapters/utils/ai-response-parser-error.d.ts +8 -0
- package/dist/adapters/utils/ai-response-parser-error.js +136 -0
- package/dist/adapters/utils/ai-response-parser-error.js.map +1 -0
- package/dist/adapters/utils/ai-response-parser.d.ts +56 -0
- package/dist/adapters/utils/ai-response-parser.js +334 -0
- package/dist/adapters/utils/ai-response-parser.js.map +1 -0
- package/dist/index.cjs +1461 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/ports/agent.port.d.ts +11 -0
- package/dist/ports/agent.port.js +5 -0
- package/dist/ports/agent.port.js.map +1 -0
- package/dist/ports/model.port.d.ts +10 -0
- package/dist/ports/model.port.js +5 -0
- package/dist/ports/model.port.js.map +1 -0
- package/dist/ports/prompt.port.d.ts +9 -0
- package/dist/ports/prompt.port.js +5 -0
- package/dist/ports/prompt.port.js.map +1 -0
- package/dist/ports/tool.port.d.ts +11 -0
- package/dist/ports/tool.port.js +5 -0
- package/dist/ports/tool.port.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for the prompt library.
|
|
3
|
+
* This file serves as the public API for the prompt library,
|
|
4
|
+
* making it easy to import all categories from a single location.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PROMPTS: {
|
|
7
|
+
readonly AGENT_LOGIC: {
|
|
8
|
+
readonly ALWAYS_RESPOND: "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>";
|
|
9
|
+
readonly SELECTIVE_RESPONSE: "\n<AGENT_LOGIC>\nOnly respond when you can provide a valuable, relevant, and substantive contribution.\nIf a response is not necessary, state that you have nothing to add.\n</AGENT_LOGIC>";
|
|
10
|
+
readonly TOOL_FIRST: "\n<AGENT_LOGIC>\nBefore formulating a response, always prioritize using your available tools to gather the most current and accurate information.\n</AGENT_LOGIC>";
|
|
11
|
+
};
|
|
12
|
+
readonly AGENT_SKILLS: {
|
|
13
|
+
readonly CREATIVE_IDEATION: "\n<AGENT_SKILL>\nYou excel at brainstorming, generating novel ideas, and thinking outside the box.\n</AGENT_SKILL>";
|
|
14
|
+
readonly INFORMATION_SYNTHESIS: "\n<AGENT_SKILL>\nYou are skilled at gathering and synthesizing information from multiple sources to provide a comprehensive answer.\n</AGENT_SKILL>";
|
|
15
|
+
readonly PROBLEM_SOLVING: "\n<AGENT_SKILL>\nYou are skilled at analyzing complex problems, breaking them down into manageable parts, and proposing systematic solutions.\n</AGENT_SKILL>";
|
|
16
|
+
};
|
|
17
|
+
readonly DIRECTIVES: {
|
|
18
|
+
readonly BE_ETHICAL: "\n<DIRECTIVE>\nAdhere to the highest ethical standards. Do not promote hate speech, discrimination, or violence.\nRespect user privacy and do not ask for or store personally identifiable information.\n</DIRECTIVE>";
|
|
19
|
+
readonly BE_FACTUAL: "\n<DIRECTIVE>\nPrioritize accuracy and rely on verifiable information.\nIf you are uncertain about an answer, state your uncertainty clearly.\nDo not invent facts or statistics. When possible, cite credible sources.\n</DIRECTIVE>";
|
|
20
|
+
readonly BE_SAFE: "\n<DIRECTIVE>\nDo not provide instructions or information that is illegal, dangerous, or harmful.\nRefuse to engage with requests that could cause real-world harm.\nPrioritize user safety and well-being in all responses.\n</DIRECTIVE>";
|
|
21
|
+
};
|
|
22
|
+
readonly DOMAIN: {
|
|
23
|
+
readonly ACADEMIC_RESEARCH: "\n<DOMAIN>\nYour expertise is in academic research. You are familiar with scholarly writing, peer-review processes, and formal citation methods.\n</DOMAIN>";
|
|
24
|
+
readonly BUSINESS_STRATEGY: "\n<DOMAIN>\nYour expertise is in business strategy, including market analysis, competitive positioning, and operational planning.\n</DOMAIN>";
|
|
25
|
+
readonly DATA_SCIENCE: "\n<DOMAIN>\nYour expertise is in data science, including statistical analysis, machine learning, and data visualization.\n</DOMAIN>";
|
|
26
|
+
readonly GENERAL: "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>";
|
|
27
|
+
readonly SOFTWARE_ENGINEERING: "\n<DOMAIN>\nYour expertise is in software engineering, including programming languages, system architecture, design patterns, and development best practices.\n</DOMAIN>";
|
|
28
|
+
};
|
|
29
|
+
readonly FORMAT: {
|
|
30
|
+
readonly JSON: "\n<FORMAT>\nRespond ONLY with a valid, well-formed JSON object.\nDo not include any explanatory text or markdown formatting outside of the JSON structure.\n</FORMAT>";
|
|
31
|
+
readonly MARKDOWN: "\n<FORMAT>\nUse Markdown for clear, structured responses.\nEmploy headings, lists, bold/italic text, and code blocks to improve readability.\n</FORMAT>";
|
|
32
|
+
readonly PLAIN_TEXT: "\n<FORMAT>\nRespond in plain text without any special formatting, lists, or structural elements.\n</FORMAT>";
|
|
33
|
+
readonly STEP_BY_STEP: "\n<FORMAT>\nBreak down instructions or processes into a clear, numbered, step-by-step list.\nEnsure each step is a distinct, actionable item.\n</FORMAT>";
|
|
34
|
+
};
|
|
35
|
+
readonly LANGUAGE: {
|
|
36
|
+
readonly ENGLISH_NATIVE: "\n<LANGUAGE>\nRespond in natural, fluent English as a native speaker would.\nUse idiomatic expressions, varied vocabulary, and natural sentence flow.\n</LANGUAGE>";
|
|
37
|
+
readonly ENGLISH_SIMPLE: "\n<LANGUAGE>\nUse simple, clear English that's easy to understand for non-native speakers.\nAvoid complex grammar, idioms, and sophisticated vocabulary.\n</LANGUAGE>";
|
|
38
|
+
readonly FRENCH_NATIVE: "\n<LANGUAGE>\nRépondez en français naturel et fluide comme le ferait un locuteur natif.\nUtilisez des expressions idiomatiques et un vocabulaire varié.\n</LANGUAGE>";
|
|
39
|
+
readonly FRENCH_SIMPLE: "\n<LANGUAGE>\nUtilisez un français simple et clair, facile à comprendre.\nÉvitez la grammaire complexe et le vocabulaire sophistiqué.\n</LANGUAGE>";
|
|
40
|
+
readonly SPANISH_NATIVE: "\n<LANGUAGE>\nResponde en español natural y fluido como lo haría un hablante nativo.\nUsa expresiones idiomáticas y vocabulario variado.\n</LANGUAGE>";
|
|
41
|
+
readonly SPANISH_SIMPLE: "\n<LANGUAGE>\nUsa español simple y claro que sea fácil de entender para no nativos.\nEvita la gramática compleja y el vocabulario sofisticado.\n</LANGUAGE>";
|
|
42
|
+
};
|
|
43
|
+
readonly PERSONA: {
|
|
44
|
+
readonly COMMUNITY_ANIMATOR: "\n<PERSONA>\nYou are the Community Animator, the heart and soul of a digital community like Discord.\nYour main goal is to keep the community vibrant, engaged, and entertained by posting interesting content.\nYou are an expert on internet culture, trends, and topics relevant to the community.\n</PERSONA>";
|
|
45
|
+
readonly CREATIVE_PARTNER: "\n<PERSONA>\nYou are a creative partner, here to help brainstorm and explore new ideas.\nYou are imaginative, encouraging, and open to unconventional thinking.\nYour goal is to inspire and collaborate.\n</PERSONA>";
|
|
46
|
+
readonly EXPERT_ADVISOR: "\n<PERSONA>\nYou are an expert advisor in your specified domain.\nYou provide authoritative, well-reasoned guidance.\nYour tone is confident, knowledgeable, and objective.\n</PERSONA>";
|
|
47
|
+
readonly SUPPORT_AGENT: "\n<PERSONA>\nYou are a friendly and empathetic support agent.\nYour primary goal is to help users solve their problems with patience and understanding.\nYou are a good listener and provide clear, step-by-step assistance.\n</PERSONA>";
|
|
48
|
+
readonly TUTOR: "\n<PERSONA>\nYou are a patient and knowledgeable tutor.\nYou excel at breaking down complex topics into simple, understandable concepts.\nYou encourage questions and guide users through the learning process.\n</PERSONA>";
|
|
49
|
+
};
|
|
50
|
+
readonly PRESETS: {
|
|
51
|
+
readonly CREATIVE_BRAINSTORMER: readonly ["\n<DIRECTIVE>\nAdhere to the highest ethical standards. Do not promote hate speech, discrimination, or violence.\nRespect user privacy and do not ask for or store personally identifiable information.\n</DIRECTIVE>", "\n<PERSONA>\nYou are a creative partner, here to help brainstorm and explore new ideas.\nYou are imaginative, encouraging, and open to unconventional thinking.\nYour goal is to inspire and collaborate.\n</PERSONA>", "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>", "\n<TONE>\nEmploy light-hearted humor, wit, and cleverness.\nKeep the mood fun and engaging, but avoid inappropriate or offensive jokes.\n</TONE>", "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>", "\n<FORMAT>\nUse Markdown for clear, structured responses.\nEmploy headings, lists, bold/italic text, and code blocks to improve readability.\n</FORMAT>", "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>", "\n<AGENT_SKILL>\nYou excel at brainstorming, generating novel ideas, and thinking outside the box.\n</AGENT_SKILL>"];
|
|
52
|
+
readonly DISCORD_COMMUNITY_ANIMATOR: readonly ["\n<DIRECTIVE>\nDo not provide instructions or information that is illegal, dangerous, or harmful.\nRefuse to engage with requests that could cause real-world harm.\nPrioritize user safety and well-being in all responses.\n</DIRECTIVE>", "\n<PERSONA>\nYou are the Community Animator, the heart and soul of a digital community like Discord.\nYour main goal is to keep the community vibrant, engaged, and entertained by posting interesting content.\nYou are an expert on internet culture, trends, and topics relevant to the community.\n</PERSONA>", "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>", "\n<TONE>\nEmploy light-hearted humor, wit, and cleverness.\nKeep the mood fun and engaging, but avoid inappropriate or offensive jokes.\n</TONE>", "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>", "\n<FORMAT>\nUse Markdown for clear, structured responses.\nEmploy headings, lists, bold/italic text, and code blocks to improve readability.\n</FORMAT>", "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>", "\n<AGENT_SKILL>\nYou excel at brainstorming, generating novel ideas, and thinking outside the box.\n</AGENT_SKILL>"];
|
|
53
|
+
readonly EMPATHETIC_SUPPORT_AGENT: readonly ["\n<DIRECTIVE>\nDo not provide instructions or information that is illegal, dangerous, or harmful.\nRefuse to engage with requests that could cause real-world harm.\nPrioritize user safety and well-being in all responses.\n</DIRECTIVE>", "\n<DIRECTIVE>\nAdhere to the highest ethical standards. Do not promote hate speech, discrimination, or violence.\nRespect user privacy and do not ask for or store personally identifiable information.\n</DIRECTIVE>", "\n<PERSONA>\nYou are a friendly and empathetic support agent.\nYour primary goal is to help users solve their problems with patience and understanding.\nYou are a good listener and provide clear, step-by-step assistance.\n</PERSONA>", "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>", "\n<TONE>\nAdopt a warm, understanding, and supportive tone.\nAcknowledge the user's feelings and show you are listening.\n</TONE>", "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>", "\n<FORMAT>\nBreak down instructions or processes into a clear, numbered, step-by-step list.\nEnsure each step is a distinct, actionable item.\n</FORMAT>", "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>", "\n<AGENT_SKILL>\nYou are skilled at analyzing complex problems, breaking them down into manageable parts, and proposing systematic solutions.\n</AGENT_SKILL>"];
|
|
54
|
+
};
|
|
55
|
+
readonly TONE: {
|
|
56
|
+
readonly EMPATHETIC: "\n<TONE>\nAdopt a warm, understanding, and supportive tone.\nAcknowledge the user's feelings and show you are listening.\n</TONE>";
|
|
57
|
+
readonly HUMOROUS: "\n<TONE>\nEmploy light-hearted humor, wit, and cleverness.\nKeep the mood fun and engaging, but avoid inappropriate or offensive jokes.\n</TONE>";
|
|
58
|
+
readonly NEUTRAL: "\n<TONE>\nMaintain an impartial, objective, and straightforward tone.\nAvoid emotional language and stick to the facts.\n</TONE>";
|
|
59
|
+
readonly PROFESSIONAL: "\n<TONE>\nUse a formal, respectful, and clear tone.\nStructure your communication logically and avoid slang or overly casual language.\n</TONE>";
|
|
60
|
+
};
|
|
61
|
+
readonly VERBOSITY: {
|
|
62
|
+
readonly CONCISE: "\n<VERBOSITY>\nProvide brief, to-the-point answers.\nFocus only on the most critical information and omit background details unless requested.\n</VERBOSITY>";
|
|
63
|
+
readonly DETAILED: "\n<VERBOSITY>\nOffer comprehensive and thorough responses.\nInclude background information, context, examples, and potential edge cases.\n</VERBOSITY>";
|
|
64
|
+
readonly NORMAL: "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>";
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-exports for the prompt library.
|
|
3
|
+
* This file serves as the public API for the prompt library,
|
|
4
|
+
* making it easy to import all categories from a single location.
|
|
5
|
+
*/ import { DOMAIN } from './categories/domain.js';
|
|
6
|
+
import { AGENT_LOGIC } from './categories/agent-logic.js';
|
|
7
|
+
import { AGENT_SKILLS } from './categories/agent-skills.js';
|
|
8
|
+
import { DIRECTIVES } from './categories/directives.js';
|
|
9
|
+
import { FORMAT } from './categories/format.js';
|
|
10
|
+
import { LANGUAGE } from './categories/language.js';
|
|
11
|
+
import { PERSONA } from './categories/persona.js';
|
|
12
|
+
import { TONE } from './categories/tone.js';
|
|
13
|
+
import { VERBOSITY } from './categories/verbosity.js';
|
|
14
|
+
import { PRESETS } from './presets.js';
|
|
15
|
+
export var PROMPTS = {
|
|
16
|
+
AGENT_LOGIC: AGENT_LOGIC,
|
|
17
|
+
AGENT_SKILLS: AGENT_SKILLS,
|
|
18
|
+
DIRECTIVES: DIRECTIVES,
|
|
19
|
+
DOMAIN: DOMAIN,
|
|
20
|
+
FORMAT: FORMAT,
|
|
21
|
+
LANGUAGE: LANGUAGE,
|
|
22
|
+
PERSONA: PERSONA,
|
|
23
|
+
PRESETS: PRESETS,
|
|
24
|
+
TONE: TONE,
|
|
25
|
+
VERBOSITY: VERBOSITY
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/adapters/prompts/library/index.ts"],"sourcesContent":["/**\n * Re-exports for the prompt library.\n * This file serves as the public API for the prompt library,\n * making it easy to import all categories from a single location.\n */\n\nimport { DOMAIN } from './categories/domain.js';\n\nimport { AGENT_LOGIC } from './categories/agent-logic.js';\nimport { AGENT_SKILLS } from './categories/agent-skills.js';\nimport { DIRECTIVES } from './categories/directives.js';\nimport { FORMAT } from './categories/format.js';\nimport { LANGUAGE } from './categories/language.js';\nimport { PERSONA } from './categories/persona.js';\nimport { TONE } from './categories/tone.js';\nimport { VERBOSITY } from './categories/verbosity.js';\n\nimport { PRESETS } from './presets.js';\n\nexport const PROMPTS = {\n AGENT_LOGIC,\n AGENT_SKILLS,\n DIRECTIVES,\n DOMAIN,\n FORMAT,\n LANGUAGE,\n PERSONA,\n PRESETS,\n TONE,\n VERBOSITY,\n} as const;\n"],"names":["DOMAIN","AGENT_LOGIC","AGENT_SKILLS","DIRECTIVES","FORMAT","LANGUAGE","PERSONA","TONE","VERBOSITY","PRESETS","PROMPTS"],"mappings":"AAAA;;;;CAIC,GAED,SAASA,MAAM,QAAQ,yBAAyB;AAEhD,SAASC,WAAW,QAAQ,8BAA8B;AAC1D,SAASC,YAAY,QAAQ,+BAA+B;AAC5D,SAASC,UAAU,QAAQ,6BAA6B;AACxD,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,QAAQ,QAAQ,2BAA2B;AACpD,SAASC,OAAO,QAAQ,0BAA0B;AAClD,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,SAASC,SAAS,QAAQ,4BAA4B;AAEtD,SAASC,OAAO,QAAQ,eAAe;AAEvC,OAAO,IAAMC,UAAU;IACnBT,aAAAA;IACAC,cAAAA;IACAC,YAAAA;IACAH,QAAAA;IACAI,QAAAA;IACAC,UAAAA;IACAC,SAAAA;IACAG,SAAAA;IACAF,MAAAA;IACAC,WAAAA;AACJ,EAAW"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides ready-to-use combinations of prompt parts for common use cases.
|
|
3
|
+
*/
|
|
4
|
+
export declare const PRESETS: {
|
|
5
|
+
/**
|
|
6
|
+
* A creative partner for brainstorming and ideation.
|
|
7
|
+
*/
|
|
8
|
+
readonly CREATIVE_BRAINSTORMER: readonly ["\n<DIRECTIVE>\nAdhere to the highest ethical standards. Do not promote hate speech, discrimination, or violence.\nRespect user privacy and do not ask for or store personally identifiable information.\n</DIRECTIVE>", "\n<PERSONA>\nYou are a creative partner, here to help brainstorm and explore new ideas.\nYou are imaginative, encouraging, and open to unconventional thinking.\nYour goal is to inspire and collaborate.\n</PERSONA>", "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>", "\n<TONE>\nEmploy light-hearted humor, wit, and cleverness.\nKeep the mood fun and engaging, but avoid inappropriate or offensive jokes.\n</TONE>", "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>", "\n<FORMAT>\nUse Markdown for clear, structured responses.\nEmploy headings, lists, bold/italic text, and code blocks to improve readability.\n</FORMAT>", "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>", "\n<AGENT_SKILL>\nYou excel at brainstorming, generating novel ideas, and thinking outside the box.\n</AGENT_SKILL>"];
|
|
9
|
+
/**
|
|
10
|
+
* A fun and engaging community animator for platforms like Discord.
|
|
11
|
+
*/
|
|
12
|
+
readonly DISCORD_COMMUNITY_ANIMATOR: readonly ["\n<DIRECTIVE>\nDo not provide instructions or information that is illegal, dangerous, or harmful.\nRefuse to engage with requests that could cause real-world harm.\nPrioritize user safety and well-being in all responses.\n</DIRECTIVE>", "\n<PERSONA>\nYou are the Community Animator, the heart and soul of a digital community like Discord.\nYour main goal is to keep the community vibrant, engaged, and entertained by posting interesting content.\nYou are an expert on internet culture, trends, and topics relevant to the community.\n</PERSONA>", "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>", "\n<TONE>\nEmploy light-hearted humor, wit, and cleverness.\nKeep the mood fun and engaging, but avoid inappropriate or offensive jokes.\n</TONE>", "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>", "\n<FORMAT>\nUse Markdown for clear, structured responses.\nEmploy headings, lists, bold/italic text, and code blocks to improve readability.\n</FORMAT>", "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>", "\n<AGENT_SKILL>\nYou excel at brainstorming, generating novel ideas, and thinking outside the box.\n</AGENT_SKILL>"];
|
|
13
|
+
/**
|
|
14
|
+
* A friendly and empathetic support agent for general queries.
|
|
15
|
+
*/
|
|
16
|
+
readonly EMPATHETIC_SUPPORT_AGENT: readonly ["\n<DIRECTIVE>\nDo not provide instructions or information that is illegal, dangerous, or harmful.\nRefuse to engage with requests that could cause real-world harm.\nPrioritize user safety and well-being in all responses.\n</DIRECTIVE>", "\n<DIRECTIVE>\nAdhere to the highest ethical standards. Do not promote hate speech, discrimination, or violence.\nRespect user privacy and do not ask for or store personally identifiable information.\n</DIRECTIVE>", "\n<PERSONA>\nYou are a friendly and empathetic support agent.\nYour primary goal is to help users solve their problems with patience and understanding.\nYou are a good listener and provide clear, step-by-step assistance.\n</PERSONA>", "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>", "\n<TONE>\nAdopt a warm, understanding, and supportive tone.\nAcknowledge the user's feelings and show you are listening.\n</TONE>", "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>", "\n<FORMAT>\nBreak down instructions or processes into a clear, numbered, step-by-step list.\nEnsure each step is a distinct, actionable item.\n</FORMAT>", "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>", "\n<AGENT_SKILL>\nYou are skilled at analyzing complex problems, breaking them down into manageable parts, and proposing systematic solutions.\n</AGENT_SKILL>"];
|
|
17
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DOMAIN } from './categories/domain.js';
|
|
2
|
+
import { AGENT_LOGIC } from './categories/agent-logic.js';
|
|
3
|
+
import { AGENT_SKILLS } from './categories/agent-skills.js';
|
|
4
|
+
import { DIRECTIVES } from './categories/directives.js';
|
|
5
|
+
import { FORMAT } from './categories/format.js';
|
|
6
|
+
import { PERSONA } from './categories/persona.js';
|
|
7
|
+
import { TONE } from './categories/tone.js';
|
|
8
|
+
import { VERBOSITY } from './categories/verbosity.js';
|
|
9
|
+
/**
|
|
10
|
+
* Provides ready-to-use combinations of prompt parts for common use cases.
|
|
11
|
+
*/ export var PRESETS = {
|
|
12
|
+
/**
|
|
13
|
+
* A creative partner for brainstorming and ideation.
|
|
14
|
+
*/ CREATIVE_BRAINSTORMER: [
|
|
15
|
+
DIRECTIVES.BE_ETHICAL,
|
|
16
|
+
PERSONA.CREATIVE_PARTNER,
|
|
17
|
+
DOMAIN.GENERAL,
|
|
18
|
+
TONE.HUMOROUS,
|
|
19
|
+
VERBOSITY.NORMAL,
|
|
20
|
+
FORMAT.MARKDOWN,
|
|
21
|
+
AGENT_LOGIC.ALWAYS_RESPOND,
|
|
22
|
+
AGENT_SKILLS.CREATIVE_IDEATION
|
|
23
|
+
],
|
|
24
|
+
/**
|
|
25
|
+
* A fun and engaging community animator for platforms like Discord.
|
|
26
|
+
*/ DISCORD_COMMUNITY_ANIMATOR: [
|
|
27
|
+
DIRECTIVES.BE_SAFE,
|
|
28
|
+
PERSONA.COMMUNITY_ANIMATOR,
|
|
29
|
+
DOMAIN.GENERAL,
|
|
30
|
+
TONE.HUMOROUS,
|
|
31
|
+
VERBOSITY.NORMAL,
|
|
32
|
+
FORMAT.MARKDOWN,
|
|
33
|
+
AGENT_LOGIC.ALWAYS_RESPOND,
|
|
34
|
+
AGENT_SKILLS.CREATIVE_IDEATION
|
|
35
|
+
],
|
|
36
|
+
/**
|
|
37
|
+
* A friendly and empathetic support agent for general queries.
|
|
38
|
+
*/ EMPATHETIC_SUPPORT_AGENT: [
|
|
39
|
+
DIRECTIVES.BE_SAFE,
|
|
40
|
+
DIRECTIVES.BE_ETHICAL,
|
|
41
|
+
PERSONA.SUPPORT_AGENT,
|
|
42
|
+
DOMAIN.GENERAL,
|
|
43
|
+
TONE.EMPATHETIC,
|
|
44
|
+
VERBOSITY.NORMAL,
|
|
45
|
+
FORMAT.STEP_BY_STEP,
|
|
46
|
+
AGENT_LOGIC.ALWAYS_RESPOND,
|
|
47
|
+
AGENT_SKILLS.PROBLEM_SOLVING
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=presets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/adapters/prompts/library/presets.ts"],"sourcesContent":["import { DOMAIN } from './categories/domain.js';\n\nimport { AGENT_LOGIC } from './categories/agent-logic.js';\nimport { AGENT_SKILLS } from './categories/agent-skills.js';\nimport { DIRECTIVES } from './categories/directives.js';\nimport { FORMAT } from './categories/format.js';\nimport { PERSONA } from './categories/persona.js';\nimport { TONE } from './categories/tone.js';\nimport { VERBOSITY } from './categories/verbosity.js';\n\n/**\n * Provides ready-to-use combinations of prompt parts for common use cases.\n */\nexport const PRESETS = {\n /**\n * A creative partner for brainstorming and ideation.\n */\n CREATIVE_BRAINSTORMER: [\n DIRECTIVES.BE_ETHICAL,\n PERSONA.CREATIVE_PARTNER,\n DOMAIN.GENERAL,\n TONE.HUMOROUS,\n VERBOSITY.NORMAL,\n FORMAT.MARKDOWN,\n AGENT_LOGIC.ALWAYS_RESPOND,\n AGENT_SKILLS.CREATIVE_IDEATION,\n ],\n\n /**\n * A fun and engaging community animator for platforms like Discord.\n */\n DISCORD_COMMUNITY_ANIMATOR: [\n DIRECTIVES.BE_SAFE,\n PERSONA.COMMUNITY_ANIMATOR,\n DOMAIN.GENERAL,\n TONE.HUMOROUS,\n VERBOSITY.NORMAL,\n FORMAT.MARKDOWN,\n AGENT_LOGIC.ALWAYS_RESPOND,\n AGENT_SKILLS.CREATIVE_IDEATION,\n ],\n\n /**\n * A friendly and empathetic support agent for general queries.\n */\n EMPATHETIC_SUPPORT_AGENT: [\n DIRECTIVES.BE_SAFE,\n DIRECTIVES.BE_ETHICAL,\n PERSONA.SUPPORT_AGENT,\n DOMAIN.GENERAL,\n TONE.EMPATHETIC,\n VERBOSITY.NORMAL,\n FORMAT.STEP_BY_STEP,\n AGENT_LOGIC.ALWAYS_RESPOND,\n AGENT_SKILLS.PROBLEM_SOLVING,\n ],\n} as const;\n"],"names":["DOMAIN","AGENT_LOGIC","AGENT_SKILLS","DIRECTIVES","FORMAT","PERSONA","TONE","VERBOSITY","PRESETS","CREATIVE_BRAINSTORMER","BE_ETHICAL","CREATIVE_PARTNER","GENERAL","HUMOROUS","NORMAL","MARKDOWN","ALWAYS_RESPOND","CREATIVE_IDEATION","DISCORD_COMMUNITY_ANIMATOR","BE_SAFE","COMMUNITY_ANIMATOR","EMPATHETIC_SUPPORT_AGENT","SUPPORT_AGENT","EMPATHETIC","STEP_BY_STEP","PROBLEM_SOLVING"],"mappings":"AAAA,SAASA,MAAM,QAAQ,yBAAyB;AAEhD,SAASC,WAAW,QAAQ,8BAA8B;AAC1D,SAASC,YAAY,QAAQ,+BAA+B;AAC5D,SAASC,UAAU,QAAQ,6BAA6B;AACxD,SAASC,MAAM,QAAQ,yBAAyB;AAChD,SAASC,OAAO,QAAQ,0BAA0B;AAClD,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,SAASC,SAAS,QAAQ,4BAA4B;AAEtD;;CAEC,GACD,OAAO,IAAMC,UAAU;IACnB;;KAEC,GACDC,uBAAuB;QACnBN,WAAWO,UAAU;QACrBL,QAAQM,gBAAgB;QACxBX,OAAOY,OAAO;QACdN,KAAKO,QAAQ;QACbN,UAAUO,MAAM;QAChBV,OAAOW,QAAQ;QACfd,YAAYe,cAAc;QAC1Bd,aAAae,iBAAiB;KACjC;IAED;;KAEC,GACDC,4BAA4B;QACxBf,WAAWgB,OAAO;QAClBd,QAAQe,kBAAkB;QAC1BpB,OAAOY,OAAO;QACdN,KAAKO,QAAQ;QACbN,UAAUO,MAAM;QAChBV,OAAOW,QAAQ;QACfd,YAAYe,cAAc;QAC1Bd,aAAae,iBAAiB;KACjC;IAED;;KAEC,GACDI,0BAA0B;QACtBlB,WAAWgB,OAAO;QAClBhB,WAAWO,UAAU;QACrBL,QAAQiB,aAAa;QACrBtB,OAAOY,OAAO;QACdN,KAAKiB,UAAU;QACfhB,UAAUO,MAAM;QAChBV,OAAOoB,YAAY;QACnBvB,YAAYe,cAAc;QAC1Bd,aAAauB,eAAe;KAC/B;AACL,EAAW"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Prompt } from '../../ports/prompt.port.js';
|
|
2
|
+
/**
|
|
3
|
+
* System prompt adapter that generates a system prompt from a list of strings
|
|
4
|
+
*/
|
|
5
|
+
export declare class SystemPromptAdapter implements Prompt {
|
|
6
|
+
private readonly finalPrompt;
|
|
7
|
+
constructor(...prompts: readonly (readonly string[] | string)[]);
|
|
8
|
+
generate(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* System prompt adapter that generates a system prompt from a list of strings
|
|
35
|
+
*/ export var SystemPromptAdapter = /*#__PURE__*/ function() {
|
|
36
|
+
"use strict";
|
|
37
|
+
function SystemPromptAdapter() {
|
|
38
|
+
for(var _len = arguments.length, prompts = new Array(_len), _key = 0; _key < _len; _key++){
|
|
39
|
+
prompts[_key] = arguments[_key];
|
|
40
|
+
}
|
|
41
|
+
_class_call_check(this, SystemPromptAdapter);
|
|
42
|
+
_define_property(this, "finalPrompt", void 0);
|
|
43
|
+
var flattenedPrompts = prompts.flat();
|
|
44
|
+
this.finalPrompt = flattenedPrompts.join('\n\n');
|
|
45
|
+
}
|
|
46
|
+
_create_class(SystemPromptAdapter, [
|
|
47
|
+
{
|
|
48
|
+
key: "generate",
|
|
49
|
+
value: function generate() {
|
|
50
|
+
return this.finalPrompt;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]);
|
|
54
|
+
return SystemPromptAdapter;
|
|
55
|
+
}();
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=system-prompt.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/prompts/system-prompt.adapter.ts"],"sourcesContent":["import type { Prompt } from '../../ports/prompt.port.js';\n\n/**\n * System prompt adapter that generates a system prompt from a list of strings\n */\nexport class SystemPromptAdapter implements Prompt {\n private readonly finalPrompt: string;\n\n constructor(...prompts: readonly (readonly string[] | string)[]) {\n const flattenedPrompts = prompts.flat();\n this.finalPrompt = flattenedPrompts.join('\\n\\n');\n }\n\n generate(): string {\n return this.finalPrompt;\n }\n}\n"],"names":["SystemPromptAdapter","prompts","finalPrompt","flattenedPrompts","flat","join","generate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;CAEC,GACD,OAAO,IAAA,AAAMA,oCAAN;;aAAMA;QAGG,IAAA,IAAA,OAAA,UAAA,QAAA,AAAGC,UAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA;YAAGA,QAAH,QAAA,SAAA,CAAA,KAAmD;;gCAHtDD;QACT,uBAAiBE,eAAjB,KAAA;QAGI,IAAMC,mBAAmBF,QAAQG,IAAI;QACrC,IAAI,CAACF,WAAW,GAAGC,iBAAiBE,IAAI,CAAC;;kBALpCL;;YAQTM,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,CAACJ,WAAW;YAC3B;;;WAVSF;IAWZ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Prompt } from '../../ports/prompt.port.js';
|
|
2
|
+
/**
|
|
3
|
+
* User prompt adapter that generates a user prompt from a list of strings
|
|
4
|
+
*/
|
|
5
|
+
export declare class UserPromptAdapter implements Prompt {
|
|
6
|
+
private readonly finalPrompt;
|
|
7
|
+
constructor(...prompts: readonly (readonly string[] | string)[]);
|
|
8
|
+
generate(): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* User prompt adapter that generates a user prompt from a list of strings
|
|
35
|
+
*/ export var UserPromptAdapter = /*#__PURE__*/ function() {
|
|
36
|
+
"use strict";
|
|
37
|
+
function UserPromptAdapter() {
|
|
38
|
+
for(var _len = arguments.length, prompts = new Array(_len), _key = 0; _key < _len; _key++){
|
|
39
|
+
prompts[_key] = arguments[_key];
|
|
40
|
+
}
|
|
41
|
+
_class_call_check(this, UserPromptAdapter);
|
|
42
|
+
_define_property(this, "finalPrompt", void 0);
|
|
43
|
+
var flattenedPrompts = prompts.flat();
|
|
44
|
+
this.finalPrompt = flattenedPrompts.join('\n\n');
|
|
45
|
+
}
|
|
46
|
+
_create_class(UserPromptAdapter, [
|
|
47
|
+
{
|
|
48
|
+
key: "generate",
|
|
49
|
+
value: function generate() {
|
|
50
|
+
return this.finalPrompt;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]);
|
|
54
|
+
return UserPromptAdapter;
|
|
55
|
+
}();
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=user-prompt.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/prompts/user-prompt.adapter.ts"],"sourcesContent":["import type { Prompt } from '../../ports/prompt.port.js';\n\n/**\n * User prompt adapter that generates a user prompt from a list of strings\n */\nexport class UserPromptAdapter implements Prompt {\n private readonly finalPrompt: string;\n\n constructor(...prompts: readonly (readonly string[] | string)[]) {\n const flattenedPrompts = prompts.flat();\n this.finalPrompt = flattenedPrompts.join('\\n\\n');\n }\n\n generate(): string {\n return this.finalPrompt;\n }\n}\n"],"names":["UserPromptAdapter","prompts","finalPrompt","flattenedPrompts","flat","join","generate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;CAEC,GACD,OAAO,IAAA,AAAMA,kCAAN;;aAAMA;QAGG,IAAA,IAAA,OAAA,UAAA,QAAA,AAAGC,UAAH,UAAA,OAAA,OAAA,GAAA,OAAA,MAAA;YAAGA,QAAH,QAAA,SAAA,CAAA,KAAmD;;gCAHtDD;QACT,uBAAiBE,eAAjB,KAAA;QAGI,IAAMC,mBAAmBF,QAAQG,IAAI;QACrC,IAAI,CAACF,WAAW,GAAGC,iBAAiBE,IAAI,CAAC;;kBALpCL;;YAQTM,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,CAACJ,WAAW;YAC3B;;;WAVSF;IAWZ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LoggerPort } from '@jterrazz/logger';
|
|
2
|
+
import { DynamicStructuredTool, DynamicTool } from 'langchain/tools';
|
|
3
|
+
import type { z } from 'zod/v4';
|
|
4
|
+
import type { Tool } from '../../ports/tool.port.js';
|
|
5
|
+
export interface SafeToolOptions<T> {
|
|
6
|
+
logger?: LoggerPort;
|
|
7
|
+
schema?: z.ZodSchema<T>;
|
|
8
|
+
}
|
|
9
|
+
export type ToolConfig<T = void> = {
|
|
10
|
+
description: string;
|
|
11
|
+
execute: ToolFunction<T>;
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
export type ToolFunction<T = void> = T extends void ? () => Promise<string> : (args: T) => Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Safe tool adapter that provides error handling and logging for LangChain tools
|
|
17
|
+
*/
|
|
18
|
+
export declare class SafeToolAdapter<T = void> implements Tool {
|
|
19
|
+
private readonly config;
|
|
20
|
+
private readonly options;
|
|
21
|
+
private readonly dynamicTool;
|
|
22
|
+
constructor(config: ToolConfig<T>, options?: SafeToolOptions<T>);
|
|
23
|
+
/**
|
|
24
|
+
* Get the underlying LangChain DynamicTool instance
|
|
25
|
+
*/
|
|
26
|
+
getDynamicTool(): DynamicStructuredTool<z.ZodSchema<unknown>> | DynamicTool;
|
|
27
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _class_call_check(instance, Constructor) {
|
|
31
|
+
if (!(instance instanceof Constructor)) {
|
|
32
|
+
throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for(var i = 0; i < props.length; i++){
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
45
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
46
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
47
|
+
return Constructor;
|
|
48
|
+
}
|
|
49
|
+
function _define_property(obj, key, value) {
|
|
50
|
+
if (key in obj) {
|
|
51
|
+
Object.defineProperty(obj, key, {
|
|
52
|
+
value: value,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
obj[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
function _instanceof(left, right) {
|
|
63
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
64
|
+
return !!right[Symbol.hasInstance](left);
|
|
65
|
+
} else {
|
|
66
|
+
return left instanceof right;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function _ts_generator(thisArg, body) {
|
|
70
|
+
var f, y, t, _ = {
|
|
71
|
+
label: 0,
|
|
72
|
+
sent: function() {
|
|
73
|
+
if (t[0] & 1) throw t[1];
|
|
74
|
+
return t[1];
|
|
75
|
+
},
|
|
76
|
+
trys: [],
|
|
77
|
+
ops: []
|
|
78
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
79
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
80
|
+
return this;
|
|
81
|
+
}), g;
|
|
82
|
+
function verb(n) {
|
|
83
|
+
return function(v) {
|
|
84
|
+
return step([
|
|
85
|
+
n,
|
|
86
|
+
v
|
|
87
|
+
]);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function step(op) {
|
|
91
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
92
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
93
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
94
|
+
if (y = 0, t) op = [
|
|
95
|
+
op[0] & 2,
|
|
96
|
+
t.value
|
|
97
|
+
];
|
|
98
|
+
switch(op[0]){
|
|
99
|
+
case 0:
|
|
100
|
+
case 1:
|
|
101
|
+
t = op;
|
|
102
|
+
break;
|
|
103
|
+
case 4:
|
|
104
|
+
_.label++;
|
|
105
|
+
return {
|
|
106
|
+
value: op[1],
|
|
107
|
+
done: false
|
|
108
|
+
};
|
|
109
|
+
case 5:
|
|
110
|
+
_.label++;
|
|
111
|
+
y = op[1];
|
|
112
|
+
op = [
|
|
113
|
+
0
|
|
114
|
+
];
|
|
115
|
+
continue;
|
|
116
|
+
case 7:
|
|
117
|
+
op = _.ops.pop();
|
|
118
|
+
_.trys.pop();
|
|
119
|
+
continue;
|
|
120
|
+
default:
|
|
121
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
122
|
+
_ = 0;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
126
|
+
_.label = op[1];
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
130
|
+
_.label = t[1];
|
|
131
|
+
t = op;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
if (t && _.label < t[2]) {
|
|
135
|
+
_.label = t[2];
|
|
136
|
+
_.ops.push(op);
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (t[2]) _.ops.pop();
|
|
140
|
+
_.trys.pop();
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
op = body.call(thisArg, _);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
op = [
|
|
146
|
+
6,
|
|
147
|
+
e
|
|
148
|
+
];
|
|
149
|
+
y = 0;
|
|
150
|
+
} finally{
|
|
151
|
+
f = t = 0;
|
|
152
|
+
}
|
|
153
|
+
if (op[0] & 5) throw op[1];
|
|
154
|
+
return {
|
|
155
|
+
value: op[0] ? op[1] : void 0,
|
|
156
|
+
done: true
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
import { DynamicStructuredTool, DynamicTool } from 'langchain/tools';
|
|
161
|
+
/**
|
|
162
|
+
* Safe tool adapter that provides error handling and logging for LangChain tools
|
|
163
|
+
*/ export var SafeToolAdapter = /*#__PURE__*/ function() {
|
|
164
|
+
"use strict";
|
|
165
|
+
function SafeToolAdapter(config) {
|
|
166
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
167
|
+
_class_call_check(this, SafeToolAdapter);
|
|
168
|
+
_define_property(this, "config", void 0);
|
|
169
|
+
_define_property(this, "options", void 0);
|
|
170
|
+
_define_property(this, "dynamicTool", void 0);
|
|
171
|
+
this.config = config;
|
|
172
|
+
this.options = options;
|
|
173
|
+
var logger = options.logger, schema = options.schema;
|
|
174
|
+
if (schema) {
|
|
175
|
+
// Use DynamicStructuredTool for parameterized tools
|
|
176
|
+
this.dynamicTool = new DynamicStructuredTool({
|
|
177
|
+
description: config.description,
|
|
178
|
+
func: function(args) {
|
|
179
|
+
return _async_to_generator(function() {
|
|
180
|
+
var error, errorMessage;
|
|
181
|
+
return _ts_generator(this, function(_state) {
|
|
182
|
+
switch(_state.label){
|
|
183
|
+
case 0:
|
|
184
|
+
_state.trys.push([
|
|
185
|
+
0,
|
|
186
|
+
2,
|
|
187
|
+
,
|
|
188
|
+
3
|
|
189
|
+
]);
|
|
190
|
+
return [
|
|
191
|
+
4,
|
|
192
|
+
config.execute(args)
|
|
193
|
+
];
|
|
194
|
+
case 1:
|
|
195
|
+
return [
|
|
196
|
+
2,
|
|
197
|
+
_state.sent()
|
|
198
|
+
];
|
|
199
|
+
case 2:
|
|
200
|
+
error = _state.sent();
|
|
201
|
+
errorMessage = _instanceof(error, Error) ? error.message : String(error);
|
|
202
|
+
logger === null || logger === void 0 ? void 0 : logger.error("Unexpected error in ".concat(config.name), {
|
|
203
|
+
args: args,
|
|
204
|
+
error: errorMessage,
|
|
205
|
+
toolName: config.name
|
|
206
|
+
});
|
|
207
|
+
return [
|
|
208
|
+
2,
|
|
209
|
+
"Tool ".concat(config.name, " failed to execute")
|
|
210
|
+
];
|
|
211
|
+
case 3:
|
|
212
|
+
return [
|
|
213
|
+
2
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
})();
|
|
218
|
+
},
|
|
219
|
+
name: config.name,
|
|
220
|
+
schema: schema
|
|
221
|
+
});
|
|
222
|
+
} else {
|
|
223
|
+
// Use DynamicTool for simple tools
|
|
224
|
+
this.dynamicTool = new DynamicTool({
|
|
225
|
+
description: config.description,
|
|
226
|
+
func: function() {
|
|
227
|
+
return _async_to_generator(function() {
|
|
228
|
+
var error, errorMessage;
|
|
229
|
+
return _ts_generator(this, function(_state) {
|
|
230
|
+
switch(_state.label){
|
|
231
|
+
case 0:
|
|
232
|
+
_state.trys.push([
|
|
233
|
+
0,
|
|
234
|
+
2,
|
|
235
|
+
,
|
|
236
|
+
3
|
|
237
|
+
]);
|
|
238
|
+
return [
|
|
239
|
+
4,
|
|
240
|
+
config.execute()
|
|
241
|
+
];
|
|
242
|
+
case 1:
|
|
243
|
+
return [
|
|
244
|
+
2,
|
|
245
|
+
_state.sent()
|
|
246
|
+
];
|
|
247
|
+
case 2:
|
|
248
|
+
error = _state.sent();
|
|
249
|
+
errorMessage = _instanceof(error, Error) ? error.message : String(error);
|
|
250
|
+
logger === null || logger === void 0 ? void 0 : logger.error("Unexpected error in ".concat(config.name), {
|
|
251
|
+
error: errorMessage,
|
|
252
|
+
toolName: config.name
|
|
253
|
+
});
|
|
254
|
+
return [
|
|
255
|
+
2,
|
|
256
|
+
"Tool ".concat(config.name, " failed to execute")
|
|
257
|
+
];
|
|
258
|
+
case 3:
|
|
259
|
+
return [
|
|
260
|
+
2
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
})();
|
|
265
|
+
},
|
|
266
|
+
name: config.name
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
_create_class(SafeToolAdapter, [
|
|
271
|
+
{
|
|
272
|
+
/**
|
|
273
|
+
* Get the underlying LangChain DynamicTool instance
|
|
274
|
+
*/ key: "getDynamicTool",
|
|
275
|
+
value: function getDynamicTool() {
|
|
276
|
+
return this.dynamicTool;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
]);
|
|
280
|
+
return SafeToolAdapter;
|
|
281
|
+
}();
|
|
282
|
+
|
|
283
|
+
//# sourceMappingURL=safe-tool.adapter.js.map
|