مرجع
SDK
استورد QiClient في كودك. CLI وخادم MCP غلافان حول هذا العميل: إصلاح هنا يصل إلى الثلاثة.
التثبيت
الحزمة نفسها التي تستخدمها الـ CLI، مضافة إلى مشروعك: npm install @sumeria.ai/qi.
# Same package as the CLI, added to your project
npm install @sumeria.ai/qiبيانات الاعتماد
يكفي تمرير مفتاح API: فهو يحمل المستأجر الخاص به. من دون وسائط، تُحل بيانات الاعتماد كما في الـ CLI: QI_API_KEY أو المفتاح الذي حفظه qi auth login. عنوان URL الأساسي مجرد إعداد متقدم، مثلًا لبيئة أخرى:
// The key is enough. baseUrl is an advanced override, e.g. for a staging environment.
const staging = new QiClient({
apiKey: process.env.STAGING_QI_API_KEY,
baseUrl: process.env.STAGING_QI_BASE_URL,
});الرفع
تقبل uploadAudio وuploadText وuploadBot مسارات الملفات. تبني resolveFiles القائمة من المجلدات والأنماط، وتغيّر nameRules الاسم الذي يُرسل به كل ملف.
import { QiClient, nameRules, resolveFiles } from "@sumeria.ai/qi";
const qi = new QiClient(); // QI_API_KEY, or the key "qi auth login" saved
const files = resolveFiles(["./calls"], { recursive: true, include: ["*.mp3"], exclude: ["*tmp*"] });
const report = await qi.uploadAudio(files, {
form: "VENTAS", // key, or an id resolved to its key
analysis: "full", // shared tenants: "transcript" skips evaluation
rename: nameRules({ prefix: "dev_", key: "VENTAS" }), // the name it is sent under
concurrency: 4, // requests of 10 files in flight (default 2)
retries: 3, // 429 / 5xx, exponential backoff (default 3)
onProgress: ({ done, total, file }) => console.log(done, total, file.name, file.status),
});
report.accepted; // [{ path, name, status, attempts }]
report.rejected; // ... with errors: [{ code, params }]
report.failed; // ... with message (network, 5xx after retries)
await qi.uploadText(["./chat.csv"], { form: "SOPORTE" });
await qi.uploadBot(["./chat.json"], { bot: "Asistente", form: "BOTQA" });- تُرسل الملفات في طلبات من 10، عدة طلبات في وقت واحد بحسب concurrency.
- يُعاد 429 أو 5xx بتراجع أسّي، حتى retries مرة.
- تُفحص الأسماء محليًا قبل الإرسال. الملف الذي يرفضه API يُستبعد وتُعاد بقية الدفعة.
- لا يرمي استثناءً أبدًا بسبب ملف: يذكر التقرير ما حدث لكل واحد — مقبول، أو مرفوض مع رموزه، أو فاشل مع رسالته.
للتحقق من اسم دون اتصال، بالقواعد نفسها كما في API:
import { QiClient, nameModeFor, validateName } from "@sumeria.ai/qi";
const qi = new QiClient();
validateName("call.mp3", nameModeFor(qi.tenant), { tenant: qi.tenant }); // [] or [{ code, params }]العرض والتفاصيل
تعيد دوال القراءة ما يعيده API، بعد إزالة غلاف data.
| الدالة | ما تعيده |
|---|---|
listInteractions | صفحة واحدة: data وtotal_records وtotal_pages وhas_next_page. |
iterateInteractions | كل الصفحات، 200 في كل مرة، كمكرِّر غير متزامن. |
getInteraction | التفاصيل: الحالة لكل مرحلة والحوار والإجابات. |
waitForInteraction | تنتظر حتى تستقر كل المراحل. افتراضيًا، سقف 10 دقائق واستطلاع كل 5 ثوانٍ. |
listForms | النماذج مع معرّفها وعنوانها ونوعها ومفتاحها. |
listBotProfiles | ملفات الروبوتات الشخصية. 403 MODULE_NOT_IN_PLAN بدون الوحدة. |
getUsage | الخطة ورموز QI المستخدمة والمتاحة ونهاية الفترة والوحدات والتقرير الكامل. |
const page = await qi.listInteractions({ limit: 10, from: "2026-09-01", to: "2026-09-08" });
console.log(page.total_records, page.data);
for await (const row of qi.iterateInteractions({ sourceType: "audio" })) {
// every page, 200 at a time
}
const detail = await qi.getInteraction(id); // status, dialogue, answered_form, ...
const done = await qi.waitForInteraction(id, { timeout: 15 * 60_000, interval: 10_000 });
const forms = await qi.listForms({ type: "audio" }); // [{ id, title, type, key }]
const bots = await qi.listBotProfiles(); // 403 MODULE_NOT_IN_PLAN without the module
const usage = await qi.getUsage(); // { plan, tokensUsed, tokensLimit, nextPayment, modules, report }الأخطاء
أي شيء ليس لكل ملف يرمي QiError مع status وcode وretryable (صحيح للرمزين 429 و5xx). تُصدَّر withRetry وmapLimit لاستدعاءاتك الخاصة.
import { QiError } from "@sumeria.ai/qi";
try {
await qi.listBotProfiles();
} catch (error) {
if (error instanceof QiError) {
console.error(error.status, error.code); // 403 MODULE_NOT_IN_PLAN
if (error.retryable) {
// 429 or 5xx: the same request could succeed later
}
}
}يجيب API برموز لا بجمل. يُبقيها QiError في المتناول لتتبع الرسالة لغة القارئ.
موجِّه للوكلاء
الصق هذا في وكيل برمجة ليربط SDK بكودك.
You are integrating the Sumeria Quality Intelligence SDK (@sumeria.ai/qi) into this codebase.
1. Install: npm install @sumeria.ai/qi
2. Import QiClient and QiError. new QiClient({ apiKey }) is enough: the key carries its
tenant. Without arguments it reads QI_API_KEY or the key "qi auth login" saved — never
hardcode a key in source.
3. Use client methods: qi.uploadAudio(paths, options), qi.uploadText(paths, options),
qi.listInteractions({ limit }), qi.getInteraction(id), qi.waitForInteraction(id).
4. Uploads never throw per file: read report.accepted / report.rejected / report.failed.
Other errors throw QiError — check error.code, not the message, and map codes to this
project's own user-facing copy instead of showing them raw.
5. Wire this into: <name the module or service in this codebase that should call it,
and what should happen on success and on failure>.
Ask before deciding where credentials are read from if this project already has its own
secrets convention.