gocoon

module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2026 License: Apache-2.0

README

gocoon

Pure-Go COCOON client. Run decentralized AI inference on TON without Telegram's C++ runner build chain.

  • Standalone CLI with an OpenAI-compatible local HTTP API
  • OpenAI function calling support (tools array, tool_calls response)
  • Full on-chain payment flow: stake → chat → close → withdraw
  • Static cross-platform binaries (linux / darwin / windows × amd64 / arm64, android / arm64)

Mainnet only. The full quick start spends ~20 TON of real mainnet funds to deploy the client smart contract and stake the channel. There is no testnet path today.

Install

git clone https://github.com/TONresistor/gocoon.git
cd gocoon
make build
export PATH="$PWD/dist:$PATH"

make build-cross and make build-android produce release-grade static binaries for every supported target.

Quick Start

gocoon init --dir ./gocoon-data

init prints a fund_address and a recommended amount. Send the TON, then:

gocoon wallet wait-funded \
  --wallet ./gocoon-data/wallet.json \
  --config ./gocoon-data/client-config.json

gocoon run --config ./gocoon-data/client-config.json

The runner blocks. In a second terminal:

gocoon chat "Reply in one short sentence."

Or hit the OpenAI-compatible endpoint directly:

curl http://127.0.0.1:10000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"default","messages":[{"role":"user","content":"hi"}]}'

When you are done, recover the funds:

gocoon channel close
gocoon wallet withdraw \
  --wallet ./gocoon-data/wallet.json \
  --config ./gocoon-data/client-config.json \
  --to <YOUR_TON_ADDRESS>

What's Inside

Path Role
cmd/gocoon Standalone CLI
cmd/gocoon-runner Local runner, HTTP control plane on 127.0.0.1:10000
pkg/cocoon Client library: sessions, inference, payments, discovery
pkg/contracts COCOON root / client / wallet contract helpers
pkg/router Direct proxy dialer: TCP, PoW, TLS 1.3
pkg/tl TL primitives and wire framing
pkg/store Persistence (memory and bbolt backends)

Documentation

Development

make test          # tests with race detector and coverage
make vet           # static analysis
make build-cross   # release-grade cross-builds

See DEVELOPMENT.md for the full contributor workflow.

License

Apache-2.0. Copyright 2026 Digital Resistance.

This repository implements compatibility with the public COCOON protocol and smart-contract interfaces published by Telegram FZ-LLC. See NOTICE for upstream attributions. gocoon is not affiliated with or endorsed by Telegram.

Directories

Path Synopsis
cmd
gocoon command
Command gocoon is the standalone COCOON client CLI.
Command gocoon is the standalone COCOON client CLI.
gocoon-runner command
Command gocoon-runner is the browser-compat runner binary, drop-in replacement for upstream cocoon-runner.
Command gocoon-runner is the browser-compat runner binary, drop-in replacement for upstream cocoon-runner.
pkg
cocoon
Package cocoon is the public client API for the COCOON decentralized AI inference network on TON.
Package cocoon is the public client API for the COCOON decentralized AI inference network on TON.
cocoon/internal/fakeproxy
Package fakeproxy implements an in-process fake COCOON proxy that speaks the same wire protocol as the real upstream proxy.
Package fakeproxy implements an in-process fake COCOON proxy that speaks the same wire protocol as the real upstream proxy.
contracts
Package contracts contains Go ports of the COCOON smart-contract wrappers originally published in TypeScript at TelegramMessenger/cocoon-contracts.
Package contracts contains Go ports of the COCOON smart-contract wrappers originally published in TypeScript at TelegramMessenger/cocoon-contracts.
contracts/client
Package client wraps the cocoon_client smart contract: a per-(client,proxy) payment channel.
Package client wraps the cocoon_client smart contract: a per-(client,proxy) payment channel.
contracts/root
Package root wraps the cocoon_root smart contract on TON mainnet.
Package root wraps the cocoon_root smart contract on TON mainnet.
contracts/wallet
Package wallet wraps the cocoon_wallet smart contract: a custom Ed25519 wallet used as the cocoon-node identity.
Package wallet wraps the cocoon_wallet smart contract: a custom Ed25519 wallet used as the cocoon-node identity.
router
Package router implements the COCOON upstream proxy dialer used by pkg/cocoon.
Package router implements the COCOON upstream proxy dialer used by pkg/cocoon.
store
Package store defines the persistence interface used by pkg/cocoon and supplies in-memory and bbolt-backed implementations.
Package store defines the persistence interface used by pkg/cocoon and supplies in-memory and bbolt-backed implementations.
store/bbolt
Package bbolt provides a persistent store.Store implementation using etcd-io/bbolt.
Package bbolt provides a persistent store.Store implementation using etcd-io/bbolt.
store/memory
Package memory provides an in-memory implementation of store.Store.
Package memory provides an in-memory implementation of store.Store.
tl
Package tl implements the Telegram TL (Type Language) wire format used by the COCOON network protocol.
Package tl implements the Telegram TL (Type Language) wire format used by the COCOON network protocol.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL