Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions locales/af.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Geen aktiewe doelwit nie."
config_read_failed: "⚠️ Kon nie config.yaml lees nie: {error}"
config_save_failed: "⚠️ Kon nie konfigurasie stoor nie: {error}"
line_quick_reply:
allow_once: "Eenmalig toelaat"
this_session: "Hierdie sessie"
always_allow: "Altyd toelaat"
deny: "Weier"
cancel: "Kanselleer"

model:
error_prefix: "Fout: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Kein aktives Ziel."
config_read_failed: "⚠️ config.yaml konnte nicht gelesen werden: {error}"
config_save_failed: "⚠️ Konfiguration konnte nicht gespeichert werden: {error}"
line_quick_reply:
allow_once: "Einmal erlauben"
this_session: "Diese Sitzung"
always_allow: "Immer erlauben"
deny: "Ablehnen"
cancel: "Abbrechen"

model:
error_prefix: "Fehler: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ gateway:
no_active_goal: "No active goal."
config_read_failed: "⚠️ Could not read config.yaml: {error}"
config_save_failed: "⚠️ Could not save config: {error}"
line_quick_reply:
allow_once: "Allow Once"
this_session: "This Session"
always_allow: "Always Allow"
deny: "Deny"
cancel: "Cancel"

# /model command output -- shown after a model switch or when listing models.
# Provider names, model IDs, capability strings, and cost figures are NOT
Expand Down
6 changes: 6 additions & 0 deletions locales/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "No hay objetivo activo."
config_read_failed: "⚠️ No se pudo leer config.yaml: {error}"
config_save_failed: "⚠️ No se pudo guardar la configuración: {error}"
line_quick_reply:
allow_once: "Permitir una vez"
this_session: "Esta sesión"
always_allow: "Permitir siempre"
deny: "Denegar"
cancel: "Cancelar"

model:
error_prefix: "Error: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Aucun objectif actif."
config_read_failed: "⚠️ Impossible de lire config.yaml : {error}"
config_save_failed: "⚠️ Impossible de sauvegarder la configuration : {error}"
line_quick_reply:
allow_once: "Autoriser une fois"
this_session: "Cette session"
always_allow: "Toujours autoriser"
deny: "Refuser"
cancel: "Annuler"

model:
error_prefix: "Erreur : {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/ga.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ gateway:
no_active_goal: "Níl aon sprioc ghníomhach ann."
config_read_failed: "⚠️ Níorbh fhéidir config.yaml a léamh: {error}"
config_save_failed: "⚠️ Níorbh fhéidir an chumraíocht a shábháil: {error}"
line_quick_reply:
allow_once: "Ceadaigh uair amháin"
this_session: "An seisiún seo"
always_allow: "Ceadaigh i gcónaí"
deny: "Diúltaigh"
cancel: "Cealaigh"

model:
error_prefix: "Earráid: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/hu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Nincs aktív cél."
config_read_failed: "⚠️ Nem sikerült olvasni a config.yaml fájlt: {error}"
config_save_failed: "⚠️ Nem sikerült menteni a konfigurációt: {error}"
line_quick_reply:
allow_once: "Egyszer engedélyez"
this_session: "Ez a munkamenet"
always_allow: "Mindig engedélyez"
deny: "Elutasít"
cancel: "Mégse"

model:
error_prefix: "Hiba: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Nessun obiettivo attivo."
config_read_failed: "⚠️ Impossibile leggere config.yaml: {error}"
config_save_failed: "⚠️ Impossibile salvare la configurazione: {error}"
line_quick_reply:
allow_once: "Consenti una volta"
this_session: "Questa sessione"
always_allow: "Consenti sempre"
deny: "Nega"
cancel: "Annulla"

model:
error_prefix: "Errore: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "アクティブな目標はありません。"
config_read_failed: "⚠️ config.yaml を読み込めませんでした: {error}"
config_save_failed: "⚠️ 設定を保存できませんでした: {error}"
line_quick_reply:
allow_once: "今回のみ許可"
this_session: "このセッション"
always_allow: "常に許可"
deny: "拒否"
cancel: "キャンセル"

