SDK ကို load လုပ်ပါ
<script src="/sdk/nebo.global.js"></script>
<script>
const { nebo, identity, storage, agents, janus, decide, chat, surfaces } = NeboAppSDK;
</script> global သည် NeboAppSDK ဖြစ်ပြီး nebo global မရှိပါ။ NeboAppSDK.nebo သည် SDK instance ဖြစ်ပြီး module တိုင်းကို ထိပ်ဆုံးအဆင့်တွင်လည်း export လုပ်ထားသောကြောင့် NeboAppSDK.storage နှင့် NeboAppSDK.nebo.storage သည် object တစ်ခုတည်း ဖြစ်သည်။ browser ကို ဖုံးအုပ်ခြင်း မဖြစ်စေရန် nebo.fetch ကို neboFetch အဖြစ်နှင့် nebo.WebSocket ကို NeboWebSocket အဖြစ် export လုပ်ထားပါသည်။
identity
| ခေါ်ဆိုမှု | ပြန်ပေးသည် |
|---|---|
identity.get() | အက်ပ်၏ ဝန်ထမ်းအတွက် {id, name, displayName, description, persona, model, skills, inputValues}။ Cache လုပ်ထားသည်။ |
identity.invalidate() | cache ကို ရှင်းလင်းသည်။ |
storage
အက်ပ်အတွက် key-value store။ ၎င်းသည် storage:readwrite လိုအပ်ပါသည်။ ၎င်းသည် အက်ပ်၏ ဝန်ထမ်း ဖတ်ပြီး ပြောင်းလဲသော store တစ်ခုတည်း ဖြစ်သည်- ပိုင်ရှင်က ဝန်ထမ်းနှင့် စကားပြော၍ ထည့်သော မှတ်တမ်းသည် စာမျက်နှာပေါ်တွင် ပေါ်လာပြီး စာမျက်နှာထဲ ရိုက်ထည့်သော မှတ်တမ်းကို ဝန်ထမ်းက ရှာတွေ့နိုင်ပါသည်။
const deals = (await NeboAppSDK.storage.getItem('deals')) ?? [];
deals.push({ name: 'Example renewal', closes: '2026-10-31' });
await NeboAppSDK.storage.setItem('deals', deals); | ခေါ်ဆိုမှု | အပြုအမူ |
|---|---|
storage.getItem(key) | setItem သိမ်းဆည်းခဲ့သည့်အရာ အတိအကျ (object၊ list၊ number သို့မဟုတ် string) သို့မဟုတ် null။ |
storage.setItem(key, value) | မည်သည့် JSON တန်ဖိုးကိုမဆို သိမ်းဆည်းသည်။ |
storage.removeItem(key) | key တစ်ခုကို ဖယ်ရှားသည်၊ ၎င်းသည် keys() တွင် မပေါ်တော့ပါ။ |
storage.keys() | key အားလုံး။ |
storage.clear() | key အားလုံးကို ဖယ်ရှားသည်။ |
storage.onChange(handler) | ဝန်ထမ်း (source: "employee") သို့မဟုတ် ဤဝင်းဒိုး အပါအဝင် အက်ပ်၏ ဖွင့်ထားသော မည်သည့် ဝင်းဒိုး (source: "page") ကမဆို ရေးပြီးတိုင်း handler({appId, keys, action, source}) ကို ခေါ်သည်။ နားထောင်ခြင်းကို ရပ်သော function ကို ပြန်ပေးသည်။ |
ဒေတာ ပြောင်းလဲသည့်အခါ မည်သူ ပြောင်းလဲသည်ဖြစ်စေ ပြန်ဆွဲပါ-
async function load() {
render((await NeboAppSDK.storage.getItem('deals')) ?? []);
}
load();
const stop = NeboAppSDK.storage.onChange((change) => {
// { appId, keys: ['deals'], action: 'set' | 'delete', source: 'employee' | 'page' }
if (change.keys.includes('deals')) load();
}); အက်ပ်၏ ကိုယ်ပိုင် ဝန်ထမ်းသာ ဤ store ကို ၎င်း၏ ကိုယ်ပိုင် အက်ပ်အတွက်သာ ဝင်ရောက်နိုင်ပြီး အခြား ဝန်ထမ်းတစ်ဦးက အက်ပ်၏ ဝန်ထမ်းကို မေးရပါသည်။ နှစ်ဖက်စလုံး ရှာတွေ့နိုင်သော key များကို ရွေးပါ (စာရင်းတစ်ခုပါ key တစ်ခု သို့မဟုတ် deal:42 ကဲ့သို့ prefix အောက်ရှိ မှတ်တမ်းတစ်ခုလျှင် key တစ်ခု) နှင့် ၎င်းတို့ကို ဝန်ထမ်း၏ ညွှန်ကြားချက်များတွင် ဖော်ပြပါ။ "42" ကဲ့သို့ ကိုယ်တိုင် မှန်ကန်သော JSON ဖြစ်သည့် string သည် parse လုပ်ပြီး ပြန်လာသောကြောင့် အမျိုးအစား အရေးကြီးပါက object ထဲ ထုပ်ပါ။ တန်ဖိုးတစ်ခုစီကို 2 MB အောက် အများကြီး ထားပါ။ ရေးခြင်းကို ငြင်းပယ်သည့်အခါ setItem က အမှား မပစ်ပါ။
agents
အက်ပ်၏ ဝန်ထမ်း သို့မဟုတ် အခြား ဝန်ထမ်းကို မေးပြီး ၎င်း၏ အဖြေကို ရယူပါ။ အခြား ဝန်ထမ်းကို မေးရန် subagent:<employee-id> လိုအပ်ပါသည်။
const { text } = await NeboAppSDK.agents.invoke('Which open deals close this month?');
for await (const part of NeboAppSDK.agents.stream('Summarize the pipeline.')) {
output.textContent += part.text;
} | ခေါ်ဆိုမှု | ပြန်ပေးသည် |
|---|---|
agents.invoke(message, {agent, data}) | ဝန်ထမ်း ပြီးဆုံးသည့်အခါ {text, tools}။ |
agents.stream(message, {agent, data}) | {text, done} ၏ async iterator။ |
janus
persona၊ မှတ်ဉာဏ် သို့မဟုတ် ကိရိယာ မပါသော မော်ဒယ်ကို တိုက်ရိုက် ခေါ်ဆိုမှု။
| ခေါ်ဆိုမှု | ပြန်ပေးသည် |
|---|---|
janus.complete({messages, model, temperature, max_tokens, system}) | ပြန်ကြားစာ စာသားကို string အဖြစ်။ |
janus.stream(same) | စာသား အပိုင်းများ၏ async iterator။ |
decide
Typed ဆုံးဖြတ်ချက်များ- ဒေတာအချို့အကြောင်း အမည်ပေးထားသော မေးခွန်းများ မေးပြီး အဖြေတစ်ခုစီကို ဖြစ်နိုင်ခြေများနှင့် ယုံကြည်မှုနှင့်အတူ မြန်ဆန်သော ခေါ်ဆိုမှု တစ်ကြိမ်တည်းဖြင့် ပြန်ရယူပါ။ စာသားအဖြစ် ဘာမှ မရေးသောကြောင့် ဆုံးဖြတ်ချက်များ (ဤ lead သည် စိတ်ဝင်စားမှု မြင့်သလား၊ ဤ ticket သည် မည်သည့် အမျိုးအစားထဲ ပါသလဲ၊ မည်မျှ အရေးပေါ်သလဲ) အတွက် အသုံးပြုပြီး ရေတွက်ခြင်း၊ ရက်စွဲများနှင့် threshold များကို သင့်ကိုယ်ပိုင် ကုဒ်တွင် ထားပါ။ အက်ပ်၏ ဝန်ထမ်းသည် ၎င်း၏ decide ကိရိယာဖြင့် တူညီသော မေးခွန်းများကို မေးနိုင်ပါသည်၊ ဥပမာ အက်ပ်၏ သိမ်းဆည်းထားသော မှတ်တမ်းများအပေါ်။
const { answers } = await NeboAppSDK.decide({
state: { company: 'Example Co', status: 'asked for a quote today' },
questions: {
tier: {
type: 'choice',
instructions: 'How warm is this lead, judging by `status`?',
criteria: { hot: 'ready to buy', warm: 'interested', cold: 'not now', other: "can't tell" }
},
fit: {
type: 'score',
instructions: 'How well does `company` fit our customers?',
criteria: ['poor', 'fair', 'good', 'great']
},
reply: { type: 'noul', instructions: '`status` asks us for a reply.' }
}
});
if (answers.tier.choice === 'hot' && answers.tier.confidence > 0.8) flag(lead);
// answers.fit.score is fractional: 0 is "poor", 1.5 is between "fair" and "good".
// answers.reply.noul is the probability the statement holds, from 0 to 1. | မေးခွန်း အမျိုးအစား | criteria | အဖြေ |
|---|---|---|
choice | အမည်ပေးထားသော ရွေးချယ်စရာ 2 မှ 255 အထိ object၊ {option: description}။ စာရင်း မပြည့်စုံသည့်အခါ other ကဲ့သို့ ထွက်ပေါက် ရွေးချယ်စရာကို ထည့်ပါ။ | choice (ရွေးထားသော ရွေးချယ်စရာ)၊ confidence (0 မှ 1) နှင့် ရွေးချယ်စရာ တစ်ခုလျှင် probabilities။ |
score | အနိမ့်ဆုံးမှ စ၍ စီထားသော အဆင့် 2 မှ 10 အထိ စာရင်း။ | score (ဒသမ၊ 0 သည် ပထမ အဆင့်)၊ confidence နှင့် အဆင့်တစ်ခုလျှင် probabilities။ |
noul | မရှိ- မေးခွန်းသည် ဆုံးဖြတ်ရမည့် ဖော်ပြချက် တစ်ခု ဖြစ်သည်။ | noul၊ ဖော်ပြချက် မှန်ကန်နိုင်ခြေ။ သီးခြား ယုံကြည်မှု မရှိ။ |
decide({state, questions})သည်{model, answers, usage}အဖြစ် ပြန်ပေးပြီး အဖြေတစ်ခုစီသည် ၎င်း၏ မေးခွန်းကို သင်ပေးထားသော အမည်အောက်တွင် ရှိသည်။stateသည် စာသား သို့မဟုတ် မည်သည့် JSON မဆို ဖြစ်သည်။ မေးခွန်းများ လိုအပ်သော field များကိုသာ ထားပြီး ထို field များကိုinstructionsအတွင်း backtick ထဲတွင် အမည်တပ်ပါ။ မေးခွန်း တစ်ခုလုံးသည်instructionsထဲတွင် ရှိပြီး မေးခွန်း၏ အမည်သည် အဖြေကို အညွှန်းတပ်ရုံသာ ဖြစ်သည်။ အလွန်ရှည်သော state ကို မပို့မီ အလယ်တွင် တိုစေပါသည်။- ၎င်းသည် အကြောင်းရင်းကို မက်ဆေ့ချ်အဖြစ် ပါသော error တစ်ခုကို throw လုပ်သည်။ error တွင် status code မရှိသောကြောင့် ကိစ္စများကို ခွဲခြားရန် လိုလျှင် မက်ဆေ့ချ်ကို နှိုင်းယှဉ်ပါ–
- ပုံစံမမှန်သော မေးခွန်း၊ ဥပမာ ရွေးချယ်စရာ တစ်ခုတည်းပါသော choice (bot က 400 ဖြင့် ဘာမှားသည်ကို ဖြေသည်)။
- ပိုင်ရှင်၏ အကောင့်တွင် အလုပ် မကျန်တော့ပါ- "သင့်အကောင့်တွင် ပါဝင်သော အလုပ်အားလုံးကို သုံးပြီးပါပြီ။ ဆက်လက်ရန် အစီအစဉ်တစ်ခု ရွေးပါ သို့မဟုတ် ခရက်ဒစ် ထည့်ပါ။" (429)။ ပိုင်ရှင်က အစီအစဉ် သို့မဟုတ် ခရက်ဒစ် မထည့်မချင်း ပြန်ကြိုးစားခြင်း အကူအညီ မဖြစ်ပါ။
- ဆုံးဖြတ်ချက်များ တစ်ပြိုင်နက် များလွန်းသည်- "ဆုံးဖြတ်ချက်များ တစ်ပြိုင်နက် များလွန်းပါသည်။ ခဏအကြာတွင် ထပ်စမ်းကြည့်ပါ။" (429)။
- bot သည် အကောင့်ဝင်မထားပါ- "ဆုံးဖြတ်ချက်များအတွက် NeboAI ချိတ်ဆက်ထားရန် လိုအပ်ပါသည်။ NeboAI သို့ အကောင့်ဝင်ပြီး ထပ်စမ်းကြည့်ပါ။" (503)။
- ဆုံးဖြတ်ချက် ဝန်ဆောင်မှု မအောင်မြင်ပါ (502)။
- ဆုံးဖြတ်ချက်များကို မည်သည့် မော်ဒယ် ခေါ်ဆိုမှုကဲ့သို့ပင် bot ပိုင်ရှင်၏ NeboAI အကောင့်သို့ ငွေတောင်းခံပါသည်။ စျေးနှုန်း ကို ကြည့်ပါ။
neboFetch
// Relative path: the app's own sidecar.
const res = await NeboAppSDK.neboFetch('/deals?stage=open');
// Absolute URL: through Nebo's proxy. Needs network:api.example.com.
const rates = await NeboAppSDK.neboFetch('https://api.example.com/rates'); relative path သည် /apps/<id>/api/<path> ရှိ အက်ပ်၏ sidecar သို့ သွားပါသည်။ absolute http သို့မဟုတ် https URL သည် Nebo ၏ proxy မှတစ်ဆင့် သွားပြီး network:<host> သို့မဟုတ် network:* လိုအပ်ပါသည်။
NeboWebSocket
new NeboAppSDK.NeboWebSocket() သည် အက်ပ်၏ ဝန်ထမ်းထံ live socket ကို ဖွင့်ပြီး backoff ဖြင့် ပြန်ချိတ်ဆက်ပါသည်။ ၎င်းသည် argument မယူဘဲ send(data)၊ close()၊ onopen၊ onmessage၊ onerror နှင့် onclose ပါရှိသည်။
surfaces နှင့် a2ui
surfaces.connect() သည် အက်ပ်၏ live ချန်နယ်ကို ဖွင့်ပါသည်။ ယနေ့ ၎င်းသည် အက်ပ်၏ ဝန်ထမ်းထံမှ အပြန်အလှန် ကတ်များကို သယ်ဆောင်ပါသည်- သင့်စာမျက်နှာက bundle လုပ်ထားသော @a2ui/web_core မှ MessageProcessor ဖြင့် a2ui.init(processor) ကို ခေါ်ပါ (SDK တွင် ကိုယ်ပိုင် renderer မရှိပါ)။ ကတ်တစ်ခုသည် ၎င်းကို ဖန်တီးထားသော အက်ပ်သို့သာ ရောက်ပြီး ၎င်းကို နှိပ်ခြင်းသည် ထိုအက်ပ်၏ ဝန်ထမ်းထံ သွားကာ ကတ်ပို့ပြီးနောက် ဖွင့်သော စာမျက်နှာသည် ၎င်းကို မလက်ခံရသောကြောင့် စာမျက်နှာက အမြဲ ပြသရမည့်အရာကို storage တွင် ထားပါ။
SDK သည် text_content၊ state_delta နှင့် surface_update ကဲ့သို့ typed ဖြစ်ရပ်များကို surfaces.on(type, handler)၊ surfaces.send(name, payload) နှင့် surfaces.state တို့နှင့်အတူ သတ်မှတ်ထားပါသည်။ Nebo သည် ထိုဖြစ်ရပ်များကို အက်ပ် စာမျက်နှာများထံ မပို့သေးပါ၊ send ကိုလည်း ဘာမှ မဖြေပါ။ live ဒေတာအတွက် storage.onChange ကို အသုံးပြုပါ။
chat
အက်ပ်၏ ဝန်ထမ်းနှင့် Nebo ၏ ချတ်ကို စာမျက်နှာထဲ ထည့်သွင်းပါ။
NeboAppSDK.chat.mount(document.getElementById('chat'), {
placeholder: 'Ask about a deal',
contextId: 'deal-42'
});
NeboAppSDK.chat.setContext({ deal: 'Example renewal' }); | ခေါ်ဆိုမှု | အပြုအမူ |
|---|---|
chat.mount(element, options) | ရွေးချယ်စရာများ- placeholder၊ theme၊ height၊ borderless၊ contextId၊ scope။ |
chat.send(text) | မက်ဆေ့ချ် ပို့သည်။ |
chat.setContext(context) | ဝန်ထမ်း မြင်ရသော context ကို သတ်မှတ်သည်၊ null က ၎င်းကို ရှင်းလင်းသည်။ |
chat.onMessage(handler) | မက်ဆေ့ချ်များကို လက်ခံသည်။ |
chat.newThread() | thread အသစ် စတင်သည်။ |
chat.unmount() | ချတ်ကို ဖယ်ရှားသည်။ |
ဖွဲ့စည်းမှု
Nebo အတွင်းတွင် SDK သည် app id နှင့် base URL ကို ကိုယ်တိုင် ရှာတွေ့သည်။ အခြားနေရာမှ ပေးသော စာမျက်နှာအတွက် nebo.configure({appId, baseUrl}) ကို ခေါ်ပါ၊ သို့မဟုတ် NeboAppSDK.setAppId(id) နှင့် NeboAppSDK.setBaseUrl(url) ကို ခေါ်ပါ။ getAppId() နှင့် getBaseUrl() က ၎င်းတို့ကို ပြန်ဖတ်ပေးသည်။