docs(service): add root service docs#4747
docs(service): add root service docs#4747Shreyas281299 wants to merge 1 commit intowebex:task-refactorfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b30e86b543
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| | **Agent** | login, logout, state change, buddy agents, station, RONA | [`agent/ai-docs/AGENTS.md`](../agent/ai-docs/AGENTS.md) | [`agent/ai-docs/ARCHITECTURE.md`](../agent/ai-docs/ARCHITECTURE.md) | | ||
| | **Task** | task, hold, transfer, conference, wrapup, outdial, consult, accept, decline, state machine, XState, task states, guards, actions | [`task/ai-docs/AGENTS.md`](../task/ai-docs/AGENTS.md) | [`task/ai-docs/ARCHITECTURE.md`](../task/ai-docs/ARCHITECTURE.md) | | ||
| | **Config** | profile, register, teams, aux codes, desktop profile, org settings, dial plan | [`config/ai-docs/AGENTS.md`](../config/ai-docs/AGENTS.md) | [`config/ai-docs/ARCHITECTURE.md`](../config/ai-docs/ARCHITECTURE.md) | | ||
| | **Core** | websocket, HTTP, connection, reconnect, aqm, utils, errors, keepalive | [`core/ai-docs/AGENTS.md`](../core/ai-docs/AGENTS.md) | [`core/ai-docs/ARCHITECTURE.md`](../core/ai-docs/ARCHITECTURE.md) | | ||
|
|
There was a problem hiding this comment.
Replace service-doc routes that currently resolve to nothing
This routing table sends readers to agent/task/config/core ai-docs files that are not present under src/services/, while this document also says those docs should always be loaded before making changes. In practice that creates dead-end navigation for the documented workflow and makes the new “authoritative” guide non-actionable unless those targets are added or the links are changed to existing sources.
Useful? React with 👍 / 👎.
| ContactCenter (cc.ts) — public API surface | ||
| │ | ||
| ├── WebexRequest.getInstance({webex}) ← initialized FIRST (singleton) | ||
| ├── Services.getInstance({webex, config}) ← initialized SECOND (singleton) |
There was a problem hiding this comment.
Use the actual Services.getInstance option key
The example call uses Services.getInstance({webex, config}), but Services is wired around connectionConfig (as seen in src/services/index.ts and the real call site in src/cc.ts). Copying this snippet passes no subscription config into ConnectionService, so the guide currently demonstrates an invocation shape that does not match runtime expectations.
Useful? React with 👍 / 👎.
| 4. **Data services** (`AddressBook`, `EntryPoint`, `Queue`) — Created after `register()` succeeds and agent profile is available. | ||
| 5. **`TaskManager`** — Created after `stationLogin()` succeeds. | ||
| 6. **`WebCallingService`** — Created only when `loginOption === 'BROWSER'`. |
There was a problem hiding this comment.
Correct the documented bootstrap sequencing
The “critical” order here says data services are created after register(), TaskManager after stationLogin(), and WebCallingService only for BROWSER login, but ContactCenter instantiates all three in the READY handler before either API call (src/cc.ts constructor). This contradiction makes the architecture guidance unreliable for troubleshooting initialization issues or extending startup logic.
Useful? React with 👍 / 👎.
Shreyas281299
left a comment
There was a problem hiding this comment.
Review: docs(service): add root service docs
Overall
The documentation is well-structured and comprehensive -- the file structure tree, key capabilities table, architecture diagrams, bootstrap order, and request/response flow patterns are all clear and useful. This will be a strong reference for AI agents and developers working in the services layer.
Issues to Address
1. PR Template Not Filled Out (Compliance)
The PR description still has the default template placeholders, and none of the checkboxes are ticked. The template itself states:
FAILING TO FILL OUT THIS TEMPLATE WILL RESULT IN REJECTION OF YOUR PULL REQUEST. This is for compliance purposes with FedRAMP program.
Please fill out the PR description -- at minimum the "addresses", "changes", "Change Type" (Documentation update), GAI policy, and "I certified" sections.
2. Verify Relative Links to Package Root
Several links in the "Related" section point three levels up to the package root. Please verify these paths exist on the task-refactor branch:
../../../AGENTS.mdresolves topackages/@webex/contact-center/AGENTS.md../../../ai-docs/RULES.mdresolves topackages/@webex/contact-center/ai-docs/RULES.md../../../ai-docs/patterns/resolves topackages/@webex/contact-center/ai-docs/patterns/../../../ai-docs/patterns/typescript-patterns.md
If these do not exist yet (or are planned for a future PR), consider noting them as "TODO" or removing the dead links.
3. Sub-Service ai-docs Existence
The Service Routing table links to ai-docs under agent/, task/, config/, core/, and task/state-machine/. Are these already merged or in-flight? If they do not exist yet, readers/agents following these links will hit dead ends. Consider adding a note like: "These docs are being added incrementally -- check the folder for availability."
Suggestions (Non-blocking)
4. Consider Adding an ARCHITECTURE.md Companion
Other service folders (agent, task, config, core) have both AGENTS.md and ARCHITECTURE.md. For consistency, consider whether a companion ARCHITECTURE.md would be useful here -- even if it is lighter-weight, covering just the Services singleton internals and construction details.
5. PageCache Note Placement
The note about src/utils/PageCache.ts at the bottom of the File Structure section feels slightly out of place. Consider moving it to the Data Services Pattern section where PageCache is directly referenced and more contextually relevant.
Summary
Good documentation overall. Main action items: (1) fill out the PR template for compliance, (2) verify the relative links, (3) clarify sub-service docs availability.
ciscoRankush
left a comment
There was a problem hiding this comment.
Review: Service Root-level AGENTS.md
Good overall structure — the service routing table, architecture diagram, and AqmReqs factory pattern documentation are valuable for AI agent navigation. A few accuracy issues need fixing before merge, mostly around bootstrap order and event flow.
3 Important | 2 Medium | 2 Minor
| ContactCenter (cc.ts) — public API surface | ||
| │ | ||
| ├── WebexRequest.getInstance({webex}) ← initialized FIRST (singleton) | ||
| ├── Services.getInstance({webex, config}) ← initialized SECOND (singleton) |
There was a problem hiding this comment.
[Important] Services.getInstance({webex, config}) — the second parameter is connectionConfig, not config.
Actual signature in services/index.ts:39:
constructor(options: {webex: WebexSDK; connectionConfig: SubscribeRequest})Suggest:
├── Services.getInstance({webex, connectionConfig}) ← initialized SECOND (singleton)
| ├── TaskManager ← task lifecycle, created after login | ||
| ├── WebCallingService ← WebRTC calling, created on BROWSER login | ||
| ├── AddressBook ← REST data service, created after register | ||
| ├── EntryPoint ← REST data service, created after register | ||
| ├── Queue ← REST data service, created after register | ||
| └── MetricsManager.getInstance({webex}) ← telemetry singleton | ||
| ``` | ||
|
|
||
| ### Bootstrap Order (Critical) | ||
|
|
||
| Understanding the instantiation order is essential — getting it wrong causes runtime errors: | ||
|
|
||
| 1. **`WebexRequest.getInstance({webex})`** — Must be called first. The singleton HTTP client that all services depend on. | ||
| 2. **`Services.getInstance({webex, connectionConfig})`** — Creates `WebSocketManager`, `AqmReqs`, `ConnectionService`, `AgentConfigService`, `routingAgent`, `routingContact`, `aqmDialer`. | ||
| 3. **`MetricsManager.getInstance({webex})`** — Telemetry singleton. | ||
| 4. **Data services** (`AddressBook`, `EntryPoint`, `Queue`) — Created after `register()` succeeds and agent profile is available. | ||
| 5. **`TaskManager`** — Created after `stationLogin()` succeeds. | ||
| 6. **`WebCallingService`** — Created only when `loginOption === 'BROWSER'`. |
There was a problem hiding this comment.
[Important] Bootstrap order is inaccurate. In cc.ts:register() (lines 350-376), all of these are created during register():
WebexRequestServicesWebCallingService(always instantiated; onlyregisterWebCallingLine()is conditional on BROWSER)MetricsManagerTaskManager- Data services (
AddressBook,EntryPoint,Queue)
- Line 170: TaskManager is not created "after login" — it's created in
register(). - Line 171: WebCallingService is not "created on BROWSER login" — it's always created; only line registration is conditional.
- Lines 185-187: Same errors in the numbered list.
Same errors repeat in "What Services does NOT create" section (lines 250-251): "TaskManager — created after successful station login" and "WebCallingService — created only for BROWSER login" are both inaccurate.
| → WebSocketManager emits 'message' | ||
| → AqmReqs.onMessage() — checks if message correlates to a pending request | ||
| → If match: resolves/rejects the pending Promise | ||
| → If no match: ignored by AqmReqs | ||
| → cc.ts webSocketManager.on('message') — routes to appropriate handler: | ||
| → Agent events → emitted on cc EventEmitter (AGENT_EVENTS) | ||
| → Task events → forwarded to TaskManager → Task state machine | ||
| → Connection events → handled by ConnectionService | ||
| ``` |
There was a problem hiding this comment.
[Important] This event flow implies cc.ts is a central router that forwards events to TaskManager and ConnectionService. In reality, there are 4 independent listeners on webSocketManager.on('message'):
AqmReqs—aqm-reqs.ts:20(registered in AqmReqs constructor)cc.ts—cc.ts:358(registered in register())TaskManager—TaskManager.ts:314(registered in registerTaskListeners())ConnectionService—connection-service.ts:44-45(registered in constructor)
cc.ts does not route or forward events to TaskManager or ConnectionService — each listener independently processes the same WebSocket messages.
[Medium] Also, line 359 says "Agent events → emitted on cc EventEmitter" but cc.ts uses two different emission mechanisms: this.emit() (EventEmitter) for agent events and this.trigger() (WebexPlugin) for task events (cc.ts:1075-1177). This distinction matters for consumers subscribing to events.
| ``` | ||
| src/services/ | ||
| ├── index.ts # Services singleton — composes all services | ||
| ├── constants.ts # Shared constants (WCC_API_GATEWAY, API paths) |
There was a problem hiding this comment.
[Medium] constants.ts only gets a one-liner here. This file contains important shared constants that AI agents need when adding new endpoints or services:
WCC_API_GATEWAY— service identifier used in all HTTP requestsSUBSCRIBE_API,LOGIN_API,STATE_CHANGE_API— API path constantsWEB_RTC_PREFIX— prefix for WebRTC endpointsWEBSOCKET_EVENT_TIMEOUT— 20000ms timeoutDEFAULT_RTMS_DOMAIN,WCC_CALLING_RTMS_DOMAIN— WebRTC domain constantsMETHODSobject — WebCallingService method name constants
Consider adding a brief "Shared Constants" section or expanding this annotation so AI agents discover these naming conventions.
|
|
||
| > **Note**: The task state machine (`task/state-machine/`) is part of the Task service, not a separate service. Its dedicated docs live at [`task/state-machine/ai-docs/AGENTS.md`](../task/state-machine/ai-docs/AGENTS.md) and [`ARCHITECTURE.md`](../task/state-machine/ai-docs/ARCHITECTURE.md). Load these when working on state transitions, guards, or actions. | ||
|
|
||
| **Data services** (AddressBook, Queue, EntryPoint) and **WebCallingService** do not have dedicated ai-docs. For these, read the source files directly — they follow the same patterns documented in [`ai-docs/patterns/typescript-patterns.md`](../../../ai-docs/patterns/typescript-patterns.md). |
There was a problem hiding this comment.
[Medium] WebCallingService does not follow "the same patterns documented in typescript-patterns.md" as data services. Data services use REST + pagination + PageCache caching. WebCallingService extends EventEmitter, wraps @webex/calling (createClient/ICallingClient/ILine/ICall), manages call lifecycle with a callTaskMap, and has an async registration flow with timeout — a completely different pattern. Consider noting this distinction rather than grouping it with data services.
| │ │ ├── constants.ts # TaskState, TaskEvent enums | ||
| │ │ ├── types.ts # TaskContext type | ||
| │ │ ├── guards.ts # State transition guards | ||
| │ │ ├── actions.ts # State transition actions |
There was a problem hiding this comment.
[Minor] File tree omits state-machine/index.ts — this file exists and serves as the barrel export for all state machine public API (createTaskStateMachine, TaskState, TaskEvent, guards, actions, createInitialContext, types). Should be listed here alongside the other state machine files.
| | **Caching** | `PageCache<T>` — caches pages for simple pagination, bypasses cache for search/filter | | ||
| | **Metrics** | `timeEvent` on API call start, `trackEvent` on success/failure | | ||
| | **Logging** | `LoggerProxy` with `{module: 'ClassName', method: 'methodName'}` context | | ||
| | **Error handling** | try/catch with `LoggerProxy.error` + `metricsManager.trackEvent` for failures | |
There was a problem hiding this comment.
[Minor] Error handling pattern says "try/catch with LoggerProxy.error + metricsManager.trackEvent" but omits that data services re-throw the error after logging (e.g., AddressBook.ts catch block logs then throws). The re-throw is important — it means errors propagate to callers rather than being silently swallowed.
COMPLETES #< INSERT LINK TO ISSUE >
This pull request addresses
< DESCRIBE THE CONTEXT OF THE ISSUE >
by making the following changes
< DESCRIBE YOUR CHANGES >
Change Type
The following scenarios were tested
< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >
The GAI Coding Policy And Copyright Annotation Best Practices
I certified that
Make sure to have followed the contributing guidelines before submitting.