model:
error_prefix: "エラー: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "활성 목표가 없습니다."
config_read_failed: "⚠️ config.yaml을 읽을 수 없습니다: {error}"
config_save_failed: "⚠️ 설정을 저장할 수 없습니다: {error}"
line_quick_reply:
allow_once: "한 번 허용"
this_session: "이 세션"
always_allow: "항상 허용"
deny: "거부"
cancel: "취소"

model:
error_prefix: "오류: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Não há objetivo ativo."
config_read_failed: "⚠️ Não foi possível ler config.yaml: {error}"
config_save_failed: "⚠️ Não foi possível guardar a configuração: {error}"
line_quick_reply:
allow_once: "Permitir uma vez"
this_session: "Esta sessão"
always_allow: "Permitir sempre"
deny: "Negar"
cancel: "Cancelar"

model:
error_prefix: "Erro: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Нет активной цели."
config_read_failed: "⚠️ Не удалось прочитать config.yaml: {error}"
config_save_failed: "⚠️ Не удалось сохранить конфигурацию: {error}"
line_quick_reply:
allow_once: "Разрешить раз"
this_session: "Этот сеанс"
always_allow: "Всегда разрешать"
deny: "Отклонить"
cancel: "Отмена"

model:
error_prefix: "Ошибка: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/tr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Aktif hedef yok."
config_read_failed: "⚠️ config.yaml okunamadı: {error}"
config_save_failed: "⚠️ Yapılandırma kaydedilemedi: {error}"
line_quick_reply:
allow_once: "Bir kez izin ver"
this_session: "Bu oturum"
always_allow: "Her zaman izin ver"
deny: "Reddet"
cancel: "İptal"

model:
error_prefix: "Hata: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "Немає активної цілі."
config_read_failed: "⚠️ Не вдалося прочитати config.yaml: {error}"
config_save_failed: "⚠️ Не вдалося зберегти конфігурацію: {error}"
line_quick_reply:
allow_once: "Дозволити раз"
this_session: "Ця сесія"
always_allow: "Завжди дозволяти"
deny: "Відхилити"
cancel: "Скасувати"

model:
error_prefix: "Помилка: {error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/zh-hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "目前沒有作用中的目標。"
config_read_failed: "⚠️ 無法讀取 config.yaml:{error}"
config_save_failed: "⚠️ 無法儲存設定:{error}"
line_quick_reply:
allow_once: "批准一次"
this_session: "本次工作階段"
always_allow: "永遠批准"
deny: "拒絕"
cancel: "取消"

model:
error_prefix: "錯誤:{error}"
Expand Down
6 changes: 6 additions & 0 deletions locales/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ gateway:
no_active_goal: "当前没有活跃的目标。"
config_read_failed: "⚠️ 无法读取 config.yaml:{error}"
config_save_failed: "⚠️ 无法保存配置:{error}"
line_quick_reply:
allow_once: "批准一次"
this_session: "本次会话"
always_allow: "始终批准"
deny: "拒绝"
cancel: "取消"

model:
error_prefix: "错误:{error}"
Expand Down
126 changes: 126 additions & 0 deletions plugins/platforms/line/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
cache_image_from_bytes,
)
from gateway.config import Platform
from agent.i18n import t


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -581,6 +582,27 @@ def build_postback_button_message(
}


def _attach_quick_reply(
message: Dict[str, Any],
actions: List[Tuple[str, str]],
) -> Dict[str, Any]:
"""Attach LINE quick-reply message actions to an outbound message."""
message["quickReply"] = {
"items": [
{
"type": "action",
"action": {
"type": "message",
"label": label[:20],
"text": text[:300],
},
}
for label, text in actions
]
}
return message


# Prefixes the gateway uses for system busy-acks (interrupting / queued /
# steered). When the postback cache has a PENDING entry we *bypass* the
# cache for these so they reach the user as visible bubbles instead of
Expand Down Expand Up @@ -700,6 +722,13 @@ def __init__(self, config, **kwargs):
os.getenv("LINE_INTERRUPTED_TEXT")
or extra.get("interrupted_text", DEFAULT_INTERRUPTED_TEXT)
)
self.language = (
os.getenv("LINE_LANGUAGE")
or os.getenv("LINE_LOCALE")
or extra.get("language")
or extra.get("locale")
or None
)

