How kuingsmile/word-gpt-plus works
1. What this repo is
- This is a Microsoft Word add-in, not a standalone desktop app.
- The UI is a Vue single-page app built with TypeScript and Vite, then hosted inside Word’s add-in webview.
- Its job is to let users chat with AI and let an agent read/write/format the current Word document.
2. Execution boundary
- The app runs in the Word add-in host and depends on the Office/Word environment to access the document.
- It also connects outward directly to AI providers such as OpenAI-compatible APIs, Azure OpenAI, Gemini, Groq, and local Ollama.
- That means there are two major external boundaries: the Word document boundary and the model-provider boundary.
3. UI shell and navigation
- src/main.ts bootstraps the app into src/App.vue.
- src/router/index.ts routes between the main task-pane views: HomePage.vue, SettingsPage.vue, and checkPointsPage.vue.
- The Home page is the primary chat/agent workspace; Settings configures providers and behavior; the checkpoints page appears to manage saved workflow/document states.
4. Component layer
- Reusable UI is concentrated in src/components/.
- These components implement the add-in’s custom controls and layout blocks: buttons, inputs, messages, setting cards, sections, and selects.
- The component layer is presentation-focused and sits above the action/state logic in utils/ and api/.
5. Provider and request layer
- src/api/ holds the abstraction for talking to AI backends.
- common.ts, types.ts, union.ts, and checkpoints.ts suggest a shared request/response model plus provider-specific variations and checkpoint-related operations.
- This layer is the outbound network boundary for model calls and likely handles provider differences, streaming, and request normalization.
6. Agent/document-tool layer
- The repo’s agent mode is centered around src/utils/wordTools.ts, wordFormatter.ts, and related helpers.
- This layer exposes Word-specific capabilities to the AI: reading selection/content, inserting and replacing text, formatting paragraphs, managing tables/bookmarks, and similar document operations.
- Conceptually, this is the bridge between LLM reasoning and the actual Word document state.
7. Prompting, settings, and user preferences
- src/utils/settingForm.ts, settingPreset.ts, and constant.ts define the shape and defaults of provider settings.
- src/utils/enum.ts and src/utils/common.ts support shared app logic and configuration interpretation.
- Settings are persisted locally in the add-in environment, matching the README’s privacy model: no central backend stores user API keys.
8. Response handling and messaging
- src/utils/message.ts, generalTools.ts, and the Message.vue component indicate a structured chat/message pipeline.
- The app appears to support streaming AI output, per-message actions like replace/append/copy, and user-visible status/error reporting.
- This layer is where AI responses are turned into interactive chat UI updates and document actions.
9. Formatting pipeline
- wordFormatter.ts is an important architecture piece because AI output is not shown raw; it is transformed into Word-friendly formatting.
- The add-in supports markdown-style response rendering and conversion into Word styles, so formatting is part of the product’s core behavior, not just a UI concern.
- That makes the output path: model response → formatter → Word-compatible display/actions.
10. Internationalization
- src/i18n/ contains English and Simplified Chinese locale files.
- Localization is built into the UI layer, so language selection affects labels, settings, and prompts across the task pane.
- This is a pure presentation/config boundary, separate from provider logic.
11. Static assets and hosting
- public/ contains static files including PrivacyPage.html and assets like the logo.
- The repo includes release/instant-use/manifest.xml and release/self-hosted/manifest.xml, which show two deployment modes: a hosted “instant use” manifest and a self-hosted manifest.
- Dockerfile and the GitHub workflow indicate the frontend can be packaged into a container for simple deployment.
12. Word add-in packaging
- index.html, vite.config.js, and the Office add-in manifests define the browser entrypoint and how Word loads the app.
- wordgpt.bat and async_hook.js look like support scripts for Windows/add-in startup or environment integration.
- The overall packaging model is: build the SPA, serve it over HTTP(S), and point Word’s manifest to that URL.
13. Likely end-to-end data flow
- User action in Word → task-pane UI event → settings/model selection → API request to provider → streamed response back to UI.
- In agent mode, the response may include tool calls that are resolved through Word/document utilities, then fed back into the conversation.
- Final output can be rendered in the chat UI, inserted into the document, or both.
14. How to draw the architecture
- Draw a central “Word GPT Plus Add-in UI” box containing pages/components/router.
- Connect it to a “Local settings/store” boundary for API keys, prompts, and preferences.
- Connect it outward to “AI Providers” and inward to “Word document APIs / Office host.”
- Place the agent/tool layer between the LLM and Word to show that document actions are mediated, not direct from the UI alone.
Main entry points: HomePage.vue Home · index.ts Router · common.ts API Core · SettingsPage.vue Settings
Components 21
Add-in UI
Vue task-pane shell, pages, and reusable presentation components.
- Main · Bootstraps the Vue app into the add-in shell.
src/main.ts - App Shell · Top-level SPA container for the task pane.
src/App.vue - Router · Routes between home, settings, and checkpoints views.
src/router/index.ts - Home · Primary chat and agent workspace.
src/pages/HomePage.vue - Settings · Provider and behavior configuration view.
src/pages/SettingsPage.vue - Checkpoints · Saved document or workflow state management.
src/pages/checkPointsPage.vue - UI Controls · Reusable buttons, inputs, cards, selects, and message blocks.
src/components - Locales · Language strings and translation setup.
src/i18n/index.ts
Agent & Docs
Word-specific tools, formatting, and chat/message handling.
- Chat State · Structured message handling and UI message flow.
src/utils/message.ts - Word Tools · Reads, writes, and edits Word document content.
src/utils/wordTools.ts - Formatter · Converts model output into Word-friendly formatting.
src/utils/wordFormatter.ts - Tools Core · Shared agent utilities and action helpers.
src/utils/generalTools.ts - Settings Model · Provider settings shape, defaults, and presets.
src/utils/settingForm.ts
AI Providers
Outbound request layer and provider abstractions.
- API Core · Shared request/response behavior and provider normalization.
src/api/common.ts - API Types · Common provider and message type definitions.
src/api/types.ts - Provider Union · Provider-specific request variations and dispatch.
src/api/union.ts - Checkpoint API · Checkpoint-related request or persistence operations.
src/api/checkpoints.ts
Packaging
Word add-in entrypoints, manifests, and deployment assets.
- Packaging · Build and Word add-in loading entrypoints and manifests.
index.html
Other components
- Word Host · Microsoft Word task-pane and document runtime boundary.
- Model Providers · OpenAI-compatible, Azure OpenAI, Gemini, Groq, and Ollama endpoints.
- Local Store · In-host storage for settings, keys, and preferences.
Connections 25
- Main → App Shell: mounts · Initial app bootstrap into the SPA shell.
- App Shell → Router: uses · Application shell delegates page selection to the router.
- Router → Home: routes · Primary workspace view.
- Router → Settings: routes · Configuration view.
- Router → Checkpoints: routes · Saved state view.
- Home → UI Controls: renders · Uses shared controls and message UI.
- Settings → UI Controls: renders · Uses settings cards, inputs, and selects.
- Checkpoints → UI Controls: renders · Uses shared UI controls.
- Home → Chat State: manages · Conversation state and streaming updates.
- Home → Word Tools: tools · Agent actions are mediated through document tools.
- Home → Formatter: formats · Converts AI output into Word-friendly display/actions.
- Chat State → API Core: requests · Chat interactions flow into provider calls.
- API Core → API Types: contracts · Shared request/response schema.
- API Core → Provider Union: adapts · Provider-specific behavior and routing.
- API Core → Model Providers: calls · Outbound network boundary to model endpoints.
- Settings → Settings Model: configures · Settings page edits provider and behavior defaults.
- Settings Model → Local Store: persists · API keys and preferences are stored locally in-host.
- Word Tools → Word Host: reads/writes · Document boundary through the Office/Word runtime.
- Formatter → Word Host: renders to · Produces Word-compatible formatting and document output.
- Tools Core → Word Tools: supports · Shared document/agent helpers.
- Locales → Home: localizes · Language selection affects task-pane UI.
- Locales → Settings: localizes · Settings labels and descriptions.
- Packaging → Word Host: loads in · Word add-in packaging and task-pane entry boundary.
- Packaging → Main: starts · Build output points to the SPA entrypoint.
- Checkpoint API → Checkpoints: supports · Checkpoint state operations used by the checkpoints page.