@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/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@newheap/platform-ai-chat",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/cdk": "^20.2.14",
|
|
6
|
+
"@angular/common": "^20.3.28",
|
|
7
|
+
"@angular/core": "^20.3.28",
|
|
8
|
+
"@angular/router": "^20.3.28",
|
|
9
|
+
"@ngx-translate/core": "^17.0.0",
|
|
10
|
+
"dompurify": "^3.4.0",
|
|
11
|
+
"marked": "^18.0.0",
|
|
12
|
+
"rxjs": "~7.8.0"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"tslib": "^2.3.0"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
"./i18n/*.json": {
|
|
20
|
+
"default": "./i18n/*.json"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": {
|
|
23
|
+
"default": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./index.d.ts",
|
|
27
|
+
"default": "./fesm2022/newheap-platform-ai-chat.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./admin": {
|
|
30
|
+
"types": "./admin/index.d.ts",
|
|
31
|
+
"default": "./fesm2022/newheap-platform-ai-chat-admin.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./testing": {
|
|
34
|
+
"types": "./testing/index.d.ts",
|
|
35
|
+
"default": "./fesm2022/newheap-platform-ai-chat-testing.mjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"description": "Angular assistant panel for NewHeap AI chat endpoints with streaming, tool-call and approval cards.",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/NewHeap/NewHeap-Platform.git"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/NewHeap/NewHeap-Platform#readme",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/NewHeap/NewHeap-Platform/issues"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"registry": "https://registry.npmjs.org/",
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"module": "fesm2022/newheap-platform-ai-chat.mjs",
|
|
53
|
+
"typings": "index.d.ts"
|
|
54
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { AssistantStatus, AgentSummary, Conversation, ClientContext, AssistantPreferences, ToolCatalogEntry, AdminAgentInput, McpServerInput } from '@newheap/platform-ai-chat';
|
|
2
|
+
import * as _angular_core from '@angular/core';
|
|
3
|
+
import { InjectionToken, EnvironmentProviders } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
/** Streams text as `message.delta` events, split into word-sized pieces. */
|
|
6
|
+
interface NhAssistantMockTextStep {
|
|
7
|
+
/** Fixed text, or text built from the page context the client sent with the message. */
|
|
8
|
+
text: string | ((pageContext: ClientContext | null) => string);
|
|
9
|
+
}
|
|
10
|
+
/** Runs one tool: `tool.started` followed by `tool.completed`. */
|
|
11
|
+
interface NhAssistantMockToolStep {
|
|
12
|
+
tool: {
|
|
13
|
+
toolId: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
toolVersion?: number;
|
|
16
|
+
argumentsPreview?: string | null;
|
|
17
|
+
resultPreview?: string | null;
|
|
18
|
+
/** Default `succeeded`. */
|
|
19
|
+
status?: 'succeeded' | 'failed';
|
|
20
|
+
resultCode?: string | null;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pauses the turn for approval: `tool.started`, `approval.required` and
|
|
25
|
+
* `turn.completed` with status `waiting-for-approval`. The decision resumes the turn with
|
|
26
|
+
* the `approved` or `rejected` steps.
|
|
27
|
+
*/
|
|
28
|
+
interface NhAssistantMockApprovalStep {
|
|
29
|
+
approval: {
|
|
30
|
+
toolId: string;
|
|
31
|
+
displayName: string;
|
|
32
|
+
toolVersion?: number;
|
|
33
|
+
summary: string;
|
|
34
|
+
argumentsPreview: string;
|
|
35
|
+
targets: string[];
|
|
36
|
+
/** Default 300 seconds. */
|
|
37
|
+
expiresInSeconds?: number;
|
|
38
|
+
/** Result preview of the tool after approval. */
|
|
39
|
+
resultPreview?: string | null;
|
|
40
|
+
approved: NhAssistantMockStep[];
|
|
41
|
+
rejected: NhAssistantMockStep[];
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Ends the stream with an `error` event. */
|
|
45
|
+
interface NhAssistantMockErrorStep {
|
|
46
|
+
error: {
|
|
47
|
+
code: string;
|
|
48
|
+
messageKey: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Ends the turn with `turn.completed` status `failed`. */
|
|
52
|
+
interface NhAssistantMockFailStep {
|
|
53
|
+
fail: {
|
|
54
|
+
errorCode: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
type NhAssistantMockStep = NhAssistantMockTextStep | NhAssistantMockToolStep | NhAssistantMockApprovalStep | NhAssistantMockErrorStep | NhAssistantMockFailStep;
|
|
58
|
+
/** A scripted assistant turn, chosen by matching the user's message. */
|
|
59
|
+
interface NhAssistantMockTurn {
|
|
60
|
+
/** Case-insensitive substring, regular expression or predicate. Omit to match every message. */
|
|
61
|
+
match?: string | RegExp | ((text: string, agentId: string, pageContext: ClientContext | null) => boolean);
|
|
62
|
+
steps: NhAssistantMockStep[];
|
|
63
|
+
}
|
|
64
|
+
interface NhAssistantMockTiming {
|
|
65
|
+
/** Delay before the first event of a stream. Default 200 ms. */
|
|
66
|
+
firstEventDelayMs?: number;
|
|
67
|
+
/** Delay between events. Default 40 ms. */
|
|
68
|
+
eventDelayMs?: number;
|
|
69
|
+
/** Size of the byte chunks the stream is cut into, to exercise the client parser. Default 23. */
|
|
70
|
+
chunkSize?: number;
|
|
71
|
+
}
|
|
72
|
+
/** A tool that a simulated remote MCP server lists. */
|
|
73
|
+
interface NhAssistantMockRemoteTool {
|
|
74
|
+
remoteName: string;
|
|
75
|
+
description: string;
|
|
76
|
+
/** Changing the hash between two syncs simulates a changed remote input schema. */
|
|
77
|
+
inputSchemaHash: string;
|
|
78
|
+
/** Remote annotation; the mock passes it on as an untrusted hint. */
|
|
79
|
+
readOnlyHint?: boolean | null;
|
|
80
|
+
}
|
|
81
|
+
/** A simulated MCP server. The mock stores `secret` but never returns it. */
|
|
82
|
+
interface NhAssistantMockMcpServer extends McpServerInput {
|
|
83
|
+
remoteTools?: NhAssistantMockRemoteTool[];
|
|
84
|
+
}
|
|
85
|
+
/** A preconfigured agent. Code agents default to the scenario's chat agents. */
|
|
86
|
+
interface NhAssistantMockAdminAgent extends AdminAgentInput {
|
|
87
|
+
source: 'code' | 'admin';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Administration data of the mock. Hosts without an admin scenario still get working
|
|
91
|
+
* `admin/*` endpoints with code agents derived from `agents` and an empty context.
|
|
92
|
+
*/
|
|
93
|
+
interface NhAssistantMockAdminScenario {
|
|
94
|
+
/** Default `true`. Without it `admin/*` answers `403`. */
|
|
95
|
+
canAdminister?: boolean;
|
|
96
|
+
context?: string;
|
|
97
|
+
/** Tool catalog for the selector picker. Enabled MCP tools are added automatically. */
|
|
98
|
+
tools?: ToolCatalogEntry[];
|
|
99
|
+
agents?: NhAssistantMockAdminAgent[];
|
|
100
|
+
mcpServers?: NhAssistantMockMcpServer[];
|
|
101
|
+
/** Policies the host knows; `requiredPolicy` must be one of them. Default: any value. */
|
|
102
|
+
policies?: string[];
|
|
103
|
+
/** Hosts that may receive the user's token (`forward-user-token`). Default: none. */
|
|
104
|
+
forwardUserTokenHosts?: string[];
|
|
105
|
+
}
|
|
106
|
+
/** The scenario the mock API plays without a back-end. */
|
|
107
|
+
interface NhAssistantMockScenario {
|
|
108
|
+
/** Default `true`. */
|
|
109
|
+
enabled?: boolean;
|
|
110
|
+
limits?: Partial<AssistantStatus['limits']>;
|
|
111
|
+
agents: AgentSummary[];
|
|
112
|
+
/** Conversations that exist before the first request. */
|
|
113
|
+
conversations?: Conversation[];
|
|
114
|
+
/** Tried in order; the first matching turn answers. */
|
|
115
|
+
turns: NhAssistantMockTurn[];
|
|
116
|
+
timing?: NhAssistantMockTiming;
|
|
117
|
+
/** Stored preferences of the caller. Default: default style, informal, normal length. */
|
|
118
|
+
preferences?: AssistantPreferences;
|
|
119
|
+
admin?: NhAssistantMockAdminScenario;
|
|
120
|
+
}
|
|
121
|
+
/** One request the mock API received, for assertions in tests. */
|
|
122
|
+
interface NhAssistantMockRequest {
|
|
123
|
+
method: string;
|
|
124
|
+
path: string;
|
|
125
|
+
headers: Record<string, string>;
|
|
126
|
+
body: unknown;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare const NH_ASSISTANT_MOCK_SCENARIO: InjectionToken<NhAssistantMockScenario>;
|
|
130
|
+
/**
|
|
131
|
+
* In-memory implementation of the assistant HTTP API and its event streams. It keeps
|
|
132
|
+
* conversations, plays scripted turns as contract events through a real
|
|
133
|
+
* `text/event-stream` response and handles approvals, cancellation and the feature flag.
|
|
134
|
+
*/
|
|
135
|
+
declare class NhAssistantMockBackend {
|
|
136
|
+
private readonly scenario;
|
|
137
|
+
private readonly config;
|
|
138
|
+
private readonly conversations;
|
|
139
|
+
private readonly pendingApprovals;
|
|
140
|
+
private readonly runs;
|
|
141
|
+
/** Page context of the latest message per conversation, as the server stores it. */
|
|
142
|
+
private readonly pageContexts;
|
|
143
|
+
private readonly enabledState;
|
|
144
|
+
private readonly admin;
|
|
145
|
+
private readonly canAdministerState;
|
|
146
|
+
private sequence;
|
|
147
|
+
/** Requests received so far, oldest first. */
|
|
148
|
+
readonly requests: NhAssistantMockRequest[];
|
|
149
|
+
readonly enabled: _angular_core.Signal<boolean>;
|
|
150
|
+
readonly canAdminister: _angular_core.Signal<boolean>;
|
|
151
|
+
constructor();
|
|
152
|
+
/** Switches the simulated `NewHeap:AI:Assistant:Enabled` flag. */
|
|
153
|
+
setEnabled(enabled: boolean): void;
|
|
154
|
+
/** Switches whether the caller passes the admin policy (`canAdminister`, `admin/*`). */
|
|
155
|
+
setCanAdminister(canAdminister: boolean): void;
|
|
156
|
+
/** Replaces the tools a simulated MCP server lists; the next sync picks them up. */
|
|
157
|
+
setRemoteTools(serverId: string, tools: NhAssistantMockRemoteTool[]): void;
|
|
158
|
+
/** A `fetch` implementation that answers the assistant endpoints below `apiBaseUrl`. */
|
|
159
|
+
readonly fetch: (input: string, init: RequestInit) => Promise<Response>;
|
|
160
|
+
private route;
|
|
161
|
+
private list;
|
|
162
|
+
private create;
|
|
163
|
+
private sendMessage;
|
|
164
|
+
private decide;
|
|
165
|
+
private cancel;
|
|
166
|
+
private playSteps;
|
|
167
|
+
private pauseForApproval;
|
|
168
|
+
private stream;
|
|
169
|
+
private findTurn;
|
|
170
|
+
private update;
|
|
171
|
+
private nextId;
|
|
172
|
+
private result;
|
|
173
|
+
private json;
|
|
174
|
+
private empty;
|
|
175
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<NhAssistantMockBackend, never>;
|
|
176
|
+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<NhAssistantMockBackend>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Replaces the assistant transport with an in-memory back-end that plays `script`.
|
|
181
|
+
* Register it after `provideNhAssistant(...)` in the same injector. Every client feature
|
|
182
|
+
* (status, agents, conversations, streamed turns, approvals, cancellation) then works
|
|
183
|
+
* without a server. Inject `NhAssistantMockBackend` to switch the feature flag or to
|
|
184
|
+
* inspect the received requests.
|
|
185
|
+
*/
|
|
186
|
+
declare function provideNhAssistantMockApi(script: NhAssistantMockScenario): EnvironmentProviders;
|
|
187
|
+
|
|
188
|
+
export { NH_ASSISTANT_MOCK_SCENARIO, NhAssistantMockBackend, provideNhAssistantMockApi };
|
|
189
|
+
export type { NhAssistantMockAdminAgent, NhAssistantMockAdminScenario, NhAssistantMockApprovalStep, NhAssistantMockErrorStep, NhAssistantMockFailStep, NhAssistantMockMcpServer, NhAssistantMockRemoteTool, NhAssistantMockRequest, NhAssistantMockScenario, NhAssistantMockStep, NhAssistantMockTextStep, NhAssistantMockTiming, NhAssistantMockToolStep, NhAssistantMockTurn };
|