You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(ui): let ExApps register reference providers and Smart Picker entries - #1174
Implements #1099: an ExApp can register reference providers, so it can add an entry to the Smart Picker, ship its own picker UI, and turn its links into rich previews in Text, Talk, Deck and the other apps that render references.
API
POST, GET and DELETE on /ocs/v2.php/apps/app_api/api/v1/ui/reference-provider, next to the top menu endpoints:
parameter
meaning
providerId
unique ID, [a-zA-Z0-9_.-]{1,64}. The picker script registers its custom element under the same ID
title, iconUrl, order
the Smart Picker entry. iconUrl is a path inside the ExApp or an http(s) URL
searchProvidersIds
unified search providers the picker can use, as for PHP providers
matchPatterns
PCRE patterns of the links the provider resolves
scriptPath
the picker script inside the ExApp, or empty for a provider without a custom element
An ExApp can only register, read or delete providers under its own app ID. A provider ID owned by another ExApp is refused with 400.
How it works
Each provider of an enabled ExApp becomes an anonymous ADiscoverableReferenceProvider (also ISearchableReferenceProvider), registered in Application::register() under a synthetic class name. This is the pattern TaskProcessingService::registerExAppTaskProcessingProviders() used, so the number of providers is not capped. There is no reference provider event, unlike GetTaskProcessingProvidersEvent, so it has to be done in register(). The rows are read from the distributed cache.
Resolve, server side:matchReference() checks the stored patterns in PHP, so only a matching link costs a request: POST /reference/resolve on the ExApp with {provider_id, reference}. The answer (title, description, image_url, url, rich_object_type, rich_object) becomes the Reference. The cache key is per user, because the ExApp answers per user.
Picker, browser side: a RenderReferenceEvent listener adds app_api-reference.js, which adds each ExApp's picker script and publishes the base URL the browser must use: /exapps/<appid> with HaRP, the PHP proxy otherwise. This answers open question 1 of the issue. The script registers its element with registerCustomPickerElement(), as PHP apps do.
Lifecycle: providers are deleted with the ExApp and hidden while it is disabled, and the cache is reset on enable and disable.
Security
scriptPath and a relative iconUrl must stay inside the ExApp: only [A-Za-z0-9._~/-], no ., .. or empty segments. That refuses schemes, %-encoding, \, ? and #. Without this, ../other_app/x.js would make every page that shows the Smart Picker run another ExApp's script.
The loader also checks, in the browser, that the resolved script URL is same-origin and under the ExApp's base path. This covers rows stored before validation and a base URL that is a prefix of another app ID (app1 and app10).
Tests
PHPUnit: ReferenceProviderServiceTest covers listing only enabled ExApps, ownership, validation, pattern matching, the cache prefix, and path escapes for scriptPath and iconUrl. OCSUiControllerTest covers the endpoint round trip and errors. Full suite: 385 tests pass.
vitest: referenceLoader.spec.js covers ordering, de-duplication, and the scripts it must not load.
Psalm, php-cs-fixer and eslint are clean, openapi*.json is regenerated, and js/app_api-reference.js is built.
Manually, on Nextcloud master with Text, HaRP and the PHP proxy: an ExApp (meatybot/caption_obvious) registered a provider on enable. The entry showed in the Smart Picker, the picker loaded its own Vue UI through /exapps/, inserted a link, and the link rendered as a preview. Disabling and removing the ExApp removed the provider. A second ExApp registered its own provider next to it: both pickers loaded on the same page, each link went to its own provider, and the second ExApp could not take over, read or delete the first one's provider.
Notes
This bumps the version to 36.0.0-dev.1 for the migration (Version036000Date20261024120000, table ex_ui_reference_providers).
nc_py_api support (nc.ui.reference_provider, sync and async) is written but not proposed yet. I would rather settle the API here first. Until then, ExApps can call the OCS endpoint directly, as caption_obvious does.
The change adds ExApp reference-provider storage, validation, registration and removal endpoints, and server-side matching and resolution. During reference rendering, the app provides picker metadata and loads eligible ExApp scripts. The frontend checks script URLs against the page origin and ExApp base path, and avoids loading a shared script more than once.
Priority: Normal
Estimated code review effort:
Merge Risk: Low · up to 0a92f
On APCu-only installations, disabled or removed providers may remain visible until a web process clears its cache. This bounded configuration risk merits an owner decision before merging.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 38.24% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the primary change: enabling ExApps to register reference providers and Smart Picker entries.
Description check
The description directly explains the reference-provider API, Smart Picker integration, link resolution, security validation, lifecycle behavior, and tests covered by the changeset.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 38.24% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 34 functions across 18 files. (6 skipped: 6 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
js/app_api-reference.js
ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.
src/reference.js
ESLint skipped: the matched ESLint configuration already failed (missing-dependency).
src/referenceLoader.js
ESLint skipped: the matched ESLint configuration already failed (missing-dependency).
2 others
PHPStan (2.3.1)
PHPStan reported 3 non-file analysis error(s); analysis is incomplete
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Stability & Availability · Quick win
Supported by static analysis
Script executed:
#!/bin/bash# Compare cache setup across AppAPI services and find the reason for the APCu guard.
rg -n -C4 'createDistributed' lib/Service
rg -n -C3 'APCu' lib/Service
git log -S'APCu::class' --oneline -- lib/Service/ExAppService.php | head
Repository: nextcloud/app_api
Length of output: 6277
Script executed:
# Read cache usage and reset paths in the new service and the reference ExAppService guard.
rg -n -e 'cache' -e 'resetCacheEnabled' -e 'CACHE_KEY' lib/Service/UI/ReferenceProviderService.php ||test"$?" -eq 1
echo'--- ExAppService cache setup and reset ---'
rg -n -e 'resetCacheEnabled' -e 'cache->set' -e 'cache->remove' lib/Service/ExAppService.php ||test"$?" -eq 1
echo'--- ExAppService lines 58-80 ---'
sed -n '58,80p' lib/Service/ExAppService.php
Repository: nextcloud/app_api
Length of output: 2206
Guard the distributed cache when APCu is the only backend.
ExAppService skips its distributed cache when the effective backend is APCu (commit b5f8caf, "disable caching if APCu detected"). This constructor does not apply that check. On an APCu-only instance, the cache can outlive a disable or unregister and keep stale reference-provider entries in the web process.
The stale-entry path works as follows:
getEnabledReferenceProviders() writes its result with $this->cache?->set(self::CACHE_KEY, $records);. The call passes no TTL, so the entry has no explicit expiry.
resetCacheEnabled() clears only self::CACHE_KEY in the cache instance of the current process. ExAppService calls it from the lifecycle flow at lines 250-254.
APCu storage is per process. A reset in a CLI process does not clear the entry held by the web (FPM) process.
The proposed fix adds an IConfig dependency and mirrors the ExAppService condition:
♻️ Possible fix (mirror the ExAppService APCu guard)
Without the cache, each call to getEnabledReferenceProviders() runs a database query. Confirm that this cost is acceptable on APCu-only instances.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #1099: an ExApp can register reference providers, so it can add an entry to the Smart Picker, ship its own picker UI, and turn its links into rich previews in Text, Talk, Deck and the other apps that render references.
API
POST,GETandDELETEon/ocs/v2.php/apps/app_api/api/v1/ui/reference-provider, next to the top menu endpoints:providerId[a-zA-Z0-9_.-]{1,64}. The picker script registers its custom element under the same IDtitle,iconUrl,ordericonUrlis a path inside the ExApp or anhttp(s)URLsearchProvidersIdsmatchPatternsscriptPathAn ExApp can only register, read or delete providers under its own app ID. A provider ID owned by another ExApp is refused with 400.
How it works
Each provider of an enabled ExApp becomes an anonymous
ADiscoverableReferenceProvider(alsoISearchableReferenceProvider), registered inApplication::register()under a synthetic class name. This is the patternTaskProcessingService::registerExAppTaskProcessingProviders()used, so the number of providers is not capped. There is no reference provider event, unlikeGetTaskProcessingProvidersEvent, so it has to be done inregister(). The rows are read from the distributed cache.matchReference()checks the stored patterns in PHP, so only a matching link costs a request:POST /reference/resolveon the ExApp with{provider_id, reference}. The answer (title,description,image_url,url,rich_object_type,rich_object) becomes theReference. The cache key is per user, because the ExApp answers per user.RenderReferenceEventlistener addsapp_api-reference.js, which adds each ExApp's picker script and publishes the base URL the browser must use:/exapps/<appid>with HaRP, the PHP proxy otherwise. This answers open question 1 of the issue. The script registers its element withregisterCustomPickerElement(), as PHP apps do.Security
scriptPathand a relativeiconUrlmust stay inside the ExApp: only[A-Za-z0-9._~/-], no.,..or empty segments. That refuses schemes,%-encoding,\,?and#. Without this,../other_app/x.jswould make every page that shows the Smart Picker run another ExApp's script.app1andapp10).Tests
ReferenceProviderServiceTestcovers listing only enabled ExApps, ownership, validation, pattern matching, the cache prefix, and path escapes forscriptPathandiconUrl.OCSUiControllerTestcovers the endpoint round trip and errors. Full suite: 385 tests pass.referenceLoader.spec.jscovers ordering, de-duplication, and the scripts it must not load.openapi*.jsonis regenerated, andjs/app_api-reference.jsis built.Manually, on Nextcloud master with Text, HaRP and the PHP proxy: an ExApp (meatybot/caption_obvious) registered a provider on enable. The entry showed in the Smart Picker, the picker loaded its own Vue UI through
/exapps/, inserted a link, and the link rendered as a preview. Disabling and removing the ExApp removed the provider. A second ExApp registered its own provider next to it: both pickers loaded on the same page, each link went to its own provider, and the second ExApp could not take over, read or delete the first one's provider.Notes
36.0.0-dev.1for the migration (Version036000Date20261024120000, tableex_ui_reference_providers).nc_py_apisupport (nc.ui.reference_provider, sync and async) is written but not proposed yet. I would rather settle the API here first. Until then, ExApps can call the OCS endpoint directly, as caption_obvious does./exapps/) are not part of this PR. The verb question has since been handled in fix(harp): send the route verb to HaRP #1138 and fix(proxy): match the route verb like HaRP #1144.