G

sdk.transport

sdk.transport

Send and receive messages via Meshii Protocol — end-to-end encrypted, P2P when online, relay-fallback when offline. No server stores message history by default.


Send a Message

await sdk.transport.message.send({
  to:         'alice.gao',       // recipient's Gao Domain or routing tag
  content:    'Hello!',
  type?:      'text',            // 'text' | 'notification' | 'agent_action'
  encrypted?: true,              // default true — always E2EE
})

All messages are end-to-end encrypted using Signal Protocol. The relay stores only an encrypted blob with a routing tag — it cannot read content.


Receive Messages

const unsub = sdk.transport.message.subscribe((msg: IncomingMessage) => {
  console.log(msg.from)                // sender's domain
  console.log(msg.decrypted.content)  // decrypted message text
  console.log(msg.decrypted.type)     // message type
  console.log(msg.timestamp)          // unix ms
})

// Stop listening (call on component unmount)
unsub()

---

### Agent Sends as Bot Identity

When an agent sends a message, it appears as the agent’s identity — not the domain owner.

await sdk.transport.message.sendAsAgent(
  'booking-bot-id',         // agent ID registered in sdk.intelligence
  'customer-routing-tag',   // recipient
  'Your appointment is confirmed for tomorrow at 3pm.'
)

Message Types

Type

Use

text

Standard chat message

notification

One-way alert (no reply expected)

agent_action

Agent-to-agent or agent-to-user task communication


Routing

// Select best relay node for routing
const route = await sdk.transport.selectRoute({
  recipient: 'alice.gao',
  priority: 'low_latency',    // 'low_latency' | 'high_reliability'
})

// Validate a relay path
const valid = await sdk.transport.validateRelayPath(['relay1.meshii.app', 'relay2.meshii.app'])

---

### React Hook

import { useMessages } from '@gao/system-sdk/react'

function ChatWindow({ contact }: { contact: string }) {
  const { messages, send, loading } = useMessages(sdk, contact)

  return (
    <div>
      {messages.map(msg => (
        <div key={msg.id} className={msg.from === sdk.domain ? 'sent' : 'received'}>
          {msg.decrypted.content}
        </div>
      ))}
      <input
        onKeyDown={(e) => {
          if (e.key === 'Enter') send(e.currentTarget.value)
        }}
      />
    </div>
  )
}

Storage Modes

By default, messages exist only in RAM during the session. Users can opt in to storage:

// Default  no storage
sdk.transport.setStorageMode('none')

// Save locally on device (encrypted)
sdk.transport.setStorageMode('local')

// Backup to GaoStorage (encrypted, user pays fee)
sdk.transport.setStorageMode('depin')

---

### Privacy Model

What relay sees

What relay cannot see

Routing tag (opaque recipient ID)

Message content

Ciphertext blob

Sender identity (in plaintext)

TTL timestamp

Conversation history

Messages are deleted from relay **immediately on delivery ACK**. Maximum TTL is 7 days  after which undelivered messages are purged automatically.

---

### Common Patterns

#### Booking Confirmation

await sdk.transport.message.send({
  to: customerDomain,
  content: `✓ Confirmed: ${service} on ${date} at ${time}. Reply to reschedule.`,
  type: 'notification',
})

#### Payment Notification

await sdk.transport.message.send({
  to: merchantDomain,
  content: JSON.stringify({
    type: 'payment_received',
    amount: '25.00',
    currency: 'USDC',
    from: customerDomain,
  }),
  type: 'agent_action',
})

#### Support Bot

const unsub = sdk.transport.message.subscribe(async (msg) => {
  if (msg.decrypted.type === 'text') {
    const reply = await sdk.intelligence.runAgent('support-bot', msg.decrypted.content)
    await sdk.transport.message.sendAsAgent('support-bot', msg.from, reply.output)
  }
})