hazo_llm_api 1.0.4 → 1.0.6
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/components/index.d.ts +7 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +7 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/layout/index.d.ts +7 -0
- package/dist/components/layout/index.d.ts.map +1 -0
- package/dist/components/layout/index.js +7 -0
- package/dist/components/layout/index.js.map +1 -0
- package/dist/components/layout/layout.d.ts +21 -0
- package/dist/components/layout/layout.d.ts.map +1 -0
- package/dist/components/layout/layout.js +18 -0
- package/dist/components/layout/layout.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config/config_parser.d.ts +131 -0
- package/dist/lib/config/config_parser.d.ts.map +1 -0
- package/dist/lib/config/config_parser.js +297 -0
- package/dist/lib/config/config_parser.js.map +1 -0
- package/dist/lib/config/index.d.ts +8 -0
- package/dist/lib/config/index.d.ts.map +1 -0
- package/dist/lib/config/index.js +22 -0
- package/dist/lib/config/index.js.map +1 -0
- package/dist/lib/config/provider_loader.d.ts +113 -0
- package/dist/lib/config/provider_loader.d.ts.map +1 -0
- package/dist/lib/config/provider_loader.js +169 -0
- package/dist/lib/config/provider_loader.js.map +1 -0
- package/dist/lib/database/index.d.ts +8 -0
- package/dist/lib/database/index.d.ts.map +1 -0
- package/dist/lib/database/index.js +10 -0
- package/dist/lib/database/index.js.map +1 -0
- package/dist/lib/database/init_database.d.ts +118 -0
- package/dist/lib/database/init_database.d.ts.map +1 -0
- package/dist/lib/database/init_database.js +591 -0
- package/dist/lib/database/init_database.js.map +1 -0
- package/dist/lib/database/utils.d.ts +53 -0
- package/dist/lib/database/utils.d.ts.map +1 -0
- package/dist/lib/database/utils.js +87 -0
- package/dist/lib/database/utils.js.map +1 -0
- package/dist/lib/index.d.ts +14 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +17 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/llm_api/chain_helpers.d.ts +117 -0
- package/dist/lib/llm_api/chain_helpers.d.ts.map +1 -0
- package/dist/lib/llm_api/chain_helpers.js +445 -0
- package/dist/lib/llm_api/chain_helpers.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_image.d.ts +26 -0
- package/dist/lib/llm_api/hazo_llm_image_image.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_image.js +94 -0
- package/dist/lib/llm_api/hazo_llm_image_image.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.d.ts +26 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.js +222 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_text.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_image_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_text.js +78 -0
- package/dist/lib/llm_api/hazo_llm_image_text.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.js +368 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_image.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_text_image.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_image.js +69 -0
- package/dist/lib/llm_api/hazo_llm_text_image.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.d.ts +26 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.js +154 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_text.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_text_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_text.js +91 -0
- package/dist/lib/llm_api/hazo_llm_text_text.js.map +1 -0
- package/dist/lib/llm_api/index.d.ts +223 -0
- package/dist/lib/llm_api/index.d.ts.map +1 -0
- package/dist/lib/llm_api/index.js +1220 -0
- package/dist/lib/llm_api/index.js.map +1 -0
- package/dist/lib/llm_api/provider_helper.d.ts +163 -0
- package/dist/lib/llm_api/provider_helper.d.ts.map +1 -0
- package/dist/lib/llm_api/provider_helper.js +346 -0
- package/dist/lib/llm_api/provider_helper.js.map +1 -0
- package/dist/lib/llm_api/types.d.ts +667 -0
- package/dist/lib/llm_api/types.d.ts.map +1 -0
- package/dist/lib/llm_api/types.js +49 -0
- package/dist/lib/llm_api/types.js.map +1 -0
- package/dist/lib/prompts/get_prompt.d.ts +76 -0
- package/dist/lib/prompts/get_prompt.d.ts.map +1 -0
- package/dist/lib/prompts/get_prompt.js +342 -0
- package/dist/lib/prompts/get_prompt.js.map +1 -0
- package/dist/lib/prompts/index.d.ts +9 -0
- package/dist/lib/prompts/index.d.ts.map +1 -0
- package/dist/lib/prompts/index.js +9 -0
- package/dist/lib/prompts/index.js.map +1 -0
- package/dist/lib/prompts/prompt_cache.d.ts +151 -0
- package/dist/lib/prompts/prompt_cache.d.ts.map +1 -0
- package/dist/lib/prompts/prompt_cache.js +276 -0
- package/dist/lib/prompts/prompt_cache.js.map +1 -0
- package/dist/lib/prompts/substitute_variables.d.ts +38 -0
- package/dist/lib/prompts/substitute_variables.d.ts.map +1 -0
- package/dist/lib/prompts/substitute_variables.js +171 -0
- package/dist/lib/prompts/substitute_variables.js.map +1 -0
- package/dist/lib/providers/gemini/gemini_client.d.ts +25 -0
- package/dist/lib/providers/gemini/gemini_client.d.ts.map +1 -0
- package/dist/lib/providers/gemini/gemini_client.js +235 -0
- package/dist/lib/providers/gemini/gemini_client.js.map +1 -0
- package/dist/lib/providers/gemini/gemini_provider.d.ts +111 -0
- package/dist/lib/providers/gemini/gemini_provider.d.ts.map +1 -0
- package/dist/lib/providers/gemini/gemini_provider.js +431 -0
- package/dist/lib/providers/gemini/gemini_provider.js.map +1 -0
- package/dist/lib/providers/gemini/index.d.ts +8 -0
- package/dist/lib/providers/gemini/index.d.ts.map +1 -0
- package/dist/lib/providers/gemini/index.js +8 -0
- package/dist/lib/providers/gemini/index.js.map +1 -0
- package/dist/lib/providers/index.d.ts +8 -0
- package/dist/lib/providers/index.d.ts.map +1 -0
- package/dist/lib/providers/index.js +8 -0
- package/dist/lib/providers/index.js.map +1 -0
- package/dist/lib/providers/qwen/index.d.ts +8 -0
- package/dist/lib/providers/qwen/index.d.ts.map +1 -0
- package/dist/lib/providers/qwen/index.js +8 -0
- package/dist/lib/providers/qwen/index.js.map +1 -0
- package/dist/lib/providers/qwen/qwen_client.d.ts +154 -0
- package/dist/lib/providers/qwen/qwen_client.d.ts.map +1 -0
- package/dist/lib/providers/qwen/qwen_client.js +1002 -0
- package/dist/lib/providers/qwen/qwen_client.js.map +1 -0
- package/dist/lib/providers/qwen/qwen_provider.d.ts +139 -0
- package/dist/lib/providers/qwen/qwen_provider.d.ts.map +1 -0
- package/dist/lib/providers/qwen/qwen_provider.js +304 -0
- package/dist/lib/providers/qwen/qwen_provider.js.map +1 -0
- package/dist/lib/providers/registry.d.ts +66 -0
- package/dist/lib/providers/registry.d.ts.map +1 -0
- package/dist/lib/providers/registry.js +158 -0
- package/dist/lib/providers/registry.js.map +1 -0
- package/dist/lib/providers/types.d.ts +145 -0
- package/dist/lib/providers/types.d.ts.map +1 -0
- package/dist/lib/providers/types.js +37 -0
- package/dist/lib/providers/types.js.map +1 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +50 -0
- package/dist/server.js.map +1 -0
- package/package.json +12 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM API Types
|
|
3
|
+
*
|
|
4
|
+
* TypeScript interfaces and types for the LLM API module.
|
|
5
|
+
* Includes configuration, function parameters, and response types.
|
|
6
|
+
*/
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// LLM Error Types
|
|
9
|
+
// =============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Error codes for LLM API errors
|
|
12
|
+
* Use these codes for programmatic error handling
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { LLM_ERROR_CODES } from 'hazo_llm_api/server';
|
|
17
|
+
*
|
|
18
|
+
* if (response.error_info?.code === LLM_ERROR_CODES.RATE_LIMITED) {
|
|
19
|
+
* // Implement retry logic
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const LLM_ERROR_CODES = {
|
|
24
|
+
/** Provider not found in registry */
|
|
25
|
+
PROVIDER_NOT_FOUND: 'PROVIDER_NOT_FOUND',
|
|
26
|
+
/** Provider is not enabled in configuration */
|
|
27
|
+
PROVIDER_NOT_ENABLED: 'PROVIDER_NOT_ENABLED',
|
|
28
|
+
/** Provider does not support the requested service type */
|
|
29
|
+
CAPABILITY_NOT_SUPPORTED: 'CAPABILITY_NOT_SUPPORTED',
|
|
30
|
+
/** API key is missing or invalid */
|
|
31
|
+
API_KEY_MISSING: 'API_KEY_MISSING',
|
|
32
|
+
/** Rate limit exceeded */
|
|
33
|
+
RATE_LIMITED: 'RATE_LIMITED',
|
|
34
|
+
/** Network error (connection failed, timeout, etc.) */
|
|
35
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
36
|
+
/** Invalid request parameters */
|
|
37
|
+
INVALID_REQUEST: 'INVALID_REQUEST',
|
|
38
|
+
/** API returned an error */
|
|
39
|
+
API_ERROR: 'API_ERROR',
|
|
40
|
+
/** Request timed out */
|
|
41
|
+
TIMEOUT: 'TIMEOUT',
|
|
42
|
+
/** Database error */
|
|
43
|
+
DATABASE_ERROR: 'DATABASE_ERROR',
|
|
44
|
+
/** Prompt not found */
|
|
45
|
+
PROMPT_NOT_FOUND: 'PROMPT_NOT_FOUND',
|
|
46
|
+
/** Unknown/unexpected error */
|
|
47
|
+
UNKNOWN: 'UNKNOWN',
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/llm_api/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsTH,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,qCAAqC;IACrC,kBAAkB,EAAE,oBAAoB;IACxC,+CAA+C;IAC/C,oBAAoB,EAAE,sBAAsB;IAC5C,2DAA2D;IAC3D,wBAAwB,EAAE,0BAA0B;IACpD,oCAAoC;IACpC,eAAe,EAAE,iBAAiB;IAClC,0BAA0B;IAC1B,YAAY,EAAE,cAAc;IAC5B,uDAAuD;IACvD,aAAa,EAAE,eAAe;IAC9B,iCAAiC;IACjC,eAAe,EAAE,iBAAiB;IAClC,4BAA4B;IAC5B,SAAS,EAAE,WAAW;IACtB,wBAAwB;IACxB,OAAO,EAAE,SAAS;IAClB,qBAAqB;IACrB,cAAc,EAAE,gBAAgB;IAChC,uBAAuB;IACvB,gBAAgB,EAAE,kBAAkB;IACpC,+BAA+B;IAC/B,OAAO,EAAE,SAAS;CACV,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Retrieval Module
|
|
3
|
+
*
|
|
4
|
+
* Functions to retrieve prompts from the prompts_library database table.
|
|
5
|
+
* Searches by prompt_area, prompt_key, and optional local filters.
|
|
6
|
+
*/
|
|
7
|
+
import type { Database as SqlJsDatabase } from 'sql.js';
|
|
8
|
+
import type { Logger, PromptRecord } from '../llm_api/types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Options for local filter fields when retrieving prompts
|
|
11
|
+
*/
|
|
12
|
+
export interface LocalFilterOptions {
|
|
13
|
+
local_1?: string | null;
|
|
14
|
+
local_2?: string | null;
|
|
15
|
+
local_3?: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve a prompt from the database by prompt_area and prompt_key
|
|
19
|
+
* @param db - Database instance
|
|
20
|
+
* @param prompt_area - Area/category of the prompt
|
|
21
|
+
* @param prompt_key - Key identifier for the prompt
|
|
22
|
+
* @param logger - Logger instance
|
|
23
|
+
* @returns The prompt record if found, null otherwise
|
|
24
|
+
*/
|
|
25
|
+
export declare function get_prompt_by_area_and_key(db: SqlJsDatabase, prompt_area: string, prompt_key: string, logger: Logger): PromptRecord | null;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve a prompt from the database by prompt_area, prompt_key, and optional local filters
|
|
28
|
+
* Uses fallback logic: tries most specific match first, then progressively less specific
|
|
29
|
+
*
|
|
30
|
+
* Fallback order:
|
|
31
|
+
* 1. Exact match with all specified local filters
|
|
32
|
+
* 2. Match with local_1 and local_2 only (if local_3 was specified)
|
|
33
|
+
* 3. Match with local_1 only (if local_2 was specified)
|
|
34
|
+
* 4. Match with no local filters (base prompt)
|
|
35
|
+
*
|
|
36
|
+
* @param db - Database instance
|
|
37
|
+
* @param prompt_area - Area/category of the prompt
|
|
38
|
+
* @param prompt_key - Key identifier for the prompt
|
|
39
|
+
* @param locals - Optional local filter values
|
|
40
|
+
* @param logger - Logger instance
|
|
41
|
+
* @returns The prompt record if found, null otherwise
|
|
42
|
+
*/
|
|
43
|
+
export declare function get_prompt_by_area_key_and_locals(db: SqlJsDatabase, prompt_area: string, prompt_key: string, locals: LocalFilterOptions | null, logger: Logger): PromptRecord | null;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve the prompt text only by prompt_area and prompt_key
|
|
46
|
+
* @param db - Database instance
|
|
47
|
+
* @param prompt_area - Area/category of the prompt
|
|
48
|
+
* @param prompt_key - Key identifier for the prompt
|
|
49
|
+
* @param logger - Logger instance
|
|
50
|
+
* @returns The prompt text if found, null otherwise
|
|
51
|
+
*/
|
|
52
|
+
export declare function get_prompt_text(db: SqlJsDatabase, prompt_area: string, prompt_key: string, logger: Logger): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Get all prompts by prompt_area
|
|
55
|
+
* @param db - Database instance
|
|
56
|
+
* @param prompt_area - Area/category of the prompts
|
|
57
|
+
* @param logger - Logger instance
|
|
58
|
+
* @returns Array of prompt records
|
|
59
|
+
*/
|
|
60
|
+
export declare function get_prompts_by_area(db: SqlJsDatabase, prompt_area: string, logger: Logger): PromptRecord[];
|
|
61
|
+
/**
|
|
62
|
+
* Get a prompt by its UUID
|
|
63
|
+
* @param db - Database instance
|
|
64
|
+
* @param uuid - UUID of the prompt
|
|
65
|
+
* @param logger - Logger instance
|
|
66
|
+
* @returns The prompt record if found, null otherwise
|
|
67
|
+
*/
|
|
68
|
+
export declare function get_prompt_by_uuid(db: SqlJsDatabase, uuid: string, logger: Logger): PromptRecord | null;
|
|
69
|
+
/**
|
|
70
|
+
* Get all prompts from the library
|
|
71
|
+
* @param db - Database instance
|
|
72
|
+
* @param logger - Logger instance
|
|
73
|
+
* @returns Array of all prompt records
|
|
74
|
+
*/
|
|
75
|
+
export declare function get_all_prompts(db: SqlJsDatabase, logger: Logger): PromptRecord[];
|
|
76
|
+
//# sourceMappingURL=get_prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_prompt.d.ts","sourceRoot":"","sources":["../../../src/lib/prompts/get_prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOhE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAMD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,aAAa,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,YAAY,GAAG,IAAI,CAoDrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iCAAiC,CAC/C,EAAE,EAAE,aAAa,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,kBAAkB,GAAG,IAAI,EACjC,MAAM,EAAE,MAAM,GACb,YAAY,GAAG,IAAI,CAsGrB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,aAAa,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,IAAI,CAmBf;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,aAAa,EACjB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,GACb,YAAY,EAAE,CA8ChB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,aAAa,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,YAAY,GAAG,IAAI,CA8CrB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,aAAa,EACjB,MAAM,EAAE,MAAM,GACb,YAAY,EAAE,CA6ChB"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Retrieval Module
|
|
3
|
+
*
|
|
4
|
+
* Functions to retrieve prompts from the prompts_library database table.
|
|
5
|
+
* Searches by prompt_area, prompt_key, and optional local filters.
|
|
6
|
+
*/
|
|
7
|
+
import { row_to_prompt_record } from '../database/utils.js';
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Prompt Retrieval Functions
|
|
10
|
+
// =============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve a prompt from the database by prompt_area and prompt_key
|
|
13
|
+
* @param db - Database instance
|
|
14
|
+
* @param prompt_area - Area/category of the prompt
|
|
15
|
+
* @param prompt_key - Key identifier for the prompt
|
|
16
|
+
* @param logger - Logger instance
|
|
17
|
+
* @returns The prompt record if found, null otherwise
|
|
18
|
+
*/
|
|
19
|
+
export function get_prompt_by_area_and_key(db, prompt_area, prompt_key, logger) {
|
|
20
|
+
const file_name = 'get_prompt.ts';
|
|
21
|
+
const select_sql = `
|
|
22
|
+
SELECT * FROM prompts_library
|
|
23
|
+
WHERE prompt_area = ? AND prompt_key = ?
|
|
24
|
+
AND local_1 IS NULL AND local_2 IS NULL AND local_3 IS NULL
|
|
25
|
+
LIMIT 1
|
|
26
|
+
`;
|
|
27
|
+
try {
|
|
28
|
+
logger.debug('Retrieving prompt from database', {
|
|
29
|
+
file: file_name,
|
|
30
|
+
line: 62,
|
|
31
|
+
data: { prompt_area, prompt_key },
|
|
32
|
+
});
|
|
33
|
+
const result = db.exec(select_sql, [prompt_area, prompt_key]);
|
|
34
|
+
if (result.length === 0 || result[0].values.length === 0) {
|
|
35
|
+
logger.warn('Prompt not found in database', {
|
|
36
|
+
file: file_name,
|
|
37
|
+
line: 71,
|
|
38
|
+
data: { prompt_area, prompt_key },
|
|
39
|
+
});
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const row = result[0].values[0];
|
|
43
|
+
const columns = result[0].columns;
|
|
44
|
+
const record = row_to_prompt_record(row, columns);
|
|
45
|
+
logger.info('Prompt retrieved successfully', {
|
|
46
|
+
file: file_name,
|
|
47
|
+
line: 82,
|
|
48
|
+
data: {
|
|
49
|
+
uuid: record.uuid,
|
|
50
|
+
prompt_area: record.prompt_area,
|
|
51
|
+
prompt_key: record.prompt_key,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return record;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
58
|
+
logger.error('Failed to retrieve prompt from database', {
|
|
59
|
+
file: file_name,
|
|
60
|
+
line: 94,
|
|
61
|
+
data: { error: error_message, prompt_area, prompt_key },
|
|
62
|
+
});
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Retrieve a prompt from the database by prompt_area, prompt_key, and optional local filters
|
|
68
|
+
* Uses fallback logic: tries most specific match first, then progressively less specific
|
|
69
|
+
*
|
|
70
|
+
* Fallback order:
|
|
71
|
+
* 1. Exact match with all specified local filters
|
|
72
|
+
* 2. Match with local_1 and local_2 only (if local_3 was specified)
|
|
73
|
+
* 3. Match with local_1 only (if local_2 was specified)
|
|
74
|
+
* 4. Match with no local filters (base prompt)
|
|
75
|
+
*
|
|
76
|
+
* @param db - Database instance
|
|
77
|
+
* @param prompt_area - Area/category of the prompt
|
|
78
|
+
* @param prompt_key - Key identifier for the prompt
|
|
79
|
+
* @param locals - Optional local filter values
|
|
80
|
+
* @param logger - Logger instance
|
|
81
|
+
* @returns The prompt record if found, null otherwise
|
|
82
|
+
*/
|
|
83
|
+
export function get_prompt_by_area_key_and_locals(db, prompt_area, prompt_key, locals, logger) {
|
|
84
|
+
const file_name = 'get_prompt.ts';
|
|
85
|
+
// If no locals provided, use the base function
|
|
86
|
+
if (!locals || (!locals.local_1 && !locals.local_2 && !locals.local_3)) {
|
|
87
|
+
return get_prompt_by_area_and_key(db, prompt_area, prompt_key, logger);
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
logger.debug('Retrieving prompt with local filters', {
|
|
91
|
+
file: file_name,
|
|
92
|
+
data: { prompt_area, prompt_key, locals },
|
|
93
|
+
});
|
|
94
|
+
// Build fallback queries from most specific to least specific
|
|
95
|
+
const fallback_queries = [];
|
|
96
|
+
// Level 1: All three locals specified
|
|
97
|
+
if (locals.local_1 && locals.local_2 && locals.local_3) {
|
|
98
|
+
fallback_queries.push({
|
|
99
|
+
sql: `SELECT * FROM prompts_library
|
|
100
|
+
WHERE prompt_area = ? AND prompt_key = ?
|
|
101
|
+
AND local_1 = ? AND local_2 = ? AND local_3 = ?
|
|
102
|
+
LIMIT 1`,
|
|
103
|
+
params: [prompt_area, prompt_key, locals.local_1, locals.local_2, locals.local_3],
|
|
104
|
+
description: 'all locals',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// Level 2: local_1 and local_2 specified
|
|
108
|
+
if (locals.local_1 && locals.local_2) {
|
|
109
|
+
fallback_queries.push({
|
|
110
|
+
sql: `SELECT * FROM prompts_library
|
|
111
|
+
WHERE prompt_area = ? AND prompt_key = ?
|
|
112
|
+
AND local_1 = ? AND local_2 = ? AND local_3 IS NULL
|
|
113
|
+
LIMIT 1`,
|
|
114
|
+
params: [prompt_area, prompt_key, locals.local_1, locals.local_2],
|
|
115
|
+
description: 'local_1 and local_2',
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// Level 3: Only local_1 specified
|
|
119
|
+
if (locals.local_1) {
|
|
120
|
+
fallback_queries.push({
|
|
121
|
+
sql: `SELECT * FROM prompts_library
|
|
122
|
+
WHERE prompt_area = ? AND prompt_key = ?
|
|
123
|
+
AND local_1 = ? AND local_2 IS NULL AND local_3 IS NULL
|
|
124
|
+
LIMIT 1`,
|
|
125
|
+
params: [prompt_area, prompt_key, locals.local_1],
|
|
126
|
+
description: 'local_1 only',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// Level 4: Base prompt (no locals)
|
|
130
|
+
fallback_queries.push({
|
|
131
|
+
sql: `SELECT * FROM prompts_library
|
|
132
|
+
WHERE prompt_area = ? AND prompt_key = ?
|
|
133
|
+
AND local_1 IS NULL AND local_2 IS NULL AND local_3 IS NULL
|
|
134
|
+
LIMIT 1`,
|
|
135
|
+
params: [prompt_area, prompt_key],
|
|
136
|
+
description: 'base (no locals)',
|
|
137
|
+
});
|
|
138
|
+
// Try each query in order
|
|
139
|
+
for (const query of fallback_queries) {
|
|
140
|
+
const result = db.exec(query.sql, query.params);
|
|
141
|
+
if (result.length > 0 && result[0].values.length > 0) {
|
|
142
|
+
const row = result[0].values[0];
|
|
143
|
+
const columns = result[0].columns;
|
|
144
|
+
const record = row_to_prompt_record(row, columns);
|
|
145
|
+
logger.info('Prompt retrieved with local filters', {
|
|
146
|
+
file: file_name,
|
|
147
|
+
data: {
|
|
148
|
+
uuid: record.uuid,
|
|
149
|
+
prompt_area: record.prompt_area,
|
|
150
|
+
prompt_key: record.prompt_key,
|
|
151
|
+
local_1: record.local_1,
|
|
152
|
+
local_2: record.local_2,
|
|
153
|
+
local_3: record.local_3,
|
|
154
|
+
matched_level: query.description,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
return record;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
logger.warn('Prompt not found with local filters', {
|
|
161
|
+
file: file_name,
|
|
162
|
+
data: { prompt_area, prompt_key, locals },
|
|
163
|
+
});
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
168
|
+
logger.error('Failed to retrieve prompt with local filters', {
|
|
169
|
+
file: file_name,
|
|
170
|
+
data: { error: error_message, prompt_area, prompt_key, locals },
|
|
171
|
+
});
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Retrieve the prompt text only by prompt_area and prompt_key
|
|
177
|
+
* @param db - Database instance
|
|
178
|
+
* @param prompt_area - Area/category of the prompt
|
|
179
|
+
* @param prompt_key - Key identifier for the prompt
|
|
180
|
+
* @param logger - Logger instance
|
|
181
|
+
* @returns The prompt text if found, null otherwise
|
|
182
|
+
*/
|
|
183
|
+
export function get_prompt_text(db, prompt_area, prompt_key, logger) {
|
|
184
|
+
const file_name = 'get_prompt.ts';
|
|
185
|
+
const prompt_record = get_prompt_by_area_and_key(db, prompt_area, prompt_key, logger);
|
|
186
|
+
if (prompt_record) {
|
|
187
|
+
logger.debug('Prompt text retrieved', {
|
|
188
|
+
file: file_name,
|
|
189
|
+
line: 121,
|
|
190
|
+
data: {
|
|
191
|
+
prompt_area,
|
|
192
|
+
prompt_key,
|
|
193
|
+
text_length: prompt_record.prompt_text.length,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
return prompt_record.prompt_text;
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get all prompts by prompt_area
|
|
202
|
+
* @param db - Database instance
|
|
203
|
+
* @param prompt_area - Area/category of the prompts
|
|
204
|
+
* @param logger - Logger instance
|
|
205
|
+
* @returns Array of prompt records
|
|
206
|
+
*/
|
|
207
|
+
export function get_prompts_by_area(db, prompt_area, logger) {
|
|
208
|
+
const file_name = 'get_prompt.ts';
|
|
209
|
+
const select_sql = `
|
|
210
|
+
SELECT * FROM prompts_library
|
|
211
|
+
WHERE prompt_area = ?
|
|
212
|
+
ORDER BY prompt_key
|
|
213
|
+
`;
|
|
214
|
+
try {
|
|
215
|
+
logger.debug('Retrieving prompts by area', {
|
|
216
|
+
file: file_name,
|
|
217
|
+
line: 157,
|
|
218
|
+
data: { prompt_area },
|
|
219
|
+
});
|
|
220
|
+
const result = db.exec(select_sql, [prompt_area]);
|
|
221
|
+
if (result.length === 0 || result[0].values.length === 0) {
|
|
222
|
+
logger.info('No prompts found for area', {
|
|
223
|
+
file: file_name,
|
|
224
|
+
line: 165,
|
|
225
|
+
data: { prompt_area },
|
|
226
|
+
});
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
const columns = result[0].columns;
|
|
230
|
+
const records = result[0].values.map(row => row_to_prompt_record(row, columns));
|
|
231
|
+
logger.info('Prompts retrieved by area', {
|
|
232
|
+
file: file_name,
|
|
233
|
+
line: 175,
|
|
234
|
+
data: { prompt_area, count: records.length },
|
|
235
|
+
});
|
|
236
|
+
return records;
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
240
|
+
logger.error('Failed to retrieve prompts by area', {
|
|
241
|
+
file: file_name,
|
|
242
|
+
line: 183,
|
|
243
|
+
data: { error: error_message, prompt_area },
|
|
244
|
+
});
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get a prompt by its UUID
|
|
250
|
+
* @param db - Database instance
|
|
251
|
+
* @param uuid - UUID of the prompt
|
|
252
|
+
* @param logger - Logger instance
|
|
253
|
+
* @returns The prompt record if found, null otherwise
|
|
254
|
+
*/
|
|
255
|
+
export function get_prompt_by_uuid(db, uuid, logger) {
|
|
256
|
+
const file_name = 'get_prompt.ts';
|
|
257
|
+
const select_sql = `
|
|
258
|
+
SELECT * FROM prompts_library
|
|
259
|
+
WHERE uuid = ?
|
|
260
|
+
`;
|
|
261
|
+
try {
|
|
262
|
+
logger.debug('Retrieving prompt by UUID', {
|
|
263
|
+
file: file_name,
|
|
264
|
+
line: 211,
|
|
265
|
+
data: { uuid },
|
|
266
|
+
});
|
|
267
|
+
const result = db.exec(select_sql, [uuid]);
|
|
268
|
+
if (result.length === 0 || result[0].values.length === 0) {
|
|
269
|
+
logger.warn('Prompt not found by UUID', {
|
|
270
|
+
file: file_name,
|
|
271
|
+
line: 219,
|
|
272
|
+
data: { uuid },
|
|
273
|
+
});
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
const row = result[0].values[0];
|
|
277
|
+
const columns = result[0].columns;
|
|
278
|
+
const record = row_to_prompt_record(row, columns);
|
|
279
|
+
logger.info('Prompt retrieved by UUID', {
|
|
280
|
+
file: file_name,
|
|
281
|
+
line: 229,
|
|
282
|
+
data: { uuid },
|
|
283
|
+
});
|
|
284
|
+
return record;
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
288
|
+
logger.error('Failed to retrieve prompt by UUID', {
|
|
289
|
+
file: file_name,
|
|
290
|
+
line: 237,
|
|
291
|
+
data: { error: error_message, uuid },
|
|
292
|
+
});
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get all prompts from the library
|
|
298
|
+
* @param db - Database instance
|
|
299
|
+
* @param logger - Logger instance
|
|
300
|
+
* @returns Array of all prompt records
|
|
301
|
+
*/
|
|
302
|
+
export function get_all_prompts(db, logger) {
|
|
303
|
+
const file_name = 'get_prompt.ts';
|
|
304
|
+
const select_sql = `
|
|
305
|
+
SELECT * FROM prompts_library
|
|
306
|
+
ORDER BY prompt_area, prompt_key
|
|
307
|
+
`;
|
|
308
|
+
try {
|
|
309
|
+
logger.debug('Retrieving all prompts', {
|
|
310
|
+
file: file_name,
|
|
311
|
+
line: 265,
|
|
312
|
+
data: {},
|
|
313
|
+
});
|
|
314
|
+
const result = db.exec(select_sql);
|
|
315
|
+
if (result.length === 0 || result[0].values.length === 0) {
|
|
316
|
+
logger.info('No prompts found in library', {
|
|
317
|
+
file: file_name,
|
|
318
|
+
line: 273,
|
|
319
|
+
data: {},
|
|
320
|
+
});
|
|
321
|
+
return [];
|
|
322
|
+
}
|
|
323
|
+
const columns = result[0].columns;
|
|
324
|
+
const records = result[0].values.map(row => row_to_prompt_record(row, columns));
|
|
325
|
+
logger.info('All prompts retrieved', {
|
|
326
|
+
file: file_name,
|
|
327
|
+
line: 283,
|
|
328
|
+
data: { count: records.length },
|
|
329
|
+
});
|
|
330
|
+
return records;
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
334
|
+
logger.error('Failed to retrieve all prompts', {
|
|
335
|
+
file: file_name,
|
|
336
|
+
line: 291,
|
|
337
|
+
data: { error: error_message },
|
|
338
|
+
});
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
//# sourceMappingURL=get_prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_prompt.js","sourceRoot":"","sources":["../../../src/lib/prompts/get_prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAe5D,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CACxC,EAAiB,EACjB,WAAmB,EACnB,UAAkB,EAClB,MAAc;IAEd,MAAM,SAAS,GAAG,eAAe,CAAC;IAElC,MAAM,UAAU,GAAG;;;;;GAKlB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE;YAC9C,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE;SAClC,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAE9D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzD,MAAM,CAAC,IAAI,CAAC,8BAA8B,EAAE;gBAC1C,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE;aAClC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC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,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7E,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE;YAC7C,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE;SAC/B,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts Module Exports
|
|
3
|
+
*
|
|
4
|
+
* Export all prompt-related functions from this module
|
|
5
|
+
*/
|
|
6
|
+
export { get_prompt_by_area_and_key, get_prompt_by_area_key_and_locals, get_prompt_text, get_prompts_by_area, get_prompt_by_uuid, get_all_prompts, type LocalFilterOptions, } from './get_prompt.js';
|
|
7
|
+
export { substitute_variables, parse_prompt_variables, validate_variables, } from './substitute_variables.js';
|
|
8
|
+
export { PromptCache, type PromptCacheConfig, type CacheStats, get_prompt_cache, configure_prompt_cache, clear_prompt_cache, } from './prompt_cache.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/prompts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,0BAA0B,EAC1B,iCAAiC,EACjC,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,KAAK,kBAAkB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompts Module Exports
|
|
3
|
+
*
|
|
4
|
+
* Export all prompt-related functions from this module
|
|
5
|
+
*/
|
|
6
|
+
export { get_prompt_by_area_and_key, get_prompt_by_area_key_and_locals, get_prompt_text, get_prompts_by_area, get_prompt_by_uuid, get_all_prompts, } from './get_prompt.js';
|
|
7
|
+
export { substitute_variables, parse_prompt_variables, validate_variables, } from './substitute_variables.js';
|
|
8
|
+
export { PromptCache, get_prompt_cache, configure_prompt_cache, clear_prompt_cache, } from './prompt_cache.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/prompts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,0BAA0B,EAC1B,iCAAiC,EACjC,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,WAAW,EAGX,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Cache Module
|
|
3
|
+
*
|
|
4
|
+
* Simple LRU cache for frequently accessed prompts.
|
|
5
|
+
* Reduces database queries for repeated prompt lookups.
|
|
6
|
+
*/
|
|
7
|
+
import type { PromptRecord } from '../llm_api/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Cache configuration options
|
|
10
|
+
*/
|
|
11
|
+
export interface PromptCacheConfig {
|
|
12
|
+
/** Time-to-live in milliseconds (default: 5 minutes) */
|
|
13
|
+
ttl_ms?: number;
|
|
14
|
+
/** Maximum number of entries (default: 100) */
|
|
15
|
+
max_size?: number;
|
|
16
|
+
/** Whether caching is enabled (default: true) */
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Cache statistics
|
|
21
|
+
*/
|
|
22
|
+
export interface CacheStats {
|
|
23
|
+
hits: number;
|
|
24
|
+
misses: number;
|
|
25
|
+
size: number;
|
|
26
|
+
max_size: number;
|
|
27
|
+
hit_rate: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Simple LRU cache for prompts
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const cache = new PromptCache({ ttl_ms: 60000, max_size: 50 });
|
|
35
|
+
*
|
|
36
|
+
* // Check cache first
|
|
37
|
+
* const cached = cache.get('marketing', 'greeting');
|
|
38
|
+
* if (cached) {
|
|
39
|
+
* return cached;
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // Fetch from database and cache
|
|
43
|
+
* const prompt = get_prompt_by_area_and_key(db, 'marketing', 'greeting', logger);
|
|
44
|
+
* if (prompt) {
|
|
45
|
+
* cache.set(prompt);
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class PromptCache {
|
|
50
|
+
private cache;
|
|
51
|
+
private ttl_ms;
|
|
52
|
+
private max_size;
|
|
53
|
+
private enabled;
|
|
54
|
+
private hits;
|
|
55
|
+
private misses;
|
|
56
|
+
constructor(config?: PromptCacheConfig);
|
|
57
|
+
/**
|
|
58
|
+
* Generate cache key from area and key
|
|
59
|
+
*/
|
|
60
|
+
private make_key;
|
|
61
|
+
/**
|
|
62
|
+
* Check if an entry is expired
|
|
63
|
+
*/
|
|
64
|
+
private is_expired;
|
|
65
|
+
/**
|
|
66
|
+
* Evict least recently used entries if cache is full
|
|
67
|
+
*/
|
|
68
|
+
private evict_if_needed;
|
|
69
|
+
/**
|
|
70
|
+
* Get a prompt from the cache
|
|
71
|
+
*
|
|
72
|
+
* @param area - Prompt area
|
|
73
|
+
* @param key - Prompt key
|
|
74
|
+
* @returns Cached prompt or null if not found/expired
|
|
75
|
+
*/
|
|
76
|
+
get(area: string, key: string): PromptRecord | null;
|
|
77
|
+
/**
|
|
78
|
+
* Get a prompt by UUID from the cache
|
|
79
|
+
*
|
|
80
|
+
* @param uuid - Prompt UUID
|
|
81
|
+
* @returns Cached prompt or null if not found/expired
|
|
82
|
+
*/
|
|
83
|
+
get_by_uuid(uuid: string): PromptRecord | null;
|
|
84
|
+
/**
|
|
85
|
+
* Add a prompt to the cache
|
|
86
|
+
*
|
|
87
|
+
* @param prompt - Prompt record to cache
|
|
88
|
+
*/
|
|
89
|
+
set(prompt: PromptRecord): void;
|
|
90
|
+
/**
|
|
91
|
+
* Remove a prompt from the cache
|
|
92
|
+
*
|
|
93
|
+
* @param area - Prompt area
|
|
94
|
+
* @param key - Prompt key
|
|
95
|
+
*/
|
|
96
|
+
invalidate(area: string, key: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Remove a prompt by UUID from the cache
|
|
99
|
+
*
|
|
100
|
+
* @param uuid - Prompt UUID
|
|
101
|
+
*/
|
|
102
|
+
invalidate_by_uuid(uuid: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Invalidate all prompts in an area
|
|
105
|
+
*
|
|
106
|
+
* @param area - Prompt area to invalidate
|
|
107
|
+
*/
|
|
108
|
+
invalidate_area(area: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Clear all cached entries
|
|
111
|
+
*/
|
|
112
|
+
clear(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Remove all expired entries
|
|
115
|
+
*
|
|
116
|
+
* @returns Number of entries removed
|
|
117
|
+
*/
|
|
118
|
+
cleanup(): number;
|
|
119
|
+
/**
|
|
120
|
+
* Get cache statistics
|
|
121
|
+
*/
|
|
122
|
+
get_stats(): CacheStats;
|
|
123
|
+
/**
|
|
124
|
+
* Enable or disable the cache
|
|
125
|
+
*
|
|
126
|
+
* @param enabled - Whether to enable caching
|
|
127
|
+
*/
|
|
128
|
+
set_enabled(enabled: boolean): void;
|
|
129
|
+
/**
|
|
130
|
+
* Check if caching is enabled
|
|
131
|
+
*/
|
|
132
|
+
is_enabled(): boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get the global prompt cache instance
|
|
136
|
+
* Creates one with default settings if not configured
|
|
137
|
+
*
|
|
138
|
+
* @returns Global prompt cache
|
|
139
|
+
*/
|
|
140
|
+
export declare function get_prompt_cache(): PromptCache;
|
|
141
|
+
/**
|
|
142
|
+
* Configure the global prompt cache
|
|
143
|
+
*
|
|
144
|
+
* @param config - Cache configuration options
|
|
145
|
+
*/
|
|
146
|
+
export declare function configure_prompt_cache(config: PromptCacheConfig): void;
|
|
147
|
+
/**
|
|
148
|
+
* Clear the global prompt cache
|
|
149
|
+
*/
|
|
150
|
+
export declare function clear_prompt_cache(): void;
|
|
151
|
+
//# sourceMappingURL=prompt_cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt_cache.d.ts","sourceRoot":"","sources":["../../../src/lib/prompts/prompt_cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAyBxD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,WAAW;IACtB,OA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