SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
Loading...
Searching...
No Matches

Functions

void nus_agent_reset (void)
 ล้าง id ของ ask ที่ค้างอยู่และ accumulator ไม่ต้อง init ไม่มีการจับ lock ไม่มีค่าคืน
void nus_agent_note_ask (const char *id)
 บันทึก id ของ ask ที่ค้างอยู่ id ที่เป็น NULL หรือว่างเปล่าจะรีเซ็ต agent ไม่มีผู้เรียกที่ใดเลย
int nus_agent_handle_token (const char *json, const jsmntok_t *toks, int n_toks)
 ต่อ "delta" เข้ากับ accumulator คืน -1 เมื่อ id ไม่ตรง (ถูกทิ้งไปเงียบ ๆ)
int nus_agent_handle_done (const char *json, const jsmntok_t *toks, int n_toks)
 ส่งข้อความสุดท้ายต่อไปยังหน้าบน CM55 ผ่าน IPC แล้วรีเซ็ต ฟิลด์ "text" เป็นตัวชี้ขาด
int nus_agent_handle_tool_call (const char *json, const jsmntok_t *toks, int n_toks)
 เพื่อการสังเกตเท่านั้น — ส่งข้อความใบ้สั้น ๆ ผ่าน IPC ให้ marquee บน CM55 แสดงว่าเครื่องมือใดกำลังทำงาน
size_t nus_agent_buffer_len (void)
 จำนวนไบต์ที่พักไว้สำหรับ ask ที่ค้างอยู่ เป็น probe สำหรับ telemetry ไม่ใช่กลไกการซิงโครไนซ์

Detailed Description

6 ฟังก์ชัน: handler ของ stream ในกลุ่ม nus_agent_* คอมไพล์เฉพาะเมื่อ ENABLE_PAGE_BENTO_BUDDY=1 (ค่าตั้งต้นคือ 0, proj_cm33_ns/Makefile:64, :305) ให้ build ใหม่หลังจาก make getlibs — ดู Flag gate (อ่านก่อน)

