@ownhelp/widget 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API_CONTRACT.md +14 -3
- package/README.md +15 -1
- package/dist/lib/index.js +400 -272
- package/dist/widget.js +61 -12
- package/package.json +1 -1
package/API_CONTRACT.md
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
This is the contract between the embeddable widget (`widget/`) and the Orchestration Gateway.
|
|
4
4
|
The real implementation is `gateway/src/routes/chat.js`. `widget/mock/mock_gateway.js` is an
|
|
5
5
|
executable reference mock (no retrieval, no generation, no database), and
|
|
6
|
-
`widget/tests/mock_gateway.test.js` checks the widget client against it. The mock
|
|
7
|
-
|
|
6
|
+
`widget/tests/mock_gateway.test.js` checks the widget client against it. The mock mirrors the
|
|
7
|
+
session id format, body size caps and origin check, but with one global origin allowlist instead of
|
|
8
|
+
per-tenant origins, and it has no `GET /api/chat` recording-notice lookup; the real gateway has both.
|
|
8
9
|
|
|
9
10
|
## Request
|
|
10
11
|
|
|
@@ -28,6 +29,15 @@ Accept: text/event-stream, application/json
|
|
|
28
29
|
| `message` | string | Required, non-empty, at most 2000 characters. |
|
|
29
30
|
| `session_id` | string | Required. 16 to 128 characters from `A-Za-z0-9_.:-` (a UUID qualifies). Generated and stored by the widget (`localStorage`, per tenant). Not a credential; the gateway keys conversation history on it. |
|
|
30
31
|
|
|
32
|
+
Optional field: `recording_notice` (boolean). The widget sends `true` only while its "This conversation is
|
|
33
|
+
recorded" notice is on screen. A business that turned on conversation recording has a turn stored only
|
|
34
|
+
when this is `true`, so a client that never showed the notice is never recorded. Any other value, or
|
|
35
|
+
omitting it, means "not recorded".
|
|
36
|
+
|
|
37
|
+
To learn whether to show that notice, the widget calls `GET /api/chat?tenant_id=example_tenant` first. It
|
|
38
|
+
returns `{"record_conversations": true|false}` (same origin check and tenant rules as `POST`; `400`, `403`,
|
|
39
|
+
`404` use the usual error shape). Treat any failure as `false`.
|
|
40
|
+
|
|
31
41
|
The body is limited to 16 KB. The request carries **no cookies and no `Authorization` header**. It is a
|
|
32
42
|
public, anonymous endpoint. The gateway answers CORS itself (`POST, OPTIONS`, `Content-Type` only, no
|
|
33
43
|
credentials) and checks the request `Origin` against the tenant's allowed origins.
|
|
@@ -106,7 +116,8 @@ as a ticket in `ticket_logs`, in the schema the dashboard's review queue already
|
|
|
106
116
|
|
|
107
117
|
The visitor gets the normal reply. When the ticket save succeeds, the gateway can offer email follow-up. One ticket exists per
|
|
108
118
|
conversation: a further escalation updates it (and re-opens it if it was resolved) and keeps the admin's notes
|
|
109
|
-
and contact details. Ordinary answered conversations are not written to the database
|
|
119
|
+
and contact details. Ordinary answered conversations are not written to the database, unless the business
|
|
120
|
+
opted in to conversation recording (see `recording_notice` above). If saving the ticket
|
|
110
121
|
fails, the visitor's reply is unaffected and the failure is logged.
|
|
111
122
|
|
|
112
123
|
## Error responses (before streaming starts)
|
package/README.md
CHANGED
|
@@ -81,6 +81,17 @@ tenant before going live.
|
|
|
81
81
|
The follow-up token is kept in memory only.
|
|
82
82
|
- **Start again:** the header's **New chat** button aborts in-flight requests, clears the form and
|
|
83
83
|
follow-up state, and stores a new session id. Server history and admin tickets are untouched.
|
|
84
|
+
- **Recording notice:** when the business turned on conversation recording, the widget shows
|
|
85
|
+
"This conversation is recorded to improve the assistant." above the input. On first open it asks
|
|
86
|
+
`GET {apiUrl}/api/chat?tenant_id=...`; it sends `recording_notice: true` with messages only while
|
|
87
|
+
that notice is on screen, and the gateway records a turn only then. If the lookup fails, no notice
|
|
88
|
+
is shown and nothing is recorded. Older widget versions never send the flag, so they are never
|
|
89
|
+
recorded. See the [API contract](API_CONTRACT.md).
|
|
90
|
+
- **Phones:** below 640px wide (or on short landscape screens) the open chat fills the screen. It
|
|
91
|
+
follows the visual viewport so the header and greeting stay visible and the input sits above the
|
|
92
|
+
on-screen keyboard, inputs are 16px (no iOS zoom), and the input is not auto-focused on touch
|
|
93
|
+
devices so the keyboard does not cover the greeting. All of this lives inside the widget's shadow
|
|
94
|
+
root; the host page is never modified.
|
|
84
95
|
- Stop and Retry buttons, and fixed visitor-safe error messages, are built in.
|
|
85
96
|
|
|
86
97
|
## Local development
|
|
@@ -95,7 +106,10 @@ npm run build # dist/widget.js (script tag) and dist/lib/index.js (React impor
|
|
|
95
106
|
|
|
96
107
|
In the mock, a message containing `human` returns follow-up metadata, `nostream` the JSON fallback,
|
|
97
108
|
and `ratelimit`, `unknown`, `error`, `cutoff` and `slow` exercise failures (see the header of
|
|
98
|
-
`mock/mock_gateway.js`). The mock saves nothing; use fictional data.
|
|
109
|
+
`mock/mock_gateway.js`). The mock saves nothing; use fictional data. It enforces the real gateway's
|
|
110
|
+
input rules (session id format, size caps, origin allowlist). By default it allows the Vite dev and
|
|
111
|
+
preview origins on localhost and 127.0.0.1; set `MOCK_ALLOWED_ORIGINS` (comma separated) to serve the
|
|
112
|
+
host page from elsewhere.
|
|
99
113
|
|
|
100
114
|
## Publish checklist
|
|
101
115
|
|