<!-- OpenSmartRoute: Word add-in. https://opensmartroute.ai/docs/OFFICE -->
# Word add-in

The OpenSmartRoute add-in for Microsoft Word puts the router in a pane beside your document. Select a passage
and the pane tells you what it is - the kind of writing task, the language, how long it is, whether it carries
personal data - and what the router would do with it: the recommended model, what the request costs, what the
cheapest and the best model would cost instead, and what a month of such requests adds up to. Then **Ask** a
question about the passage, **Explain** or **Summarise** it, or **Rewrite** and **Proofread** it in place: the
answer comes back through the router with the model that wrote it, its price and its time, and the two in-place
actions replace the selection (Word's Undo takes it back).

The analysis runs in the pane, on your computer; nothing leaves it until you ask for a quote or an answer.
Personal data - e-mail addresses, phone and card numbers, IBANs, national ids, IP addresses, API keys - is replaced
by placeholders before a request is sent and put back in the answer, so the model never sees the values.

Word for Windows, Word for Mac and Word on the web (Microsoft 365). Works with the hosted platform at
[opensmartroute.ai](https://opensmartroute.ai) and with your own deployment of the platform.

## Install

The add-in is described by a manifest file the site writes for its own address:
[`/office/manifest.xml`](https://opensmartroute.ai/office/manifest.xml) (a self-hosted deployment serves its own
at the same path - the file names the server it was downloaded from).

- **For yourself (sideload):** in Word on the web open **Insert › Add-ins › More Add-ins › My Add-ins › Upload My
  Add-in** and pick the file. In Word for Windows the same dialog takes it (**Home › Add-ins › More Add-ins**); on
  a Mac, copy it into `~/Library/Containers/com.microsoft.Word/Data/Documents/wef/` and restart Word.
- **For everyone (administrator):** in the Microsoft 365 admin centre go to **Settings › Integrated apps › Upload
  custom apps**, choose *Office Add-in*, point it at the manifest URL above and assign the users or groups. The
  add-in then appears in their Word without anything to install, and an update of the manifest reaches them the
  same way.

An **OpenSmartRoute** button lands in Word's **Home** tab; it opens the pane. The *Get started* notice Word shows
once explains the three steps: select, read the analysis, ask.

## Sign in

The pane uses the same sign-in as the website, so the dashboard and the pane are one workspace.

- **Sign in** shows a code and opens the browser on the platform's approval page; approve the code while signed
  in to your workspace and the pane is connected. The credential stays in the pane's own storage on your computer.
- **Use a key** takes an API key from the dashboard (`osr_live_...`) or the token of a self-hosted server.
- **Sign out** removes it.

Without a sign-in the pane still analyses the selection and asks for an anonymous quote (rate limited, with the
public catalogue and prices); routing an answer needs a workspace.

## The pane

- **Selection** - the local analysis: the task the text asks for (summarisation, translation, rewriting, a
  question ...), the language, the complexity and how much reasoning it needs, the words and tokens in the
  selection and in the paragraphs around it, the domains, and the personal data found - by type and count - with a
  note that it will be redacted. The pane follows the selection as you move it.
- **Quote** - what the platform answers: the recommended model with the cost of this request and the input and
  output tokens it was priced on; under it the cheapest model, the best model and the fastest when they differ,
  each with cost, expected latency and quality estimate; and a projection for a thousand such requests a month.
- **Ask the router** - a box for your question or instruction (leave it empty for the default of each button) and
  the five buttons: **Ask**, **Explain**, **Summarise** show the answer in the pane with **Insert below the
  selection** and **Copy**; **Rewrite in place** and **Proofread in place** replace the selection when the answer
  is complete. **Cancel** stops a request in flight.
- **Answer** - the model that wrote it, its cost and time, and **Good** / **Not good**, which send the rating back
  so the router learns which model to prefer for that kind of writing.

## What is sent

A request carries the selected passage, the paragraphs it touches (context), the document's title, and your
instruction - as one prompt in the OpenAI-compatible `/v1/chat/completions` shape with `model: auto`, so the router
chooses; the answer is at most 1 024 tokens. The pane never sends the rest of the document, other open documents
or anything on your computer. Every personal item is replaced before the quote and before the request - the same
placeholder for the same value everywhere in the prompt - and the answer's placeholders are turned back into the
values in the pane.

## Self-hosting

The pane is part of the platform's web app: a deployment of your own serves it at `/office/taskpane` and writes
its manifest at `/office/manifest.xml` for its own hostname. Office loads the pane inside Word's own frame, so the
web app sends a Content-Security-Policy for `/office/*` that allows Office's hosts as frame ancestors and
Microsoft's CDN for Office.js (the only place add-ins may load it from); nothing else about the deployment
changes. Office requires `https` for everything the manifest names.

## Troubleshooting

- **The pane says "outside Office"** - it was opened in a browser tab. Open it from Word's Home tab.
- **"sign in to continue"** - the credential was removed or expired; **Sign in** again, or **Use a key**.
- **"the workspace is over its quota or rate limit"** - the plan's monthly requests are used up or the anonymous
  quote limit was hit; the dashboard's Usage page shows the quota, signing in lifts the anonymous limit.
- **The button is missing from the ribbon** - Word caches add-ins; in Word on the web reload the page, on the
  desktop close Word and open it again, and check the manifest was accepted (an upload names any problem).
- **A rewrite changed the formatting** - the replacement is written as plain text with the selection's paragraph
  breaks; bold and italic runs inside it are not kept. Undo and select a smaller passage.
