MobileApp
🚃 TrainLCD is a mobile application that simulates Japanese railway company LCDs, providing real-time navigation and station information for train passengers.
- 77
- TypeScript
- MIT
- 5 h ago
👷 Cloudflare Workers for the TrainLCD mobile app.
Repo TrainLCD/Functions, read from GitHub 1 min ago. TrainLCD has not joined Take My Repo.
TrainLCD/Functions is a public repo on GitHub by TrainLCD. 👷 Cloudflare Workers for the TrainLCD mobile app. It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It is written mainly in TypeScript, has 0 stars and last changed on 2026-11-22. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-22.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
The Cloudflare Worker that powers the TrainLCD backend. It replaces the former Firebase Cloud Functions, consolidating the HTTP, queue, and Cron handlers into a single Worker.
POST /tts): synthesizes plain text into audio via ElevenLabs Eleven v4 and caches it in KV/R2.POST /auth/token): issues a short-lived session JWT from an install ID (the replacement for Firebase anonymous auth).POST /postFeedback): enqueues feedback onto the triage queue.POST /feedback/upload-image): stores feedback images in R2 and returns a public URL.GET /config/maintenance, GET /config/remote): maintenance status and GPS thresholds (the replacement for Remote Config).feedback-triage): summarizes and classifies feedback with Workers AI, then creates a GitHub Issue and notifies Discord. Actionable feedback whose root-cause component the AI identifies confidently also gets a linked stub Issue in the matching public repo (see public repo routing for the exact conditions)./tts handler to R2 + KV (no queue is used, because audio does not fit within the 128 KB Queues limit).fetch / queue / scheduled handlersfeedback-triage (+ feedback-triage-dlq as its dead letter queue)AGENT_MODEL varnpm install)cd functions
npm installReplace the id / bucket_name placeholders in wrangler.jsonc with the real
values issued by the commands below (for both dev and prod).
# KV wrangler kv namespace create TTS_KV wrangler kv namespace create CONFIG_KV wrangler kv namespace create STATE_KV # R2 wrangler r2 bucket create trainlcd-tts-dev wrangler r2 bucket create trainlcd-uploads-dev # Queues wrangler queues create feedback-triage-dev wrangler queues create feedback-triage-dev-dlq # dead letter queue (no consumer)
The names above are the dev ones. Production uses the same set without the
-dev suffix (trainlcd-tts, trainlcd-uploads, feedback-triage,
feedback-triage-dlq); create those too if you are setting up prod from
scratch. Both environments' resources already exist on the TrainLCD account.
wrangler secret put SESSION_JWT_SECRET # signing key for session JWTs (any long random string) wrangler secret put GOOGLE_PLAY_SA_KEY # Android Publisher SA key JSON (single-line string) wrangler secret put OPENAI_API_KEY # the conversational agent wrangler secret put ELEVENLABS_API_KEY # ElevenLabs API key (for POST /tts) wrangler secret put GOOGLE_VERTEX_SA_KEY # Vertex AI SA key JSON; only when AGENT_MODEL is "google:<model>" wrangler secret put OCTOKIT_PAT wrangler secret put DISCORD_CS_WEBHOOK_URL wrangler secret put DISCORD_CRASH_WEBHOOK_URL wrangler secret put DISCORD_REVIEW_WEBHOOK_URL
For local development, put the same keys in .dev.vars (gitignored).
You can also bulk-load secrets with the helper scripts: copy
.secrets.env.example to .secrets.env, fill in the values, then run
./scripts/put-secrets.sh (or ./scripts/put-secrets.ps1 on Windows).
See vars in wrangler.jsonc. Configure the Japanese TTS voice ID,
AI model name, package name, and public upload URL per environment.
English uses Imogen in every environment. TTS authenticates directly with
ElevenLabs using ELEVENLABS_API_KEY and does not use Cloudflare AI Gateway.
Deploys run from GitHub Actions. The target is fixed by the workflow file and its trigger rather than chosen by an expression, so no branch can point at an environment it was not meant to reach:
| Workflow | Trigger | Result |
|---|---|---|
.github/workflows/ci.yml |
PRs, and pushes to other branches | Verify only, no deploy |
.github/workflows/deploy_dev.yml |
push to dev |
Deploy trainlcd-worker-dev |
.github/workflows/deploy_production.yml |
push to master |
Deploy trainlcd-worker |
All three run the same .github/actions/verify composite action first — npm ci, lint, typecheck, tests, and a wrangler deploy --dry-run of both the
dev and the production config. The dry run bundles the Worker for real, so
import mistakes and missing nodejs_compat APIs fail there rather than at
deploy time, and building the production config on every run catches an
env.production that only breaks after the merge to master. npm ci installs
wrangler from package-lock.json, so the version that deploys is the version
the lockfile pins — there is no second place to bump.
Each deploy workflow needs two secrets on its GitHub environment (dev and
production respectively):
CLOUDFLARE_API_TOKEN — the Edit Cloudflare Workers template plus
Queues: Edit, since wrangler deploy also applies the queue consumer
settings from wrangler.jsonc.CLOUDFLARE_ACCOUNT_ID — wrangler.jsonc carries no account_id.Keeping them on the environment rather than on the repository is what stops an
arbitrary branch from reading the production token: ci.yml deliberately
declares no environment, and it needs no credentials because --dry-run never
calls the Cloudflare API.
Worker secrets (SESSION_JWT_SECRET, OCTOKIT_PAT, …) are not touched by
the workflows. wrangler deploy preserves the secrets already on a Worker, so
they stay a manual scripts/put-secrets.sh step — see Setting
secrets.
POST /tts and POST /postFeedback keep the Firebase callable-compatible wire
format.
{ "data": { ... } } with Authorization: Bearer <session JWT>{ "result": { ... } }{ "error": { "message", "status" } }A session JWT is obtained from POST /auth/token (body { "installId": "<uuid>" }).
POST /ttsSynthesis uses Eleven v4. The client sends plain text; stray SSML tags are
stripped. English is fixed to Imogen (female); Japanese uses KV jaVoiceId
then TTS_JA_VOICE_ID. Client voice overrides are ignored.
{
"data": {
"textJa": "次は、オオサキです",
"textEn": "The next station is Osaki, J-Y 24."
}
}At least one language must contain nonempty text. Only requested languages
are synthesized, cached, and returned. Eleven v4 does not support speed:
changing the app's announcement speed does not affect generated speech.
Legacy speed, TTS_SPEED, and pitch settings are ignored; speed differences
do not create separate cache entries. The callable response format is unchanged.
The response carries only the requested languages:
{
"result": {
"id": "<sha256 of the request, used as the cache key>",
"jaAudioContent": "<base64>",
"jaAudioMimeType": "audio/mpeg",
"enAudioContent": "<base64>",
"enAudioMimeType": "audio/mpeg"
}
}Unit tests cover pure functions (TTS request building, voice/model resolution,
text validation, cache writes, triage JSON normalization, review parsing) with
Jest. Runtime integration for HTTP /
queue / Cron is verified with wrangler dev / wrangler dev --test-scheduled.
Feedback triage reads config:fewshot (FEW_SHOT_KV_KEY) from CONFIG_KV.
The few-shot data is unrelated to TTS, so it lives in the config KV (the same
namespace as config:maintenance / config:remote). The format is JSONL, one
example per line (see fewshot.example.jsonl):
{"input": "user body text", "output": "{\"title\":...,\"isSpam\":false,...}"}The output of each example must include component / componentConfidence
as well; the model imitates the examples, so examples without those fields make
it omit them and public repo routing never fires.
Optional per-example fields: weight (a value above 1 makes the example more
likely to survive sampling) and disabled: true (skips the line). Only
FEW_SHOT_LIMIT examples are sampled per request, so a component or category
with a single example — praise, functions, website — must carry a
weight, otherwise it drops out of the prompt and the model never produces it.
Upload (the file is stored verbatim as a single KV value):
# dev (wrangler v4 defaults to the local emulator; --remote targets the real KV) wrangler kv key put --binding CONFIG_KV "config:fewshot" --path fewshot.jsonl --remote # prod wrangler kv key put --binding CONFIG_KV "config:fewshot" --path fewshot.jsonl --env production --remote
If it is not present, triage fails hard with FEW_SHOT_NOT_AVAILABLE (a
fail-hard guard that prevents mis-training).
Two guards keep bad triage output from degrading the backlog
(src/consumers/feedbackTriage.ts):
category: "praise"
(💚 Praise, P3) instead of 💩 Spam — there is nothing to fix, but it is
still a real message from a real user. Spam means content unrelated to
improving the app: announcement transcripts, unrelated chit-chat, ads.looksLikeSpam() only
scores announcement-transcript signals when an actual announcement phrase is
present — "停車駅" / "方面" / station enumerations are core domain vocabulary
and appear in legitimate data reports. When the heuristic and the model
disagree and the model is confident (confidence ≥
SPAM_OVERRIDE_MAX_CONFIDENCE), the model wins and the Issue is tagged
❓ Unknown Type for a human check instead of being buried as spam.findBrokenTitleReason() rejects
titles that are missing, mojibake, foreign-script, looping, or a run of
particles. Those are filed with the 要約失敗 marker plus ❓ Unknown Type,
and a console.warn records the reason so the corruption rate can be measured
with wrangler tail. A broken title is never propagated into the summary.AI_TRIAGE_MODEL therefore needs decent Japanese generation quality — it writes
the Issue title and summary. Before switching it, verify three things against the
real prompt (wrangler dev with the AI binding hits the live API even locally):
wrangler ai models schema <model> must
list response_format / json_schema.response, others only
choices[0].message.content. pickModelResponse() accepts both; a model
returning neither would fail every message.max_tokens headroom — reasoning models spend most of the budget on the
trace before the JSON. Watch for finish_reason: "length", which truncates
the JSON and looks like a parse failure.Measured with the real prompt + few-shot (2026-08): @cf/google/gemma-4-26b-a4b-it
completes in 5–17 s at 26–62 neurons per feedback, versus ~1 s and ~4.7 neurons
for the old 8B model. Queue consumers use max_batch_size: 5, so a batch stays
well inside the invocation limit.
POST /postFeedback では、キューへの投函前に OCTOKIT_PAT で
TrainLCD/Issues のリポジトリ情報を取得します。PAT 未設定・失効、GitHub の
HTTP エラー、5 秒のタイムアウト、Issues 無効時には、HTTP 503 と
{ "error": { "status": "unavailable", "message": "Feedback service is temporarily unavailable. Please try again later." } }
を返します。失敗した投稿はキューへ投函しません。
アプリの useFeedback は HTTP エラーを送信失敗として扱い、フィードバック画面で
エラーダイアログを表示します。成功応答はキューへの受付完了を示します。
受付後の PAT 失効や Issue 作成時の検証エラーまで同期的に保証するものではありません。
GitHub の Issue 作成失敗は、キューのログに HTTP ステータス、リクエストID、
検証エラーの項目を残します。レート制限時は Retry-After と
x-ratelimit-reset に従って再試行を遅らせます。
processFeedbackMessage() rethrows on failure so the consumer can retry(),
but retrying does not help when the cause is permanent — a credential that no
longer grants access, a repo that was renamed. Without a dead letter queue the
message is simply dropped once max_retries: 3 is exhausted, and the feedback
is lost for good.
The consumers therefore declare dead_letter_queue (feedback-triage-dlq, and
feedback-triage-dev-dlq for dev). The DLQ intentionally has no consumer —
running the same handler against it would fail for the same reason.
Do not look for the wiring on the DLQ itself. Moving a message into a DLQ is
something Cloudflare does internally, not something the Worker sends, so a
correctly configured DLQ still reports zero producers and zero consumers in
wrangler queues list. The link lives on the source queue's consumer, and it
only exists once the config has been deployed:
wrangler queues consumer list feedback-triage-dev # or feedback-triage for prod # dead_letter_queue must name the DLQ; "-" means this environment is still # dropping messages once max_retries is exhausted.
A DLQ is not archival storage. Messages sitting in it expire on the queue's retention period, which both DLQs inherit from the account default (4 days on a paid plan, and not extendable beyond 24 h on the free plan). That is the replay deadline: once it passes the feedback is gone just as surely as it was before this queue existed. Check and extend it if an incident may outlast it:
# 1209600 = 14 days, the paid-plan maximum. The free tier is capped at 86400 # (24 h) and rejects anything above it, so use that value instead on free. # Run this for the dev DLQ too — retention is per queue, and # feedback-triage-dev-dlq inherits nothing from the prod one. RETENTION=1209600 for q in feedback-triage-dlq feedback-triage-dev-dlq; do wrangler queues update "$q" --message-retention-period-secs "$RETENTION" done
wrangler queues info does not print the retention period (as of wrangler 4.103),
so there is no CLI read-back for it — set it explicitly, or check the dashboard.
To recover, fix the root cause first, then replay by temporarily attaching a
consumer to the DLQ. Give that consumer its own dead letter queue — a replay
consumer runs the same handler, so anything still failing would hit max_retries
and be deleted outright, which is the exact loss this section exists to prevent.
# production. For dev: DLQ=feedback-triage-dev-dlq, SCRIPT=trainlcd-worker-dev DLQ=feedback-triage-dlq SCRIPT=trainlcd-worker RETENTION=1209600 # 86400 on the free tier, as above wrangler queues info "$DLQ" # backlog size, current consumers # Catches whatever still fails on replay. Give it the same retention as the DLQ, # otherwise it silently falls back to the account default. wrangler queues create "$DLQ-quarantine" --message-retention-period-secs "$RETENTION" # --batch-size 5 matches the max_batch_size the regular consumer runs with; the # default of 10 is a lot for one invocation at 5–17 s of inference per message. wrangler queues consumer add "$DLQ" "$SCRIPT" \ --dead-letter-queue "$DLQ-quarantine" --batch-size 5 # ...wait for the backlog to drain, then detach: wrangler queues consumer remove "$DLQ" "$SCRIPT"
The replay consumer is deliberately not declared in wrangler.jsonc — it exists
only for the duration of an incident, so nothing will remove it for you. Leaving
it attached means every later failure gets reprocessed by it instead of landing
in the DLQ where you can see it.
$DLQ-quarantine outlives the incident as well. queues create fails if it
already exists, so on the next incident either reuse it (confirm it is empty
first — anything left in it is unprocessed feedback) or wrangler queues delete
it once you have dealt with whatever landed there.
Note that DLQ messages carry the full feedback payload, so the DLQ is subject to
the same handling rules as the private TrainLCD/Issues repo.
A retry re-runs processFeedbackMessage() from the top, so anything that throws
after the Issue has been created files the same feedback again — up to four
Issues with max_retries: 3, plus one more for every DLQ replay.
To prevent that, the consumer keeps a per-report marker in STATE_KV under
feedbackTriage:processed:<report.id> (30-day TTL, long enough to cover a DLQ
replay). It records the created Issue number and URL, the public stub URL, the
triage result, and whether the Discord notification went out. The marker decides
what each delivery still has to do:
Nothing between the Issue being created and the marker being written may throw,
because a throw there is a retry with no marker to stop it. So a malformed
Issue-creation response and a failed marker write are logged and swallowed, and
notifyDiscord() turns every failure into a return value instead of an
exception — including fetch() itself rejecting on a network or DNS error,
which is what made this reachable in practice.
Past that point a throw is safe, and one is deliberate. The marker records
whether Discord actually accepted the request, so a failed notification is saved
as notified: false and then rethrown as FeedbackNotifyError, which retries
the message: the retry reads the marker, skips straight to the notification, and
leaves the Issue alone. Retrying the handler for a Discord outage is exactly
what used to duplicate Issues — the marker is what makes it safe now. A
notification that never succeeds ends up in the DLQ after max_retries, which
is how a broken webhook becomes visible.
The one case that is not retried is a notification failure where the marker write also failed. Without the marker a retry would file the Issue again, so the notification is given up and the message acked — the feedback is on GitHub either way.
KV is not a lock, and the marker read is what makes this work — so the retry
has to be slow enough for the read to see it. KV caches the absence of a key
at the edge for the read's cacheTtl (60 s by default), so a retry that runs
immediately after the failure can miss a marker that was written seconds ago and
file the Issue again. The consumer therefore retries with
message.retry({ delaySeconds: FEEDBACK_RETRY_DELAY_SECONDS }) (90 s) so the
negative cache has expired by the time the marker is read. Changing that
constant without understanding this is how the duplicate comes back.
The same limit applies to the writes: KV accepts at most one write per second to a given key, and one report writes that key twice — once when the Issue exists, once when the notification result is known. A notification that completes in under a second would make the second write a 429, so the consumer spaces writes to the same key ~1.1 s apart (and waits that long before its one write retry) rather than losing the notification state and re-notifying on a replay.
That covers the sequential retries of one message. It does not serialize two deliveries of the same report racing each other — Cloudflare Queues is at-least-once, so that race is possible in principle, and with an eventually consistent read there is nothing to make it safe. Strict de-duplication would take a per-report claim in a Durable Object (the only strongly consistent option here), which is a bigger change than the failure it covers.
One gap stays open by design: if the Issue-creation fetch() fails after
GitHub has already created the Issue, no marker was written and the retry files
a second one. Closing that would mean searching TrainLCD/Issues by ticket ID
before every creation, which costs a request per feedback for a case that needs
GitHub to drop the response of a request it accepted.
Feedback Issues are always created in the private TrainLCD/Issues repo with
the full report (original text, device info, reporter UID, stacktrace, image).
On top of that, the worker opens a stub Issue in the matching public repo — but
only when every condition in resolvePublicIssueRepo() holds:
reportType is feedback (crash reports are never routed — their stacktraces
are not vetted for public disclosure),triageFailed === false) and the report is not spam,needsSpamReview !== true),category is one of PUBLIC_ISSUE_CATEGORIES — bug, improvement,
feature_request (so question and praise are excluded), andcomponent ≠ unknown with componentConfidence ≥
PUBLIC_ISSUE_MIN_CONFIDENCE (0.7).The component then selects the repo:
component |
repo |
|---|---|
mobile_app |
TrainLCD/MobileApp |
station_api |
TrainLCD/StationAPI |
functions |
TrainLCD/Functions |
website |
TrainLCD/Website |
Because those repos are public, the stub carries no feedback content at all —
no original text, no AI summary or title, no device info. It only links back to
the private ticket (TrainLCD/Issues#<number> and the ticket ID), and the
private Issue gets a comment pointing at the public one so both sides are
traceable.
Public handoff uses the optional Worker secret HANDOFF_ISSUE_TOKEN, falling
back to OCTOKIT_PAT when it is empty or unset. The selected token needs
Issues: Read and write on all four destination repos. OCTOKIT_PAT still
needs access to TrainLCD/Issues for the private ticket and result comments.
GitHub Actions secrets are not automatically available to the Worker; install
the token separately for each environment, for example:
npx wrangler secret put HANDOFF_ISSUE_TOKEN --env production
A failed handoff no longer counts as completed just because Discord succeeded. Explicit rejections (401/403/404/422/429) are retried from the saved marker, without recreating the private ticket, rerunning triage, or resending a successful Discord notification. Before retrying a public Issue, the consumer lists open and closed Issues, follows GitHub’s next-page links to the end, and matches the management Issue title and ticket ID. A failed or incomplete lookup stops the attempt rather than creating another Issue. An unchanged failure does not create another trace comment. After the queue retry limit, the message remains in the DLQ for recovery after fixing the token. Network errors, 5xx, and malformed success responses may mean an Issue was already created, so these remain failed for manual reconciliation without automatically posting another Issue.
Existing failed markers can also resume when their original message is replayed within the 30-day marker TTL. Previously acknowledged messages are not restored to the queue automatically. Manually created stubs with the same title and ticket ID are also reused during reconciliation. The private Issue and pending handoff are saved before public creation; if this initial save fails, public creation is stopped, but the result comment and Discord notification are still attempted. If a later save recovers, the pending handoff resumes on retry. If a public Issue succeeds but its result cannot be saved, the message is retried and the existing public Issue is reconciled. An earlier successful marker save remains valid even if the final save fails, so a failed handoff still reaches retry/DLQ.
Maintenance tools that operate on KV (TTS_KV) and R2 (the audio bucket). Both
commands work entirely through wrangler (the bindings in wrangler.jsonc plus
your logged-in account), so no environment variables are required — just run
wrangler login first. Pass --env production to target production (it selects
the KV namespace and R2 bucket from wrangler.jsonc).
find-tts-cacheSearches the TTS cache by spoken text and optionally deletes the matching KV
document and R2 audio. KV is read via wrangler kv key list / wrangler kv bulk get and deleted via wrangler kv key delete; R2 audio is removed via wrangler r2 object delete.
npm run find-tts-cache -- "東京" --field textJa npm run find-tts-cache -- "東京" --delete npm run find-tts-cache -- "東京" --env production --delete
find-orphaned-ttsDetects audio that exists in R2 but has no KV metadata (and optionally deletes
it). wrangler has no R2 object-listing command, so this command spins up a
short-lived maintenance Worker (src/cli/maintenance-worker.ts) via wrangler dev --remote and enumerates/deletes R2 through its binding
(env.TTS_BUCKET.list() / .delete()). No S3 credentials are needed.
# dev (default) npm run find-orphaned-tts npm run find-orphaned-tts -- --delete # production npm run find-orphaned-tts -- --env production --delete
日本語のキャッシュ未命中時は、車掌タグを付けて合成した音声を既存の Workers AI binding の Whisper large-v3-turbo で文字起こしします。原稿にない「通勤電車」などのタグ由来の語を冒頭に検出した場合は、同じボイス・タグで一度だけ再生成・再検査します。再度検出した場合や検査に失敗した場合はエラーを返し、その音声は保存しません。通常の日本語キャッシュミスにつき文字起こしが1回、再生成時は計2回発生します。
英語音声は Imogen
(女性)に固定し、女性の通勤電車の車掌を指定するタグを付けます。
英語の旧 KV enVoiceId・環境変数 TTS_EN_VOICE_ID・リクエストの音声指定は使用しません。
日本語は KV jaVoiceId、環境変数 TTS_JA_VOICE_ID の順で選択します。
Eleven v4 は速度設定に対応していません。
アプリで読み上げ速度を変更しても、サーバーで生成する音声には反映されません。
互換性のためリクエストの speed は受け取りますが、TTS_SPEED とともに合成には使用せず、
速度だけが異なる要求は同じキャッシュを使用します。
dictionaries/trainlcd-stations-en.pls を ElevenLabs に一度登録し、返された
id と version_id を Worker の環境変数 TTS_EN_DICTIONARY_ID と
TTS_EN_DICTIONARY_VERSION_ID にそれぞれ設定する。開発・本番で個別に設定できる。
curl --fail-with-body https://api.elevenlabs.io/v1/pronunciation-dictionaries/add-from-file \ -H "xi-api-key: $ELEVENLABS_API_KEY" \ -F 'name=TrainLCD English Station Names' \ -F 'file=@dictionaries/trainlcd-stations-en.pls'
両方を省略すると従来どおり辞書なしで合成する。辞書を更新したら版IDも更新する。 英語を含む要求は新しいキャッシュに切り替わる。
TrainLCD/Functions is a public repo on GitHub by TrainLCD. 👷 Cloudflare Workers for the TrainLCD mobile app.
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker tagged it for Windows. That is declared by the maker; Take My Repo has not tested it.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-22. GitHub counts 3 open issues and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
🚃 TrainLCD is a mobile application that simulates Japanese railway company LCDs, providing real-time navigation and station information for train passengers.
🤖 The GraphQL API for nearby Japanese train stations and bus stops, powered by Rust and Cloudflare Workers.
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/TrainLCD/FunctionsTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.