ในบทความนี้
In this post
ตอนที่ 1 จากสิบสอง: แยกฟังก์ชันเดิม ตัวตัดสิน Jev และ pipeline ที่คืน state ชัด โดยเริ่มจากตัวอย่างร่างคำแนะนำ export CSV
คำตัดสินและร่างข้อความเริ่มต้นเป็น mock ที่ผู้เขียนกำหนด ไม่ใช่ผล Jev จริง อ่านบทเรียนคู่กับ source, tests และแบบฝึกที่ลิงก์ไปยังรุ่นตรึงใน GitHub
เป้าหมายและสิ่งที่ต้องพร้อม
เตรียม Node22.18 ขึ้นไปกับ terminal clone companion จาก GitHub ตาม README หรือดาวน์โหลด ZIP ฉบับสมบูรณ์ แตกแล้วเข้า ai-core-functional-lab ไม่ต้อง npm install ใช้ API key หรือเรียกโมเดลผ่านเครือข่าย เวลาอ่านไม่รวมการลงมือประมาณ25–45นาที เก็บชุดอ้างอิงหนึ่งชุดและทำแบบฝึกในอีกสำเนา
ดาวน์โหลด companion ZIP · README / แผนบทเรียน
ตอนนี้เน้น src/generation.mjs โดย gate state บอกผลต่อชิ้นงานและทางไปต่อ ไม่มี state ใดส่งข้อความหรือแก้บัญชีจริง
จากโค้ดเดิมสู่ขอบเขตใหม่
เริ่มจากฟังก์ชันที่คุ้นเคย รับ input แล้วคืน object ร่างคำตอบ traditionalReply เป็น template จากข้อเท็จจริงของผลิตภัณฑ์ที่เราดูแล เมื่อคำตอบมีขอบเขตแคบ วิธีนี้อาจพอแล้ว การเพิ่มโมเดลเป็นทางเลือกในการออกแบบ ไม่ใช่การยกระดับโดยอัตโนมัติ
DeskLite เป็นผลิตภัณฑ์สมมติ ผู้ใช้ถามวิธี export CSV ระบบร่างคำตอบได้ แต่ส่งไฟล์ แก้บัญชี หรือคืนเงินไม่ได้ accept หมายถึงชิ้นงานผ่านด่าน runtime ของรุ่นนี้ ไม่ได้ให้สิทธิ์กระทำกับระบบภายนอก
คำว่า functional ในที่นี้หมายถึงขอบเขต input/output ที่ชัดและฟังก์ชันที่ประกอบกันได้ ไม่ใช่ชื่อ framework ของผู้ขาย Codex ช่วยพัฒนาโค้ด ตัวสร้างข้อความเป็นอีกบทบาทหนึ่ง ส่วน Jev ตัดสินแบบมีชนิดข้อมูล แล็บนี้จำลองส่วนโมเดลทั้งสองและไม่ได้สร้าง SDK ชื่อ AI-Core ขึ้นมา
ลงมือทีละเจ็ดขั้น
ขั้นที่ 1
แตก ZIP ในโฟลเดอร์ที่เขียนไฟล์ได้ แล้วเข้า ai-core-functional-lab รัน doctor ก่อนแก้ไฟล์ ควรเห็นข้อมูลสมมติ 28 เคสและโหมดออฟไลน์ ไม่ต้องติดตั้งแพ็กเกจหรือใช้บัญชี
ขั้นที่ 2
เปิด data/facts.json อ่านข้อเท็จจริงสองข้อ Export ทำไฟล์ให้ดาวน์โหลดและไม่ส่งอีเมล ข้อมูลนี้เป็นหลักฐานที่แอปส่งให้ ไม่ใช่สิ่งที่คำตอบร่างแต่งขึ้นแล้วถือว่าจริง
ขั้นที่ 3
ไล่ traditionalReply ใน generation.mjs ซึ่งรับ input กับ facts แล้วคืน action, language, text และ citations ไม่มีการอ่าน key เรียก API หรือแก้ ticket
ขั้นที่ 4
รัน compare กับ V001 เก็บผลสองแบบ ค่าแบบเดิมเป็นร่าง ส่วน guarded มี state, history และ attempts อย่าเทียบร่างที่ยังไม่ผ่านด่านกับชิ้นงานที่ตรวจแล้วราวกับรับประกันเหมือนกัน
ขั้นที่ 5
อ่านลำดับด่าน input code, authorization, semantic input, generation, output code, semantic output และ quality แต่ละด่านหยุดงานถัดไปได้ จดลำดับนี้ก่อนอ่าน implementation
ขั้นที่ 6
รัน V004 ที่ขอ send_reply ด่านสิทธิ์ต้อง reject ก่อนเรียก provider คำตอบคล่องแคล่วไม่ได้สร้างสิทธิ์ให้ ตรวจ calls เป็นศูนย์ด้วย ไม่ดูเพียงคำว่า reject
ขั้นที่ 7
รัน pipeline tests แล้วอธิบายว่าฟังก์ชันเก่ายังช่วยตรงไหน มันเป็น deterministic fallback หลังขอแก้ร่าง ระบบใหม่เพิ่มการสังเกตและขอบเขตตัดสิน แต่ template เดิมยังมีคุณค่า
ไฟล์และคำสั่งที่รันได้
เปิด source จริงและอ่าน dependencies ก่อนแก้ นี่คือโค้ดอ้างอิงที่รันได้ ไม่ใช่ SDK ชื่อ AI-Core ที่สมมติขึ้น ลิงก์ชี้ source รุ่นตรึงของ companion สาธารณะใน GitHub
src/generation.mjs · tests ของตอนนี้ · แบบฝึกตอนนี้
export function traditionalReply(input,facts) {
// An ordinary deterministic function is preferable when a template is enough.
return {action:'draft_reply',language:input.language,
text:facts.facts.map(f=>f[input.language]).join(' '),citations:['export-csv','no-send']};
}
// The mock generator is separate from Jev. No live text generation is configured.
คำสั่งออฟไลน์:
node src/cli.mjs doctor
node src/cli.mjs compare --case V001
node src/cli.mjs run --case V004
node --test --test-reporter=spec test/pipeline.test.mjs
ผลที่ควรได้และการตรวจ
doctor แสดง OFFLINE FIXTURES และ paidCalls 0 เคส V001 accept หลัง mock สี่ครั้ง ส่วน V004 reject ด้วย action_not_authorized และไม่เรียก provider นี่คือพฤติกรรม fixture ที่รันซ้ำได้ ไม่ใช่ผลวัดความสามารถหรือการประหยัดของ Jev
อ่าน reasons, history และทุก attempt ไม่ดูเพียง label สุดท้าย usage ที่ไม่ทราบต้องยังไม่ทราบ test สีเขียวแสดงเส้นทางโค้ดที่กำหนด ไม่ได้พิสูจน์ความปลอดภัยเชิงความหมายทุกกรณี
ตัวอย่างที่ต้องเข้าใจเมื่อไม่ผ่าน
หากคืนร่างแบบเดิมจาก endpoint ทันที object ที่ดูดีอาจซ่อนการขาดด่านสิทธิ์และความหมาย compare ทำให้เห็นความต่าง โดยไม่ได้อ้างว่าทางที่มีโมเดลปลอดภัยกว่าเสมอ
แบบฝึกในสำเนาทดลอง
ในสำเนาทดลอง เพิ่มข้อเท็จจริงข้อที่สามสองภาษาแล้วรัน compare template จะเปลี่ยนทันที แต่คำตัดสินจำลองไม่ได้ฉลาดขึ้น คืนไฟล์ต้นฉบับก่อนตอนถัดไป
ทำตามไฟล์แบบฝึก เก็บต้นฉบับและคืนชุดอ้างอิงก่อนตอนถัดไป อย่าใช้ผล held-out เลือก threshold
ตรวจเมื่อผลไม่ตรง
ถ้าหา cli.mjs ไม่พบ ให้ตรวจโฟลเดอร์ terminal หากเห็นว่าต้องใช้ SDK หรือ key ให้ตรวจคำสั่ง CLI ที่ให้มาเป็นออฟไลน์และปฏิเสธ --live
จุดตรวจถัดไป
ก่อนต่อ ให้บอกคุณสมบัติที่โค้ดตรวจได้แน่นอน คำตัดสินที่ผิดได้ state ที่หยุดงาน และหลักฐานที่ต้องมีก่อนปล่อยรุ่น
แหล่งอ้างอิงและรุ่น
เอกสารต้นทางและ companion source
ตรวจเอกสาร TypeSafe วันที่24ตุลาคม2026 บทเรียนตรึงคำขอข้อความที่ jev-1.14.0 และใช้ Choice/Noul ไม่ได้อ้างว่ามีเพียงความสามารถเหล่านี้ โค้ด REST ทางเลือกยังไม่ได้ลอง live ส่วน SDK0.7.0 มีเอกสารแต่แล็บนี้ไม่ต้องติดตั้ง
สิ่งที่ควรนำไปใช้ต่อ
- เงื่อนไขแน่นอนและสิทธิ์ยังอยู่ในโค้ด
- ด่านความหมายและคุณภาพผิดพลาดได้
- accept, reject, revise และ review มีทางไปต่อคนละแบบ
Part 1 of twelve. Trace a familiar template function into a guarded workflow with explicit states and no external effects.
Default decisions and draft text are authored mocks, not live Jev results. Use the tutorial with the matching companion code, tests and exercise linked to a fixed GitHub version.
Outcome and prerequisites
Use Node22.18+ and a terminal. Clone the GitHub companion using its README, or download the complete ZIP, extract it and enter ai-core-functional-lab. No npm install, API key or network inference is needed. The reading-time label excludes about25–45 minutes of hands-on work. Keep one reference copy and make exercises in another.
Download companion ZIP · README / lesson map
This part focuses on src/generation.mjs. Expected gate states describe content and continuation; no state sends a message or changes a real account.
Old functions and the new boundary
Start with a familiar function: input goes in, a draft object comes out. traditionalReply is an ordinary template over maintained product facts. It is fast to understand and sufficient when the answer space is small. Adding a model is a design choice, not an automatic upgrade.
The sample product DeskLite is fictional. A user asks how to export CSV; our system may prepare a reply and may never send a file, modify an account or issue a refund. A result called accept means an artifact passed this release’s runtime checks. It grants no external authority.
Here functional means explicit typed boundaries and composable functions. It is not the name of a vendor framework. Codex helps develop the code; a separate generative provider would draft text; Jev supplies typed discriminative judgments. This local lab mocks both model-facing roles and implements no AI-Core SDK.
Seven practical steps
Step 1
Extract the companion ZIP into a writable folder and enter ai-core-functional-lab. Run doctor before changing files. It should identify 28 synthetic cases and offline mode; no package installation or account is necessary.
Step 2
Open data/facts.json and read both maintained claims. Export downloads a CSV locally and does not email it. These facts are evidence supplied by the application, not claims the draft can write into existence.
Step 3
Trace traditionalReply in generation.mjs. Its dependencies are the validated input and facts object. It returns action, language, text and citations; it does not read a key, make a request or mutate a ticket.
Step 4
Run compare for V001 and keep both outputs. The traditional value is a draft; the guarded value includes state, history and attempts. Do not compare a raw draft with a checked artifact as though their guarantees were identical.
Step 5
Read the pipeline stage order: input code, authorization, semantic input, generation, output code, semantic output and quality. Each stage can stop later work. Write that order down before studying the implementation.
Step 6
Run V004, which requests send_reply. Authorization must reject it before any provider call. A fluent answer cannot grant permission absent from the application policy. Check calls equals zero, not only the final word reject.
Step 7
Run the pipeline tests, then explain where the old function still helps: deterministic fallback after a repair request. The new workflow adds observability and judgment boundaries, while the template remains useful.
Files and runnable commands
Open the exact source and read its dependencies before editing. This is runnable reference code, not a fictional AI-Core SDK. The source links point to a fixed version of the public GitHub companion.
src/generation.mjs · Matching tests · This lesson’s exercise
export function traditionalReply(input,facts) {
// An ordinary deterministic function is preferable when a template is enough.
return {action:'draft_reply',language:input.language,
text:facts.facts.map(f=>f[input.language]).join(' '),citations:['export-csv','no-send']};
}
// The mock generator is separate from Jev. No live text generation is configured.
Offline commands:
node src/cli.mjs doctor
node src/cli.mjs compare --case V001
node src/cli.mjs run --case V004
node --test --test-reporter=spec test/pipeline.test.mjs
Expected output and verification
doctor reports OFFLINE FIXTURES and paidCalls 0. V001 accepts an artifact after four mock calls. V004 rejects with action_not_authorized and zero calls. These are reproducible fixture behaviors, not measured Jev intelligence or cost savings.
Inspect reasons, history and every attempt rather than only the final label. Unknown usage must remain unknown. A green test demonstrates the specified code path, not universal semantic safety.
A failure to understand
If you return the traditional draft directly from a network endpoint, its well-formed object can hide missing policy and semantic checks. The compare command exposes that difference without claiming the model-based route is universally safer.
Exercise in a disposable copy
In a disposable copy, add a third product fact in both languages and run compare again. The template changes immediately; canned model judgments do not become more intelligent. Restore the reference before continuing.
Follow the matching exercise file, retain the original and restore the reference before the next chapter. Do not use held-out results to choose a threshold.
Troubleshooting
Cannot find cli.mjs means the terminal is in the wrong folder. If you see a request for an SDK or key, inspect the command: the provided CLI is offline-only and rejects --live.
Next checkpoint
Before continuing, name the property that code checks exactly, the judgment that may be wrong, the state that stops work and the evidence needed before release.
Sources and version notes
Primary documentation and companion source
Official TypeSafe docs checked2026-10-24. This curriculum pins text requests to jev-1.14.0 and uses Choice/Noul; it does not claim those exhaust Jev’s capabilities. Optional REST code is untested live. SDK0.7.0 is documented but unnecessary for this no-install lab.
Key takeaways
- Deterministic constraints and authorization stay in code.
- Semantic guards and quality judgments are fallible.
- Accept, reject, revise and review have distinct continuation rules.