@sudobility/shapeshyft_engine 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +27 -0
- package/README.md +11 -0
- package/dist/config/providers.d.ts +111 -0
- package/dist/config/providers.d.ts.map +1 -0
- package/dist/config/providers.js +1535 -0
- package/dist/config/providers.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-helper.d.ts +35 -0
- package/dist/lib/api-helper.d.ts.map +1 -0
- package/dist/lib/api-helper.js +123 -0
- package/dist/lib/api-helper.js.map +1 -0
- package/dist/lib/capability-validator.d.ts +36 -0
- package/dist/lib/capability-validator.d.ts.map +1 -0
- package/dist/lib/capability-validator.js +140 -0
- package/dist/lib/capability-validator.js.map +1 -0
- package/dist/lib/media-constants.d.ts +55 -0
- package/dist/lib/media-constants.d.ts.map +1 -0
- package/dist/lib/media-constants.js +166 -0
- package/dist/lib/media-constants.js.map +1 -0
- package/dist/lib/media-conversion.d.ts +36 -0
- package/dist/lib/media-conversion.d.ts.map +1 -0
- package/dist/lib/media-conversion.js +87 -0
- package/dist/lib/media-conversion.js.map +1 -0
- package/dist/lib/media-utils.d.ts +35 -0
- package/dist/lib/media-utils.d.ts.map +1 -0
- package/dist/lib/media-utils.js +173 -0
- package/dist/lib/media-utils.js.map +1 -0
- package/dist/lib/output-limit.d.ts +38 -0
- package/dist/lib/output-limit.d.ts.map +1 -0
- package/dist/lib/output-limit.js +54 -0
- package/dist/lib/output-limit.js.map +1 -0
- package/dist/lib/prompt-builder.d.ts +94 -0
- package/dist/lib/prompt-builder.d.ts.map +1 -0
- package/dist/lib/prompt-builder.js +408 -0
- package/dist/lib/prompt-builder.js.map +1 -0
- package/dist/lib/reserved-fields.d.ts +41 -0
- package/dist/lib/reserved-fields.d.ts.map +1 -0
- package/dist/lib/reserved-fields.js +47 -0
- package/dist/lib/reserved-fields.js.map +1 -0
- package/dist/services/llm/anthropic.d.ts +16 -0
- package/dist/services/llm/anthropic.d.ts.map +1 -0
- package/dist/services/llm/anthropic.js +154 -0
- package/dist/services/llm/anthropic.js.map +1 -0
- package/dist/services/llm/custom.d.ts +51 -0
- package/dist/services/llm/custom.d.ts.map +1 -0
- package/dist/services/llm/custom.js +419 -0
- package/dist/services/llm/custom.js.map +1 -0
- package/dist/services/llm/extract-json.d.ts +17 -0
- package/dist/services/llm/extract-json.d.ts.map +1 -0
- package/dist/services/llm/extract-json.js +60 -0
- package/dist/services/llm/extract-json.js.map +1 -0
- package/dist/services/llm/finish-reason.d.ts +21 -0
- package/dist/services/llm/finish-reason.d.ts.map +1 -0
- package/dist/services/llm/finish-reason.js +55 -0
- package/dist/services/llm/finish-reason.js.map +1 -0
- package/dist/services/llm/gemini.d.ts +26 -0
- package/dist/services/llm/gemini.d.ts.map +1 -0
- package/dist/services/llm/gemini.js +178 -0
- package/dist/services/llm/gemini.js.map +1 -0
- package/dist/services/llm/groq.d.ts +28 -0
- package/dist/services/llm/groq.d.ts.map +1 -0
- package/dist/services/llm/groq.js +237 -0
- package/dist/services/llm/groq.js.map +1 -0
- package/dist/services/llm/index.d.ts +19 -0
- package/dist/services/llm/index.d.ts.map +1 -0
- package/dist/services/llm/index.js +88 -0
- package/dist/services/llm/index.js.map +1 -0
- package/dist/services/llm/openai.d.ts +101 -0
- package/dist/services/llm/openai.d.ts.map +1 -0
- package/dist/services/llm/openai.js +561 -0
- package/dist/services/llm/openai.js.map +1 -0
- package/dist/services/llm/types.d.ts +110 -0
- package/dist/services/llm/types.d.ts.map +1 -0
- package/dist/services/llm/types.js +16 -0
- package/dist/services/llm/types.js.map +1 -0
- package/dist/types/index.d.ts +812 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +366 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Schema-to-prompt conversion and provider-specific prompt building
|
|
3
|
+
* @description Converts JSON Schema definitions into human-readable prompt instructions,
|
|
4
|
+
* generates example output, and builds provider-optimized system/user prompts.
|
|
5
|
+
*/
|
|
6
|
+
import type { JsonSchema, LlmProvider } from "../types/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Convert JSON Schema to human-readable prompt instructions
|
|
9
|
+
*/
|
|
10
|
+
export declare function schemaToPromptInstructions(schema: JsonSchema, depth?: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate an example object from schema
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateSchemaExample(schema: JsonSchema): unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Check if schema is complex enough to need an example
|
|
17
|
+
*/
|
|
18
|
+
export declare function isComplexSchema(schema: JsonSchema): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Build the system prompt with schema instructions
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Build the base instruction section.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildBaseInstruction(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Build the task description section from the user's endpoint instructions.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildTaskDescriptionSection(userDescription: string | null): string;
|
|
30
|
+
/**
|
|
31
|
+
* Build the output structure section from a JSON schema.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildOutputStructureSection(outputSchema: JsonSchema | null): string;
|
|
34
|
+
/**
|
|
35
|
+
* Build the response format section.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildResponseFormatSection(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Build the web search routing section. Inserted between the task description
|
|
40
|
+
* and the output structure when the endpoint supports web search.
|
|
41
|
+
* Clarifies the wrapper object and overrides any conflicting rules.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildWebSearchRoutingSection(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Build the system prompt with schema instructions.
|
|
46
|
+
* Composes all sections: base → task description → output structure → response format.
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildSystemPrompt(userDescription: string | null, outputSchema: JsonSchema | null, context?: string | null): string;
|
|
49
|
+
/**
|
|
50
|
+
* Build the user prompt from input data
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildUserPrompt(inputData: unknown, isStructured: boolean): string;
|
|
53
|
+
/**
|
|
54
|
+
* Format structured input data for the prompt
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatStructuredInput(data: Record<string, unknown>): string;
|
|
57
|
+
/**
|
|
58
|
+
* Build complete prompts for an LLM request
|
|
59
|
+
*/
|
|
60
|
+
export declare function buildPrompts(inputData: unknown, outputSchema: JsonSchema | null, userDescription: string | null, isStructuredInput: boolean): {
|
|
61
|
+
system: string;
|
|
62
|
+
user: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Provider-specific prompt configuration
|
|
66
|
+
*/
|
|
67
|
+
export interface ProviderPromptConfig {
|
|
68
|
+
/** Base instruction for the assistant role */
|
|
69
|
+
baseInstruction: string;
|
|
70
|
+
/** How to format JSON output requirement */
|
|
71
|
+
jsonInstruction: string;
|
|
72
|
+
/** Whether to include example output */
|
|
73
|
+
includeExample: boolean;
|
|
74
|
+
/** Whether to be more verbose in schema descriptions */
|
|
75
|
+
verboseSchema: boolean;
|
|
76
|
+
/** Additional provider-specific instructions */
|
|
77
|
+
additionalInstructions?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get provider-specific prompt configuration
|
|
81
|
+
*/
|
|
82
|
+
export declare function getProviderPromptConfig(provider: LlmProvider): ProviderPromptConfig;
|
|
83
|
+
/**
|
|
84
|
+
* Build system prompt optimized for a specific provider
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildSystemPromptForProvider(userDescription: string | null, outputSchema: JsonSchema | null, provider: LlmProvider): string;
|
|
87
|
+
/**
|
|
88
|
+
* Build complete prompts optimized for a specific provider
|
|
89
|
+
*/
|
|
90
|
+
export declare function buildPromptsForProvider(inputData: unknown, outputSchema: JsonSchema | null, userDescription: string | null, isStructuredInput: boolean, provider: LlmProvider): {
|
|
91
|
+
system: string;
|
|
92
|
+
user: string;
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=prompt-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-builder.d.ts","sourceRoot":"","sources":["../../src/lib/prompt-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjE;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,UAAU,EAClB,KAAK,GAAE,MAAU,GAChB,MAAM,CAkFR;AAoBD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAsDjE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAY3D;AAED;;GAEG;AACH;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,GAAG,IAAI,GAC7B,MAAM,CAGR;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,UAAU,GAAG,IAAI,GAC9B,MAAM,CAiBR;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAMnD;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAkBrD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,GAAG,IAAI,EAC9B,YAAY,EAAE,UAAU,GAAG,IAAI,EAC/B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAUR;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,OAAO,EAClB,YAAY,EAAE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-specific prompt building
|
|
3
|
+
* @description Converts JSON Schema definitions into human-readable prompt instructions,
|
|
4
|
+
* generates example output, and builds provider-optimized system/user prompts.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Convert JSON Schema to human-readable prompt instructions
|
|
8
|
+
*/
|
|
9
|
+
export function schemaToPromptInstructions(schema, depth = 0) {
|
|
10
|
+
const indent = " ".repeat(depth);
|
|
11
|
+
const lines = [];
|
|
12
|
+
const schemaType = schema.type ?? "object";
|
|
13
|
+
if (schemaType === "object" && schema.properties) {
|
|
14
|
+
const required = schema.required ?? [];
|
|
15
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
16
|
+
const prop = propSchema;
|
|
17
|
+
const isRequired = required.includes(propName);
|
|
18
|
+
const reqMarker = isRequired ? "(required)" : "(optional)";
|
|
19
|
+
// Handle map type (x-map with additionalProperties)
|
|
20
|
+
if (prop["x-map"] &&
|
|
21
|
+
prop.additionalProperties &&
|
|
22
|
+
typeof prop.additionalProperties === "object") {
|
|
23
|
+
const valueProp = prop.additionalProperties;
|
|
24
|
+
const keyDesc = prop["x-key-description"];
|
|
25
|
+
const valueType = valueProp.type ?? "any";
|
|
26
|
+
const valueDesc = valueProp.description ?? "";
|
|
27
|
+
const propDesc = prop.description ?? "";
|
|
28
|
+
lines.push(`${indent}- \`${propName}\` (map) ${reqMarker}: ${propDesc}`);
|
|
29
|
+
lines.push(`${indent} Key: string${keyDesc ? ` — ${keyDesc}` : ""}`);
|
|
30
|
+
lines.push(`${indent} Value: ${valueType}${valueDesc ? ` — ${valueDesc}` : ""}`);
|
|
31
|
+
// Handle complex value types
|
|
32
|
+
if (valueType === "object" && valueProp.properties) {
|
|
33
|
+
lines.push(`${indent} Value properties:`);
|
|
34
|
+
lines.push(schemaToPromptInstructions(valueProp, depth + 2));
|
|
35
|
+
}
|
|
36
|
+
else if (valueType === "array" && valueProp.items) {
|
|
37
|
+
lines.push(`${indent} (each value is an array of items:)`);
|
|
38
|
+
lines.push(schemaToPromptInstructions(valueProp.items, depth + 2));
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const propType = prop.type ?? "any";
|
|
43
|
+
const propDesc = prop.description ?? "";
|
|
44
|
+
lines.push(`${indent}- \`${propName}\` (${propType}) ${reqMarker}: ${propDesc}`);
|
|
45
|
+
// Handle enums
|
|
46
|
+
if (prop.enum) {
|
|
47
|
+
const enumValues = prop.enum.map(v => `"${v}"`).join(", ");
|
|
48
|
+
lines.push(`${indent} Allowed values: ${enumValues}`);
|
|
49
|
+
}
|
|
50
|
+
// Handle constraints
|
|
51
|
+
const constraints = extractConstraints(prop);
|
|
52
|
+
if (constraints) {
|
|
53
|
+
lines.push(`${indent} Constraints: ${constraints}`);
|
|
54
|
+
}
|
|
55
|
+
// Handle nested objects/arrays
|
|
56
|
+
if (propType === "object" && prop.properties) {
|
|
57
|
+
lines.push(`${indent} Properties:`);
|
|
58
|
+
lines.push(schemaToPromptInstructions(prop, depth + 2));
|
|
59
|
+
}
|
|
60
|
+
else if (propType === "array" && prop.items) {
|
|
61
|
+
lines.push(`${indent} (array of items, each item should have:)`);
|
|
62
|
+
lines.push(schemaToPromptInstructions(prop.items, depth + 2));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return lines.join("\n");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Extract validation constraints from schema property
|
|
70
|
+
*/
|
|
71
|
+
function extractConstraints(schema) {
|
|
72
|
+
const constraints = [];
|
|
73
|
+
if (schema.minimum !== undefined)
|
|
74
|
+
constraints.push(`min: ${schema.minimum}`);
|
|
75
|
+
if (schema.maximum !== undefined)
|
|
76
|
+
constraints.push(`max: ${schema.maximum}`);
|
|
77
|
+
if (schema.minLength !== undefined)
|
|
78
|
+
constraints.push(`min length: ${schema.minLength}`);
|
|
79
|
+
if (schema.maxLength !== undefined)
|
|
80
|
+
constraints.push(`max length: ${schema.maxLength}`);
|
|
81
|
+
if (schema.pattern)
|
|
82
|
+
constraints.push(`pattern: ${schema.pattern}`);
|
|
83
|
+
if (schema.format)
|
|
84
|
+
constraints.push(`format: ${schema.format}`);
|
|
85
|
+
return constraints.join(", ");
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Generate an example object from schema
|
|
89
|
+
*/
|
|
90
|
+
export function generateSchemaExample(schema) {
|
|
91
|
+
const schemaType = schema.type ?? "object";
|
|
92
|
+
if (schema.default !== undefined)
|
|
93
|
+
return schema.default;
|
|
94
|
+
if (schema.enum && schema.enum.length > 0)
|
|
95
|
+
return schema.enum[0];
|
|
96
|
+
// Map type: object with x-map and additionalProperties
|
|
97
|
+
if (schemaType === "object" &&
|
|
98
|
+
schema["x-map"] &&
|
|
99
|
+
schema.additionalProperties &&
|
|
100
|
+
typeof schema.additionalProperties === "object") {
|
|
101
|
+
const keyDesc = schema["x-key-description"];
|
|
102
|
+
const sampleKey = keyDesc
|
|
103
|
+
? `<${keyDesc.split(/[\s(,]/)[0].toLowerCase()}>`
|
|
104
|
+
: "<key>";
|
|
105
|
+
return {
|
|
106
|
+
[sampleKey]: generateSchemaExample(schema.additionalProperties),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (schemaType === "object" && schema.properties) {
|
|
110
|
+
const example = {};
|
|
111
|
+
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
112
|
+
example[propName] = generateSchemaExample(propSchema);
|
|
113
|
+
}
|
|
114
|
+
return example;
|
|
115
|
+
}
|
|
116
|
+
if (schemaType === "array") {
|
|
117
|
+
if (schema.items) {
|
|
118
|
+
return [generateSchemaExample(schema.items)];
|
|
119
|
+
}
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
// Primitive types
|
|
123
|
+
switch (schemaType) {
|
|
124
|
+
case "string":
|
|
125
|
+
return "<string>";
|
|
126
|
+
case "number":
|
|
127
|
+
return 0.0;
|
|
128
|
+
case "integer":
|
|
129
|
+
return 0;
|
|
130
|
+
case "boolean":
|
|
131
|
+
return true;
|
|
132
|
+
default:
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Check if schema is complex enough to need an example
|
|
138
|
+
*/
|
|
139
|
+
export function isComplexSchema(schema) {
|
|
140
|
+
if (!schema.properties)
|
|
141
|
+
return false;
|
|
142
|
+
const properties = Object.values(schema.properties);
|
|
143
|
+
if (properties.length > 3)
|
|
144
|
+
return true;
|
|
145
|
+
return properties.some(p => {
|
|
146
|
+
const prop = p;
|
|
147
|
+
return (prop.type === "object" ||
|
|
148
|
+
prop.type === "array" ||
|
|
149
|
+
prop["x-map"]);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Build the system prompt with schema instructions
|
|
154
|
+
*/
|
|
155
|
+
/**
|
|
156
|
+
* Build the base instruction section.
|
|
157
|
+
*/
|
|
158
|
+
export function buildBaseInstruction() {
|
|
159
|
+
return "You are a helpful assistant that produces structured data output.";
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Build the task description section from the user's endpoint instructions.
|
|
163
|
+
*/
|
|
164
|
+
export function buildTaskDescriptionSection(userDescription) {
|
|
165
|
+
if (!userDescription)
|
|
166
|
+
return "";
|
|
167
|
+
return `\n## Task Description\n${userDescription}`;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Build the output structure section from a JSON schema.
|
|
171
|
+
*/
|
|
172
|
+
export function buildOutputStructureSection(outputSchema) {
|
|
173
|
+
if (!outputSchema)
|
|
174
|
+
return "";
|
|
175
|
+
const parts = [];
|
|
176
|
+
const schemaInstructions = schemaToPromptInstructions(outputSchema);
|
|
177
|
+
parts.push(`\n## Output Structure\nYour response must include the following fields:\n${schemaInstructions}`);
|
|
178
|
+
if (isComplexSchema(outputSchema)) {
|
|
179
|
+
const example = generateSchemaExample(outputSchema);
|
|
180
|
+
parts.push(`\n## Example Output Structure\n\`\`\`json\n${JSON.stringify(example, null, 2)}\n\`\`\``);
|
|
181
|
+
}
|
|
182
|
+
return parts.join("\n");
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Build the response format section.
|
|
186
|
+
*/
|
|
187
|
+
export function buildResponseFormatSection() {
|
|
188
|
+
return ("\n## Response Format\nRespond with valid JSON only. Do not include any text outside the JSON object. " +
|
|
189
|
+
'IMPORTANT: All string values must use proper JSON escaping — use \\" for double quotes, \\n for newlines, \\\\ for backslashes. ' +
|
|
190
|
+
"Do NOT escape single quotes — \\' is invalid JSON. Write apostrophes and single quotes literally.");
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Build the web search routing section. Inserted between the task description
|
|
194
|
+
* and the output structure when the endpoint supports web search.
|
|
195
|
+
* Clarifies the wrapper object and overrides any conflicting rules.
|
|
196
|
+
*/
|
|
197
|
+
export function buildWebSearchRoutingSection() {
|
|
198
|
+
return ("\n## Response Wrapper (OVERRIDES conflicting rules above)\n" +
|
|
199
|
+
"Your JSON response is a wrapper object. You MUST always provide `user_data`.\n\n" +
|
|
200
|
+
"- `user_data` (object, REQUIRED) — your IRenderable response goes here. " +
|
|
201
|
+
"Always fill this with either a clarification form or a complete answer.\n" +
|
|
202
|
+
"- `web_search_needed` (boolean, optional, defaults to false) — " +
|
|
203
|
+
"set to true when you would otherwise say 'I don't have real-time data' " +
|
|
204
|
+
"or 'I cannot access current listings'. The system WILL perform a web " +
|
|
205
|
+
"search for you and call you again with the results.\n\n" +
|
|
206
|
+
"When previous rules say 'return one root IRenderable', they mean inside `user_data`.\n\n" +
|
|
207
|
+
"`web_search_needed` = false:\n" +
|
|
208
|
+
"- Asking user for location/preferences/details (clarification)\n" +
|
|
209
|
+
"- Answering from training data (recipes, coding, general knowledge)\n\n" +
|
|
210
|
+
"`web_search_needed` = true:\n" +
|
|
211
|
+
"- You have the user's location/date but need live data (listings, prices, events, weather)\n" +
|
|
212
|
+
"- You would otherwise respond with 'I don't have access to real-time data'");
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Build the system prompt with schema instructions.
|
|
216
|
+
* Composes all sections: base → task description → output structure → response format.
|
|
217
|
+
*/
|
|
218
|
+
export function buildSystemPrompt(userDescription, outputSchema, context) {
|
|
219
|
+
return [
|
|
220
|
+
buildBaseInstruction(),
|
|
221
|
+
buildTaskDescriptionSection(userDescription),
|
|
222
|
+
context ? `\n## Context\n${context}` : "",
|
|
223
|
+
buildOutputStructureSection(outputSchema),
|
|
224
|
+
buildResponseFormatSection(),
|
|
225
|
+
]
|
|
226
|
+
.filter(Boolean)
|
|
227
|
+
.join("\n");
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Build the user prompt from input data
|
|
231
|
+
*/
|
|
232
|
+
export function buildUserPrompt(inputData, isStructured) {
|
|
233
|
+
if (isStructured && typeof inputData === "object" && inputData !== null) {
|
|
234
|
+
// Format structured input as readable key-value pairs
|
|
235
|
+
const formatted = formatStructuredInput(inputData);
|
|
236
|
+
return `Process the following data and generate the structured response:\n\n${formatted}`;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
// Free text input
|
|
240
|
+
return `Process the following text and generate the structured response:\n\n${String(inputData)}`;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Format structured input data for the prompt
|
|
245
|
+
*/
|
|
246
|
+
export function formatStructuredInput(data) {
|
|
247
|
+
const lines = [];
|
|
248
|
+
for (const [key, value] of Object.entries(data)) {
|
|
249
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
250
|
+
lines.push(`- ${key}:`);
|
|
251
|
+
for (const [k, v] of Object.entries(value)) {
|
|
252
|
+
lines.push(formatStructuredLine(k, v, " "));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
lines.push(formatStructuredLine(key, value, ""));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return lines.join("\n");
|
|
260
|
+
}
|
|
261
|
+
function formatStructuredLine(key, value, indent) {
|
|
262
|
+
if (typeof value === "string" && value.includes("\n")) {
|
|
263
|
+
const block = value
|
|
264
|
+
.split(/\r?\n/)
|
|
265
|
+
.map(line => `${indent} ${line}`)
|
|
266
|
+
.join("\n");
|
|
267
|
+
return `${indent}- ${key}: |\n${block}`;
|
|
268
|
+
}
|
|
269
|
+
return `${indent}- ${key}: ${JSON.stringify(value)}`;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Build complete prompts for an LLM request
|
|
273
|
+
*/
|
|
274
|
+
export function buildPrompts(inputData, outputSchema, userDescription, isStructuredInput) {
|
|
275
|
+
return {
|
|
276
|
+
system: buildSystemPrompt(userDescription, outputSchema),
|
|
277
|
+
user: buildUserPrompt(inputData, isStructuredInput),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Get provider-specific prompt configuration
|
|
282
|
+
*/
|
|
283
|
+
export function getProviderPromptConfig(provider) {
|
|
284
|
+
switch (provider) {
|
|
285
|
+
case "openai":
|
|
286
|
+
return {
|
|
287
|
+
baseInstruction: "You are a helpful assistant that produces structured data output.",
|
|
288
|
+
jsonInstruction: "Respond with valid JSON only. Do not include any text outside the JSON object.",
|
|
289
|
+
includeExample: true,
|
|
290
|
+
verboseSchema: false,
|
|
291
|
+
};
|
|
292
|
+
case "anthropic":
|
|
293
|
+
return {
|
|
294
|
+
baseInstruction: "You are Claude, an AI assistant. Your task is to analyze the input and produce structured data output.",
|
|
295
|
+
jsonInstruction: "Output valid JSON only. Do not include markdown code blocks, explanations, or any text outside the JSON object.",
|
|
296
|
+
includeExample: true,
|
|
297
|
+
verboseSchema: true,
|
|
298
|
+
additionalInstructions: "Think step by step about the data structure before generating output.",
|
|
299
|
+
};
|
|
300
|
+
case "gemini":
|
|
301
|
+
return {
|
|
302
|
+
baseInstruction: "You are a helpful assistant that produces structured JSON data.",
|
|
303
|
+
jsonInstruction: "Return only valid JSON matching the specified schema.",
|
|
304
|
+
includeExample: false, // Gemini uses responseSchema natively
|
|
305
|
+
verboseSchema: false,
|
|
306
|
+
};
|
|
307
|
+
case "mistral":
|
|
308
|
+
return {
|
|
309
|
+
baseInstruction: "You are a helpful assistant specialized in producing structured data output.",
|
|
310
|
+
jsonInstruction: 'Respond with valid JSON only. No markdown, no explanations, just the JSON object. Use proper JSON escaping in strings — \\" for double quotes, \\n for newlines.',
|
|
311
|
+
includeExample: true,
|
|
312
|
+
verboseSchema: false,
|
|
313
|
+
};
|
|
314
|
+
case "cohere":
|
|
315
|
+
return {
|
|
316
|
+
baseInstruction: "You are a helpful assistant that generates structured data responses.",
|
|
317
|
+
jsonInstruction: 'Output valid JSON only. Do not include any text, markdown, or explanations outside the JSON. Use proper JSON escaping in strings — \\" for double quotes, \\n for newlines.',
|
|
318
|
+
includeExample: true,
|
|
319
|
+
verboseSchema: true,
|
|
320
|
+
};
|
|
321
|
+
case "groq":
|
|
322
|
+
return {
|
|
323
|
+
baseInstruction: "You are a fast, efficient assistant that produces structured data.",
|
|
324
|
+
jsonInstruction: 'Respond with valid JSON only. Use proper JSON escaping in strings — \\" for double quotes, \\n for newlines.',
|
|
325
|
+
includeExample: true,
|
|
326
|
+
verboseSchema: false,
|
|
327
|
+
};
|
|
328
|
+
case "xai":
|
|
329
|
+
return {
|
|
330
|
+
baseInstruction: "You are Grok, an AI assistant. Generate structured data output based on the given input.",
|
|
331
|
+
jsonInstruction: 'Return valid JSON only. No additional text or formatting. Use proper JSON escaping in strings — \\" for double quotes, \\n for newlines.',
|
|
332
|
+
includeExample: true,
|
|
333
|
+
verboseSchema: true,
|
|
334
|
+
};
|
|
335
|
+
case "deepseek":
|
|
336
|
+
return {
|
|
337
|
+
baseInstruction: "You are a helpful assistant that produces structured JSON output.",
|
|
338
|
+
jsonInstruction: 'Respond with valid JSON only. Do not include markdown code blocks or any text outside the JSON. Use proper JSON escaping in strings — \\" for double quotes, \\n for newlines.',
|
|
339
|
+
includeExample: true,
|
|
340
|
+
verboseSchema: true,
|
|
341
|
+
additionalInstructions: "Analyze the input carefully before generating the structured response.",
|
|
342
|
+
};
|
|
343
|
+
case "perplexity":
|
|
344
|
+
return {
|
|
345
|
+
baseInstruction: "You are a helpful assistant that produces structured data output based on available information.",
|
|
346
|
+
jsonInstruction: 'Output valid JSON only. No citations, no explanations, just the JSON object. Use proper JSON escaping in strings — \\" for double quotes, \\n for newlines.',
|
|
347
|
+
includeExample: true,
|
|
348
|
+
verboseSchema: false,
|
|
349
|
+
additionalInstructions: "Focus on the specific data requested, not general information.",
|
|
350
|
+
};
|
|
351
|
+
case "lm_studio":
|
|
352
|
+
default:
|
|
353
|
+
return {
|
|
354
|
+
baseInstruction: "You are a precise assistant that produces structured data output. " +
|
|
355
|
+
"You MUST translate exactly what is given — do not add, remove, reword, or interpret the content. " +
|
|
356
|
+
"Do not add explanations, commentary, or extra fields. " +
|
|
357
|
+
"If the input has numbered steps, the output must have the same numbered steps. " +
|
|
358
|
+
"Preserve all technical terms, variable placeholders (like {{value1}}), and formatting exactly as they appear.",
|
|
359
|
+
jsonInstruction: "Respond with valid JSON only. Do not include any text, markdown code blocks, or thinking outside the JSON object. " +
|
|
360
|
+
"IMPORTANT: All string values in the JSON must use proper JSON escaping. " +
|
|
361
|
+
'Use \\" for double quotes, \\n for newlines, \\t for tabs, and \\\\ for backslashes inside string values. ' +
|
|
362
|
+
'Do NOT escape single quotes — \\\' is invalid JSON. Write apostrophes and single quotes literally (e.g. "it\'s" not "it\\\'s"). ' +
|
|
363
|
+
"Do not put literal newlines or unescaped special characters inside JSON strings.",
|
|
364
|
+
includeExample: true,
|
|
365
|
+
verboseSchema: false,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Build system prompt optimized for a specific provider
|
|
371
|
+
*/
|
|
372
|
+
export function buildSystemPromptForProvider(userDescription, outputSchema, provider) {
|
|
373
|
+
const config = getProviderPromptConfig(provider);
|
|
374
|
+
const parts = [];
|
|
375
|
+
// Provider-specific base instruction
|
|
376
|
+
parts.push(config.baseInstruction);
|
|
377
|
+
// User's description
|
|
378
|
+
if (userDescription) {
|
|
379
|
+
parts.push(`\n## Task Description\n${userDescription}`);
|
|
380
|
+
}
|
|
381
|
+
// Schema instructions
|
|
382
|
+
if (outputSchema) {
|
|
383
|
+
const schemaInstructions = schemaToPromptInstructions(outputSchema);
|
|
384
|
+
parts.push(`\n## Output Structure\nYour response must include the following fields:\n${schemaInstructions}`);
|
|
385
|
+
// Add example if configured and schema is complex
|
|
386
|
+
if (config.includeExample && isComplexSchema(outputSchema)) {
|
|
387
|
+
const example = generateSchemaExample(outputSchema);
|
|
388
|
+
parts.push(`\n## Example Output Structure\n\`\`\`json\n${JSON.stringify(example, null, 2)}\n\`\`\``);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
// Additional provider-specific instructions
|
|
392
|
+
if (config.additionalInstructions) {
|
|
393
|
+
parts.push(`\n## Additional Guidelines\n${config.additionalInstructions}`);
|
|
394
|
+
}
|
|
395
|
+
// JSON instruction
|
|
396
|
+
parts.push(`\n## Response Format\n${config.jsonInstruction}`);
|
|
397
|
+
return parts.join("\n");
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Build complete prompts optimized for a specific provider
|
|
401
|
+
*/
|
|
402
|
+
export function buildPromptsForProvider(inputData, outputSchema, userDescription, isStructuredInput, provider) {
|
|
403
|
+
return {
|
|
404
|
+
system: buildSystemPromptForProvider(userDescription, outputSchema, provider),
|
|
405
|
+
user: buildUserPrompt(inputData, isStructuredInput),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=prompt-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-builder.js","sourceRoot":"","sources":["../../src/lib/prompt-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAAkB,EAClB,QAAgB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5C,IAAI,MAAM,CAAC,sBAAsB,EAAE,CAAC;QAClC,KAAK,CAAC,IAAI,CAAC,+BAA+B,MAAM,CAAC,sBAAsB,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,mBAAmB;IACnB,KAAK,CAAC,IAAI,CAAC,yBAAyB,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;IAE9D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,SAAkB,EAClB,YAA+B,EAC/B,eAA8B,EAC9B,iBAA0B,EAC1B,QAAqB;IAErB,OAAO;QACL,MAAM,EAAE,4BAA4B,CAClC,eAAe,EACf,YAAY,EACZ,QAAQ,CACT;QACD,IAAI,EAAE,eAAe,CAAC,SAAS,EAAE,iBAAiB,CAAC;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Reserved input field extraction for AI invocations
|
|
3
|
+
* @description A handful of input keys are consumed by ShapeShyft rather than
|
|
4
|
+
* passed to the model: `context`, `web_search`, and `max_output_tokens`.
|
|
5
|
+
*
|
|
6
|
+
* They are pulled out in one pass, before the prompt is built, so a reserved key
|
|
7
|
+
* can never leak into the text the model sees. Doing this per-field at different
|
|
8
|
+
* points in the request is what previously let `web_search` reach the prompt.
|
|
9
|
+
*/
|
|
10
|
+
/** Input keys ShapeShyft consumes instead of forwarding to the model. */
|
|
11
|
+
export declare const RESERVED_INPUT_FIELDS: readonly ["context", "web_search", "max_output_tokens"];
|
|
12
|
+
/** Reserved values pulled from an invocation's input. */
|
|
13
|
+
export interface ReservedFields {
|
|
14
|
+
/**
|
|
15
|
+
* Per-call override of the endpoint's configured context. Only a non-empty
|
|
16
|
+
* string counts; anything else is discarded so a malformed value cannot blank
|
|
17
|
+
* out the endpoint's own context.
|
|
18
|
+
*/
|
|
19
|
+
context?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The caller's `web_search` preference: `false` only for an explicit `false`,
|
|
22
|
+
* `true` for any other present value, `undefined` when absent. Whether search
|
|
23
|
+
* actually runs is still gated by the endpoint -- this can only turn it off.
|
|
24
|
+
*/
|
|
25
|
+
webSearch?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Raw `max_output_tokens` as supplied. Left unvalidated here so the caller
|
|
28
|
+
* sees one validation error from `resolveMaxOutputTokens`, which owns the rule.
|
|
29
|
+
*/
|
|
30
|
+
maxOutputTokens?: unknown;
|
|
31
|
+
/** The input with every reserved key removed. */
|
|
32
|
+
cleanedInput: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Split an invocation's input into reserved values and the payload for the model.
|
|
36
|
+
*
|
|
37
|
+
* @param inputData - Raw input: a JSON body, or parsed query parameters
|
|
38
|
+
* @returns The reserved values plus a copy of the input without them
|
|
39
|
+
*/
|
|
40
|
+
export declare function extractReservedFields(inputData: unknown): ReservedFields;
|
|
41
|
+
//# sourceMappingURL=reserved-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reserved-fields.d.ts","sourceRoot":"","sources":["../../src/lib/reserved-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,yDAIxB,CAAC;AAEX,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iDAAiD;IACjD,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,OAAO,GAAG,cAAc,CAoCxE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Reserved input field extraction for AI invocations
|
|
3
|
+
* @description A handful of input keys are consumed by ShapeShyft rather than
|
|
4
|
+
* passed to the model: `context`, `web_search`, and `max_output_tokens`.
|
|
5
|
+
*
|
|
6
|
+
* They are pulled out in one pass, before the prompt is built, so a reserved key
|
|
7
|
+
* can never leak into the text the model sees. Doing this per-field at different
|
|
8
|
+
* points in the request is what previously let `web_search` reach the prompt.
|
|
9
|
+
*/
|
|
10
|
+
/** Input keys ShapeShyft consumes instead of forwarding to the model. */
|
|
11
|
+
export const RESERVED_INPUT_FIELDS = [
|
|
12
|
+
"context",
|
|
13
|
+
"web_search",
|
|
14
|
+
"max_output_tokens",
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* Split an invocation's input into reserved values and the payload for the model.
|
|
18
|
+
*
|
|
19
|
+
* @param inputData - Raw input: a JSON body, or parsed query parameters
|
|
20
|
+
* @returns The reserved values plus a copy of the input without them
|
|
21
|
+
*/
|
|
22
|
+
export function extractReservedFields(inputData) {
|
|
23
|
+
if (typeof inputData !== "object" ||
|
|
24
|
+
inputData === null ||
|
|
25
|
+
Array.isArray(inputData)) {
|
|
26
|
+
return { cleanedInput: inputData };
|
|
27
|
+
}
|
|
28
|
+
const { context, web_search: webSearchRaw, max_output_tokens: maxOutputTokens, ...cleanedInput } = inputData;
|
|
29
|
+
const result = { cleanedInput };
|
|
30
|
+
if (typeof context === "string" && context.trim().length > 0) {
|
|
31
|
+
result.context = context;
|
|
32
|
+
}
|
|
33
|
+
if (webSearchRaw !== undefined) {
|
|
34
|
+
// A GET invocation's params are strings, so an explicit `web_search=false`
|
|
35
|
+
// arrives as the string "false". Treating that as truthy would silently
|
|
36
|
+
// ignore the caller's only way to turn search off on that path.
|
|
37
|
+
const isFalse = webSearchRaw === false ||
|
|
38
|
+
(typeof webSearchRaw === "string" &&
|
|
39
|
+
webSearchRaw.toLowerCase() === "false");
|
|
40
|
+
result.webSearch = !isFalse;
|
|
41
|
+
}
|
|
42
|
+
if (maxOutputTokens !== undefined) {
|
|
43
|
+
result.maxOutputTokens = maxOutputTokens;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=reserved-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reserved-fields.js","sourceRoot":"","sources":["../../src/lib/reserved-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,YAAY;IACZ,mBAAmB;CACX,CAAC;AAyBX;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAkB;IACtD,IACE,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,KAAK,IAAI;QAClB,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EACxB,CAAC;QACD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;IACrC,CAAC;IAED,MAAM,EACJ,OAAO,EACP,UAAU,EAAE,YAAY,EACxB,iBAAiB,EAAE,eAAe,EAClC,GAAG,YAAY,EAChB,GAAG,SAAoC,CAAC;IAEzC,MAAM,MAAM,GAAmB,EAAE,YAAY,EAAE,CAAC;IAEhD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IACD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,2EAA2E;QAC3E,wEAAwE;QACxE,gEAAgE;QAChE,MAAM,OAAO,GACX,YAAY,KAAK,KAAK;YACtB,CAAC,OAAO,YAAY,KAAK,QAAQ;gBAC/B,YAAY,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,CAAC;QAC5C,MAAM,CAAC,SAAS,GAAG,CAAC,OAAO,CAAC;IAC9B,CAAC;IACD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Anthropic LLM provider
|
|
3
|
+
* @description Implements the ILLMProvider interface for Anthropic Claude models.
|
|
4
|
+
* Uses tool_use for structured output extraction. Supports image input
|
|
5
|
+
* via base64 and URL formats.
|
|
6
|
+
*/
|
|
7
|
+
import type { ILLMProvider, LLMRequest, LLMResponse, ProviderConfig } from "./types.js";
|
|
8
|
+
export declare class AnthropicProvider implements ILLMProvider {
|
|
9
|
+
readonly providerName: "anthropic";
|
|
10
|
+
private client;
|
|
11
|
+
private defaultModel;
|
|
12
|
+
constructor(config: ProviderConfig);
|
|
13
|
+
generate(request: LLMRequest): Promise<LLMResponse>;
|
|
14
|
+
buildApiPayload(request: LLMRequest): Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/services/llm/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,cAAc,EACf,MAAM,YAAY,CAAC;AAQpB,qBAAa,iBAAkB,YAAW,YAAY;IACpD,QAAQ,CAAC,YAAY,EAAG,WAAW,CAAU;IAC7C,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,YAAY,CAAS;gBAEjB,MAAM,EAAE,cAAc;IAQ5B,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;IA8FzD,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CA0D9D"}
|