@newheap/platform-ai-chat 0.1.0
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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +294 -0
- package/admin/index.d.ts +294 -0
- package/fesm2022/newheap-platform-ai-chat-admin.mjs +785 -0
- package/fesm2022/newheap-platform-ai-chat-admin.mjs.map +1 -0
- package/fesm2022/newheap-platform-ai-chat-testing.mjs +911 -0
- package/fesm2022/newheap-platform-ai-chat-testing.mjs.map +1 -0
- package/fesm2022/newheap-platform-ai-chat.mjs +3103 -0
- package/fesm2022/newheap-platform-ai-chat.mjs.map +1 -0
- package/i18n/en.json +376 -0
- package/i18n/nl.json +376 -0
- package/index.d.ts +937 -0
- package/package.json +54 -0
- package/testing/index.d.ts +189 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# @newheap/platform-ai-chat
|
|
2
|
+
|
|
3
|
+
Angular assistant panel for NewHeap AI chat endpoints with streaming, tool-call and approval cards.
|
|
4
|
+
|
|
5
|
+
The package talks to the assistant HTTP API of `NewHeap.Platform.AI.Chat.AspNet`
|
|
6
|
+
(`MapNewHeapAssistant("/api/assistant")`): it lists agents and conversations,
|
|
7
|
+
streams turns as server-sent events, shows tool calls, and pauses mutations on an
|
|
8
|
+
approval card until the user approves or rejects them. It has no dependency on
|
|
9
|
+
ng-bootstrap or on a specific authentication library; the host supplies the token
|
|
10
|
+
and the access decision.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
The package is public on npmjs.org and installs without a registry token. An optional project `.npmrc` can make the public source explicit:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
registry=https://registry.npmjs.org/
|
|
18
|
+
@newheap:registry=https://registry.npmjs.org/
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Install the package with its peer dependencies:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @newheap/platform-ai-chat @angular/cdk @angular/router marked dompurify
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
View available versions on [npmjs.org](https://www.npmjs.com/package/@newheap/platform-ai-chat). For NuGet, npm and AI-plugin installation, see [Consume public packages](../../../../docs/how-to/consume-public-packages.md).
|
|
28
|
+
|
|
29
|
+
Peer dependencies: Angular `^20.3.28` (`@angular/core`, `@angular/common`),
|
|
30
|
+
`@angular/cdk` `^20.2.14`, `@angular/router` `^20.3.28`, `@ngx-translate/core` `^17.0.0`, `marked` `^18.0.0`,
|
|
31
|
+
`dompurify` `^3.4.0` and `rxjs` `~7.8.0`.
|
|
32
|
+
|
|
33
|
+
The panel is a CDK overlay. Load the CDK overlay styles once, for example in
|
|
34
|
+
`angular.json`:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
"styles": [
|
|
38
|
+
"node_modules/@angular/cdk/overlay-prebuilt.css",
|
|
39
|
+
"src/styles.scss"
|
|
40
|
+
]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Providers
|
|
44
|
+
|
|
45
|
+
Register the assistant once in the root providers:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { ApplicationConfig, Injectable, inject } from '@angular/core';
|
|
49
|
+
import { NhAssistantAccessPolicy, provideNhAssistant } from '@newheap/platform-ai-chat';
|
|
50
|
+
import { map } from 'rxjs';
|
|
51
|
+
|
|
52
|
+
@Injectable()
|
|
53
|
+
export class AssistantAccessPolicy implements NhAssistantAccessPolicy {
|
|
54
|
+
private readonly auth = inject(AppAuthService);
|
|
55
|
+
|
|
56
|
+
canUse() {
|
|
57
|
+
return this.auth.authSubject.pipe(map(() => this.auth.isOnePermissionGranted(['app.assistant.access'])));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const appConfig: ApplicationConfig = {
|
|
62
|
+
providers: [
|
|
63
|
+
provideNhAssistant({
|
|
64
|
+
apiBaseUrl: environment.api.baseUrl + '/assistant',
|
|
65
|
+
getAccessToken: () => inject(AppAuthService).getAuthorization()?.token ?? null,
|
|
66
|
+
accessPolicy: AssistantAccessPolicy,
|
|
67
|
+
defaultAgentId: 'order-assistant',
|
|
68
|
+
adminRoute: '/admin/assistant'
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Option | Default | Meaning |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `apiBaseUrl` | required | Base URL of the assistant endpoints. |
|
|
77
|
+
| `getAccessToken` | required | Returns the bearer token or `null`. Runs in the assistant's injection context before every request, so it may use `inject(...)`. |
|
|
78
|
+
| `accessPolicy` | always allowed | Injectable class whose `canUse()` returns a boolean or an observable. |
|
|
79
|
+
| `defaultAgentId` | first agent | Agent selected for new conversations. |
|
|
80
|
+
| `translations` | `'bundled'` | `'bundled'` merges the library's `en` and `nl` texts into `TranslateService`; `'host'` leaves all texts to the host. |
|
|
81
|
+
| `getPageContext` | none | Returns what the user has open (`{ route, title?, entities? }`). Runs in the assistant's injection context when the panel opens and before every message; see [Page context](#page-context). |
|
|
82
|
+
| `adminRoute` | none | Router link of the host's administration page. The panel links to it only when the server reports `canAdminister`. |
|
|
83
|
+
| `markdown` | `{ enabled: true }` | Renders assistant text as sanitized Markdown; `false` shows plain text. |
|
|
84
|
+
|
|
85
|
+
Requests use `fetch` instead of the host's `HttpClient`, because `EventSource`
|
|
86
|
+
cannot send an `Authorization` header and streamed responses must bypass response
|
|
87
|
+
interceptors. Every request carries `Authorization: Bearer <token>` when a token
|
|
88
|
+
exists and `Accept-Language` from `TranslateService`.
|
|
89
|
+
|
|
90
|
+
## Host integration
|
|
91
|
+
|
|
92
|
+
Place the launcher in the header and one panel in the layout:
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<header>
|
|
96
|
+
<nh-assistant-launcher />
|
|
97
|
+
</header>
|
|
98
|
+
<router-outlet />
|
|
99
|
+
<nh-assistant-panel />
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The launcher renders nothing while `GET status` reports `enabled: false`, the
|
|
103
|
+
endpoint is unavailable, or the access policy denies the user. It shows a badge
|
|
104
|
+
when a conversation waits for approval. Projected content replaces its default
|
|
105
|
+
icon. Other components open the panel through `NhAssistantPanelService`:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
inject(NhAssistantPanelService).open(conversationId);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The drawer is 420 px wide on the right and fills the screen below 600 px. Escape
|
|
112
|
+
closes it and focus returns to the element that opened it.
|
|
113
|
+
|
|
114
|
+
`NhAssistantStore` exposes the state as signals (`enabled`, `agents`,
|
|
115
|
+
`conversations`, `activeConversation`, `streaming`, `pendingApproval`, `error` and
|
|
116
|
+
more) and the actions `send`, `decide`, `cancel`, `openConversation`,
|
|
117
|
+
`startNewConversation` and `selectAgent`. The building blocks
|
|
118
|
+
`nh-assistant-thread`, `nh-assistant-composer`, `nh-assistant-conversation-list`,
|
|
119
|
+
`nh-assistant-tool-call-card`, `nh-assistant-approval-card` and
|
|
120
|
+
`nh-assistant-agent-picker` are exported for custom layouts. All components are
|
|
121
|
+
standalone and use `OnPush`.
|
|
122
|
+
|
|
123
|
+
Assistant text is rendered as Markdown with `marked` and sanitized with DOMPurify
|
|
124
|
+
against a small allow-list. Inline HTML in model text is shown as text, images
|
|
125
|
+
render as their alt text, `javascript:` and `data:` links lose their target, and
|
|
126
|
+
links open in a new tab with `rel="noopener noreferrer"`.
|
|
127
|
+
|
|
128
|
+
## Page context
|
|
129
|
+
|
|
130
|
+
With `getPageContext` every message carries what the user has open, so the model can
|
|
131
|
+
answer "this project" without asking:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
getPageContext: () => inject(CurrentPage).value() ?? { route: inject(Router).url, title: inject(Title).getTitle() }
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// On a project page
|
|
139
|
+
this.currentPage.set({
|
|
140
|
+
route: `/projects/${project.key}`,
|
|
141
|
+
title: project.name,
|
|
142
|
+
entities: [{ type: 'project', id: project.key, label: `Project ${project.key}` }]
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The library validates and truncates the result: route at most 200 characters, title
|
|
147
|
+
and labels at most 120, at most five entities with a dash-case `type` and an `id` of
|
|
148
|
+
at most 64 characters. Entities with an invalid type or id are dropped rather than
|
|
149
|
+
truncated. An invalid shape, an exception or a rejected promise leaves the context out
|
|
150
|
+
of that message; sending continues. A chip above the message box shows what is sent;
|
|
151
|
+
its close button leaves the context out of the next message, which then sends
|
|
152
|
+
`clientContext: null`. Page context is untrusted data: the server treats entity ids as
|
|
153
|
+
search hints and still authorizes every tool call.
|
|
154
|
+
|
|
155
|
+
## Preferences
|
|
156
|
+
|
|
157
|
+
The panel header opens `nh-assistant-preferences`. Users choose a style (standard,
|
|
158
|
+
straight to the point, personal or detailed), the form of address, the answer length
|
|
159
|
+
and optional own instructions of at most 1,000 characters. The component loads and
|
|
160
|
+
saves through `NhAssistantApiService.getPreferences()` and `updatePreferences()`.
|
|
161
|
+
Preferences steer the style only; the server keeps them below the application
|
|
162
|
+
context and the agent instructions and never lets them change approvals or tool
|
|
163
|
+
access.
|
|
164
|
+
|
|
165
|
+
## Administration
|
|
166
|
+
|
|
167
|
+
The administration page is a separate entry point, so it stays out of the initial
|
|
168
|
+
bundle. Route to it lazily behind the host's admin permission and pass the route as
|
|
169
|
+
`adminRoute`:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
{
|
|
173
|
+
path: 'admin/assistant',
|
|
174
|
+
canActivate: [IsAssistantAdministratorGuard],
|
|
175
|
+
loadComponent: () => import('@newheap/platform-ai-chat/admin').then(module => module.NhAssistantAdminComponent)
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`nh-assistant-admin` shows a no-access state unless the server reports
|
|
180
|
+
`canAdminister`, and has three tabs:
|
|
181
|
+
|
|
182
|
+
- **Context**: the application context with its version and hash, the version
|
|
183
|
+
history and a conflict message instead of overwriting a newer version.
|
|
184
|
+
- **Agents**: code agents (override, disable, reset) and agents created by
|
|
185
|
+
administrators (edit, disable, delete). The editor chooses tool selectors from the
|
|
186
|
+
tool catalog or as patterns and assigns MCP servers.
|
|
187
|
+
- **MCP servers**: server editor, connection test, tool sync and the tool table.
|
|
188
|
+
The secret is write-only: the page shows only whether one is set and offers to
|
|
189
|
+
replace or clear it. Synced tools start disabled and are treated as changes until
|
|
190
|
+
an administrator enables them and chooses the effect; remote annotations such as
|
|
191
|
+
`readOnlyHint` appear as hints only, and a changed remote input schema disables the
|
|
192
|
+
tool and shows a warning.
|
|
193
|
+
|
|
194
|
+
`NhAssistantAdminApiService` (main entry) is the typed client of the `admin/*`
|
|
195
|
+
endpoints. A `409` becomes the code `assistant-version-conflict`.
|
|
196
|
+
|
|
197
|
+
## Theme
|
|
198
|
+
|
|
199
|
+
The components define light and dark defaults and follow `prefers-color-scheme`.
|
|
200
|
+
Map them onto the host's design tokens with custom properties:
|
|
201
|
+
|
|
202
|
+
```scss
|
|
203
|
+
:root {
|
|
204
|
+
--nh-assistant-font: var(--font-sans);
|
|
205
|
+
--nh-assistant-background: var(--surface);
|
|
206
|
+
--nh-assistant-surface: var(--surface-subtle);
|
|
207
|
+
--nh-assistant-text: var(--ink);
|
|
208
|
+
--nh-assistant-text-muted: var(--muted);
|
|
209
|
+
--nh-assistant-border: var(--line);
|
|
210
|
+
--nh-assistant-accent: var(--primary);
|
|
211
|
+
--nh-assistant-highlight: var(--brand);
|
|
212
|
+
--nh-assistant-focus: var(--accent);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Further properties: `--nh-assistant-surface-strong`, `-accent-contrast`,
|
|
217
|
+
`-user-bubble`, `-user-text`, `-success`, `-success-soft`, `-warning`,
|
|
218
|
+
`-warning-soft`, `-danger`, `-danger-soft`, `-shadow`, `-radius`,
|
|
219
|
+
`-radius-control`, `-font-mono`, and `--nh-assistant-launcher-size`, `-color`,
|
|
220
|
+
`-background`, `-border` and `-badge-ring` for the launcher.
|
|
221
|
+
|
|
222
|
+
Use the host's icon library through `NH_ASSISTANT_ICONS`; icons without a class
|
|
223
|
+
use small built-in outline glyphs:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
{ provide: NH_ASSISTANT_ICONS, useValue: { assistant: 'ph ph-sparkle', close: 'ph ph-x', send: 'ph ph-paper-plane-right' } }
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Translations
|
|
230
|
+
|
|
231
|
+
All keys live under `nh-assistant.`. With `translations: 'bundled'` the library
|
|
232
|
+
merges its `en` and `nl` texts whenever the host loads a language; other
|
|
233
|
+
languages receive English. Keys the host defines under `nh-assistant.` win, so a
|
|
234
|
+
host adds only what the server decides:
|
|
235
|
+
|
|
236
|
+
```json
|
|
237
|
+
{
|
|
238
|
+
"nh-assistant": {
|
|
239
|
+
"agents": {
|
|
240
|
+
"order-assistant": { "name": "Order assistant", "description": "Answers questions about orders." }
|
|
241
|
+
},
|
|
242
|
+
"errors": { "assistant-budget-exceeded": "The daily assistant budget is used up." }
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Error events are shown through their `messageKey`, then `nh-assistant.errors.<code>`,
|
|
248
|
+
then a generic text. Tool result codes use `nh-assistant.result-codes.<code>` and
|
|
249
|
+
fall back to the code. With `translations: 'host'`, copy the bundles from
|
|
250
|
+
`NH_ASSISTANT_TRANSLATIONS` or from `@newheap/platform-ai-chat/i18n/en.json` and
|
|
251
|
+
`nl.json`.
|
|
252
|
+
|
|
253
|
+
## Mock API
|
|
254
|
+
|
|
255
|
+
`@newheap/platform-ai-chat/testing` plays a scripted assistant without a back-end,
|
|
256
|
+
for tests, demos and front-end work before the API exists:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { provideNhAssistantMockApi } from '@newheap/platform-ai-chat/testing';
|
|
260
|
+
|
|
261
|
+
providers: [
|
|
262
|
+
provideNhAssistant({ apiBaseUrl: '/api/assistant', getAccessToken: () => null }),
|
|
263
|
+
provideNhAssistantMockApi({
|
|
264
|
+
agents: [{ id: 'demo', version: 1, displayNameKey: 'nh-assistant.agents.demo.name', descriptionKey: 'nh-assistant.agents.demo.description', canMutate: true }],
|
|
265
|
+
turns: [
|
|
266
|
+
{
|
|
267
|
+
match: /hold/i,
|
|
268
|
+
steps: [{
|
|
269
|
+
approval: {
|
|
270
|
+
toolId: 'orders.update-status', displayName: 'Update status', summary: 'Put order 42 on hold',
|
|
271
|
+
argumentsPreview: '{"id":42}', targets: ['Order 42'],
|
|
272
|
+
approved: [{ text: 'Order 42 is on hold.' }], rejected: [{ text: 'Nothing changed.' }]
|
|
273
|
+
}
|
|
274
|
+
}]
|
|
275
|
+
},
|
|
276
|
+
{ steps: [{ tool: { toolId: 'orders.list', displayName: 'List orders' } }, { text: 'There are **3** open orders.' }] }
|
|
277
|
+
]
|
|
278
|
+
})
|
|
279
|
+
]
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Steps are `text`, `tool`, `approval`, `error` and `fail`. The optional `preferences`
|
|
283
|
+
and `admin` parts of the scenario seed the preference and administration endpoints:
|
|
284
|
+
context, tool catalog, agents, MCP servers with simulated remote tools, known
|
|
285
|
+
policies and hosts that may receive the user's token. The mock answers every
|
|
286
|
+
endpoint in memory and sends each turn as contract events over a chunked
|
|
287
|
+
`text/event-stream` response, so the real client, parser and store run unchanged.
|
|
288
|
+
Inject `NhAssistantMockBackend` to switch the simulated feature flag with
|
|
289
|
+
`setEnabled(false)`, the admin permission with `setCanAdminister(false)`, to change
|
|
290
|
+
the remote tools of a server with `setRemoteTools(...)` or to assert the received
|
|
291
|
+
`requests`.
|
|
292
|
+
|
|
293
|
+
The SampleProjectManagement management portal shows the complete integration
|
|
294
|
+
(sample cases SPM-248 and SPM-253).
|