Skip to content

@tasco/ai/prompts

Prompt library có version. Đổi nội dung prompt thì tăng version và thêm eval case — xem MCP & AI review.

Biến

extractJson

ts
const extractJson: PromptDef<"content" | "schema">;

Trích xuất dữ liệu có cấu trúc — ép model trả JSON thuần.


promptLibrary

ts
const promptLibrary: readonly [PromptDef<"app_name">, PromptDef<"max_points" | "content">, PromptDef<"content" | "schema">];

Danh sách toàn bộ prompt trong library — eval CI chạy qua tập này.


summarize

ts
const summarize: PromptDef<"max_points" | "content">;

Tóm tắt văn bản/nghiệp vụ thành gạch đầu dòng.


tascoAssistant

ts
const tascoAssistant: PromptDef<"app_name">;

Persona trợ lý mặc định cho CChat trong app sản phẩm Tasco.

Hàm

definePrompt()

ts
function definePrompt<V>(def): PromptDef<V>;

Helper giữ literal type cho tên biến (autocomplete khi render).

Tham số kiểu

Tham số kiểu
V extends string

Tham số

Tham sốKiểu
defPromptDef<V>

Trả về

PromptDef<V>


listPlaceholders()

ts
function listPlaceholders(template): string[];

Liệt kê tên placeholder xuất hiện trong template (không trùng lặp).

Tham số

Tham sốKiểu
templatestring

Trả về

string[]


renderPrompt()

ts
function renderPrompt<V>(def, vars?): string;

Render prompt với biến — ném lỗi khi thiếu biến khai báo hoặc template còn placeholder không được cấp giá trị (typo guard).

Tham số kiểu

Tham số kiểu
V extends string

Tham số

Tham sốKiểu
defPromptDef<V>
varsRecord<V, string>

Trả về

string

Interface

PromptDef

Định nghĩa một prompt có version. V là union tên biến, tạo bằng definePrompt để giữ literal type.

Tham số kiểu

Tham số kiểuDefault type
V extends stringstring

Thuộc tính

Thuộc tínhKiểuMô tả
descriptionstringPrompt dùng để làm gì — hiện trong docs và báo cáo eval.
idstringĐịnh danh duy nhất, kebab-case — dùng trong eval case và log.
templatestringTemplate với placeholder {{tên_biến}}.
variables?readonly V[]Biến bắt buộc phải truyền khi render.
versionnumberTăng khi đổi nội dung template — eval CI so sánh chất lượng giữa version.