[PR #6259] [MERGED] Expose token estimator API to Personal Extensions #7109

Closed
opened 2026-10-23 04:16:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6259
Author: @minikkeuen
Created: 9/16/2026
Status: ✅ Merged
Merged: 9/16/2026
Merged by: @SpicyMarinara

Base: staging ← Head: pr/personal-extension-token-api


📝 Commits (4)

  • 3b60248 feat(personal-extensions): expose token estimator API
  • 5d21a63 fix(personal-extensions): serialize token estimator helpers
  • 2da5f37 docs(personal-extensions): document token estimator API
  • 95db530 Merge remote-tracking branch 'origin/staging' into review/6259-extension-tokens

📊 Changes

10 files changed (+175 additions, -3 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/extending/personal-extensions.md (+10 -0)
📝 packages/client/src/components/layout/PersonalExtensionInjector.tsx (+4 -1)
📝 packages/server/src/assets/personal-extension-runner.mjs (+10 -0)
📝 packages/server/src/routes/personal-extensions.routes.ts (+2 -0)
📝 packages/server/src/services/extensions/personal-server-extension-runtime.ts (+2 -1)
📝 packages/shared/src/types/personal-extension.ts (+6 -0)
📝 packages/shared/src/utils/token-estimator.ts (+11 -0)
📝 scripts/regressions/extension-ipc.regression.ts (+34 -1)
➕ scripts/regressions/extension-token-estimator.regression.ts (+95 -0)

📄 Description

Linked issue

Closes #6257

Why this change

  • Personal Extensions currently have no public API for using Marinara's built-in text token estimator.
  • Extensions that need token estimates must duplicate the estimation logic, which can produce results that differ from Marinara's own UI and require separate maintenance.
  • Exposing the shared estimator allows extensions to stay consistent with Marinara's token estimation behavior.

What changed

  • Added marinara.estimateTextTokens(text) to the Personal Extension API.
  • Exposed the estimator to Browser, Full Page, and Server Personal Extensions.
  • Added serialization support for the estimator and its helper functions so it can run correctly inside sandboxed extension environments.
  • Added regression coverage for the Personal Extension token estimator API.
  • Documented the new API in the Personal Extensions documentation.
  • Added the new API to the [Unreleased] changelog.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • The Personal Extension token estimator regression coverage passes for the exposed API and sandbox serialization path.
  • No UI changes are included in this PR.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Translation follow-up: #6258

UI evidence (if applicable)

Not applicable; this change does not modify the UI.

Summary by CodeRabbit

  • New Features

    • Personal Extensions can estimate text token counts with the synchronous marinara.estimateTextTokens(text) API.
    • Available across Browser, Full Page, and Server extensions without additional capabilities.
    • Provides model-agnostic estimates for multilingual text, emoji, and mixed content.
  • Documentation

    • Added usage guidance, availability details, and compatibility notes for older Engine versions.
  • Bug Fixes

    • Improved extension sandbox compatibility while keeping token estimation isolated and secure.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6259 **Author:** [@minikkeuen](https://github.com/minikkeuen) **Created:** 9/16/2026 **Status:** ✅ Merged **Merged:** 9/16/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `pr/personal-extension-token-api` --- ### 📝 Commits (4) - [`3b60248`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3b60248f1954c96c5204d3f89ece879be5b4ea51) feat(personal-extensions): expose token estimator API - [`5d21a63`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5d21a63b12ce09b7bce8f39f97b4caf0b6f4c61d) fix(personal-extensions): serialize token estimator helpers - [`2da5f37`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2da5f3785b23b05de3ea40d227b3dafed0dbf0f7) docs(personal-extensions): document token estimator API - [`95db530`](https://github.com/Pasta-Devs/Marinara-Engine/commit/95db530c1284a3c40066830f6921ebc1dd281c0b) Merge remote-tracking branch 'origin/staging' into review/6259-extension-tokens ### 📊 Changes **10 files changed** (+175 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/extending/personal-extensions.md` (+10 -0) 📝 `packages/client/src/components/layout/PersonalExtensionInjector.tsx` (+4 -1) 📝 `packages/server/src/assets/personal-extension-runner.mjs` (+10 -0) 📝 `packages/server/src/routes/personal-extensions.routes.ts` (+2 -0) 📝 `packages/server/src/services/extensions/personal-server-extension-runtime.ts` (+2 -1) 📝 `packages/shared/src/types/personal-extension.ts` (+6 -0) 📝 `packages/shared/src/utils/token-estimator.ts` (+11 -0) 📝 `scripts/regressions/extension-ipc.regression.ts` (+34 -1) ➕ `scripts/regressions/extension-token-estimator.regression.ts` (+95 -0) </details> ### 📄 Description ## Linked issue Closes #6257 ## Why this change - Personal Extensions currently have no public API for using Marinara's built-in text token estimator. - Extensions that need token estimates must duplicate the estimation logic, which can produce results that differ from Marinara's own UI and require separate maintenance. - Exposing the shared estimator allows extensions to stay consistent with Marinara's token estimation behavior. ## What changed - Added `marinara.estimateTextTokens(text)` to the Personal Extension API. - Exposed the estimator to Browser, Full Page, and Server Personal Extensions. - Added serialization support for the estimator and its helper functions so it can run correctly inside sandboxed extension environments. - Added regression coverage for the Personal Extension token estimator API. - Documented the new API in the Personal Extensions documentation. - Added the new API to the `[Unreleased]` changelog. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - The Personal Extension token estimator regression coverage passes for the exposed API and sandbox serialization path. - No UI changes are included in this PR. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Translation follow-up: #6258 ## UI evidence (if applicable) Not applicable; this change does not modify the UI. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Personal Extensions can estimate text token counts with the synchronous `marinara.estimateTextTokens(text)` API. - Available across Browser, Full Page, and Server extensions without additional capabilities. - Provides model-agnostic estimates for multilingual text, emoji, and mixed content. - **Documentation** - Added usage guidance, availability details, and compatibility notes for older Engine versions. - **Bug Fixes** - Improved extension sandbox compatibility while keeping token estimation isolated and secure. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:16:37 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7109
No description provided.