aimarket_agent library

AI Market Protocol v2 Consumer SDK for Dart/Flutter.

Use this to embed marketplace economy into Flutter desktop apps (macOS/Windows/Linux), Dart servers, and any Dart application.

Quick Start

import 'package:aimarket_agent/aimarket_agent.dart';

void main() async {
  final agent = AimarketAgent(
    hubUrl: 'https://hub.aicom.io',
    walletKey: 'your-wallet-private-key-hex',
  );

  // Phase 1: Discover career capabilities
  final plan = await agent.discover(
    intent: 'ATS scoring rules for fintech roles',
    budget: 1.00,
    category: 'career',
  );

  // Phase 2: Open a $5 channel on Base
  final channel = await agent.openChannel(5.00, token: 'USDT', chain: 'base');

  // Phase 3: Invoke the top result
  final result = await agent.invoke(
    capabilityId: plan.first.capability.id,
    input: {'target_role': 'Senior PM', 'industry': 'fintech'},
    channelId: channel.id,
  );

  // Phase 4: Settle the channel
  await agent.closeChannel(channel.id);

  // Phase 5: Verify TEE receipt (optional)
  if (result.teeReceipt != null) {
    final ok = agent.verifyTeeReceipt(
      result.teeReceipt!,
      jsonEncode({'target_role': 'Senior PM'}),
      jsonEncode(result.output),
    );
    print('TEE verified: $ok');
  }

  print('Spent: \$${result.priceUsd}');
  agent.dispose();
}

Exports

This library re-exports all public types from its modules:

Core Agent

Data Models

Signing & Crypto

TEE Verification

Dependencies

  • http for HTTP/HTTPS transport
  • crypto for SHA-256 hashing and HMAC

Platform Support

Platform Status
Flutter macOS Full
Flutter Windows Full
Flutter Linux Full
Dart CLI Full
Flutter Web Partial (CORS dependent)
Flutter iOS/Android Untested

Classes

AimarketAgent
AI Market Protocol v2 consumer.
AimarketAgentConfig
Configuration for AimarketAgent behavior.
BillOfMaterials
Bill of Materials — full trace of a marketplace interaction.
Capability
A discoverable capability from the marketplace.
Channel
A pre-funded payment channel.
Eip712Domain
InvokeResult
Result of a capability invocation.
MarketSigner
PlanStep
A plan step from discovery — capability matched to an intent.
SearchResponse
A hub search/discovery response — the typed shape returned by the /search endpoint.
Settlement
Settlement returned after closing a payment channel.
TeeAttestation
TEE attestation proving code runs in a secure enclave.
TeePlatform
Recognized TEE platform identifiers.
TeeReceipt
Receipt proving execution happened inside a TEE.
TeeVerificationResult
Result of a TEE attestation verification with detailed failure reasons.
TeeVerifier
Verifies TEE attestations and receipts client-side.
TrustedHashCache
Caches trusted code hashes fetched from the hub, with TTL expiry.
TypedData

Functions

computeDebitDigest({required String channelId, required String hub, required String token, required BigInt amount, required String receiptId, required BigInt nonce, required int deadline, int chainId = 8453, String verifyingContract = '0x0000000000000000000000000000000000000000'}) Uint8List
Compute EIP-712 digest for a debit authorization.
jsonRoundTrip<T>(JsonFactory<T> fromJson, Map<String, dynamic> input) bool
Verify that a model round-trips through JSON without field loss.

Typedefs

JsonFactory<T> = T Function(Map<String, dynamic>)
JSON serialization round-trip helper for models.

Exceptions / Errors

AimarketException
Base exception for AI Market Protocol errors.
AimarketNetworkException
Network-level error: timeout, connection refused, DNS failure, etc.
AimarketPaymentException
Payment failure: depleted channel, insufficient funds, or expired credit.
AimarketSafetyException
Safety gate blocked the invocation.