mugib_sdk 1.0.0 copy "mugib_sdk: ^1.0.0" to clipboard
mugib_sdk: ^1.0.0 copied to clipboard

Official Flutter SDK for Mugib — chat sessions, voice agents, KB, and widget APIs with one apiKey.

mugib_sdk #

Official unified Flutter SDK for Mugib tenant integrations.

One project API key covers:

  • Chat — sessions, messages (JSON + SSE streaming), dynamic payload, handoff poll, tool confirmations, conversions, CSAT
  • Voice — real-time Gemini Live calls (same API as legacy mugib_voice)
  • KB — list / add / update / delete entries
  • Widget — bot config, stats, metrics

Voice is unchanged from mugib_voice. This package adds full chat on top.


What you need #

Item Where
Project API key Project → Settings → API Key
Voice agent id (voice only) Project → Voice Agents → numeric id
API base URL https://api.mugib.com (default)

Install #

dependencies:
  mugib_sdk: ^1.0.0
flutter pub get

Requirements: Flutter 3.24+ / Dart 3.5+ · iOS & Android (voice needs microphone permissions).


Quick start — chat + voice #

import 'package:mugib_sdk/mugib_sdk.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await MugibSdk.initialize();
  runApp(const MyApp());
}

final mugib = MugibClient(apiKey: 'YOUR_PROJECT_API_KEY');

// 1. Open chat session
final session = await mugib.chat.createSession(pageUrl: '/app');

// 2. Send message with payload (name, plan, balance, …)
final reply = await session.send(
  'What plan fits me?',
  payload: {'name': 'Ahmed', 'plan': 'trial'},
);
print(reply.reply);

// 3. Streaming reply (SSE)
await for (final event in session.sendStream('Explain Pro plan')) {
  if (event is MugibStreamText) stdout.write(event.text);
}

// 4. Voice call — same session context
final call = mugib.voice.client(34);
await call.start(options: MugibVoiceCallOptions(
  chatSessionId: session.id,
  userContext: {'name': 'Ahmed'},
));
call.transcripts.listen((t) => print('${t.role}: ${t.text}'));
await call.end();

Chat API #

MugibClient.chat #

Method REST endpoint Description
createSession({pageUrl}) POST /api/v1/sessions New session (chat_…)
listSessions() GET /api/v1/sessions Active sessions
session(id) Bind existing session id

MugibChatSession #

Method REST endpoint Description
send(message, {payload}) POST …/messages Blocking JSON reply
sendStream(message, {payload}) POST …/messages?stream=true SSE token stream
sendStreamText(…) same Convenience: full string
getHistory() GET …/sessions/{id} Message history
reset() DELETE …/sessions/{id} Clear session
poll({agentAfter}) GET …/poll Human-agent handoff messages
pendingConfirmations() GET …/pending-confirmations MCP tools awaiting approval
confirmTool(id, {confirm}) POST …/confirmations/{id} Approve / decline tool
trackConversion({goalName, …}) POST …/conversions Conversion event
submitCsat({rating, comment}) POST /api/v1/csat/{id} 1–5 star rating

Payload #

Pass dynamic user context on every message (merged server-side):

await session.send('Check my balance', payload: {
  'name': 'أحمد',
  'account_id': 'ACC-9921',
  'balance': '45 IQD',
});

The same payload is reused when you pass chatSessionId to a voice call.

Streaming metadata #

The final SSE event may be MugibStreamMetadata with KB sources:

await for (final event in session.sendStream('…')) {
  switch (event) {
    case MugibStreamText(:final text):
      print(text);
    case MugibStreamMetadata(:final sources):
      print('Sources: ${sources.map((s) => s.title)}');
  }
}

Voice API #

Voice behaviour is identical to mugib_voice v0.6.x — see voice section in docs/flutter-sdk.md or mugib_voice README for permissions, errors, metrics.

// List agents
final agents = await mugib.voice.listAgents();

// Create call client
final call = mugib.voice.client(agents.first.id);
await call.start(); // or MugibVoiceCallOptions for payload / chatSessionId

// Analytics
final stats = await mugib.voice.analytics(34, days: 7);

Or use the legacy import (re-export):

import 'package:mugib_voice/mugib_voice.dart'; // voice-only, depends on mugib_sdk

KB, config & stats #

// Widget branding
final config = await mugib.getWidgetConfig();
print(config.welcomeMessage);

// Stats
final stats = await mugib.getStats();

// Knowledge base
final kb = await mugib.kb.list(search: 'pricing');
await mugib.kb.add(title: 'FAQ', content: '…');

Platform permissions (voice) #

iOS — Info.plist #

<key>NSMicrophoneUsageDescription</key>
<string>We need the microphone for voice conversations with our support agent.</string>

Android — AndroidManifest.xml #

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />

minSdkVersion 23 or higher.


Error handling #

try {
  await session.send('Hello');
} on MugibException catch (e) {
  switch (e.code) {
    case MugibErrorCode.quotaExceeded:
      // upgrade plan
    case MugibErrorCode.rateLimited:
      // slow down
    default:
      print(e.message);
  }
}

Voice errors use MugibVoiceException / MugibVoiceErrorCode (same as before).


Migration from mugib_voice #

Before After
mugib_voice: ^0.6.1 mugib_sdk: ^1.0.0
MugibVoiceClient(apiKey:, agentId:) MugibClient(apiKey:).voice.client(agentId)
REST for chat mugib.chat.createSession() + session.send()

Existing voice-only apps can keep mugib_voice: ^0.7.0 — it re-exports voice from mugib_sdk.


Example app #

cd sdk/flutter/mugib_sdk/example
flutter pub get
flutter run --dart-define=MUGIB_API_KEY=your_key

Maintainers #

cd sdk/flutter/mugib_sdk
make help
make check
make update   # publish to pub.dev

See PUBLISHING.md.



License #

MIT — see LICENSE.

1
likes
0
points
1.1k
downloads

Publisher

unverified uploader

Weekly Downloads

Official Flutter SDK for Mugib — chat sessions, voice agents, KB, and widget APIs with one apiKey.

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #chatbot #voice #sdk #gemini

License

unknown (license)

Dependencies

flutter, flutter_pcm_sound, http, permission_handler, record, web_socket_channel

More

Packages that depend on mugib_sdk