iLink Hub Bridge Profile SDK — write one async function, get a cross-platform P0-compliant profile
Project description
ilink-bridge-profile
Python SDK for writing iLink Hub Bridge profile handlers.
Implements the P0 exec protocol — reads ILINK_* env vars injected by the bridge,
calls your async handler, writes P0-formatted output to stdout. Works on macOS, Linux, and Windows.
Install
pip install ilink-bridge-profile
Quick start
# my_profile.py
from ilink_bridge import create_profile
async def handler(ctx):
# call any LLM API here
reply = await my_llm(ctx.message)
return reply # plain str, or ProfileResult(response=reply)
create_profile(handler)
Configure in ilink-hub-bridge.yaml:
profiles:
my-ai:
command: python
args: [/path/to/my_profile.py]
stdin: none
timeout_secs: 120
With session continuity
from ilink_bridge import create_profile, load_history, append_history, HistoryEntry, ProfileResult
async def handler(ctx):
history = load_history(ctx.session_id)
messages = [
{"role": e.role, "content": e.content}
for e in history
] + [{"role": "user", "content": ctx.message}]
reply = await call_openai(messages)
append_history(ctx.session_id, [
HistoryEntry(role="user", content=ctx.message),
HistoryEntry(role="assistant", content=reply),
])
return ProfileResult(response=reply, session_id=ctx.session_id)
create_profile(handler)
History is stored in ~/.ilink-hub/sessions/<session_id>.jsonl (one JSON object per line).
API
create_profile(handler)
Runs the P0 protocol loop: reads env vars → calls handler(ctx) → writes stdout → exits.
ctx (ProfileContext) fields:
| Field | Env var | Description |
|---|---|---|
message |
ILINK_MESSAGE |
User message text |
session_id |
ILINK_SESSION_ID |
Hub-persisted backend session UUID |
session_name |
ILINK_SESSION_NAME |
Human-readable session name |
from_user |
ILINK_FROM_USER |
Sender user ID |
context_token |
ILINK_CONTEXT_TOKEN |
Hub context token |
Return: ProfileResult(response, session_id?) or plain str.
load_history(session_id, session_dir?) → List[HistoryEntry]
Load conversation history from ~/.ilink-hub/sessions/<session_id>.jsonl.
append_history(session_id, entries, session_dir?)
Append [HistoryEntry(role, content, ts?)] entries to the JSONL history file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ilink_bridge_profile-0.1.0.tar.gz.
File metadata
- Download URL: ilink_bridge_profile-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea565b3a41d244448cb247c7eb6dc53374863e7ef04c551766bd1a7e0d6634c7
|
|
| MD5 |
e951a61f8d7bd6b2a74f2a709471d02c
|
|
| BLAKE2b-256 |
b308e38903ec4ee3f91c1f7dfd16a256754daed5281166e450814d80418f10a0
|
File details
Details for the file ilink_bridge_profile-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ilink_bridge_profile-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df20ab24cdaea2e216b332096776ec1269e9644979f8cd09d89b6f41bda4a22a
|
|
| MD5 |
78c241a188dd7df06a3a65a97e90d24e
|
|
| BLAKE2b-256 |
9b2fb2840498059f0d41c2d0ba528ec7a4f59fc312a8d9606c3d7afa93b4f8ce
|