Download the PHP package vielhuber/aihelper without Composer
On this page you can find all versions of the php package vielhuber/aihelper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vielhuber/aihelper
More information about vielhuber/aihelper
Files in vielhuber/aihelper
Package aihelper
Short Description Consistent interface for multiple ai providers.
License MIT
Informations about the package aihelper
🤖 aihelper 🤖
aihelper provides a single, consistent php interface for multiple ai providers. it supports chat and vision use cases, session-aware conversations, robust retry logic, logging, simple cost tracking, and optional model context protocol (mcp) integration — all behind one method.
installation
usage
cli harnesses
the providers claudecode, codex and opencode drive the locally installed cli agent instead of a chat completion endpoint. they own their system prompt, tools and history, so only the newest user turn is handed over. install and log them in once:
by default every turn continues the newest thread of cli_workdir and opens a new one only when that directory has none yet.
set cli_resume_latest: false for an explicitly fresh thread, then persist $ai->getCliSessionId() and pass it as
cli_session_id on later calls to resume that exact native thread. an explicit cli_session_id always takes precedence.
codex keeps injected config and skills isolated per aihelper session while storing its threads in the native
~/.codex state. to include threads originally started by aihelper's non-interactive codex exec, resume from
an interactive terminal with codex resume --last --include-non-interactive.
pass cli_session_home to keep one harness session's native history, configuration and skills in a dedicated
persistent directory. pass cli_auth_home separately to share one authenticated subscription across multiple
session homes without sharing their histories or configuration. both options work for claude code, codex and
opencode and can also be changed before the first request with setCliStorage().
set cli_native_memory: false when the caller supplies its own long-term memory. claude code then disables auto
memory while retaining CLAUDE.md, plugins and skills; codex neither generates nor loads its native memories.
opencode currently has no equivalent automatic semantic memory layer, so the option does not alter its sessions
or instruction files.
set cli_ssh_host to run the agent on another machine instead of locally — the working directory, the login and the threads are then that machine's:
streaming
aihelper can stream model output to a browser using server‑sent events (see). in this mode the php backend connects to the model provider with http streaming and forwards chunks to the client as sse events in real time. see an example implementation at /tests/stream/index.html.
event: reasoning contains native model reasoning and a provider-independent, redacted process transcript for tool, shell, file, search, plan and skill activity. Large details are shortened only in this visible stream; getSessionContent() retains the complete structured tool history. if streaming stutters on apache2 with php‑fpm, be sure that gzip is disabled for the streaming route and also adjust your virtualhost so fastcgi forwards packets immediately (no buffering):
before
after
aborting a request
pass an abort_callback to stop a request that is already running. it is asked between chunks, so keep it cheap — a file check or a flag, never a database round trip. hand it over on create() or later with setAbortCallback(), which also accepts null to clear it again.
with a chat completion endpoint the http stream is cancelled mid-transfer. a cli harness receives SIGINT first so it can close its append-only session file the way ctrl+c would, and is terminated on the local and the remote side only afterwards; the interrupted turn stays in the native thread and is resumed by the next call. check $result['aborted'] to tell a stop apart from a failure — a stopped request has no answer, but nothing went wrong, and it is never retried. a callback that throws counts as
"keep going", so an unreachable cancel signal cannot kill a healthy request.