Commit Graph
1863 Commits
Author SHA1 Message Date
Zezae Oh 968745bd16 feat(providers): enable Codex prompt cache controls (#1310) 2026-06-30 18:25:28 +07:00
Zezae Oh b8726ff4f4 fix(providers): parse Codex cached token usage (#1309) 2026-06-30 16:53:46 +07:00
8963ec3177 fix(ollama): always send num_ctx to prevent context-window errors (#1307)
* feat(ollama): auto-detect context window, allow user override

Query Ollama API (/api/show) to fetch model's actual context_length
on provider startup/hot-registration. Use queried value by default,
but allow user to override via num_ctx field in provider settings.

- backend: query API, store in provider config, use in requests
- frontend: add num_ctx input field to Ollama provider dialog (4 langs)
- fallback: 131072 tokens (128K) if API unreachable

Fixes context-window errors when using large-context models.

* fix(ollama): route to /api/chat endpoint to honor num_ctx

Ollama's /v1/chat/completions (OpenAI-compat shim) ignores options.num_ctx.
Route to /api/chat (native endpoint) which respects num_ctx.

Request body is identical, only endpoint URL changes:
- Before: /v1/chat/completions (ignores options.num_ctx)
- After: /api/chat (honors options.num_ctx)

Fixes context-window errors when using models with large context windows.

* refactor(providers): replace OpenAI-wrapped Ollama with native SDK

Implement dedicated OllamaProvider using github.com/ollama/ollama/api
official client library. Replaces the broken approach of wrapping
Ollama behind OpenAI-compatible parsing.

Benefits:
- Proper response parsing (Ollama native format, not OpenAI)
- Automatic /v1 suffix stripping
- Built-in num_ctx support (injected into every request)
- Tool call support via Ollama's native ToolCall schema
- Token usage mapping from Ollama Metrics
- Clean streaming implementation

Fixes context-window errors by using Ollama native API directly.
Removes dependency on OpenAI response format hacks.

- new: internal/providers/ollama.go (OllamaProvider)
- updated: cmd/gateway_providers.go, internal/http/providers.go
- updated: go.mod (added github.com/ollama/ollama)

* fix(ollama): fetch num_ctx for config-registered providers

Config-file-registered Ollama providers (cfg.Providers.Ollama.Host)
were hardcoding numCtx=nil, so num_ctx was never sent to Ollama.

Add FetchOllamaModelContext call for config providers, same as
DB-registered providers. Now config Ollama providers also auto-detect
and send the model's context window to the Ollama API.

Fixes context-window errors when using config-registered Ollama.

* fix(ollama): always send num_ctx to prevent context window errors

OllamaProvider.buildRequest only injected options.num_ctx when an
explicit override was configured. When resolveOllamaNumCtx saw that
/api/show returned the OllamaDefaultNumCtx value (131072), it returned
nil, causing the provider to omit num_ctx entirely. Ollama then fell
back to the model's baked-in default (4096 tokens), causing requests
with long system prompts to fail with "request exceeds context size".

Fix both layers:
- resolveOllamaNumCtx now always returns &numCtx instead of nil when
  /api/show returns the default, so the explicit value is always passed.
- OllamaProvider.buildRequest falls back to OllamaDefaultNumCtx (131072)
  when p.numCtx is nil, ensuring every request carries a large context
  window even if the startup query was skipped.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-30 02:56:45 +07:00
Clark Cant c8d292c691 Merge pull request #1306 from aaron-tsar/fix/telegram-instance-per-topic-config
fix(telegram): honor per-group/topic overrides for DB instances
2026-06-29 23:54:41 +07:00
Aaron Vu a62980bf7c fix(telegram): honor per-group/topic overrides for DB instances
The dashboard persists per-group/per-topic overrides (enabled,
require_mention, skills, tools, system_prompt, ...) into the channel
instance config, but telegramInstanceConfig had no groups field, so the
payload was dropped on unmarshal. config.TelegramConfig.Groups stayed
nil, resolveTopicConfig fell back to global defaults, and the bot
replied in every forum topic regardless of the configured per-topic
gating.

Map the groups field through the DB-instance factory so per-topic
config takes effect for dashboard-created channels, matching the static
file-config path.
2026-06-29 23:23:02 +07:00
Clark Cant 09610e4bfe Merge pull request #1305 from bclermont/fix/mcp-settings
fix(mcp): Update button silently doing nothing due to hidden Zod vali…
2026-06-29 21:54:50 +07:00
Bruno ClermontandClaude Sonnet 4.6 cccb9691f9 fix(mcp): Update button silently doing nothing due to hidden Zod validation errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-29 10:27:07 -04:00
978a0f255e Fix/skill violation display (#1304)
* feat(skills): display structured security violations in upload error

When skill upload fails due to security violations, show each violation
as a clear list with line number and reason in the error display.

Changes:
- Add ApiError.getViolations() method to extract violations from response
- Update HTTP upload client to capture violations in error details
- Add violations field to SkillEntry type
- Display violations as bulleted list in SkillSubtitle when present
- Add i18n keys for security violations display (en, vi, zh, ko)

New UI behavior: Instead of a generic "Upload failed" message, users
now see structured violation details:
  Security violations:
  - Line 5: SQL DROP TABLE
  - Line 12: curl pipe to shell

Backward compatible - falls back to generic error message if violations
array is absent from response.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(skills): return structured JSON violations array in upload error response

Replace flat string formatting with a structured violations array (line, reason)
so clients can display per-line security rule details instead of a generic error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-29 20:54:30 +07:00
nguyenha935andGoClaw Operator 969a5879ae fix: unify no reply detection on dev (#1303)
Co-authored-by: GoClaw Operator <operator@goclaw>
2026-06-29 11:25:13 +07:00
SYNITYandDangTinh311 23a4b7407c fix(bitrix24): OpenLine greeting and MCP provisioning (#1284)
* fix(bitrix24): skip join greeting in open channels [B24:2794]

* wip: rework bitrix24 mcp provisioning + skills prompt section (tam thoi, se lam lai) [B24:2794]

---------

Co-authored-by: DangTinh311 <dangtinh31193@gmail.com>
2026-06-29 08:54:00 +07:00
Bruno ClermontandBruno Clermont 0184678dc3 fix(tts): validate voice compatibility with selected provider before synthesis (#1302)
An agent's tts_voice_id (e.g. "en-US-GuyNeural" for Edge) was applied
regardless of the selected TTS provider, causing OpenAI and other
providers to reject unknown voice IDs.

- Add internal/audio/voice_compat.go with IsVoiceCompatible,
  GetProviderDefaultVoice, and FilterVoiceForProvider helpers
- Update TtsTool.resolveVoiceAndModel to report whether the voice
  came from an agent override (voiceFromAgent)
- Apply applyVoiceCompat per-provider branch in Execute so
  incompatible agent voices fall back to the provider's default
  with a slog.Warn for operator visibility
- Add voice_compat_test.go with table-driven tests for all cases

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
2026-06-29 06:54:45 +07:00
nguyenha935andGoClaw Operator 22efff8c0d fix: filter streamed thinking tags (#1300)
Co-authored-by: GoClaw Operator <operator@goclaw>
2026-06-29 03:54:20 +07:00
Clark Cant 85b17f698f Merge pull request #1301 from bclermont/fix/db-usage-snapshots-agent-fk
fix(db): add FK constraint on usage_snapshots.agent_id [#1244]
2026-06-29 03:26:09 +07:00
Duc Nguyenandntduc 79822410e8 fix(web): preserve mcp args and instance labels (#1299)
Co-authored-by: ntduc <ntduc@cpp.ai.vn>
2026-06-29 02:54:49 +07:00
admin adde5c6bc9 fix(db): add FK constraint on usage_snapshots.agent_id [#1244] 2026-06-28 15:05:37 -04:00
nguyenha935andGoClaw Operator 64596bf0c1 fix: preflight compact v3 context before model calls (#1297)
Run pruning before ThinkStage so oversized histories compact before the provider request is built.

Persist V3 last_prompt_tokens with the post-flush persisted message count so post-run compaction calibration has current usage data.

Tests: go test ./internal/pipeline -run "TestNewDefaultPipeline_PrunesBeforeThink|TestFinalizeStage_UpdateMetadataReceivesPersistedMessageCount" -count=1; go test ./internal/agent -run "^$" -count=1

Co-authored-by: GoClaw Operator <operator@goclaw>
2026-06-29 01:24:51 +07:00
SYNITYandDangTinh311 4675aa3fd4 fix(bitrix24): skip native-group mention gate for Open Channel sessions [B24:2794] (#1296)
Follow-up to #1295. After scoping the Open Channel mention gate by
connector, customer messages on 1-to-1 connectors (Facebook Messenger,
Zalo OA, …) were STILL being silently dropped — by the second
mention-gate stanza further down in handleMessage, which checks the
channel-level c.RequireMention() flag without distinguishing Open
Channel traffic from native group chats (CRM deal/task chats).

For a channel like nguyen-dao-openline configured with RequireMention=true,
the flow was:

  1. isOpenChannel block → shouldRequireMentionForOpenline("facebook|...")
     returns false (facebook isn't in the whitelist) → no drop.
  2. isGroup block (isOpenChannel implies isGroup) → c.RequireMention()=true
     AND mentioned=false → DROP.

Net effect: the gate-by-connector decision was overridden one stanza
later, and every Facebook customer turn disappeared.

Fix: scope the drop check inside the isGroup block to native-group chats
only (!isOpenChannel). Open Channel sessions already own their mention
policy in the earlier isOpenChannel block; re-applying the channel-level
RequireMention flag here second-guesses that decision.

Importantly, the text-processing that follows the drop check
(MessageOriginal fallback, stripMention, bxConvertUserMentionsToReadable)
stays unconditional, so an Open Channel STAFF turn that does come in with
"[USER=<botID>]Bot[/USER]" BBCode still gets cleaned up the same way it
always did. The only thing the new guard suppresses is the drop itself.

Verified live: Facebook Messenger customer turn (IS_CONNECTOR=Y,
CHAT_ENTITY_ID=facebook|34|…) now reaches the agent loop and the bot
replies, matching the intent from #1295.

Surface parity: backend-only. No API contract / web UI / CLI change.

Co-authored-by: DangTinh311 <dangtinh31193@gmail.com>
2026-06-28 13:54:19 +07:00
SYNITYandDangTinh311 164ea2ea4a feat(bitrix24): scope Open Channel mention gate to group-style connectors only [B24:2794] (#1295)
Before: every Open Channel message required a bot @mention before the agent
picked it up — including external-customer turns on 1-to-1 connectors
(Facebook Messenger, Zalo OA, …) where the customer has no syntactic way
to produce a mention. The gate, designed for group-style connectors
(Zalo personal pools multiple customers into one Open Channel chat),
was silently dropping every legitimate customer message on every other
connector.

This change scopes the gate by connector:

- Internal staff (IS_CONNECTOR=N) — STILL gate. Operators can @-mention
  and we don't want the bot jumping into operator-to-operator chatter
  in the same session.

- External customer (IS_CONNECTOR=Y) on a whitelisted connector
  (default: synity_zalo_personal) — STILL gate. Multiple customers
  share the chat, so untagged turns would otherwise spam them.

- External customer on any other connector (Facebook, Zalo OA, the long
  tail of 1-to-1 connectors, legacy payloads without CHAT_ENTITY_ID) —
  do NOT gate. Every message is addressed to the bot by construction.

The whitelist is overridable via BITRIX24_REQUIRE_MENTION_CONNECTORS
(comma-separated connector codes — the leading token of CHAT_ENTITY_ID).
Default keeps synity_zalo_personal gated so a fresh deployment is safe.
Adding a future group-style connector (e.g. a Zalo group flavour) is an
env edit + restart, not a code change.

- mention_gate.go (new):
    connectorCodeFromEntityID() parses "synity_zalo_personal|20|grp|960"
        into "synity_zalo_personal".
    requireMentionConnectorSet() reads the env once (sync.Once cache)
        and falls back to the hardcoded default {synity_zalo_personal}.
    shouldRequireMentionForOpenline() is the policy matrix.
- mention_gate_test.go (new): pins the parser, the env-override path,
    and every row of the policy matrix.
- handle.go: replaces the unconditional Open Channel mention gate with
    a call to shouldRequireMentionForOpenline(). Adds chat_entity_id to
    the drop log so operators can see which connector tripped the gate.
- handle_test.go:
    Update existing "ConnectorWithoutMentionDropped" test to set
    ChatEntityID to the whitelisted connector — that's what the gate now
    keys on.
    Add new "OneToOneConnectorWithoutMentionForwarded" test pinning the
    new behavior: facebook (not whitelisted) forwards every customer
    message without a mention.

Surface parity: backend-only. No API contract / web UI / CLI change.
The env var follows the same operational model as the other BITRIX24_*
vars in docker-compose.yml; documenting it there is a no-op until the
default needs overriding.

Co-authored-by: DangTinh311 <dangtinh31193@gmail.com>
2026-06-28 11:54:57 +07:00
SYNITYandDangTinh311 abe80de946 feat(bitrix24): inject <media:*> tags into user message so the LLM sees attachments [B24:2794] (#1294)
Without these tags the Bitrix-borne PDF / audio / image arrive as bare text
to the agent loop: the LLM never realizes an attachment exists and degrades
to "no file attached" replies (or worse, hallucinates a CRM document id and
fires crm.documentgenerator at it). The other channels (Telegram, Slack,
Discord) all prepend <media:*> tags before publish via the shared
media.BuildMediaTags helper — Bitrix24 was the lone holdout.

The agent loop's enrichInputMedia REPLACES tags it finds (it does NOT
insert new ones), so adding the tag at the channel boundary is the fix
that aligns Bitrix with the other channels AND unlocks enrich's
read_document / read_audio / read_image routing downstream.

- media_tags.go: mediaFilesToInfos() adapter from bus.MediaFile to
  media.MediaInfo + classifyMediaType() MIME prefix → media.Type* mapping.
  Unknown MIMEs fall back to TypeDocument (read_document handles generic
  binaries safely; a bogus audio tag on a non-audio file would mislead the
  LLM). Bitrix ships voice notes as audio/* — they're classified as
  TypeAudio (read_audio handles both audio and voice identically).
- handle.go: prepend BuildMediaTags(...) output to text right before
  HandleMessageMedia. No-op when no media files.
- media_tags_test.go: pins the MIME map, the conversion, and the
  end-to-end tag shape through BuildMediaTags.

Surface parity: backend-only. No API / web UI / CLI impact.

Co-authored-by: DangTinh311 <dangtinh31193@gmail.com>
2026-06-28 10:25:22 +07:00
Clark Cant ea00d1f979 Merge pull request #1292 from zezaeoh/fix/session-reset-provider-fallback
feat(gateway): add provider-backed llm rpc
2026-06-28 07:24:04 +07:00
Thoth (goclaw) 821e02cc4c fix(permissions): classify llm complete rpc 2026-06-27 23:23:21 +00:00
Thoth (goclaw) 1c53447b99 feat(gateway): add provider-backed llm rpc 2026-06-27 23:15:02 +00:00
Duc Nguyenandntduc d460c90403 fix(feishu): gate group pairing by target bot (#1291)
* fix(feishu): require exact bot_open_id match for mention detection

- Previously, when bot_open_id was empty, ALL mentions were treated as bot mentions
- This caused multiple agents in same group to all respond to any mention
- Now requires bot_open_id to be set AND match exactly for mentionedBot=true
- Fixes issue where CPPAI PM would respond even when other agent was mentioned

* fix(feishu): gate group pairing by target bot

---------

Co-authored-by: ntduc <ntduc@cpp.ai.vn>
2026-06-28 00:25:49 +07:00
nguyenha935andGoClaw Operator b72959b34c fix(db): correct channel contact merged_id foreign key (#1290)
Co-authored-by: GoClaw Operator <operator@goclaw>
2026-06-27 21:24:52 +07:00
Zezae Oh 24a6b02506 feat(cron): add command payload form (#1289) 2026-06-27 12:54:34 +07:00
Zezae Oh a90127c3d6 feat(cron): create command payloads in UI (#1288) 2026-06-27 12:27:03 +07:00
Zezae Oh 7a9210b765 feat(cron): edit command payloads in UI (#1287) 2026-06-27 12:04:13 +07:00
Zezae Oh 99e2b7f851 feat(cron): show command payloads in UI (#1286) 2026-06-27 11:24:55 +07:00
Zezae Oh 226e33ddfb fix(config): overlay cron command flag from system configs (#1285) 2026-06-27 10:24:16 +07:00
Henrique GoncalvesandClaude Opus 4.6 23ddc0858c fix(sandbox): sanitize @ in container names for WhatsApp LID chat IDs (#1031)
WhatsApp LID-format chat IDs contain @ (e.g. 551152861098:5@s.whatsapp.net)
which is invalid in Docker container names, causing sandbox creation to fail
for any WhatsApp-triggered agent session.

Add @ to the sanitizeKey replacer alongside the existing : / . and space
characters. Adds a test case with a realistic WhatsApp LID key.

Fixes #1029

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-06-27 02:25:36 +07:00
codebit0 e6ab6838cb feat(i18n): 한국어(ko) 로컬라이제이션 추가 (#1081)
- 백엔드: LocaleKO 상수, IsSupported에 ko 추가, catalog_ko.go 185개 문자열
- 웹 UI: 38개 네임스페이스 JSON 파일 (locales/ko/)
- constants.ts SUPPORTED_LANGUAGES에 ko 추가
- index.ts에 ko 리소스 등록 및 getInitialLanguage에 ko 감지
- en/topbar.json languages에 한국어 옵션 추가
- webui handler: index.html에 no-cache 헤더 추가하여 배포 후 캐시 문제 방지
2026-06-27 00:14:48 +07:00
Quoc-Anh Nguyen ce4535f305 feat(auth): inherit tenant_users.role for paired sessions (#1066)
Both WS pairing (router.go Path 3a) and HTTP X-GoClaw-Sender-Id auth
were pinned to RoleOperator. Now they map tenant_users.role ->
permissions.Role (owner/admin/operator|member/viewer) so a tenant admin
who logs in via pairing actually gets admin in the dashboard. Falls
back to RoleOperator when the user has no membership row (backward
compatible). Tenant is inferred from a single membership when no hint
is provided.

Signed-off-by: imcvampire <anhnq0@gmail.com>
2026-06-26 22:55:17 +07:00
mozaa 3a4d0a762a feat(telegram): /addcron /removecron /croners group cron-permission commands (#1106)
Mirror the existing /addwriter /removewriter /writers UX for the cron
permission type so group admins can grant cron-management access without
elevating to full file_writer. Bootstrap policy: first call in a group
is free (no cron managers yet); subsequent calls require an existing
cron manager OR a file_writer.

  - new commands_cron_perm.go: handleCronPermCommand (add/remove),
    handleListCronPerm; uses store.ConfigTypeCron with scope
    "group:<channel>:<chatID>".
  - commands.go: route /addcron, /removecron, /croners.
  - commands_pairing.go: register the 3 commands in the bot menu.
2026-06-26 13:20:12 +07:00
e0f40a3878 fix(skills): normalize backslash in ZIP entry names for Windows compatibility (#1103)
* fix(skills): normalize backslash in ZIP entry names for Windows compatibility

ZIP archives created on Windows may use backslash (\) as path separator
instead of forward slash (/). When extracted on Linux, this causes files
like 'scripts\search.py' to be created as a single flat file instead of
the proper 'scripts/search.py' directory structure.

The ZIP specification (PKZIP APPNOTE) requires forward slashes, but many
Windows tools produce non-conforming archives.

This adds a strings.ReplaceAll backslash normalization step during skill
ZIP extraction to handle this edge case.

* test(skills): cover backslash zip extraction

---------

Co-authored-by: buidackim <221586880+buidackim@users.noreply.github.com>
Co-authored-by: Mỹ Ngân <goclaw-maintain@users.noreply.github.com>
2026-06-26 05:59:35 +07:00
Aaron VuandAaron Vu c1ea0c0090 docs(openapi): cover the full HTTP API surface (#1171)
* docs(openapi): add vault endpoints + schemas

The committed OpenAPI spec only documented 41 of ~286 actual routes. This
adds the 19 Vault endpoints — 16 under /v1/vault/* and 3 under
/v1/agents/{agentID}/vault/* — plus their request/response schemas.

Routes covered (matches internal/http/vault_handler_*.go and
vault_graph_handler.go registrations):

- documents:    list, create, get, update, delete (per-agent and cross-agent)
- documents/{docID}/links:  outlinks + backlinks + name lookup
- links:        create, delete, batch get outlinks
- upload:       multipart, allowed exts whitelist
- rescan:       per-tenant workspace rescan w/ concurrency guard (409)
- tree:         lazy sidebar listing
- search:       hybrid FTS + vector
- enrichment:   status + stop
- graph:        lightweight nodes/edges for visualization

Schemas: VaultDocument, VaultDocumentInput, VaultDocumentUpdateInput,
VaultLink, VaultBacklink, VaultSearchResult, VaultTreeEntry,
VaultGraphNode, VaultGraphEdge. Tags: Vault, Vault Graph.

Pure spec addition — no handler changes. The insertion is surgical
(no reformatting of existing entries), so the diff is additive only.

* docs(openapi): cover the remaining HTTP endpoints

Continues the gap-fill started for Vault. Adds 150 more path operations
spanning every other HTTP-route file under internal/http/, with 19 new
component schemas and 8 new tags. After this commit the spec covers 210
paths vs 60 previously committed (the actual handler surface is ~258).

Coverage by area (file → routes added):
  knowledge_graph_handlers.go     9   (Knowledge Graph: extract, graph, stats,
                                       dedup scan/dismiss, merge, single entity)
  vault_graph_handler.go          1   (kg/graph/compact)
  memory_handlers.go              6   (documents CRUD with {path...}, chunks,
                                       index, index-all)
  oauth.go                        8   (chatgpt + openai: status, start,
                                       callback, logout × 2)
  storage.go                      4   (files {path...} read/delete, size, move;
                                       POST upload merged into the existing
                                       /v1/storage/files block so the path key
                                       stays unique and YAML-strict parsers like
                                       Swagger UI's loader accept the spec)
  agents.go                       22  (sync-workspace, shares CRUD, regenerate /
                                       resummon / cancel-summon, system-prompt-
                                       preview, export {preview,download/token},
                                       import {preview,merge}, teams export/import,
                                       instances + metadata, orchestration,
                                       v3-flags)
  evolution_handlers.go           3   (metrics, suggestions, suggestion review)
  episodic_handlers.go            2   (list, search)
  skills.go                       18  (versions, files, files/{path...}, upload,
                                       grants agent/user × revoke, install-deps
                                       trio, runtimes, toggle, tenant-config,
                                       export {preview}, import)
  mcp.go + mcp_user_credentials.go 16 (test, reconnect, grants + per-user creds,
                                       requests CRUD + review, export {preview},
                                       import, agent-grants list)
  providers.go                    4   (verify-embedding, codex-pool-activity,
                                       claude-cli auth-status, embedding/status)
  tenants.go + users              7   (CRUD + tenant users + tenant-users list,
                                       users/search)
  secure_cli.go + agent_grants    17  (cli-credentials full CRUD + presets +
                                       check-binary + test + user-credentials +
                                       agent-grants)
  system_configs.go               4   (list, get, put, delete)
  backup_handler.go + s3 + tenant 12  (system backup preflight/download/s3 set,
                                       tenant backup + restore)
  packages.go                     6   (list, install/uninstall, runtimes,
                                       github-releases, shell-deny-groups)
  builtin_tools.go                3   (tenant-config get/set/delete)
  tts.go + voices.go + caps       6   (config, synthesize, test-connection,
                                       capabilities, voices, voices/refresh)
  channel_instances.go +contacts +pending  10  (channel writers, writer groups,
                                       contacts resolve / merge / unmerge / merged,
                                       pending-messages)
  files.go + workspace_upload      3   (files {path...} read, files/sign,
                                       team workspace upload + move, team events,
                                       team task attachment download)
  edition.go + openapi.go          2   (edition info, openapi.json)
  api-keys + traces + usage        3   (revoke, traces/{traceID}/export,
                                       usage/breakdown)

New schemas: KGEntity, KGRelation, KGDedupCandidate, KGStats, TraversalResult,
MemoryDocument, MemoryChunk, MemorySearchHit, OAuthStatus, OAuthStartResponse,
Skill, McpServer, Tenant, TenantUser, CLICredential, Package, EvolutionMetric,
EvolutionSuggestion, EpisodicSummary.

New tags: Tenants, CLI Credentials, Packages, Contacts, Teams, TTS, Evolution,
Episodic Memory.

Purely additive — no existing operation, schema, or tag is modified. The one
overlap (`/v1/storage/files`, previously documented as GET-only) is handled
by inserting the new POST method inside the existing path block in place
rather than re-declaring the key, so each path key appears exactly once and
the spec parses cleanly under both JSON and strict YAML loaders.

Verified by parsing HEAD and the new file with python json.load + yaml.safe_load
and diffing entry-by-entry. Under `git diff --histogram`/`--patience` the diff
shows zero deletions; the default myers algorithm reports cosmetic deletion
lines but they are diff-algorithm noise, not real changes.

Where a body field or response shape was clear from the handler, the spec
captures it; where the handler accepts free-form / additive JSON payloads
the request body is documented as a generic object (additionalProperties:
true) rather than a fabricated rigid schema. Better to be honest about
flexibility than to lock callers into a wrong type.

* docs(openapi): drop nonexistent DELETE /v1/api-keys/{id}

The spec carried a DELETE /v1/api-keys/{id} operation, but
internal/http/api_keys.go registers no such route — only
GET /v1/api-keys, POST /v1/api-keys, and
POST /v1/api-keys/{id}/revoke. The DELETE entry predates this PR
(it was already on dev), so the semantic-preservation check left
it untouched; this removes the stale op so the spec matches the
registered routes. The correct POST /v1/api-keys/{id}/revoke
operation is unchanged.

Verified: json.load parses, go build ./internal/http/ and
go vet ./internal/http/ both clean.

---------

Co-authored-by: Aaron Vu <aaron-tsar@users.noreply.github.com>
2026-06-25 22:31:08 +07:00
Thanh_Dang 669eed6990 perf(agent): cache BuildFilteredTools result per run (#1282)
* fix(pipeline): defer non-tool messages until all tool results are emitted

Multi-tool responses could interleave synthetic user messages (loop
warnings, nudges) between tool results, breaking OpenAI-compatible
providers that require contiguous tool_result grouping.

Fix both sequential and parallel tool execution paths in tool_stage.go
to defer non-tool messages until after all tool results are appended.
Fix sanitizeHistory lookahead in loop_history_sanitize.go to reorder
interleaved non-tool messages in persisted session history.

Closes #1177

* perf(agent): cache BuildFilteredTools result per run

All filtering inputs (policy, disabled tools, bootstrap, channel,
orchestration mode, user MCP tools) are fixed for the lifetime of a
run. Only the final iteration differs (strips all tools). Cache the
tool definitions after the first call and reuse for iterations
0..maxIter-1, eliminating N-1 redundant 7-step policy evaluations per
agent run.
2026-06-25 22:17:17 +07:00
mozaa cfb7f46324 feat(web_search): add provider arg to force a specific engine (#1108)
Currently the web_search tool resolves a tenant-configured provider
chain (e.g. tavily → exa → brave) and stops at the first success.
That's the right default for cost/latency, but it makes cross-engine
corroboration impossible at the agent level: the caller has no way to
ask "search the same query on Exa specifically" once Tavily has
already returned a hit.

Add an optional `provider` argument. When set, the chain is narrowed
to the named provider (case-insensitive); other providers are not
queried. The first-success-wins fallback is preserved when the arg
is omitted.

Use case (concrete): a research agent verifying source freshness
calls web_search twice for the same query — once with provider="tavily"
and once with provider="exa" — and compares the URLs returned. URLs
that appear in both engines are high-confidence original primary
sources; URLs only in one signal a republish or low-circulation outlet
worth verifying further.

Other changes:

  - Cache key now includes the requested provider so per-engine
    results don't collide. Without this, the second call would just
    replay the first engine's cached result, defeating the purpose.
  - Unknown provider returns a clear error listing what IS configured
    for the tenant — better DX than a silent no-op.

Tests: 5 new cases covering narrowing, case-insensitivity, unknown
provider, default first-success behaviour preservation, and cache
isolation across providers.
2026-06-25 16:59:48 +07:00
nguyenha935andnguyenha935 9e97031099 fix(tts): route agent tool through tenant provider (#1277)
* fix(tts): route agent tool through tenant provider

* fix(tts): preserve fallback after tenant provider failure

---------

Co-authored-by: nguyenha935 <208228297+nguyenha935@users.noreply.github.com>
2026-06-25 12:38:49 +07:00
Nguyễn Văn Ánhandanhvn 1a607c3e6b Add the /v1 prefix to the FB webhook, as the proxy in the Vite config is interfering with the webhook. (#1281)
Co-authored-by: anhvn <anhnv@dol-tech.net>
2026-06-25 11:07:17 +07:00
Zezae OhandClaude Opus 4.8 4a79c8a208 feat(cron): deterministic command payloads (run a shell command, no LLM) (#1279)
* feat(cron): deterministic command payloads (run a shell command, no LLM)

Cron jobs always run an agent turn today, so deterministic work (health
probes, backups, syncs) pays model tokens on every fire. This adds a
"command" payload kind that runs a shell command directly in the gateway
process with zero model tokens, mirroring openclaw's command cron.

- store: CronPayload.Command (*CronCommandSpec — argv/cwd/env/input/
  timeouts/output cap). Persists in the existing payload JSON blob, so
  there is NO migration and no schema version bump.
- internal/cronexec: in-process runner with wall-clock + no-output
  timeouts, per-stream output capping, and process-group termination so a
  timed-out command's forked children are also killed.
- gateway_cron handler: command jobs run in-process and deliver stdout on
  success (honoring the NO_REPLY sentinel). A non-zero exit / timeout
  returns an error so the run is recorded as error and retried per
  cron.max_retries; failures are NOT delivered, mirroring the agent path
  (only successful output is announced — no channel spam).
- surfaces: cron.create RPC, the agent `cron` tool, and a new
  `goclaw cron create` CLI all accept command payloads.
- security: gated by cron.command_enabled (default false). Commands run
  with the gateway process's privileges, so the feature is opt-in per
  gateway; when disabled the RPC and tool reject command payloads and the
  handler refuses to run them.
- i18n (en/vi/zh), docs (08-scheduling-cron.md), and tests for the runner
  and the handler command path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(cron): gate command payloads on the update surfaces too

handleUpdate (RPC + agent tool) passed CronJobPatch.Command straight to
UpdateJob, which switches the payload to command kind for any non-nil
Command — without the command_enabled gate or ValidateCronCommandSpec that
create enforces. A normal job could therefore be mutated into a command job
(or persisted with an invalid spec, e.g. empty argv) on a gateway where
command cron is disabled, breaking the disabled-gateway contract.

Both update surfaces now require cron.command_enabled and validate the spec
before UpdateJob, matching create. The agent tool parses the command via the
same path as add and drops the raw keys so a shell-string command can't break
the generic patch unmarshal. Regression tests added for RPC and tool update
(command disabled + invalid argv), plus a positive enabled-valid case.

Addresses review feedback from @mrgoonie on #1279.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 10:23:55 +07:00
Bruno ClermontandBruno Clermont 0240a36b05 fix(hooks): allow system tenant to create tenant/agent scoped hooks (#1241) (#1280)
Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
2026-06-25 09:53:28 +07:00
Bruno ClermontandBruno Clermont 72fcf52f5d fix(channels): propagate tenant context through all channel handlers (#1278)
Pairing requests and message handlers were silently using MasterTenantID
instead of the correct tenant because context.Context had no tenant set.

Root cause: instance_loader.go passed bare ctx (no tenant) to
startChannelWithTimeout; channel handlers also missing store.WithTenantID
at entry points.

Channels fixed:
- instance_loader.go: pass instCtx (with tenant) to startChannelWithTimeout
- Telegram, Bitrix24, Feishu: add store.WithTenantID at handler entry
- Facebook: add ctx param to handleMessagingEvent/handleCommentEvent + webhook_handler
- Pancake: add ctx param to handleMessagingEvent/handleCommentEvent + webhook_handler

Also fix consolidation pruner: PruneExpired SQL had tenant_id filter that
caused zero rows to ever be deleted (context had no tenant). Remove tenant
filter — pruning is a global maintenance operation.

Add regression tests:
- internal/channels/pancake/tenant_context_test.go (6 tests)
- internal/channels/facebook/tenant_context_test.go (4 tests)
- internal/consolidation/prune_expired_test.go (5 tests)

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
2026-06-25 07:38:51 +07:00
thotam cd5ad845f5 feat(webhooks): lease heartbeat to prevent duplicate async processing (#1275)
The async webhook worker double-processed long-running agent calls: the
90s stale-running sweep reclaimed rows whose agent ran longer than 90s
(no heartbeat), re-running the agent and duplicating MCP side-effects.

Add a last_heartbeat_at column + a Heartbeat lease-renewal method (CAS on
lease_token). While an agent runs, the worker renews the lease every 30s;
ReclaimStale now keys off last_heartbeat_at instead of started_at, so a
live run is never reclaimed while a dead worker is still recovered within
the stale window. If a run loses its lease (reclaimed), the heartbeat
cancels the run context so the agent stops immediately and writes no
further side-effects.

- migrations/000085 (PG) + SQLite schema v52 + RequiredSchemaVersion 85
- WebhookCallStore.Heartbeat (PG + SQLite impls); ClaimNext/ReclaimStale
  switched to last_heartbeat_at
- worker heartbeat goroutine + cancel-on-lease-loss; invokeAgent honors ctx
- store + worker tests
2026-06-24 16:10:38 +07:00
Zezae Oh ce0472b580 fix(gateway): re-apply allowed_paths to filesystem tools after system_configs overlay (#1274)
setupToolRegistry wires the filesystem tools' AllowPaths from the config/JSON5
default before ApplySystemConfigs overlays system_configs['allowed_paths'], so
DB-configured allowed paths never reached read_file / list_files / write_file /
edit / send_file. Only the rate limiter was re-applied after the overlay (#1111);
the AllowPaths analogue was missing, so agents were denied access to configured
shared directories outside their workspace even though the DB value was present
(visible as a read_file "access denied" log whose allowedPrefixes omit the
configured path).

Extract the user-allowed-path application into applyUserAllowedPaths and re-run it
from runGateway after the overlay, mirroring the rate-limiter re-apply. The helper
is idempotent (AllowPaths is additive and the prefix check is membership-based),
so the initial wiring call plus the re-apply is safe.

Test: cmd/gateway_tools_wiring_test.go asserts a path outside the workspace is
denied before the grant and readable after, that an unrelated path stays denied,
that repeated application is safe, and that an empty list is a no-op.
2026-06-24 15:26:26 +07:00
Thanh_Dang 12a0168271 fix(security): block 198.18.0.0/15 and 240.0.0.0/4 in SSRF protection (#1269)
Add RFC 2544 benchmarking range (198.18.0.0/15) and reserved range
(240.0.0.0/4) to both SSRF blocklists (security package + web_fetch
tool) to prevent internal network access via these special-use IPs.

Closes #1218
2026-06-24 14:12:38 +07:00
Zezae Oh 505b7a9d99 fix(agent): recover interrupted runs to failed on gateway startup (#1272)
A run records its terminal run.status (completed/failed/cancelled) only
when the agent loop returns. If the gateway process is killed mid-run
(restart, crash, or SIGKILL after a slow graceful shutdown), the terminal
event is never emitted, so the run's last run.status item stays "started"
forever — it shows as perpetually running in the timeline and is never
counted as failed.

Mirror the cron scheduler's startup reset (recomputeStaleJobs flips stale
'running' jobs to 'interrupted'): add RunTimelineStore.RecoverInterruptedRuns,
invoked once on gateway startup. It finds runs that have a started run.status
but no terminal sibling and appends a terminal failed run.status item, marked
interrupted in metadata so it stays distinguishable from a genuine agent
failure. Running only at startup means nothing from before is still
executing, so there is no false-positive risk — unlike a periodic sweep
(see the deliberately-disabled tracing stale-trace loop).

- store: RecoverInterruptedRuns on the interface + PG and SQLite impls
- cmd/gateway_managed: invoke once after the timeline recorder is built
- tests: SQLite store test — orphan recovered, completed run untouched,
  idempotent on re-run
2026-06-24 14:03:00 +07:00
thotam e2ec3370dd feat(webhooks): stream provider responses for server-side runs to enable prompt caching (#1273)
Server-side webhook agent runs (sync, async, and admin test) used Stream:false,
so OpenAI-compatible routers that only cache streaming requests never populated
or served their prompt cache. Webhook runs paid full input-token price on every
turn even with a stable session and an identical multi-turn prefix, while WS chat
(Stream:true) got cache hits from the 3rd turn.

Add gateway.webhook_stream (default true, env GOCLAW_WEBHOOK_STREAM) and apply it
to all three run sites. ChatStream returns the fully assembled response, so the
payload returned to the caller is unchanged. Set to false to restore non-streaming.
2026-06-24 13:42:20 +07:00
Thanh_Dang 68ad5953d7 fix(pipeline): defer non-tool messages until all tool results are emitted (#1270)
Multi-tool responses could interleave synthetic user messages (loop
warnings, nudges) between tool results, breaking OpenAI-compatible
providers that require contiguous tool_result grouping.

Fix both sequential and parallel tool execution paths in tool_stage.go
to defer non-tool messages until after all tool results are appended.
Fix sanitizeHistory lookahead in loop_history_sanitize.go to reorder
interleaved non-tool messages in persisted session history.

Closes #1177
2026-06-24 10:49:31 +07:00
thotam 06ef06ca37 feat(webhooks): paginate list + call-history endpoints (server + web UI) (#1268)
Add total-count pagination to the webhook admin endpoints and the web UI.

Store:
- WebhookStore/WebhookCallStore gain Count; WebhookListFilter gains
  IncludeRevoked + Query (PG + SQLite, parameterized, tenant-scoped)

API:
- GET /v1/webhooks and GET /v1/webhooks/{id}/calls return
  {items, total, limit, offset} with server-side search + revoked filtering

Web UI:
- server-driven list pager + search/revoked filter; call-history dialog uses
  the real total (fixes the full-page "has more" boundary bug)
- i18n pager labels (en/vi/zh)

Tests: store pagination integration test; mock stores implement Count.
No schema migration (read-only COUNT).
2026-06-24 10:39:24 +07:00
haidang1810andDuy /zuey/ 2945d4db6c fix: update whatsmeow for WhatsApp privacy tokens (#1271)
* fix: recover whatsapp qr after deleted device

* fix: whatsapp connect

* fix whatsapp instance device scoping

* fix: update whatsmeow for whatsapp privacy tokens

---------

Co-authored-by: Duy /zuey/ <duy@wearetopgroup.com>
2026-06-24 10:30:36 +07:00