@agtlantis/core 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/types.d.ts +69 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/errors/types.js +116 -0
- package/dist/errors/types.js.map +1 -0
- package/dist/errors/utils.d.ts +17 -0
- package/dist/errors/utils.d.ts.map +1 -0
- package/dist/errors/utils.js +16 -0
- package/dist/errors/utils.js.map +1 -0
- package/dist/execution/constants.d.ts +7 -0
- package/dist/execution/constants.d.ts.map +1 -0
- package/dist/execution/constants.js +7 -0
- package/dist/execution/constants.js.map +1 -0
- package/dist/execution/index.d.ts +8 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +7 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/mapping.d.ts +17 -0
- package/dist/execution/mapping.d.ts.map +1 -0
- package/dist/execution/mapping.js +197 -0
- package/dist/execution/mapping.js.map +1 -0
- package/dist/execution/shared.d.ts +86 -0
- package/dist/execution/shared.d.ts.map +1 -0
- package/dist/execution/shared.js +100 -0
- package/dist/execution/shared.js.map +1 -0
- package/dist/execution/simple-host.d.ts +56 -0
- package/dist/execution/simple-host.d.ts.map +1 -0
- package/dist/execution/simple-host.js +126 -0
- package/dist/execution/simple-host.js.map +1 -0
- package/dist/execution/streaming-host.d.ts +79 -0
- package/dist/execution/streaming-host.d.ts.map +1 -0
- package/dist/execution/streaming-host.js +276 -0
- package/dist/execution/streaming-host.js.map +1 -0
- package/dist/execution/testing/fixtures.d.ts +67 -0
- package/dist/execution/testing/fixtures.d.ts.map +1 -0
- package/dist/execution/testing/fixtures.js +145 -0
- package/dist/execution/testing/fixtures.js.map +1 -0
- package/dist/execution/testing/helpers.d.ts +218 -0
- package/dist/execution/testing/helpers.d.ts.map +1 -0
- package/dist/execution/testing/helpers.js +327 -0
- package/dist/execution/testing/helpers.js.map +1 -0
- package/dist/execution/testing/host-configs.d.ts +56 -0
- package/dist/execution/testing/host-configs.d.ts.map +1 -0
- package/dist/execution/testing/host-configs.js +154 -0
- package/dist/execution/testing/host-configs.js.map +1 -0
- package/dist/execution/testing/vitest-assertions.d.ts +102 -0
- package/dist/execution/testing/vitest-assertions.d.ts.map +1 -0
- package/dist/execution/testing/vitest-assertions.js +142 -0
- package/dist/execution/testing/vitest-assertions.js.map +1 -0
- package/dist/execution/types.d.ts +432 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +2 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/utils.d.ts +68 -0
- package/dist/execution/utils.d.ts.map +1 -0
- package/dist/execution/utils.js +93 -0
- package/dist/execution/utils.js.map +1 -0
- package/dist/index.d.ts +10 -1506
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -2979
- package/dist/index.js.map +1 -1
- package/dist/observability/index.d.ts +4 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +2 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/logger.d.ts +161 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +31 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/types.d.ts +46 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +2 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/patterns/index.d.ts +2 -0
- package/dist/patterns/index.d.ts.map +1 -0
- package/dist/patterns/index.js +2 -0
- package/dist/patterns/index.js.map +1 -0
- package/dist/patterns/progressive/index.d.ts +2 -0
- package/dist/patterns/progressive/index.d.ts.map +1 -0
- package/dist/patterns/progressive/index.js +2 -0
- package/dist/patterns/progressive/index.js.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts +174 -0
- package/dist/patterns/progressive/progressive-pattern.d.ts.map +1 -0
- package/dist/patterns/progressive/progressive-pattern.js +260 -0
- package/dist/patterns/progressive/progressive-pattern.js.map +1 -0
- package/dist/pricing/calculator.d.ts +71 -0
- package/dist/pricing/calculator.d.ts.map +1 -0
- package/dist/pricing/calculator.js +127 -0
- package/dist/pricing/calculator.js.map +1 -0
- package/dist/pricing/config.d.ts +61 -0
- package/dist/pricing/config.d.ts.map +1 -0
- package/dist/pricing/config.js +87 -0
- package/dist/pricing/config.js.map +1 -0
- package/dist/pricing/defaults.d.ts +29 -0
- package/dist/pricing/defaults.d.ts.map +1 -0
- package/dist/pricing/defaults.js +139 -0
- package/dist/pricing/defaults.js.map +1 -0
- package/dist/pricing/index.d.ts +40 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +43 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/types.d.ts +96 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +7 -0
- package/dist/pricing/types.js.map +1 -0
- package/dist/pricing/validator.d.ts +55 -0
- package/dist/pricing/validator.d.ts.map +1 -0
- package/dist/pricing/validator.js +84 -0
- package/dist/pricing/validator.js.map +1 -0
- package/dist/prompt/errors.d.ts +112 -0
- package/dist/prompt/errors.d.ts.map +1 -0
- package/dist/prompt/errors.js +174 -0
- package/dist/prompt/errors.js.map +1 -0
- package/dist/prompt/file-prompt-repository.d.ts +80 -0
- package/dist/prompt/file-prompt-repository.d.ts.map +1 -0
- package/dist/prompt/file-prompt-repository.js +287 -0
- package/dist/prompt/file-prompt-repository.js.map +1 -0
- package/dist/prompt/index.d.ts +34 -0
- package/dist/prompt/index.d.ts.map +1 -0
- package/dist/prompt/index.js +37 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/prompt-template.d.ts +64 -0
- package/dist/prompt/prompt-template.d.ts.map +1 -0
- package/dist/prompt/prompt-template.js +90 -0
- package/dist/prompt/prompt-template.js.map +1 -0
- package/dist/prompt/template.d.ts +23 -0
- package/dist/prompt/template.d.ts.map +1 -0
- package/dist/prompt/template.js +70 -0
- package/dist/prompt/template.js.map +1 -0
- package/dist/prompt/types.d.ts +148 -0
- package/dist/prompt/types.d.ts.map +1 -0
- package/dist/prompt/types.js +7 -0
- package/dist/prompt/types.js.map +1 -0
- package/dist/provider/base-file-manager.d.ts +14 -0
- package/dist/provider/base-file-manager.d.ts.map +1 -0
- package/dist/provider/base-file-manager.js +91 -0
- package/dist/provider/base-file-manager.js.map +1 -0
- package/dist/provider/base-provider.d.ts +41 -0
- package/dist/provider/base-provider.d.ts.map +1 -0
- package/dist/provider/base-provider.js +21 -0
- package/dist/provider/base-provider.js.map +1 -0
- package/dist/provider/file-cache.d.ts +14 -0
- package/dist/provider/file-cache.d.ts.map +1 -0
- package/dist/provider/file-cache.js +29 -0
- package/dist/provider/file-cache.js.map +1 -0
- package/dist/provider/file-source.d.ts +32 -0
- package/dist/provider/file-source.d.ts.map +1 -0
- package/dist/provider/file-source.js +180 -0
- package/dist/provider/file-source.js.map +1 -0
- package/dist/provider/file-utils.d.ts +5 -0
- package/dist/provider/file-utils.d.ts.map +1 -0
- package/dist/provider/file-utils.js +15 -0
- package/dist/provider/file-utils.js.map +1 -0
- package/dist/provider/google/factory.d.ts +107 -0
- package/dist/provider/google/factory.d.ts.map +1 -0
- package/dist/provider/google/factory.js +143 -0
- package/dist/provider/google/factory.js.map +1 -0
- package/dist/provider/google/file-manager.d.ts +10 -0
- package/dist/provider/google/file-manager.d.ts.map +1 -0
- package/dist/provider/google/file-manager.js +93 -0
- package/dist/provider/google/file-manager.js.map +1 -0
- package/dist/provider/google/index.d.ts +8 -0
- package/dist/provider/google/index.d.ts.map +1 -0
- package/dist/provider/google/index.js +10 -0
- package/dist/provider/google/index.js.map +1 -0
- package/dist/provider/hash.d.ts +3 -0
- package/dist/provider/hash.d.ts.map +1 -0
- package/dist/provider/hash.js +34 -0
- package/dist/provider/hash.js.map +1 -0
- package/dist/provider/index.d.ts +10 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/provider/index.js +12 -0
- package/dist/provider/index.js.map +1 -0
- package/dist/provider/noop-file-manager.d.ts +9 -0
- package/dist/provider/noop-file-manager.d.ts.map +1 -0
- package/dist/provider/noop-file-manager.js +28 -0
- package/dist/provider/noop-file-manager.js.map +1 -0
- package/dist/provider/openai/factory.d.ts +67 -0
- package/dist/provider/openai/factory.d.ts.map +1 -0
- package/dist/provider/openai/factory.js +100 -0
- package/dist/provider/openai/factory.js.map +1 -0
- package/dist/provider/openai/file-manager.d.ts +17 -0
- package/dist/provider/openai/file-manager.d.ts.map +1 -0
- package/dist/provider/openai/file-manager.js +108 -0
- package/dist/provider/openai/file-manager.js.map +1 -0
- package/dist/provider/openai/index.d.ts +8 -0
- package/dist/provider/openai/index.d.ts.map +1 -0
- package/dist/provider/openai/index.js +8 -0
- package/dist/provider/openai/index.js.map +1 -0
- package/dist/provider/types.d.ts +105 -0
- package/dist/provider/types.d.ts.map +1 -0
- package/dist/provider/types.js +19 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/session/index.d.ts +7 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +5 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/simple-session.d.ts +98 -0
- package/dist/session/simple-session.d.ts.map +1 -0
- package/dist/session/simple-session.js +299 -0
- package/dist/session/simple-session.js.map +1 -0
- package/dist/session/streaming-session.d.ts +90 -0
- package/dist/session/streaming-session.d.ts.map +1 -0
- package/dist/session/streaming-session.js +151 -0
- package/dist/session/streaming-session.js.map +1 -0
- package/dist/session/test-utils.d.ts +19 -0
- package/dist/session/test-utils.d.ts.map +1 -0
- package/dist/session/test-utils.js +65 -0
- package/dist/session/test-utils.js.map +1 -0
- package/dist/session/types.d.ts +219 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +181 -0
- package/dist/session/types.js.map +1 -0
- package/dist/session/usage-extractors.d.ts +7 -0
- package/dist/session/usage-extractors.d.ts.map +1 -0
- package/dist/session/usage-extractors.js +71 -0
- package/dist/session/usage-extractors.js.map +1 -0
- package/dist/testing/fixtures.d.ts +34 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +65 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing/helpers.d.ts +20 -0
- package/dist/testing/helpers.d.ts.map +1 -0
- package/dist/testing/helpers.js +32 -0
- package/dist/testing/helpers.js.map +1 -0
- package/dist/testing/index.d.ts +7 -519
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +21 -2123
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/mock-provider.d.ts +79 -0
- package/dist/testing/mock-provider.d.ts.map +1 -0
- package/dist/testing/mock-provider.js +152 -0
- package/dist/testing/mock-provider.js.map +1 -0
- package/dist/testing/mock.d.ts +29 -0
- package/dist/testing/mock.d.ts.map +1 -0
- package/dist/testing/mock.js +154 -0
- package/dist/testing/mock.js.map +1 -0
- package/dist/testing/test-execution.d.ts +14 -0
- package/dist/testing/test-execution.d.ts.map +1 -0
- package/dist/testing/test-execution.js +108 -0
- package/dist/testing/test-execution.js.map +1 -0
- package/dist/utils/deep-merge.d.ts +6 -0
- package/dist/utils/deep-merge.d.ts.map +1 -0
- package/dist/utils/deep-merge.js +24 -0
- package/dist/utils/deep-merge.js.map +1 -0
- package/dist/validation/errors.d.ts +28 -0
- package/dist/validation/errors.d.ts.map +1 -0
- package/dist/validation/errors.js +38 -0
- package/dist/validation/errors.js.map +1 -0
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +4 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/types.d.ts +49 -0
- package/dist/validation/types.d.ts.map +1 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -0
- package/dist/validation/validation-history.d.ts +12 -0
- package/dist/validation/validation-history.d.ts.map +1 -0
- package/dist/validation/validation-history.js +29 -0
- package/dist/validation/validation-history.js.map +1 -0
- package/dist/validation/with-validation.d.ts +38 -0
- package/dist/validation/with-validation.d.ts.map +1 -0
- package/dist/validation/with-validation.js +58 -0
- package/dist/validation/with-validation.js.map +1 -0
- package/package.json +71 -75
- package/dist/base-provider-2TTw5HAa.d.cts +0 -1254
- package/dist/base-provider-2TTw5HAa.d.ts +0 -1254
- package/dist/index.cjs +0 -3085
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1506
- package/dist/testing/index.cjs +0 -2167
- package/dist/testing/index.cjs.map +0 -1
- package/dist/testing/index.d.cts +0 -520
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt module error classes for @agtlantis/core.
|
|
3
|
+
*
|
|
4
|
+
* Each error type has a specific code and context for precise error handling.
|
|
5
|
+
*/
|
|
6
|
+
import { AgtlantisError } from '../errors/index.js';
|
|
7
|
+
// =============================================================================
|
|
8
|
+
// Prompt Error Codes
|
|
9
|
+
// =============================================================================
|
|
10
|
+
export var PromptErrorCode;
|
|
11
|
+
(function (PromptErrorCode) {
|
|
12
|
+
/** Generic prompt error */
|
|
13
|
+
PromptErrorCode["PROMPT_ERROR"] = "PROMPT_ERROR";
|
|
14
|
+
/** Prompt not found in repository */
|
|
15
|
+
PromptErrorCode["NOT_FOUND"] = "PROMPT_NOT_FOUND";
|
|
16
|
+
/** Invalid prompt file format (e.g., malformed YAML) */
|
|
17
|
+
PromptErrorCode["INVALID_FORMAT"] = "PROMPT_INVALID_FORMAT";
|
|
18
|
+
/** Template compilation failed */
|
|
19
|
+
PromptErrorCode["TEMPLATE_ERROR"] = "PROMPT_TEMPLATE_ERROR";
|
|
20
|
+
/** File I/O operation failed */
|
|
21
|
+
PromptErrorCode["IO_ERROR"] = "PROMPT_IO_ERROR";
|
|
22
|
+
})(PromptErrorCode || (PromptErrorCode = {}));
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// Base Prompt Error
|
|
25
|
+
// =============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Base error class for prompt operations.
|
|
28
|
+
* Use specific error subclasses for more precise error handling.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* throw new PromptError('Something went wrong', {
|
|
33
|
+
* code: PromptErrorCode.PROMPT_ERROR,
|
|
34
|
+
* context: { promptId: 'greeting' }
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export class PromptError extends AgtlantisError {
|
|
39
|
+
constructor(message, options = {}) {
|
|
40
|
+
super(message, {
|
|
41
|
+
code: (options.code ?? PromptErrorCode.PROMPT_ERROR),
|
|
42
|
+
cause: options.cause,
|
|
43
|
+
context: options.context,
|
|
44
|
+
});
|
|
45
|
+
this.name = 'PromptError';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a PromptError from an unknown error.
|
|
49
|
+
*/
|
|
50
|
+
static from(error, code = PromptErrorCode.PROMPT_ERROR, context) {
|
|
51
|
+
if (error instanceof PromptError) {
|
|
52
|
+
return error;
|
|
53
|
+
}
|
|
54
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
55
|
+
return new PromptError(cause.message, { code, cause, context });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// Prompt Not Found Error
|
|
60
|
+
// =============================================================================
|
|
61
|
+
/**
|
|
62
|
+
* Error thrown when a prompt is not found in the repository.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* throw new PromptNotFoundError('greeting', '1.0.0');
|
|
67
|
+
* // Error: Prompt 'greeting' version '1.0.0' not found
|
|
68
|
+
*
|
|
69
|
+
* throw new PromptNotFoundError('greeting');
|
|
70
|
+
* // Error: Prompt 'greeting' not found
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export class PromptNotFoundError extends PromptError {
|
|
74
|
+
promptId;
|
|
75
|
+
version;
|
|
76
|
+
constructor(promptId, version, options = {}) {
|
|
77
|
+
const message = version
|
|
78
|
+
? `Prompt '${promptId}' version '${version}' not found`
|
|
79
|
+
: `Prompt '${promptId}' not found`;
|
|
80
|
+
super(message, {
|
|
81
|
+
code: PromptErrorCode.NOT_FOUND,
|
|
82
|
+
cause: options.cause,
|
|
83
|
+
context: { promptId, version, ...options.context },
|
|
84
|
+
});
|
|
85
|
+
this.name = 'PromptNotFoundError';
|
|
86
|
+
this.promptId = promptId;
|
|
87
|
+
this.version = version;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// =============================================================================
|
|
91
|
+
// Prompt Invalid Format Error
|
|
92
|
+
// =============================================================================
|
|
93
|
+
/**
|
|
94
|
+
* Error thrown when a prompt file has invalid format.
|
|
95
|
+
* Examples: malformed YAML, missing required fields, invalid schema.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* throw new PromptInvalidFormatError('greeting', 'Missing required field: system');
|
|
100
|
+
* // Error: Invalid format for prompt 'greeting': Missing required field: system
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export class PromptInvalidFormatError extends PromptError {
|
|
104
|
+
promptId;
|
|
105
|
+
details;
|
|
106
|
+
constructor(promptId, details, options = {}) {
|
|
107
|
+
super(`Invalid format for prompt '${promptId}': ${details}`, {
|
|
108
|
+
code: PromptErrorCode.INVALID_FORMAT,
|
|
109
|
+
cause: options.cause,
|
|
110
|
+
context: { promptId, details, ...options.context },
|
|
111
|
+
});
|
|
112
|
+
this.name = 'PromptInvalidFormatError';
|
|
113
|
+
this.promptId = promptId;
|
|
114
|
+
this.details = details;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// =============================================================================
|
|
118
|
+
// Prompt Template Error
|
|
119
|
+
// =============================================================================
|
|
120
|
+
/**
|
|
121
|
+
* Error thrown when template compilation fails.
|
|
122
|
+
* Examples: invalid Handlebars syntax, missing helper.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* throw new PromptTemplateError('greeting', 'Unexpected token {{/if}}');
|
|
127
|
+
* // Error: Template compilation failed for prompt 'greeting': Unexpected token {{/if}}
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export class PromptTemplateError extends PromptError {
|
|
131
|
+
promptId;
|
|
132
|
+
details;
|
|
133
|
+
constructor(promptId, details, options = {}) {
|
|
134
|
+
super(`Template compilation failed for prompt '${promptId}': ${details}`, {
|
|
135
|
+
code: PromptErrorCode.TEMPLATE_ERROR,
|
|
136
|
+
cause: options.cause,
|
|
137
|
+
context: { promptId, details, ...options.context },
|
|
138
|
+
});
|
|
139
|
+
this.name = 'PromptTemplateError';
|
|
140
|
+
this.promptId = promptId;
|
|
141
|
+
this.details = details;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// =============================================================================
|
|
145
|
+
// Prompt IO Error
|
|
146
|
+
// =============================================================================
|
|
147
|
+
/**
|
|
148
|
+
* Error thrown when file I/O operations fail.
|
|
149
|
+
* Examples: read failure, write failure, directory access denied.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* throw new PromptIOError('read', '/path/to/prompt.yaml', {
|
|
154
|
+
* cause: originalError
|
|
155
|
+
* });
|
|
156
|
+
* // Error: Failed to read prompt file: /path/to/prompt.yaml
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export class PromptIOError extends PromptError {
|
|
160
|
+
operation;
|
|
161
|
+
path;
|
|
162
|
+
constructor(operation, path, options = {}) {
|
|
163
|
+
const opText = operation === 'list' ? 'list prompts in' : `${operation} prompt file`;
|
|
164
|
+
super(`Failed to ${opText}: ${path}`, {
|
|
165
|
+
code: PromptErrorCode.IO_ERROR,
|
|
166
|
+
cause: options.cause,
|
|
167
|
+
context: { operation, path, ...options.context },
|
|
168
|
+
});
|
|
169
|
+
this.name = 'PromptIOError';
|
|
170
|
+
this.operation = operation;
|
|
171
|
+
this.path = path;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/prompt/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAA2B,MAAM,oBAAoB,CAAC;AAE7E,gFAAgF;AAChF,qBAAqB;AACrB,gFAAgF;AAEhF,MAAM,CAAN,IAAY,eAWX;AAXD,WAAY,eAAe;IACzB,2BAA2B;IAC3B,gDAA6B,CAAA;IAC7B,qCAAqC;IACrC,iDAA8B,CAAA;IAC9B,wDAAwD;IACxD,2DAAwC,CAAA;IACxC,kCAAkC;IAClC,2DAAwC,CAAA;IACxC,gCAAgC;IAChC,+CAA4B,CAAA;AAC9B,CAAC,EAXW,eAAe,KAAf,eAAe,QAW1B;AAmBD,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,WAAY,SAAQ,cAAoD;IACnF,YAAY,OAAe,EAAE,OAAO,GAAuB,EAAE;QAC3D,KAAK,CAAC,OAAO,EAAE;YACb,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,eAAe,CAAC,YAAY,CAAyC;YAC5F,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CACT,KAAc,EACd,IAAI,GAAoB,eAAe,CAAC,YAAY,EACpD,OAAiC;QAEjC,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,KAAK,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,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AAI,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE;SACjD,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { FileSystem, PromptRepository, PromptTemplateData } from './types.js';
|
|
2
|
+
export interface FilePromptRepositoryOptions {
|
|
3
|
+
/** Directory path where prompt files are stored */
|
|
4
|
+
directory: string;
|
|
5
|
+
/** Optional custom file system implementation (defaults to Node.js fs) */
|
|
6
|
+
fs?: FileSystem;
|
|
7
|
+
/** Enable in-memory caching for read operations (defaults to true) */
|
|
8
|
+
cache?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* File-based prompt repository.
|
|
12
|
+
*
|
|
13
|
+
* Prompts are stored as YAML files with naming convention: {id}-{version}.yaml
|
|
14
|
+
*
|
|
15
|
+
* Can be subclassed to customize parsing/serialization (e.g., JSON instead of YAML).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const repo = new FilePromptRepository({ directory: './prompts' });
|
|
20
|
+
*
|
|
21
|
+
* // Read latest version
|
|
22
|
+
* const prompt = await repo.read<GreetingInput>('greeting');
|
|
23
|
+
*
|
|
24
|
+
* // Subclass to use JSON format
|
|
25
|
+
* class JsonPromptRepository extends FilePromptRepository {
|
|
26
|
+
* protected parseContent(content: string, promptId: string): PromptTemplateData {
|
|
27
|
+
* return JSON.parse(content);
|
|
28
|
+
* }
|
|
29
|
+
* protected serializeContent(content: PromptTemplateData): string {
|
|
30
|
+
* return JSON.stringify(content, null, 2);
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class FilePromptRepository implements PromptRepository {
|
|
36
|
+
protected readonly directory: string;
|
|
37
|
+
protected readonly fileSystem: FileSystem;
|
|
38
|
+
protected readonly cacheEnabled: boolean;
|
|
39
|
+
private readonly contentCache;
|
|
40
|
+
constructor(options: FilePromptRepositoryOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Generates file name from prompt id and version.
|
|
43
|
+
* Override this along with `parseFileName` to change file naming convention.
|
|
44
|
+
*/
|
|
45
|
+
protected getFileName(id: string, version: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Parses file name into id and version.
|
|
48
|
+
* Override this along with `getFileName` to change file naming convention.
|
|
49
|
+
*/
|
|
50
|
+
protected parseFileName(fileName: string): {
|
|
51
|
+
id: string;
|
|
52
|
+
version: string;
|
|
53
|
+
} | null;
|
|
54
|
+
/**
|
|
55
|
+
* Parses raw file content into PromptTemplateData.
|
|
56
|
+
* Override this to support different file formats (e.g., JSON, TOML).
|
|
57
|
+
*/
|
|
58
|
+
protected parseContent(content: string, promptId: string): PromptTemplateData;
|
|
59
|
+
/**
|
|
60
|
+
* Serializes PromptTemplateData to file content string.
|
|
61
|
+
* Override this to support different file formats (e.g., JSON, TOML).
|
|
62
|
+
*/
|
|
63
|
+
protected serializeContent(content: PromptTemplateData): string;
|
|
64
|
+
private getCacheKey;
|
|
65
|
+
read(id: string, version?: string): Promise<PromptTemplateData>;
|
|
66
|
+
write(content: PromptTemplateData): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a file-based prompt repository.
|
|
70
|
+
*
|
|
71
|
+
* This is a convenience factory function. For subclassing, use `FilePromptRepository` class directly.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const repo = createFilePromptRepository({ directory: './prompts' });
|
|
76
|
+
* const prompt = await repo.read<GreetingInput>('greeting');
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function createFilePromptRepository(options: FilePromptRepositoryOptions): PromptRepository;
|
|
80
|
+
//# sourceMappingURL=file-prompt-repository.d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,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA+DpE;IAEK,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BtD;CACJ;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,2BAA2B,GAAG,gBAAgB,CAEjG"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-based prompt repository implementation.
|
|
3
|
+
*
|
|
4
|
+
* Stores prompts as YAML files with naming convention: {id}-{version}.yaml
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'node:fs/promises';
|
|
7
|
+
import * as path from 'node:path';
|
|
8
|
+
import * as yaml from 'yaml';
|
|
9
|
+
import { PromptIOError, PromptInvalidFormatError, PromptNotFoundError } from './errors.js';
|
|
10
|
+
import { compileTemplate } from './template.js';
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Error Utilities
|
|
13
|
+
// =============================================================================
|
|
14
|
+
function toErrorCause(error) {
|
|
15
|
+
return error instanceof Error ? error : undefined;
|
|
16
|
+
}
|
|
17
|
+
function toErrorMessage(error) {
|
|
18
|
+
return error instanceof Error ? error.message : String(error);
|
|
19
|
+
}
|
|
20
|
+
// =============================================================================
|
|
21
|
+
// Default File System Implementation
|
|
22
|
+
// =============================================================================
|
|
23
|
+
const defaultFileSystem = {
|
|
24
|
+
readFile: (filePath) => fs.readFile(filePath, 'utf-8'),
|
|
25
|
+
writeFile: (filePath, content) => fs.writeFile(filePath, content, 'utf-8'),
|
|
26
|
+
readdir: (dirPath) => fs.readdir(dirPath),
|
|
27
|
+
};
|
|
28
|
+
// =============================================================================
|
|
29
|
+
// Version Utilities
|
|
30
|
+
// =============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* Parses a semver version string into numeric components.
|
|
33
|
+
* @param version - Version string (e.g., '1.2.3')
|
|
34
|
+
* @returns Tuple of [major, minor, patch] or null if invalid
|
|
35
|
+
*/
|
|
36
|
+
function parseVersion(version) {
|
|
37
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)$/);
|
|
38
|
+
if (!match)
|
|
39
|
+
return null;
|
|
40
|
+
return [parseInt(match[1], 10), parseInt(match[2], 10), parseInt(match[3], 10)];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Compares two semver versions.
|
|
44
|
+
* @returns Negative if a < b, positive if a > b, zero if equal
|
|
45
|
+
*/
|
|
46
|
+
function compareVersions(a, b) {
|
|
47
|
+
const parsedA = parseVersion(a);
|
|
48
|
+
const parsedB = parseVersion(b);
|
|
49
|
+
// Invalid versions sort last
|
|
50
|
+
if (!parsedA && !parsedB)
|
|
51
|
+
return 0;
|
|
52
|
+
if (!parsedA)
|
|
53
|
+
return 1;
|
|
54
|
+
if (!parsedB)
|
|
55
|
+
return -1;
|
|
56
|
+
for (let i = 0; i < 3; i++) {
|
|
57
|
+
if (parsedA[i] !== parsedB[i]) {
|
|
58
|
+
return parsedA[i] - parsedB[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
// =============================================================================
|
|
64
|
+
// File Name Utilities
|
|
65
|
+
// =============================================================================
|
|
66
|
+
const FILE_EXTENSION = '.yaml';
|
|
67
|
+
/**
|
|
68
|
+
* Generates file name from prompt id and version.
|
|
69
|
+
* @example getFileName('greeting', '1.0.0') => 'greeting-1.0.0.yaml'
|
|
70
|
+
*/
|
|
71
|
+
function getFileName(id, version) {
|
|
72
|
+
return `${id}-${version}${FILE_EXTENSION}`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Parses file name into id and version.
|
|
76
|
+
* @example parseFileName('greeting-1.0.0.yaml') => { id: 'greeting', version: '1.0.0' }
|
|
77
|
+
*/
|
|
78
|
+
function parseFileName(fileName) {
|
|
79
|
+
if (!fileName.endsWith(FILE_EXTENSION))
|
|
80
|
+
return null;
|
|
81
|
+
const baseName = fileName.slice(0, -FILE_EXTENSION.length);
|
|
82
|
+
const lastDash = baseName.lastIndexOf('-');
|
|
83
|
+
if (lastDash === -1)
|
|
84
|
+
return null;
|
|
85
|
+
const id = baseName.slice(0, lastDash);
|
|
86
|
+
const version = baseName.slice(lastDash + 1);
|
|
87
|
+
if (!id || !parseVersion(version))
|
|
88
|
+
return null;
|
|
89
|
+
return { id, version };
|
|
90
|
+
}
|
|
91
|
+
// =============================================================================
|
|
92
|
+
// YAML Parsing & Validation
|
|
93
|
+
// =============================================================================
|
|
94
|
+
/**
|
|
95
|
+
* Parses and validates YAML content as PromptTemplateData.
|
|
96
|
+
*/
|
|
97
|
+
function parsePromptYaml(content, promptId) {
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = yaml.parse(content);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw new PromptInvalidFormatError(promptId, `Invalid YAML: ${toErrorMessage(error)}`, {
|
|
104
|
+
cause: toErrorCause(error),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
108
|
+
throw new PromptInvalidFormatError(promptId, 'Expected YAML object');
|
|
109
|
+
}
|
|
110
|
+
const obj = parsed;
|
|
111
|
+
// Validate required fields
|
|
112
|
+
const requiredFields = ['id', 'version', 'system', 'userTemplate'];
|
|
113
|
+
for (const field of requiredFields) {
|
|
114
|
+
if (typeof obj[field] !== 'string') {
|
|
115
|
+
throw new PromptInvalidFormatError(promptId, `Missing or invalid required field: ${field} (expected string)`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
id: obj.id,
|
|
120
|
+
version: obj.version,
|
|
121
|
+
system: obj.system,
|
|
122
|
+
userTemplate: obj.userTemplate,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Serializes PromptTemplateData to YAML string.
|
|
127
|
+
*/
|
|
128
|
+
function serializePromptYaml(content) {
|
|
129
|
+
return yaml.stringify(content);
|
|
130
|
+
}
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// Repository Implementation
|
|
133
|
+
// =============================================================================
|
|
134
|
+
/**
|
|
135
|
+
* File-based prompt repository.
|
|
136
|
+
*
|
|
137
|
+
* Prompts are stored as YAML files with naming convention: {id}-{version}.yaml
|
|
138
|
+
*
|
|
139
|
+
* Can be subclassed to customize parsing/serialization (e.g., JSON instead of YAML).
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const repo = new FilePromptRepository({ directory: './prompts' });
|
|
144
|
+
*
|
|
145
|
+
* // Read latest version
|
|
146
|
+
* const prompt = await repo.read<GreetingInput>('greeting');
|
|
147
|
+
*
|
|
148
|
+
* // Subclass to use JSON format
|
|
149
|
+
* class JsonPromptRepository extends FilePromptRepository {
|
|
150
|
+
* protected parseContent(content: string, promptId: string): PromptTemplateData {
|
|
151
|
+
* return JSON.parse(content);
|
|
152
|
+
* }
|
|
153
|
+
* protected serializeContent(content: PromptTemplateData): string {
|
|
154
|
+
* return JSON.stringify(content, null, 2);
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export class FilePromptRepository {
|
|
160
|
+
directory;
|
|
161
|
+
fileSystem;
|
|
162
|
+
cacheEnabled;
|
|
163
|
+
contentCache = new Map();
|
|
164
|
+
constructor(options) {
|
|
165
|
+
this.directory = options.directory;
|
|
166
|
+
this.fileSystem = options.fs ?? defaultFileSystem;
|
|
167
|
+
this.cacheEnabled = options.cache ?? true;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Generates file name from prompt id and version.
|
|
171
|
+
* Override this along with `parseFileName` to change file naming convention.
|
|
172
|
+
*/
|
|
173
|
+
getFileName(id, version) {
|
|
174
|
+
return getFileName(id, version);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Parses file name into id and version.
|
|
178
|
+
* Override this along with `getFileName` to change file naming convention.
|
|
179
|
+
*/
|
|
180
|
+
parseFileName(fileName) {
|
|
181
|
+
return parseFileName(fileName);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Parses raw file content into PromptTemplateData.
|
|
185
|
+
* Override this to support different file formats (e.g., JSON, TOML).
|
|
186
|
+
*/
|
|
187
|
+
parseContent(content, promptId) {
|
|
188
|
+
return parsePromptYaml(content, promptId);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Serializes PromptTemplateData to file content string.
|
|
192
|
+
* Override this to support different file formats (e.g., JSON, TOML).
|
|
193
|
+
*/
|
|
194
|
+
serializeContent(content) {
|
|
195
|
+
return serializePromptYaml(content);
|
|
196
|
+
}
|
|
197
|
+
getCacheKey(id, version) {
|
|
198
|
+
return `${id}:${version}`;
|
|
199
|
+
}
|
|
200
|
+
async read(id, version) {
|
|
201
|
+
if (version) {
|
|
202
|
+
const cacheKey = this.getCacheKey(id, version);
|
|
203
|
+
if (this.cacheEnabled) {
|
|
204
|
+
const cached = this.contentCache.get(cacheKey);
|
|
205
|
+
if (cached) {
|
|
206
|
+
return cached;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const fileName = this.getFileName(id, version);
|
|
210
|
+
const filePath = path.join(this.directory, fileName);
|
|
211
|
+
let content;
|
|
212
|
+
try {
|
|
213
|
+
content = await this.fileSystem.readFile(filePath);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
217
|
+
throw new PromptNotFoundError(id, version);
|
|
218
|
+
}
|
|
219
|
+
throw new PromptIOError('read', filePath, { cause: toErrorCause(error) });
|
|
220
|
+
}
|
|
221
|
+
const promptTemplate = this.parseContent(content, id);
|
|
222
|
+
if (promptTemplate.id !== id || promptTemplate.version !== version) {
|
|
223
|
+
throw new PromptInvalidFormatError(id, `File content mismatch: expected id='${id}' version='${version}', got id='${promptTemplate.id}' version='${promptTemplate.version}'`);
|
|
224
|
+
}
|
|
225
|
+
if (this.cacheEnabled) {
|
|
226
|
+
this.contentCache.set(cacheKey, promptTemplate);
|
|
227
|
+
}
|
|
228
|
+
return promptTemplate;
|
|
229
|
+
}
|
|
230
|
+
let files;
|
|
231
|
+
try {
|
|
232
|
+
files = await this.fileSystem.readdir(this.directory);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
throw new PromptIOError('list', this.directory, { cause: toErrorCause(error) });
|
|
236
|
+
}
|
|
237
|
+
const versions = [];
|
|
238
|
+
for (const file of files) {
|
|
239
|
+
const parsed = this.parseFileName(file);
|
|
240
|
+
if (parsed && parsed.id === id) {
|
|
241
|
+
versions.push(parsed.version);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (versions.length === 0) {
|
|
245
|
+
throw new PromptNotFoundError(id);
|
|
246
|
+
}
|
|
247
|
+
versions.sort((a, b) => compareVersions(b, a));
|
|
248
|
+
const latestVersion = versions[0];
|
|
249
|
+
return this.read(id, latestVersion);
|
|
250
|
+
}
|
|
251
|
+
async write(content) {
|
|
252
|
+
// Invalidate cache for this id:version (before any validation)
|
|
253
|
+
if (this.cacheEnabled) {
|
|
254
|
+
this.contentCache.delete(this.getCacheKey(content.id, content.version));
|
|
255
|
+
}
|
|
256
|
+
const fileName = this.getFileName(content.id, content.version);
|
|
257
|
+
const filePath = path.join(this.directory, fileName);
|
|
258
|
+
if (!parseVersion(content.version)) {
|
|
259
|
+
throw new PromptInvalidFormatError(content.id, `Invalid version format: '${content.version}' (expected semver like '1.0.0')`);
|
|
260
|
+
}
|
|
261
|
+
// Validate templates can be compiled (fails fast on syntax errors)
|
|
262
|
+
compileTemplate(content.system, content.id);
|
|
263
|
+
compileTemplate(content.userTemplate, content.id);
|
|
264
|
+
const yamlContent = this.serializeContent(content);
|
|
265
|
+
try {
|
|
266
|
+
await this.fileSystem.writeFile(filePath, yamlContent);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
throw new PromptIOError('write', filePath, { cause: toErrorCause(error) });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Creates a file-based prompt repository.
|
|
275
|
+
*
|
|
276
|
+
* This is a convenience factory function. For subclassing, use `FilePromptRepository` class directly.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const repo = createFilePromptRepository({ directory: './prompts' });
|
|
281
|
+
* const prompt = await repo.read<GreetingInput>('greeting');
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export function createFilePromptRepository(options) {
|
|
285
|
+
return new FilePromptRepository(options);
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=file-prompt-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-prompt-repository.js","sourceRoot":"","sources":["../../src/prompt/file-prompt-repository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAgBhD,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF,SAAS,YAAY,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC;AAED,gFAAgF;AAChF,q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AAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,wBAAwB,CAC9B,OAAO,CAAC,EAAE,EACV,4BAA4B,OAAO,CAAC,OAAO,kCAAkC,CAChF,CAAC;QACN,CAAC;QAED,mEAAmE;QACnE,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,eAAe,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAElD,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAEnD,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/E,CAAC;IACL,CAAC;CACJ;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAoC;IAC3E,OAAO,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt module for @agtlantis/core.
|
|
3
|
+
*
|
|
4
|
+
* Provides structured prompt management with versioning, templating, and repository abstraction.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import {
|
|
9
|
+
* createFilePromptRepository,
|
|
10
|
+
* PromptTemplate,
|
|
11
|
+
* type PromptRenderer,
|
|
12
|
+
* } from '@agtlantis/core';
|
|
13
|
+
*
|
|
14
|
+
* // Create a file-based repository
|
|
15
|
+
* const repo = createFilePromptRepository({ directory: './prompts' });
|
|
16
|
+
*
|
|
17
|
+
* // Read a prompt and compile to renderer
|
|
18
|
+
* interface SessionCtx { studentName: string }
|
|
19
|
+
* interface TurnCtx { answers: string[] }
|
|
20
|
+
*
|
|
21
|
+
* const data = await repo.read('greeting');
|
|
22
|
+
* const renderer = PromptTemplate.from(data).compile<SessionCtx, TurnCtx>();
|
|
23
|
+
*
|
|
24
|
+
* // Use the renderer
|
|
25
|
+
* const systemPrompt = renderer.renderSystemPrompt({ studentName: 'Kim' });
|
|
26
|
+
* const userPrompt = renderer.renderUserPrompt({ answers: ['A', 'B'] });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type { PromptTemplateData, PromptRenderer, PromptRepository, FileSystem } from './types.js';
|
|
30
|
+
export { PromptTemplate } from './prompt-template.js';
|
|
31
|
+
export { PromptErrorCode, PromptError, PromptNotFoundError, PromptInvalidFormatError, PromptTemplateError, PromptIOError, type PromptErrorOptions, } from './errors.js';
|
|
32
|
+
export { compileTemplate } from './template.js';
|
|
33
|
+
export { FilePromptRepository, createFilePromptRepository, type FilePromptRepositoryOptions, } from './file-prompt-repository.js';
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompt/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGnG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EACH,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,KAAK,kBAAkB,GAC1B,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EACH,oBAAoB,EACpB,0BAA0B,EAC1B,KAAK,2BAA2B,GACnC,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt module for @agtlantis/core.
|
|
3
|
+
*
|
|
4
|
+
* Provides structured prompt management with versioning, templating, and repository abstraction.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import {
|
|
9
|
+
* createFilePromptRepository,
|
|
10
|
+
* PromptTemplate,
|
|
11
|
+
* type PromptRenderer,
|
|
12
|
+
* } from '@agtlantis/core';
|
|
13
|
+
*
|
|
14
|
+
* // Create a file-based repository
|
|
15
|
+
* const repo = createFilePromptRepository({ directory: './prompts' });
|
|
16
|
+
*
|
|
17
|
+
* // Read a prompt and compile to renderer
|
|
18
|
+
* interface SessionCtx { studentName: string }
|
|
19
|
+
* interface TurnCtx { answers: string[] }
|
|
20
|
+
*
|
|
21
|
+
* const data = await repo.read('greeting');
|
|
22
|
+
* const renderer = PromptTemplate.from(data).compile<SessionCtx, TurnCtx>();
|
|
23
|
+
*
|
|
24
|
+
* // Use the renderer
|
|
25
|
+
* const systemPrompt = renderer.renderSystemPrompt({ studentName: 'Kim' });
|
|
26
|
+
* const userPrompt = renderer.renderUserPrompt({ answers: ['A', 'B'] });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
// PromptTemplate class
|
|
30
|
+
export { PromptTemplate } from './prompt-template.js';
|
|
31
|
+
// Errors
|
|
32
|
+
export { PromptErrorCode, PromptError, PromptNotFoundError, PromptInvalidFormatError, PromptTemplateError, PromptIOError, } from './errors.js';
|
|
33
|
+
// Template utilities
|
|
34
|
+
export { compileTemplate } from './template.js';
|
|
35
|
+
// Repository implementations
|
|
36
|
+
export { FilePromptRepository, createFilePromptRepository, } from './file-prompt-repository.js';
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompt/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAKH,uBAAuB;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,SAAS;AACT,OAAO,EACH,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,GAEhB,MAAM,aAAa,CAAC;AAErB,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,6BAA6B;AAC7B,OAAO,EACH,oBAAoB,EACpB,0BAA0B,GAE7B,MAAM,6BAA6B,CAAC"}
|