การประกาศ: nus_agent.h (มี #include "vendor/jsmn.h" ซึ่งไม่มีอยู่ในชุด include ของ dist — หมายเหตุเรื่องการแพ็กเกจ header) ส่วนการนำไปสร้างจริงใน nus_agent.c ถูกเก็บไว้ใน libbento_secure.a สถานะของโมดูลนี้คือ ask ที่ค้างอยู่ได้เพียงรายการเดียว ซึ่ง task NUS RX ตัวเดียวเป็นเจ้าของ (nus_agent.c:44) เฟรม token ที่ id ไม่ตรงกับ ask ล่าสุดจะถูกทิ้งไปเงียบ ๆ และ accumulator มีขอบเขตจำกัดที่ 256 อักขระ ส่วนที่ล้นจะถูกตัดทิ้ง

variant ที่ใช้ได้
mtb-mpy และ mtb-only

Function Documentation

◆ nus_agent_reset()

void nus_agent_reset ( void )

ล้าง id ของ ask ที่ค้างอยู่และ accumulator ไม่ต้อง init ไม่มีการจับ lock ไม่มีค่าคืน

ข้อกำหนดการเรียกใช้
ไม่ต้อง init ไม่มีการจับ lock ไม่มีค่าคืน — ล้างทั้ง id และ accumulator (บัฟเฟอร์สะสมข้อความ) (nus_agent.c:115-120) ถูกเรียกเมื่อได้ .done (:203) เมื่อได้ final ที่ว่างเปล่า (:192) และเมื่อได้ ask id ที่เป็น NULL หรือว่างเปล่า (:125) เรียกได้จากทุก task ในความหมายผู้อ่านรายเดียว/ผู้เขียนรายเดียวตามที่ header ระบุไว้ call site ในเทมเพลต: 0 (ใน archive: 3)
variant ที่ใช้ได้
mtb-mpy และ mtb-only
ที่มา
ยกมาจาก BENTO-TESAIoT-libraries/claw/common/ble_nus/nus_agent.c:115-133 (คอมไพล์รวมอยู่ใน archive สำเร็จรูป ไม่ได้ส่งมอบมาเป็นซอร์ส)

◆ nus_agent_note_ask()

void nus_agent_note_ask ( const char * id)

บันทึก id ของ ask ที่ค้างอยู่ id ที่เป็น NULL หรือว่างเปล่าจะรีเซ็ต agent ไม่มีผู้เรียกที่ใดเลย

ข้อกำหนดการเรียกใช้
บันทึก id ของ ask ที่ค้างอยู่ เพื่อให้จับคู่เฟรม token/done ที่ตามมาได้ id ที่ยาวเกินบัฟเฟอร์ภายในจะถูกตัดสั้นลง id ที่เป็น NULL หรือว่างเปล่าจะ รีเซ็ต agent (nus_agent.c:122-133 — อ้างในฐานะตัวนิยาม ไม่ใช่จุดที่มีการเรียก) ไม่มีผู้เรียกที่ใดเลย ตัวนิยามที่เรนเดอร์ไว้ใต้ nus_agent_reset() แสดงวิธีคัดลอก id ไว้แล้ว
variant ที่ใช้ได้
mtb-mpy และ mtb-only
ตัวอย่าง (เขียนขึ้นเอง — ไม่มี call site ในของที่ส่งมอบจริง)
static void bento_ex_nus_agent_note_ask(void)
{
/* Arm for the ask we are about to emit: */
nus_agent_note_ask("ask-42");
/* ...emit the bento.agent.ask event with the same id; token/done
* frames carrying any other id are now silently dropped. */
/* Leaving the ASK submode? NULL (or "") resets the accumulator: */
}

◆ nus_agent_handle_token()

int nus_agent_handle_token ( const char * json,
const jsmntok_t * toks,
int n_toks )

ต่อ "delta" เข้ากับ accumulator คืน -1 เมื่อ id ไม่ตรง (ถูกทิ้งไปเงียบ ๆ)

ข้อกำหนดการเรียกใช้
ต่อสตริง "delta" เข้ากับ accumulator คืน 0 เมื่อรับไว้ คืน -1 เมื่อ id ไม่ตรงกับ ask ปัจจุบัน (ถูกทิ้งไปเงียบ ๆ) หรือเมื่อไม่มี "delta" เป็นจุดเข้าที่เรียกจาก dispatcher เท่านั้น ผู้เรียกที่มีอยู่จริงในของที่ส่งมอบแคสต์ค่าที่คืนทิ้งด้วย (void) call site ในเทมเพลต: 0 call site ใน archive อยู่ที่ nus_commands.c:1760 ((void)nus_agent_handle_token(json, toks, n_toks); คอมไพล์รวมอยู่ใน libbento_secure.a ไม่ได้ส่งมอบมาเป็นซอร์ส)
variant ที่ใช้ได้
mtb-mpy และ mtb-only

◆ nus_agent_handle_done()

int nus_agent_handle_done ( const char * json,
const jsmntok_t * toks,
int n_toks )

ส่งข้อความสุดท้ายต่อไปยังหน้าบน CM55 ผ่าน IPC แล้วรีเซ็ต ฟิลด์ "text" เป็นตัวชี้ขาด

ข้อกำหนดการเรียกใช้
ส่งข้อความสุดท้ายต่อไปยังหน้าบน CM55 ผ่าน ipc_bento_buddy_send(IPC_CMD_BUDDY_AGENT_RESPONSE, ...) แล้วรีเซ็ต accumulator คืนค่า 0 ฟิลด์ "text" เป็นตัวชี้ขาด ถ้าไม่มีฟิลด์นี้จะส่ง delta ที่สะสมไว้แทน final ที่ว่างเปล่าก็ยังรีเซ็ตสถานะเช่นกัน ส่วนท้ายของฟังก์ชันนี้คือตัวอย่างที่เรนเดอร์ไว้ใต้ ipc_bento_buddy_send call site ในเทมเพลต: 0 call site ใน archive อยู่ที่ nus_commands.c:1764 ((void)nus_agent_handle_done(json, toks, n_toks); คอมไพล์รวมอยู่ใน libbento_secure.a ไม่ได้ส่งมอบมาเป็นซอร์ส)
variant ที่ใช้ได้
mtb-mpy และ mtb-only

◆ nus_agent_handle_tool_call()

int nus_agent_handle_tool_call ( const char * json,
const jsmntok_t * toks,
int n_toks )

เพื่อการสังเกตเท่านั้น — ส่งข้อความใบ้สั้น ๆ ผ่าน IPC ให้ marquee บน CM55 แสดงว่าเครื่องมือใดกำลังทำงาน

ข้อกำหนดการเรียกใช้
เพื่อการสังเกตเท่านั้น — การรันเครื่องมือเกิดขึ้นที่ฝั่ง desktop อุปกรณ์เพียงส่ง IPC ที่มีข้อความใบ้สั้น ๆ ให้ marquee บน CM55 แสดงว่าเครื่องมือใดกำลังทำงาน คืนค่า 0 call site ในเทมเพลต: 0 call site ใน archive อยู่ที่ nus_commands.c:1768 ((void)nus_agent_handle_tool_call(json, toks, n_toks); คอมไพล์รวมอยู่ใน libbento_secure.a ไม่ได้ส่งมอบมาเป็นซอร์ส)
variant ที่ใช้ได้
mtb-mpy และ mtb-only

◆ nus_agent_buffer_len()

size_t nus_agent_buffer_len ( void )

จำนวนไบต์ที่พักไว้สำหรับ ask ที่ค้างอยู่ เป็น probe สำหรับ telemetry ไม่ใช่กลไกการซิงโครไนซ์

ข้อกำหนดการเรียกใช้
จำนวนไบต์ที่พักไว้ในขณะนั้นสำหรับ ask ที่ค้างอยู่ คืน 0 เมื่อว่าง เป็น probe สำหรับ telemetry และการทดสอบบนเครื่อง host ไม่ใช่กลไกการซิงโครไนซ์ (มีขอบเขตจำกัดที่ 256 ค่าที่ค้างอยู่ที่ขอบเขตนั้นหมายถึงครบพอดีหรือถูกตัดสั้นอย่างใดอย่างหนึ่ง) ไม่มีผู้เรียกที่ใดเลย
variant ที่ใช้ได้
mtb-mpy และ mtb-only
ตัวอย่าง (เขียนขึ้นเอง — ไม่มี call site ในของที่ส่งมอบจริง)
static void bento_ex_nus_agent_buffer_len(void)
{
size_t buffered = nus_agent_buffer_len();
if (buffered == 0u) {
return; /* idle — no ask streaming */
}
/* Streaming in progress: e.g. surface a token-count spinner on the
* ASK submode while the desktop LLM streams deltas. */
}