# Runtime state
self._client: Optional[_LineClient] = None
Expand Down Expand Up @@ -1086,6 +1115,103 @@ async def send(

return await self._send_text_chunks(chat_id, content, force_push=False)

async def send_slash_confirm(
self,
chat_id: str,
title: str,
message: str,
session_key: str,
confirm_id: str,
metadata: Optional[Dict[str, Any]] = None,
) -> SendResult:
"""Send a LINE quick-reply prompt for slash-command confirmations."""
if not self._client:
return SendResult(success=False, error="LINE adapter not connected")

text = strip_markdown_preserving_urls(message)
if len(text) > LINE_SAFE_BUBBLE_CHARS:
text = text[: LINE_SAFE_BUBBLE_CHARS - 1].rstrip() + "..."

line_message = _attach_quick_reply(
_text_message(text),
[
(self._label("allow_once"), "/approve"),
(self._label("always_allow"), "/always"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/always and /cancel are not registered slash commands on current main, so should_bypass_active_session() returns false. When the session is active, BasePlatformAdapter queues these replies before the runner's slash-confirm interceptor can see them; the Always and Cancel chips need a generic active-session dispatch path or a callback-based flow.

(self._label("cancel"), "/cancel"),
],
)
return await self._send_message_objects(
chat_id,
[line_message],
purpose="slash confirmation quick-reply",
)

async def send_exec_approval(
self,
chat_id: str,
command: str,
session_key: str,
description: str = "dangerous command",
metadata: Optional[Dict[str, Any]] = None,
) -> SendResult:
"""Send a LINE quick-reply approval prompt for dangerous commands."""
if not self._client:
return SendResult(success=False, error="LINE adapter not connected")

cmd_preview = command[:3200] + "..." if len(command) > 3200 else command
text = (
"Command approval required\n\n"
f"{cmd_preview}\n\n"
f"Reason: {description}"
)
text = strip_markdown_preserving_urls(text)
if len(text) > LINE_SAFE_BUBBLE_CHARS:
text = text[: LINE_SAFE_BUBBLE_CHARS - 1].rstrip() + "..."

message = _attach_quick_reply(
_text_message(text),
[
(self._label("allow_once"), "/approve"),
(self._label("this_session"), "/approve session"),
(self._label("always_allow"), "/approve always"),
(self._label("deny"), "/deny"),
],
)
return await self._send_message_objects(
chat_id,
[message],
purpose="approval quick-reply",
)

async def _send_message_objects(
self,
chat_id: str,
messages: List[Dict[str, Any]],
*,
purpose: str,
) -> SendResult:
"""Send pre-built LINE message objects, preferring reply token first."""
if not self._client:
return SendResult(success=False, error="LINE adapter not connected")

token, used_reply = self._consume_reply_token(chat_id)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This direct path does not clear an existing LINE _pending_buttons slow-response cache entry. On current main, the acknowledgement/final response subsequently sent through send() is cached instead of delivered. Handle that state and add coverage with _pending_buttons plus _cache initialized.

if used_reply:
try:
await self._client.reply(token, messages[:LINE_MAX_MESSAGES_PER_CALL])
return SendResult(success=True, message_id=token)
except Exception as exc:
logger.info("LINE: %s reply token rejected (%s); falling back to push", purpose, exc)

try:
await self._client.push(chat_id, messages[:LINE_MAX_MESSAGES_PER_CALL])
return SendResult(success=True, message_id=None)
except Exception as exc:
logger.error("LINE: %s push failed: %s", purpose, exc)
return SendResult(success=False, error=str(exc))

def _label(self, key: str) -> str:
return t(f"gateway.line_quick_reply.{key}", lang=self.language)

async def _send_text_chunks(
self,
chat_id: str,
Expand Down
8 changes: 8 additions & 0 deletions plugins/platforms/line/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ optional_env:
description: "Seconds before the slow-LLM postback button fires (default: 45; set 0 to disable and always Push-fallback)"
prompt: "Slow response threshold (seconds)"
password: false
- name: LINE_LANGUAGE
description: "Locale for LINE quick-reply labels (defaults to display.language; e.g. en, zh, zh-hant, ja)"
prompt: "LINE quick-reply language"
password: false
- name: LINE_LOCALE
description: "Alias for LINE_LANGUAGE for deployments that use locale terminology"
prompt: "LINE quick-reply locale"
password: false
Loading