@treasuryspatial/render-kit 0.1.2 → 0.1.4
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/prompt-pack/builder.d.ts +4 -0
- package/dist/prompt-pack/builder.d.ts.map +1 -0
- package/dist/prompt-pack/builder.js +191 -0
- package/dist/prompt-pack/conditions.d.ts +11 -0
- package/dist/prompt-pack/conditions.d.ts.map +1 -0
- package/dist/prompt-pack/conditions.js +89 -0
- package/dist/prompt-pack/index.d.ts +4 -0
- package/dist/prompt-pack/index.d.ts.map +1 -0
- package/dist/prompt-pack/index.js +3 -0
- package/dist/prompt-pack/sources.d.ts +3 -0
- package/dist/prompt-pack/sources.d.ts.map +1 -0
- package/dist/prompt-pack/sources.js +25 -0
- package/dist/prompt-pack/types.d.ts +113 -0
- package/dist/prompt-pack/types.d.ts.map +1 -0
- package/dist/prompt-pack/types.js +1 -0
- package/dist/render-prompt.d.ts +4 -0
- package/dist/render-prompt.d.ts.map +1 -1
- package/dist/render-prompt.js +4 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PromptPack, PromptPackBuildOptions, PromptPackBuildResult } from './types';
|
|
2
|
+
export declare const buildPromptFromPack: (pack: PromptPack, options: PromptPackBuildOptions) => PromptPackBuildResult;
|
|
3
|
+
export declare const buildUserPrompt: (value: string) => string;
|
|
4
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/prompt-pack/builder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAKV,UAAU,EACV,sBAAsB,EACtB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAwJjB,eAAO,MAAM,mBAAmB,GAAI,MAAM,UAAU,EAAE,SAAS,sBAAsB,KAAG,qBA8DvF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,WAAgC,CAAC"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { buildCompositePrompt, buildRenderSpec, buildUserPromptBlock } from '../render-spec';
|
|
2
|
+
import { buildCourtyardTaskBlock } from '../render-spec';
|
|
3
|
+
import { applyTemplate, collectFieldTags, ensureSentence, evaluateCondition } from './conditions';
|
|
4
|
+
import { resolveOptionSource } from './sources';
|
|
5
|
+
const BLOCK_ORDER = ['task', 'form', 'view', 'style', 'program', 'context'];
|
|
6
|
+
const asArray = (value) => value ?? [];
|
|
7
|
+
const getStateValue = (state, path) => {
|
|
8
|
+
if (!path)
|
|
9
|
+
return undefined;
|
|
10
|
+
return path.split('.').reduce((acc, key) => {
|
|
11
|
+
if (acc && typeof acc === 'object' && key in acc) {
|
|
12
|
+
return acc[key];
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}, state);
|
|
16
|
+
};
|
|
17
|
+
const buildOptionLines = (field, option, value, neutralize, ensure) => {
|
|
18
|
+
if (!option)
|
|
19
|
+
return [];
|
|
20
|
+
if (field.promptTemplate || field.promptTemplateNeutral) {
|
|
21
|
+
const template = neutralize && field.promptTemplateNeutral ? field.promptTemplateNeutral : field.promptTemplate;
|
|
22
|
+
if (!template)
|
|
23
|
+
return [];
|
|
24
|
+
const rendered = applyTemplate(template, option, value);
|
|
25
|
+
return rendered ? [ensure ? ensureSentence(rendered) : rendered] : [];
|
|
26
|
+
}
|
|
27
|
+
const baseLines = option.promptLines?.length
|
|
28
|
+
? option.promptLines
|
|
29
|
+
: option.prompt
|
|
30
|
+
? [option.prompt]
|
|
31
|
+
: [option.label || String(option.value)];
|
|
32
|
+
const lines = neutralize && option.promptNeutral ? [option.promptNeutral] : baseLines;
|
|
33
|
+
const allLines = [...lines, ...(option.promptExtra ?? [])];
|
|
34
|
+
return allLines
|
|
35
|
+
.map((line) => (ensure ? ensureSentence(line) : line))
|
|
36
|
+
.filter((line) => Boolean(line?.trim()));
|
|
37
|
+
};
|
|
38
|
+
const resolveOptions = (pack, field, optionSourceResolver) => {
|
|
39
|
+
if (field.options?.length)
|
|
40
|
+
return field.options;
|
|
41
|
+
if (field.optionSource) {
|
|
42
|
+
const local = pack.optionSources?.[field.optionSource];
|
|
43
|
+
if (local)
|
|
44
|
+
return local;
|
|
45
|
+
const resolved = optionSourceResolver?.(field.optionSource) ?? resolveOptionSource(field.optionSource);
|
|
46
|
+
if (resolved)
|
|
47
|
+
return resolved;
|
|
48
|
+
}
|
|
49
|
+
return [];
|
|
50
|
+
};
|
|
51
|
+
const buildFieldLines = (pack, field, state, optionSourceResolver) => {
|
|
52
|
+
const value = getStateValue(state, field.id);
|
|
53
|
+
const options = resolveOptions(pack, field, optionSourceResolver);
|
|
54
|
+
const tags = new Set();
|
|
55
|
+
const neutralize = field.neutralizeWhen ? evaluateCondition(field.neutralizeWhen, { state, fieldTags: {}, anyContent: false }) : false;
|
|
56
|
+
const ensure = Boolean(field.ensureSentence);
|
|
57
|
+
if (field.type === 'toggle') {
|
|
58
|
+
const isOn = Boolean(value);
|
|
59
|
+
const text = isOn ? field.promptOn : field.promptOff;
|
|
60
|
+
if (!text)
|
|
61
|
+
return { lines: [], tags };
|
|
62
|
+
return { lines: [ensure ? ensureSentence(text) : text], tags };
|
|
63
|
+
}
|
|
64
|
+
if (field.type === 'text') {
|
|
65
|
+
if (value === undefined || value === null || String(value).trim() === '')
|
|
66
|
+
return { lines: [], tags };
|
|
67
|
+
if (field.promptTemplate || field.promptTemplateNeutral) {
|
|
68
|
+
const template = neutralize && field.promptTemplateNeutral ? field.promptTemplateNeutral : field.promptTemplate;
|
|
69
|
+
if (!template)
|
|
70
|
+
return { lines: [], tags };
|
|
71
|
+
const rendered = applyTemplate(template, null, String(value));
|
|
72
|
+
return { lines: [ensure ? ensureSentence(rendered) : rendered], tags };
|
|
73
|
+
}
|
|
74
|
+
return { lines: [ensure ? ensureSentence(String(value)) : String(value)], tags };
|
|
75
|
+
}
|
|
76
|
+
if (field.type === 'select') {
|
|
77
|
+
const option = options.find((item) => item.value === value) ?? options.find((item) => item.label === value);
|
|
78
|
+
if (option?.tags)
|
|
79
|
+
option.tags.forEach((tag) => tags.add(tag));
|
|
80
|
+
return { lines: buildOptionLines(field, option, value, neutralize, ensure), tags };
|
|
81
|
+
}
|
|
82
|
+
if (field.type === 'multi') {
|
|
83
|
+
const list = Array.isArray(value) ? value : [];
|
|
84
|
+
const lines = [];
|
|
85
|
+
list.forEach((entry) => {
|
|
86
|
+
const option = options.find((item) => item.value === entry) ?? options.find((item) => item.label === entry);
|
|
87
|
+
if (option?.tags)
|
|
88
|
+
option.tags.forEach((tag) => tags.add(tag));
|
|
89
|
+
lines.push(...buildOptionLines(field, option, entry, neutralize, ensure));
|
|
90
|
+
});
|
|
91
|
+
return { lines, tags };
|
|
92
|
+
}
|
|
93
|
+
return { lines: [], tags };
|
|
94
|
+
};
|
|
95
|
+
const buildBlock = (pack, spec, state, optionSourceResolver) => {
|
|
96
|
+
const lines = [];
|
|
97
|
+
const fieldTags = {};
|
|
98
|
+
const initialContext = { state, fieldTags, anyContent: false };
|
|
99
|
+
asArray(spec.lines).forEach((line) => {
|
|
100
|
+
if (evaluateCondition(line.when, initialContext)) {
|
|
101
|
+
lines.push(line.ensureSentence ? ensureSentence(line.text) : line.text);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
asArray(spec.fields).forEach((fieldId) => {
|
|
105
|
+
const field = pack.fields[fieldId];
|
|
106
|
+
if (!field)
|
|
107
|
+
return;
|
|
108
|
+
const { lines: fieldLines, tags } = buildFieldLines(pack, field, state, optionSourceResolver);
|
|
109
|
+
if (fieldLines.length)
|
|
110
|
+
lines.push(...fieldLines);
|
|
111
|
+
fieldTags[fieldId] = tags;
|
|
112
|
+
});
|
|
113
|
+
const context = { state, fieldTags, anyContent: lines.length > 0 };
|
|
114
|
+
asArray(spec.footerLines).forEach((line) => {
|
|
115
|
+
if (evaluateCondition(line.when, context)) {
|
|
116
|
+
lines.push(line.ensureSentence ? ensureSentence(line.text) : line.text);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
if (!lines.length)
|
|
120
|
+
return { text: '', tags: fieldTags };
|
|
121
|
+
return { text: ['<' + spec.id + '>', ...lines, '</' + spec.id + '>'].join('\n'), tags: fieldTags };
|
|
122
|
+
};
|
|
123
|
+
const buildTaskBlock = (pack, mode) => {
|
|
124
|
+
const variant = pack.task?.variants[mode] ?? pack.task?.variants.default;
|
|
125
|
+
if (variant?.length) {
|
|
126
|
+
return ['<task>', ...variant, '</task>'].join('\n');
|
|
127
|
+
}
|
|
128
|
+
return buildCourtyardTaskBlock(mode);
|
|
129
|
+
};
|
|
130
|
+
export const buildPromptFromPack = (pack, options) => {
|
|
131
|
+
const order = pack.blockOrder ?? BLOCK_ORDER;
|
|
132
|
+
const blocks = {
|
|
133
|
+
task: '',
|
|
134
|
+
form: '',
|
|
135
|
+
view: '',
|
|
136
|
+
style: '',
|
|
137
|
+
program: '',
|
|
138
|
+
context: '',
|
|
139
|
+
};
|
|
140
|
+
blocks.task = buildTaskBlock(pack, options.mode);
|
|
141
|
+
order
|
|
142
|
+
.filter((id) => id !== 'task')
|
|
143
|
+
.forEach((blockId) => {
|
|
144
|
+
const spec = pack.blocks[blockId];
|
|
145
|
+
if (!spec)
|
|
146
|
+
return;
|
|
147
|
+
const built = buildBlock(pack, spec, options.state, options.optionSourceResolver);
|
|
148
|
+
blocks[blockId] = built.text;
|
|
149
|
+
});
|
|
150
|
+
const renderSpec = buildRenderSpec({
|
|
151
|
+
blocks: {
|
|
152
|
+
task: blocks.task,
|
|
153
|
+
form: blocks.form,
|
|
154
|
+
view: blocks.view,
|
|
155
|
+
style: blocks.style,
|
|
156
|
+
program: blocks.program,
|
|
157
|
+
context: blocks.context,
|
|
158
|
+
},
|
|
159
|
+
taskEnabled: Boolean(blocks.task),
|
|
160
|
+
});
|
|
161
|
+
const fullPrompt = buildCompositePrompt({
|
|
162
|
+
renderSpec,
|
|
163
|
+
userPrompt: options.userPrompt ?? '',
|
|
164
|
+
adaptDelta: options.adaptDelta ?? '',
|
|
165
|
+
});
|
|
166
|
+
const warnings = [];
|
|
167
|
+
if (pack.warnings?.length) {
|
|
168
|
+
const fieldTags = Object.keys(pack.fields).reduce((acc, fieldId) => {
|
|
169
|
+
const field = pack.fields[fieldId];
|
|
170
|
+
if (!field)
|
|
171
|
+
return acc;
|
|
172
|
+
if (field.type === 'toggle' || field.type === 'text')
|
|
173
|
+
return acc;
|
|
174
|
+
const value = getStateValue(options.state, field.id);
|
|
175
|
+
const optionsList = resolveOptions(pack, field, options.optionSourceResolver);
|
|
176
|
+
const selected = Array.isArray(value)
|
|
177
|
+
? optionsList.filter((item) => value.includes(item.value))
|
|
178
|
+
: optionsList.filter((item) => item.value === value || item.label === value);
|
|
179
|
+
const [id, tags] = collectFieldTags(field.id, selected);
|
|
180
|
+
acc[id] = tags;
|
|
181
|
+
return acc;
|
|
182
|
+
}, {});
|
|
183
|
+
const context = { state: options.state, fieldTags, anyContent: false };
|
|
184
|
+
pack.warnings.forEach((warning) => {
|
|
185
|
+
if (evaluateCondition(warning.when, context))
|
|
186
|
+
warnings.push(warning);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return { blocks, renderSpec, fullPrompt, warnings };
|
|
190
|
+
};
|
|
191
|
+
export const buildUserPrompt = (value) => buildUserPromptBlock(value);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PromptCondition, PromptOption } from './types';
|
|
2
|
+
export type PromptConditionContext = {
|
|
3
|
+
state: Record<string, unknown>;
|
|
4
|
+
fieldTags: Record<string, Set<string>>;
|
|
5
|
+
anyContent: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const evaluateCondition: (condition: PromptCondition | undefined, context: PromptConditionContext) => boolean;
|
|
8
|
+
export declare const collectFieldTags: (fieldId: string, selected: PromptOption[]) => [string, Set<string>];
|
|
9
|
+
export declare const applyTemplate: (template: string, option: PromptOption | null, value: string | number | boolean | null | undefined) => string;
|
|
10
|
+
export declare const ensureSentence: (value: string) => string;
|
|
11
|
+
//# sourceMappingURL=conditions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditions.d.ts","sourceRoot":"","sources":["../../src/prompt-pack/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE7D,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACvC,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAkBF,eAAO,MAAM,iBAAiB,GAAI,WAAW,eAAe,GAAG,SAAS,EAAE,SAAS,sBAAsB,KAAG,OAmC3G,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,EAAE,UAAU,YAAY,EAAE,KAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAMhG,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,EAChB,QAAQ,YAAY,GAAG,IAAI,EAC3B,OAAO,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,KAClD,MAeF,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAK9C,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const getStateValue = (state, path) => {
|
|
2
|
+
if (!path)
|
|
3
|
+
return undefined;
|
|
4
|
+
return path.split('.').reduce((acc, key) => {
|
|
5
|
+
if (acc && typeof acc === 'object' && key in acc) {
|
|
6
|
+
return acc[key];
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
}, state);
|
|
10
|
+
};
|
|
11
|
+
const isTruthyValue = (value) => {
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.length > 0;
|
|
14
|
+
if (typeof value === 'string')
|
|
15
|
+
return value.trim().length > 0;
|
|
16
|
+
return Boolean(value);
|
|
17
|
+
};
|
|
18
|
+
export const evaluateCondition = (condition, context) => {
|
|
19
|
+
if (!condition)
|
|
20
|
+
return true;
|
|
21
|
+
if ('all' in condition) {
|
|
22
|
+
return condition.all.every((item) => evaluateCondition(item, context));
|
|
23
|
+
}
|
|
24
|
+
if ('any' in condition) {
|
|
25
|
+
return condition.any.some((item) => evaluateCondition(item, context));
|
|
26
|
+
}
|
|
27
|
+
if ('not' in condition) {
|
|
28
|
+
return !evaluateCondition(condition.not, context);
|
|
29
|
+
}
|
|
30
|
+
if ('anyContent' in condition) {
|
|
31
|
+
return context.anyContent;
|
|
32
|
+
}
|
|
33
|
+
if ('field' in condition && 'hasTag' in condition) {
|
|
34
|
+
const tags = context.fieldTags[condition.field];
|
|
35
|
+
return tags ? tags.has(condition.hasTag) : false;
|
|
36
|
+
}
|
|
37
|
+
if ('field' in condition && 'equals' in condition) {
|
|
38
|
+
return getStateValue(context.state, condition.field) === condition.equals;
|
|
39
|
+
}
|
|
40
|
+
if ('field' in condition && 'in' in condition) {
|
|
41
|
+
const value = getStateValue(context.state, condition.field);
|
|
42
|
+
return condition.in.includes(value);
|
|
43
|
+
}
|
|
44
|
+
if ('field' in condition && 'includes' in condition) {
|
|
45
|
+
const value = getStateValue(context.state, condition.field);
|
|
46
|
+
if (Array.isArray(value))
|
|
47
|
+
return value.includes(condition.includes);
|
|
48
|
+
if (typeof value === 'string')
|
|
49
|
+
return value.includes(condition.includes);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if ('field' in condition && 'isTruthy' in condition) {
|
|
53
|
+
return isTruthyValue(getStateValue(context.state, condition.field));
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
export const collectFieldTags = (fieldId, selected) => {
|
|
58
|
+
const tags = new Set();
|
|
59
|
+
selected.forEach((option) => {
|
|
60
|
+
option.tags?.forEach((tag) => tags.add(tag));
|
|
61
|
+
});
|
|
62
|
+
return [fieldId, tags];
|
|
63
|
+
};
|
|
64
|
+
export const applyTemplate = (template, option, value) => {
|
|
65
|
+
if (!template)
|
|
66
|
+
return '';
|
|
67
|
+
const replacements = {
|
|
68
|
+
value: value === undefined || value === null ? '' : String(value),
|
|
69
|
+
label: option?.label ?? '',
|
|
70
|
+
};
|
|
71
|
+
if (option?.meta) {
|
|
72
|
+
Object.entries(option.meta).forEach(([key, metaValue]) => {
|
|
73
|
+
replacements[key] = String(metaValue);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return template.replace(/\{([a-zA-Z0-9_-]+)\}/g, (match, key) => {
|
|
77
|
+
if (key in replacements)
|
|
78
|
+
return replacements[key];
|
|
79
|
+
return match;
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
export const ensureSentence = (value) => {
|
|
83
|
+
const trimmed = value.trim();
|
|
84
|
+
if (!trimmed)
|
|
85
|
+
return '';
|
|
86
|
+
if (/[.!?]$/.test(trimmed))
|
|
87
|
+
return trimmed;
|
|
88
|
+
return `${trimmed}.`;
|
|
89
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompt-pack/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../../src/prompt-pack/sources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,YAAY,EAAE,GAAG,SAuBvE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ERA_PRESETS, LOCATION_PRESETS, TIME_OF_DAY_PRESETS } from '../render-prompt';
|
|
2
|
+
export const resolveOptionSource = (sourceId) => {
|
|
3
|
+
if (sourceId === 'render-kit:location') {
|
|
4
|
+
return Object.entries(LOCATION_PRESETS).map(([value, preset]) => ({
|
|
5
|
+
value,
|
|
6
|
+
label: preset.label,
|
|
7
|
+
meta: { scene: preset.scene },
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
if (sourceId === 'render-kit:time-of-day') {
|
|
11
|
+
return Object.entries(TIME_OF_DAY_PRESETS).map(([value, detail]) => ({
|
|
12
|
+
value,
|
|
13
|
+
label: value.replace(/_/g, ' '),
|
|
14
|
+
meta: { detail },
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
if (sourceId === 'render-kit:era') {
|
|
18
|
+
return Object.entries(ERA_PRESETS).map(([value, preset]) => ({
|
|
19
|
+
value,
|
|
20
|
+
label: preset.label,
|
|
21
|
+
meta: { style: preset.style },
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export type PromptBlockId = 'task' | 'form' | 'view' | 'style' | 'program' | 'context';
|
|
2
|
+
export type PromptMode = 'design' | 'imagine' | 'map' | string;
|
|
3
|
+
export type PromptCondition = {
|
|
4
|
+
all: PromptCondition[];
|
|
5
|
+
} | {
|
|
6
|
+
any: PromptCondition[];
|
|
7
|
+
} | {
|
|
8
|
+
not: PromptCondition;
|
|
9
|
+
} | {
|
|
10
|
+
field: string;
|
|
11
|
+
equals: string | number | boolean | null;
|
|
12
|
+
} | {
|
|
13
|
+
field: string;
|
|
14
|
+
in: Array<string | number | boolean>;
|
|
15
|
+
} | {
|
|
16
|
+
field: string;
|
|
17
|
+
includes: string;
|
|
18
|
+
} | {
|
|
19
|
+
field: string;
|
|
20
|
+
isTruthy: true;
|
|
21
|
+
} | {
|
|
22
|
+
field: string;
|
|
23
|
+
hasTag: string;
|
|
24
|
+
} | {
|
|
25
|
+
anyContent: true;
|
|
26
|
+
};
|
|
27
|
+
export type PromptLine = {
|
|
28
|
+
text: string;
|
|
29
|
+
when?: PromptCondition;
|
|
30
|
+
ensureSentence?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type PromptOption = {
|
|
33
|
+
value: string;
|
|
34
|
+
label: string;
|
|
35
|
+
prompt?: string;
|
|
36
|
+
promptLines?: string[];
|
|
37
|
+
promptExtra?: string[];
|
|
38
|
+
promptNeutral?: string;
|
|
39
|
+
tags?: string[];
|
|
40
|
+
meta?: Record<string, string | number | boolean>;
|
|
41
|
+
};
|
|
42
|
+
export type PromptFieldBase = {
|
|
43
|
+
id: string;
|
|
44
|
+
label?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
block?: PromptBlockId;
|
|
47
|
+
optionSource?: string;
|
|
48
|
+
options?: PromptOption[];
|
|
49
|
+
promptTemplate?: string;
|
|
50
|
+
promptTemplateNeutral?: string;
|
|
51
|
+
neutralizeWhen?: PromptCondition;
|
|
52
|
+
ensureSentence?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type PromptField = (PromptFieldBase & {
|
|
55
|
+
type: 'select';
|
|
56
|
+
}) | (PromptFieldBase & {
|
|
57
|
+
type: 'multi';
|
|
58
|
+
}) | (PromptFieldBase & {
|
|
59
|
+
type: 'toggle';
|
|
60
|
+
promptOn?: string;
|
|
61
|
+
promptOff?: string;
|
|
62
|
+
}) | (PromptFieldBase & {
|
|
63
|
+
type: 'text';
|
|
64
|
+
});
|
|
65
|
+
export type PromptBlockSpec = {
|
|
66
|
+
id: PromptBlockId;
|
|
67
|
+
label?: string;
|
|
68
|
+
fields?: string[];
|
|
69
|
+
lines?: PromptLine[];
|
|
70
|
+
footerLines?: PromptLine[];
|
|
71
|
+
};
|
|
72
|
+
export type PromptTaskSpec = {
|
|
73
|
+
variants: Record<string, string[]>;
|
|
74
|
+
};
|
|
75
|
+
export type PromptWarningSpec = {
|
|
76
|
+
id: string;
|
|
77
|
+
message: string;
|
|
78
|
+
when: PromptCondition;
|
|
79
|
+
};
|
|
80
|
+
export type PromptSectionSpec = {
|
|
81
|
+
id: string;
|
|
82
|
+
label: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
blocks?: PromptBlockId[];
|
|
85
|
+
fields?: string[];
|
|
86
|
+
};
|
|
87
|
+
export type PromptPack = {
|
|
88
|
+
id: string;
|
|
89
|
+
version: string;
|
|
90
|
+
label?: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
blockOrder?: PromptBlockId[];
|
|
93
|
+
task?: PromptTaskSpec;
|
|
94
|
+
blocks: Record<PromptBlockId, PromptBlockSpec>;
|
|
95
|
+
fields: Record<string, PromptField>;
|
|
96
|
+
sections?: PromptSectionSpec[];
|
|
97
|
+
optionSources?: Record<string, PromptOption[]>;
|
|
98
|
+
warnings?: PromptWarningSpec[];
|
|
99
|
+
};
|
|
100
|
+
export type PromptPackBuildOptions = {
|
|
101
|
+
mode: PromptMode;
|
|
102
|
+
state: Record<string, unknown>;
|
|
103
|
+
userPrompt?: string;
|
|
104
|
+
adaptDelta?: string;
|
|
105
|
+
optionSourceResolver?: (sourceId: string) => PromptOption[] | undefined;
|
|
106
|
+
};
|
|
107
|
+
export type PromptPackBuildResult = {
|
|
108
|
+
blocks: Record<PromptBlockId, string>;
|
|
109
|
+
renderSpec: string;
|
|
110
|
+
fullPrompt: string;
|
|
111
|
+
warnings: PromptWarningSpec[];
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/prompt-pack/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAEvF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAE/D,MAAM,MAAM,eAAe,GACvB;IAAE,GAAG,EAAE,eAAe,EAAE,CAAA;CAAE,GAC1B;IAAE,GAAG,EAAE,eAAe,EAAE,CAAA;CAAE,GAC1B;IAAE,GAAG,EAAE,eAAe,CAAA;CAAE,GACxB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;CAAE,GAC3D;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;CAAE,GACvD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAA;CAAE,GACjC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,UAAU,EAAE,IAAI,CAAA;CAAE,CAAC;AAEzB,MAAM,MAAM,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AE,CAAC,CAAC;IAC/C,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,YAAY,EAAE,GAAG,SAAS,CAAC;CACzE,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/render-prompt.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export declare const LOCATION_PRESETS: {
|
|
|
28
28
|
readonly label: "Addis Ababa";
|
|
29
29
|
readonly scene: "Addis Ababa courtyard: basalt stone walls, corrugated metal accents, warm plaster, timber windows; courtyard with stone paving and eucalyptus planting; adjacent street with mixed asphalt and stone edges.";
|
|
30
30
|
};
|
|
31
|
+
readonly nairobi: {
|
|
32
|
+
readonly label: "Nairobi, Kenya";
|
|
33
|
+
readonly scene: "Nairobi courtyard: warm stone or stucco facades with concrete frames, timber or metal screens, and shaded balconies; courtyard with red clay tones, stone paving, and lush highland planting; adjacent street with clean asphalt, masonry curbs, and East African urban texture under bright equatorial light.";
|
|
34
|
+
};
|
|
31
35
|
readonly cairo: {
|
|
32
36
|
readonly label: "Cairo";
|
|
33
37
|
readonly scene: "Cairo courtyard: sandy limestone and plaster facades, mashrabiya screens, arched colonnades; courtyard with stone paving and shade trees; adjacent street with dusty asphalt, stone curbs, and layered urban texture.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-prompt.d.ts","sourceRoot":"","sources":["../src/render-prompt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAMd,CAAC;AAEb,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"render-prompt.d.ts","sourceRoot":"","sources":["../src/render-prompt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAMd,CAAC;AAEb,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwSnB,CAAC;AAEX,eAAO,MAAM,mBAAmB;;;;;;;CAOtB,CAAC;AAEX,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoFd,CAAC;AAEX,eAAO,MAAM,oBAAoB;;;;;;;CAOvB,CAAC;AAEX,eAAO,MAAM,aAAa,UAazB,CAAC;AAiBF,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAC3D,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAC/D,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,WAAW,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAChE,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAEjE,eAAO,MAAM,gBAAgB,EAAE,cAA4B,CAAC;AAC5D,eAAO,MAAM,mBAAm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B,CAAC,EAC3C,OAA2B,EAC3B,QAAQ,EACR,SAAS,EACT,GAAG,EACH,OAAO,EACP,UAAU,EACV,SAAS,GACV,EAAE,gCAAgC,GAAG;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAyFA"}
|
package/dist/render-prompt.js
CHANGED
|
@@ -35,6 +35,10 @@ export const LOCATION_PRESETS = {
|
|
|
35
35
|
label: 'Addis Ababa',
|
|
36
36
|
scene: 'Addis Ababa courtyard: basalt stone walls, corrugated metal accents, warm plaster, timber windows; courtyard with stone paving and eucalyptus planting; adjacent street with mixed asphalt and stone edges.',
|
|
37
37
|
},
|
|
38
|
+
nairobi: {
|
|
39
|
+
label: 'Nairobi, Kenya',
|
|
40
|
+
scene: 'Nairobi courtyard: warm stone or stucco facades with concrete frames, timber or metal screens, and shaded balconies; courtyard with red clay tones, stone paving, and lush highland planting; adjacent street with clean asphalt, masonry curbs, and East African urban texture under bright equatorial light.',
|
|
41
|
+
},
|
|
38
42
|
cairo: {
|
|
39
43
|
label: 'Cairo',
|
|
40
44
|
scene: 'Cairo courtyard: sandy limestone and plaster facades, mashrabiya screens, arched colonnades; courtyard with stone paving and shade trees; adjacent street with dusty asphalt, stone curbs, and layered urban texture.',
|