SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (ModusToolbox)
Toggle main menu visibility
Loading...
Searching...
No Matches
nus_agent.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* File Name: nus_agent.h
3
*
4
* Description: Desktop -> Device agent stream handlers for the LLM-side loop
5
* that runs inside Bento Desktop Buddy. The device originates a
6
* bento.agent.ask (from the LCD ASK submode), then the desktop
7
* streams back bento.agent.token frames, optional
8
* bento.agent.tool_call notifications (log-only on the device),
9
* and finally a bento.agent.done frame carrying the full answer.
10
*
11
* Contract:
12
* 1. One in-flight request id at a time. Token frames whose id
13
* doesn't match the latest ask are silently dropped.
14
* 2. Accumulator is bounded (256 chars) — overflow truncates.
15
* 3. On .done, the final text is forwarded to the CM55 page via
16
* IPC_CMD_BUDDY_AGENT_RESPONSE so the ASK submode can render.
17
* 4. .tool_call is observability-only: we emit a hint-text IPC
18
* so the scrolling marquee shows which tool is running.
19
*
20
******************************************************************************/
21
22
#ifndef NUS_AGENT_H
23
#define NUS_AGENT_H
24
25
#include <stddef.h>
26
#include <stdint.h>
27
28
#include "vendor/jsmn.h"
29
30
#ifdef __cplusplus
31
extern
"C"
{
32
#endif
33
34
/* Returns the number of bytes currently buffered for the in-flight agent ask.
35
* 0 when idle. Exposed for telemetry + host unit tests. */
36
size_t
nus_agent_buffer_len
(
void
);
37
38
/* Reset the accumulator — called when the LCD user leaves the ASK submode or
39
* when a new ask is issued. Discards any partial text. Safe to call from any
40
* task context (simple memset; single-reader single-writer on the BLE task). */
41
void
nus_agent_reset
(
void
);
42
43
/* Record a new in-flight ask id so subsequent token/done frames can be matched.
44
* Called from page_bento_buddy before (or in parallel with) the IPC-originated
45
* bento.agent.ask emission. Truncates ids longer than the internal buffer. */
46
void
nus_agent_note_ask
(
const
char
*
id
);
47
48
/* Handle bento.agent.token — appends the "delta" string to the in-flight
49
* request's accumulator. Returns 0 if accepted, -1 if the id doesn't match the
50
* current ask (silently dropped) or the delta field is missing. */
51
int
nus_agent_handle_token
(
const
char
*json,
const
jsmntok_t
*toks,
int
n_toks);
52
53
/* Handle bento.agent.done — emits the final text to the CM55 UI via
54
* IPC_CMD_BUDDY_AGENT_RESPONSE and resets the accumulator. Returns 0 on
55
* success. The "text" field is authoritative; if missing, the accumulated
56
* deltas are forwarded instead. */
57
int
nus_agent_handle_done
(
const
char
*json,
const
jsmntok_t
*toks,
int
n_toks);
58
59
/* Handle bento.agent.tool_call — log-only on the device (tool execution
60
* happens desktop-side). Emits a short hint-text IPC to the CM55 marquee so
61
* the user sees which tool is running. Returns 0. */
62
int
nus_agent_handle_tool_call
(
const
char
*json,
const
jsmntok_t
*toks,
int
n_toks);
63
64
#ifdef __cplusplus
65
}
66
#endif
67
68
#endif
/* NUS_AGENT_H */
jsmntok_t
struct jsmntok jsmntok_t
Definition
bento_fw.h:33
nus_agent_handle_done
int nus_agent_handle_done(const char *json, const jsmntok_t *toks, int n_toks)
ส่งข้อความสุดท้ายต่อไปยังหน้าบน CM55 ผ่าน IPC แล้วรีเซ็ต ฟิลด์ "text" เป็นตัวชี้ขาด
nus_agent_handle_tool_call
int nus_agent_handle_tool_call(const char *json, const jsmntok_t *toks, int n_toks)
เพื่อการสังเกตเท่านั้น — ส่งข้อความใบ้สั้น ๆ ผ่าน IPC ให้ marquee บน CM55 แสดงว่าเครื่องมือใดกำลังทำง...
nus_agent_buffer_len
size_t nus_agent_buffer_len(void)
จำนวนไบต์ที่พักไว้สำหรับ ask ที่ค้างอยู่ เป็น probe สำหรับ telemetry ไม่ใช่กลไกการซิงโครไนซ์
nus_agent_handle_token
int nus_agent_handle_token(const char *json, const jsmntok_t *toks, int n_toks)
ต่อ "delta" เข้ากับ accumulator คืน -1 เมื่อ id ไม่ตรง (ถูกทิ้งไปเงียบ ๆ)
nus_agent_reset
void nus_agent_reset(void)
ล้าง id ของ ask ที่ค้างอยู่และ accumulator ไม่ต้อง init ไม่มีการจับ lock ไม่มีค่าคืน
nus_agent_note_ask
void nus_agent_note_ask(const char *id)
บันทึก id ของ ask ที่ค้างอยู่ id ที่เป็น NULL หรือว่างเปล่าจะรีเซ็ต agent ไม่มีผู้เรียกที่ใดเลย
dist
ble_nus
include
nus_agent.h
Generated by
1.18.0