@bringg/dashboard-sdk 9.81.0 → 9.82.0-pre.3

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.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * api-gateway path prefix the analyst service is registered under.
3
+ *
4
+ * From `analyst-service/helm/service/_default.yaml`:
5
+ *
6
+ * service:
7
+ * endpoints:
8
+ * - path: /analyst-service
9
+ * stripPath: true
10
+ *
11
+ * `stripPath: true` means the gateway strips the prefix before forwarding, so the service receives
12
+ * `/analyst/threads` rather than `/analyst-service/analyst/threads`.
13
+ */
14
+ export declare const GATEWAY_PATH = "/analyst-service";
15
+ /**
16
+ * The graph this chat talks to, and the first segment of every path below.
17
+ *
18
+ * The service mounts one path per graph, so the URL - not a request field - is what selects the
19
+ * agent. That is why the old `agent_id` on the request body no longer exists.
20
+ */
21
+ export declare const GRAPH = "analyst";
22
+ /**
23
+ * Routes from the ag-ui contract (Confluence 5278728195, §3).
24
+ *
25
+ * `CHAT` is declared here for completeness but is **not** called from this package: it is the ag-ui
26
+ * protocol endpoint, opened by the consumer's `HttpAgent` as a streaming POST. It is exposed through
27
+ * {@link AnalystClientConfig.chatUrl} instead, so the URL is still built in one place.
28
+ *
29
+ * Note the paths deliberately do not say `agui`. If the protocol is replaced again, these do not
30
+ * have to change.
31
+ */
32
+ export declare const Routes: {
33
+ CHAT: string;
34
+ CANCEL_RUN: string;
35
+ THREADS: string;
36
+ THREAD: string;
37
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Routes = exports.GRAPH = exports.GATEWAY_PATH = void 0;
4
+ /**
5
+ * api-gateway path prefix the analyst service is registered under.
6
+ *
7
+ * From `analyst-service/helm/service/_default.yaml`:
8
+ *
9
+ * service:
10
+ * endpoints:
11
+ * - path: /analyst-service
12
+ * stripPath: true
13
+ *
14
+ * `stripPath: true` means the gateway strips the prefix before forwarding, so the service receives
15
+ * `/analyst/threads` rather than `/analyst-service/analyst/threads`.
16
+ */
17
+ exports.GATEWAY_PATH = '/analyst-service';
18
+ /**
19
+ * The graph this chat talks to, and the first segment of every path below.
20
+ *
21
+ * The service mounts one path per graph, so the URL - not a request field - is what selects the
22
+ * agent. That is why the old `agent_id` on the request body no longer exists.
23
+ */
24
+ exports.GRAPH = 'analyst';
25
+ /**
26
+ * Routes from the ag-ui contract (Confluence 5278728195, §3).
27
+ *
28
+ * `CHAT` is declared here for completeness but is **not** called from this package: it is the ag-ui
29
+ * protocol endpoint, opened by the consumer's `HttpAgent` as a streaming POST. It is exposed through
30
+ * {@link AnalystClientConfig.chatUrl} instead, so the URL is still built in one place.
31
+ *
32
+ * Note the paths deliberately do not say `agui`. If the protocol is replaced again, these do not
33
+ * have to change.
34
+ */
35
+ exports.Routes = {
36
+ CHAT: "".concat(exports.GATEWAY_PATH, "/").concat(exports.GRAPH, "/chat"),
37
+ CANCEL_RUN: "".concat(exports.GATEWAY_PATH, "/").concat(exports.GRAPH, "/chat/cancel"),
38
+ THREADS: "".concat(exports.GATEWAY_PATH, "/").concat(exports.GRAPH, "/threads"),
39
+ THREAD: "".concat(exports.GATEWAY_PATH, "/").concat(exports.GRAPH, "/threads/{:threadId}")
40
+ };
41
+ //# sourceMappingURL=Analyst.consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Analyst.consts.js","sourceRoot":"","sources":["../../src/Analyst/Analyst.consts.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACU,QAAA,YAAY,GAAG,kBAAkB,CAAC;AAE/C;;;;;GAKG;AACU,QAAA,KAAK,GAAG,SAAS,CAAC;AAE/B;;;;;;;;;GASG;AACU,QAAA,MAAM,GAAG;IACrB,IAAI,EAAE,UAAG,oBAAY,cAAI,aAAK,UAAO;IACrC,UAAU,EAAE,UAAG,oBAAY,cAAI,aAAK,iBAAc;IAClD,OAAO,EAAE,UAAG,oBAAY,cAAI,aAAK,aAAU;IAC3C,MAAM,EAAE,UAAG,oBAAY,cAAI,aAAK,yBAAsB;CACtD,CAAC"}
@@ -0,0 +1,91 @@
1
+ import type { AnalystChat } from '@bringg/types';
2
+ import Session from '../Services/Identity/Session';
3
+ /**
4
+ * Connection details for the Analyst agent's protocol client.
5
+ *
6
+ * Deliberately a plain object rather than a constructed client. The consumer builds the client
7
+ * itself - see the note on {@link Analyst}.
8
+ */
9
+ export interface AnalystClientConfig {
10
+ /** Host and gateway prefix, with no graph or endpoint path on it. */
11
+ apiUrl: string;
12
+ /** The exact URL a turn is posted to. Built here so no consumer concatenates the path itself. */
13
+ chatUrl: string;
14
+ /** Applied to every request. */
15
+ defaultHeaders: Record<string, string>;
16
+ }
17
+ /**
18
+ * Where the dashboard reaches the Analyst agent, and how it authenticates.
19
+ *
20
+ * The browser never talks to analyst-service directly - it is reached through api-gateway under a
21
+ * path prefix, exactly like `data-query-service`. The service declares `bringg-jwt`, but no JWT
22
+ * exists client-side: the gateway performs the exchange from the ordinary Bringg session token, so
23
+ * we send the same `Authorization: Token token=...` plus `Client` that every other non-hagmonia
24
+ * call sends.
25
+ *
26
+ * **Why config and not a client.** Under ag-ui the chat is a single streaming POST, opened by
27
+ * `HttpAgent` from `@ag-ui/client` and answered with `text/event-stream` until the turn ends. A
28
+ * method returning a `Promise` cannot express that, and the client that can is a browser concern
29
+ * bound to a React lifecycle. So the split falls naturally: this package owns *where and how to
30
+ * connect*, which it already knows from `Session`, and the consumer owns the transport.
31
+ *
32
+ * ```ts
33
+ * const { chatUrl, defaultHeaders } = sdk.analyst.getClientConfig();
34
+ * const agent = new HttpAgent({ url: chatUrl, headers: defaultHeaders });
35
+ * ```
36
+ *
37
+ * Everything the dashboard requests *itself* - the thread list, one thread, cancelling a run - is an
38
+ * ordinary SDK call on this class, typed from the `AnalystChat` contract in `@bringg/types` so the
39
+ * shape is enforced by the compiler in both this repo and analyst-service.
40
+ */
41
+ export declare class Analyst {
42
+ private readonly session;
43
+ private cached?;
44
+ private readonly entity;
45
+ constructor(session: Session);
46
+ /**
47
+ * The signed-in user's conversations, most recently active first.
48
+ *
49
+ * Carries no messages - the History list stays cheap, and opening a conversation hydrates it
50
+ * through {@link getThread}.
51
+ */
52
+ listThreads(): Promise<AnalystChat.ThreadSummary[]>;
53
+ /**
54
+ * One conversation, with its messages and whether a run is executing on it right now.
55
+ *
56
+ * `activeRun` is the load-bearing field: a run belongs to the server and outlives the connection
57
+ * that started it, so a caller opening a thread has to attach to that run rather than ask a new
58
+ * question - and must not accept typing meanwhile, because a normal post to a busy thread is
59
+ * answered with the running turn's feed and the typed message is discarded.
60
+ *
61
+ * Rejects on 404, which is also the answer for a thread belonging to someone else: the service
62
+ * deliberately does not distinguish "not yours" from "not there".
63
+ */
64
+ getThread(threadId: string): Promise<AnalystChat.ThreadDetail>;
65
+ /**
66
+ * Cancel the run in flight on a thread.
67
+ *
68
+ * Aborting the stream client-side stops events arriving but leaves the agent running, so Stop has
69
+ * to be this call rather than an abort. `cancelled: false` means the thread was already idle -
70
+ * a normal answer, not a failure.
71
+ *
72
+ * A cancelled run ends with no terminal event: the stream simply closes, with neither
73
+ * `RUN_FINISHED` nor `RUN_ERROR`. Callers that drive their loading state off terminal events
74
+ * alone will hang, and must treat stream close as its own case.
75
+ */
76
+ cancelRun(threadId: string): Promise<AnalystChat.CancelRunResponse>;
77
+ /**
78
+ * Returns the **same object** while the values are unchanged.
79
+ *
80
+ * Referential stability is load-bearing, not a micro-optimisation: a protocol client treats its
81
+ * config as a dependency and rebuilds itself whenever the identity changes. A fresh object per
82
+ * call rebuilds on every render, which refetches, which renders again - a loop.
83
+ *
84
+ * Recomputed each call and compared by value, so a changed session (login, region switch,
85
+ * impersonation) still produces a new config rather than a stale one.
86
+ */
87
+ getClientConfig(): AnalystClientConfig;
88
+ /** Matches the headers `ServiceRequest` builds for every other service. */
89
+ private getDefaultHeaders;
90
+ }
91
+ export default Analyst;
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.Analyst = void 0;
43
+ var Analyst_consts_1 = require("./Analyst.consts");
44
+ var AnalystEntity_1 = __importDefault(require("./Entity/AnalystEntity"));
45
+ var isSameConfig = function (a, b) {
46
+ if (a.apiUrl !== b.apiUrl || a.chatUrl !== b.chatUrl) {
47
+ return false;
48
+ }
49
+ var keys = Object.keys(a.defaultHeaders);
50
+ return (keys.length === Object.keys(b.defaultHeaders).length &&
51
+ keys.every(function (key) { return a.defaultHeaders[key] === b.defaultHeaders[key]; }));
52
+ };
53
+ /**
54
+ * Where the dashboard reaches the Analyst agent, and how it authenticates.
55
+ *
56
+ * The browser never talks to analyst-service directly - it is reached through api-gateway under a
57
+ * path prefix, exactly like `data-query-service`. The service declares `bringg-jwt`, but no JWT
58
+ * exists client-side: the gateway performs the exchange from the ordinary Bringg session token, so
59
+ * we send the same `Authorization: Token token=...` plus `Client` that every other non-hagmonia
60
+ * call sends.
61
+ *
62
+ * **Why config and not a client.** Under ag-ui the chat is a single streaming POST, opened by
63
+ * `HttpAgent` from `@ag-ui/client` and answered with `text/event-stream` until the turn ends. A
64
+ * method returning a `Promise` cannot express that, and the client that can is a browser concern
65
+ * bound to a React lifecycle. So the split falls naturally: this package owns *where and how to
66
+ * connect*, which it already knows from `Session`, and the consumer owns the transport.
67
+ *
68
+ * ```ts
69
+ * const { chatUrl, defaultHeaders } = sdk.analyst.getClientConfig();
70
+ * const agent = new HttpAgent({ url: chatUrl, headers: defaultHeaders });
71
+ * ```
72
+ *
73
+ * Everything the dashboard requests *itself* - the thread list, one thread, cancelling a run - is an
74
+ * ordinary SDK call on this class, typed from the `AnalystChat` contract in `@bringg/types` so the
75
+ * shape is enforced by the compiler in both this repo and analyst-service.
76
+ */
77
+ var Analyst = /** @class */ (function () {
78
+ function Analyst(session) {
79
+ this.session = session;
80
+ this.entity = new AnalystEntity_1.default(session);
81
+ }
82
+ /**
83
+ * The signed-in user's conversations, most recently active first.
84
+ *
85
+ * Carries no messages - the History list stays cheap, and opening a conversation hydrates it
86
+ * through {@link getThread}.
87
+ */
88
+ Analyst.prototype.listThreads = function () {
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ return __generator(this, function (_a) {
91
+ return [2 /*return*/, this.entity.listThreads()];
92
+ });
93
+ });
94
+ };
95
+ /**
96
+ * One conversation, with its messages and whether a run is executing on it right now.
97
+ *
98
+ * `activeRun` is the load-bearing field: a run belongs to the server and outlives the connection
99
+ * that started it, so a caller opening a thread has to attach to that run rather than ask a new
100
+ * question - and must not accept typing meanwhile, because a normal post to a busy thread is
101
+ * answered with the running turn's feed and the typed message is discarded.
102
+ *
103
+ * Rejects on 404, which is also the answer for a thread belonging to someone else: the service
104
+ * deliberately does not distinguish "not yours" from "not there".
105
+ */
106
+ Analyst.prototype.getThread = function (threadId) {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ return __generator(this, function (_a) {
109
+ return [2 /*return*/, this.entity.getThread(threadId)];
110
+ });
111
+ });
112
+ };
113
+ /**
114
+ * Cancel the run in flight on a thread.
115
+ *
116
+ * Aborting the stream client-side stops events arriving but leaves the agent running, so Stop has
117
+ * to be this call rather than an abort. `cancelled: false` means the thread was already idle -
118
+ * a normal answer, not a failure.
119
+ *
120
+ * A cancelled run ends with no terminal event: the stream simply closes, with neither
121
+ * `RUN_FINISHED` nor `RUN_ERROR`. Callers that drive their loading state off terminal events
122
+ * alone will hang, and must treat stream close as its own case.
123
+ */
124
+ Analyst.prototype.cancelRun = function (threadId) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ return __generator(this, function (_a) {
127
+ return [2 /*return*/, this.entity.cancelRun(threadId)];
128
+ });
129
+ });
130
+ };
131
+ /**
132
+ * Returns the **same object** while the values are unchanged.
133
+ *
134
+ * Referential stability is load-bearing, not a micro-optimisation: a protocol client treats its
135
+ * config as a dependency and rebuilds itself whenever the identity changes. A fresh object per
136
+ * call rebuilds on every render, which refetches, which renders again - a loop.
137
+ *
138
+ * Recomputed each call and compared by value, so a changed session (login, region switch,
139
+ * impersonation) still produces a new config rather than a stale one.
140
+ */
141
+ Analyst.prototype.getClientConfig = function () {
142
+ // Resolved from the SIGNED-IN USER's region, not the environment default: a user's region can
143
+ // differ from it, and resolving against the default points them at the wrong cluster.
144
+ var apiEndpoint = this.session.config.getApiEndpoint().encode();
145
+ var next = {
146
+ apiUrl: "".concat(apiEndpoint).concat(Analyst_consts_1.GATEWAY_PATH),
147
+ chatUrl: "".concat(apiEndpoint).concat(Analyst_consts_1.Routes.CHAT),
148
+ defaultHeaders: this.getDefaultHeaders()
149
+ };
150
+ if (this.cached && isSameConfig(this.cached, next)) {
151
+ return this.cached;
152
+ }
153
+ this.cached = next;
154
+ return next;
155
+ };
156
+ /** Matches the headers `ServiceRequest` builds for every other service. */
157
+ Analyst.prototype.getDefaultHeaders = function () {
158
+ var _a;
159
+ var headers = {};
160
+ var token = (_a = this.session.user) === null || _a === void 0 ? void 0 : _a.authentication_token;
161
+ if (token) {
162
+ headers.Authorization = "Token token=".concat(token);
163
+ }
164
+ if (this.session.clientId) {
165
+ headers.Client = String(this.session.clientId);
166
+ }
167
+ return headers;
168
+ };
169
+ return Analyst;
170
+ }());
171
+ exports.Analyst = Analyst;
172
+ exports.default = Analyst;
173
+ //# sourceMappingURL=Analyst.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Analyst.js","sourceRoot":"","sources":["../../src/Analyst/Analyst.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,mDAAwD;AACxD,yEAAmD;AAiBnD,IAAM,YAAY,GAAG,UAAC,CAAsB,EAAE,CAAsB;IACnE,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,EAAE;QACrD,OAAO,KAAK,CAAC;KACb;IAED,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;IAE3C,OAAO,CACN,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,MAAM;QACpD,IAAI,CAAC,KAAK,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAA/C,CAA+C,CAAC,CAClE,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IAKC,iBAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;QAC5C,IAAI,CAAC,MAAM,GAAG,IAAI,uBAAa,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACU,6BAAW,GAAxB;;;gBACC,sBAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAC;;;KACjC;IAED;;;;;;;;;;OAUG;IACU,2BAAS,GAAtB,UAAuB,QAAgB;;;gBACtC,sBAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAC;;;KACvC;IAED;;;;;;;;;;OAUG;IACU,2BAAS,GAAtB,UAAuB,QAAgB;;;gBACtC,sBAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAC;;;KACvC;IAED;;;;;;;;;OASG;IACI,iCAAe,GAAtB;QACC,8FAA8F;QAC9F,sFAAsF;QACtF,IAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,CAAC;QAClE,IAAM,IAAI,GAAwB;YACjC,MAAM,EAAE,UAAG,WAAW,SAAG,6BAAY,CAAE;YACvC,OAAO,EAAE,UAAG,WAAW,SAAG,uBAAM,CAAC,IAAI,CAAE;YACvC,cAAc,EAAE,IAAI,CAAC,iBAAiB,EAAE;SACxC,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;YACnD,OAAO,IAAI,CAAC,MAAM,CAAC;SACnB;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAEnB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,2EAA2E;IACnE,mCAAiB,GAAzB;;QACC,IAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,IAAM,KAAK,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,0CAAE,oBAAoB,CAAC;QAEtD,IAAI,KAAK,EAAE;YACV,OAAO,CAAC,aAAa,GAAG,sBAAe,KAAK,CAAE,CAAC;SAC/C;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YAC1B,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;SAC/C;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;IACF,cAAC;AAAD,CAAC,AA7FD,IA6FC;AA7FY,0BAAO;AA+FpB,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { AnalystChat } from '@bringg/types';
2
+ import Entity from '../../Core/Entity';
3
+ import type Session from '../../Services/Identity/Session';
4
+ /**
5
+ * The Analyst REST surface.
6
+ *
7
+ * **Why the chat endpoint is not here.** The ag-ui contract has four endpoints, and exactly one of
8
+ * them is the protocol: `POST /analyst/chat` is a streaming POST that answers with `text/event-stream`
9
+ * until the turn ends. A method returning a `Promise` cannot express that, and re-implementing SSE
10
+ * framing here would duplicate the transport we are deferring to - so the consumer's `HttpAgent`
11
+ * opens it, and this package's contribution is {@link Analyst.getClientConfig}: where to connect and
12
+ * how to authenticate.
13
+ *
14
+ * The other three carry no protocol content at all. They are ordinary JSON over REST, and the
15
+ * dashboard - not the protocol client - decides when to call them: the History tab asks for the
16
+ * list, opening a conversation asks for one thread, and pressing Stop cancels the run. That makes
17
+ * them ours.
18
+ */
19
+ export default class AnalystEntity extends Entity<AnalystChat.ThreadSummary> {
20
+ constructor(session: Session);
21
+ /** The signed-in user's threads, most recently active first. A bare array, no envelope. */
22
+ listThreads(): Promise<AnalystChat.ThreadSummary[]>;
23
+ /**
24
+ * One thread, with its messages and whether a run is currently executing on it.
25
+ *
26
+ * A thread belonging to another user answers **404**, never 403 - so a rejected id is
27
+ * indistinguishable from a missing one, by design.
28
+ */
29
+ getThread(threadId: string): Promise<AnalystChat.ThreadDetail>;
30
+ /**
31
+ * Cancel the run in flight on a thread.
32
+ *
33
+ * Needed because a run belongs to the server, not to the connection that started it: aborting the
34
+ * stream client-side stops the events arriving but leaves the agent working. `cancelled: false`
35
+ * means the thread was already idle, which is a normal answer rather than a failure.
36
+ */
37
+ cancelRun(threadId: string): Promise<AnalystChat.CancelRunResponse>;
38
+ }
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ var Entity_1 = __importDefault(require("../../Core/Entity"));
58
+ var Analyst_consts_1 = require("../Analyst.consts");
59
+ /**
60
+ * The Analyst REST surface.
61
+ *
62
+ * **Why the chat endpoint is not here.** The ag-ui contract has four endpoints, and exactly one of
63
+ * them is the protocol: `POST /analyst/chat` is a streaming POST that answers with `text/event-stream`
64
+ * until the turn ends. A method returning a `Promise` cannot express that, and re-implementing SSE
65
+ * framing here would duplicate the transport we are deferring to - so the consumer's `HttpAgent`
66
+ * opens it, and this package's contribution is {@link Analyst.getClientConfig}: where to connect and
67
+ * how to authenticate.
68
+ *
69
+ * The other three carry no protocol content at all. They are ordinary JSON over REST, and the
70
+ * dashboard - not the protocol client - decides when to call them: the History tab asks for the
71
+ * list, opening a conversation asks for one thread, and pressing Stop cancels the run. That makes
72
+ * them ours.
73
+ */
74
+ var AnalystEntity = /** @class */ (function (_super) {
75
+ __extends(AnalystEntity, _super);
76
+ function AnalystEntity(session) {
77
+ return _super.call(this, {
78
+ session: session,
79
+ entityName: 'threads',
80
+ routePrefix: 'analyst-service'
81
+ }) || this;
82
+ }
83
+ /** The signed-in user's threads, most recently active first. A bare array, no envelope. */
84
+ AnalystEntity.prototype.listThreads = function () {
85
+ return __awaiter(this, void 0, void 0, function () {
86
+ var threads;
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0: return [4 /*yield*/, this.service.routeGenerator
90
+ .get(Analyst_consts_1.Routes.THREADS)
91
+ .setException('Failed to fetch analyst chat threads')
92
+ .invoke()];
93
+ case 1:
94
+ threads = _a.sent();
95
+ return [2 /*return*/, threads !== null && threads !== void 0 ? threads : []];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ /**
101
+ * One thread, with its messages and whether a run is currently executing on it.
102
+ *
103
+ * A thread belonging to another user answers **404**, never 403 - so a rejected id is
104
+ * indistinguishable from a missing one, by design.
105
+ */
106
+ AnalystEntity.prototype.getThread = function (threadId) {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ return __generator(this, function (_a) {
109
+ return [2 /*return*/, this.service.routeGenerator
110
+ .get(Analyst_consts_1.Routes.THREAD)
111
+ .withRouteParams({ threadId: threadId })
112
+ .setException('Failed to fetch analyst chat thread')
113
+ .invoke()];
114
+ });
115
+ });
116
+ };
117
+ /**
118
+ * Cancel the run in flight on a thread.
119
+ *
120
+ * Needed because a run belongs to the server, not to the connection that started it: aborting the
121
+ * stream client-side stops the events arriving but leaves the agent working. `cancelled: false`
122
+ * means the thread was already idle, which is a normal answer rather than a failure.
123
+ */
124
+ AnalystEntity.prototype.cancelRun = function (threadId) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var payload;
127
+ return __generator(this, function (_a) {
128
+ payload = { threadId: threadId };
129
+ return [2 /*return*/, this.service.routeGenerator
130
+ .post(Analyst_consts_1.Routes.CANCEL_RUN)
131
+ .withPayload(payload)
132
+ .setException('Failed to cancel the analyst chat run')
133
+ .invoke()];
134
+ });
135
+ });
136
+ };
137
+ return AnalystEntity;
138
+ }(Entity_1.default));
139
+ exports.default = AnalystEntity;
140
+ //# sourceMappingURL=AnalystEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalystEntity.js","sourceRoot":"","sources":["../../../src/Analyst/Entity/AnalystEntity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6DAAuC;AAEvC,oDAA2C;AAE3C;;;;;;;;;;;;;;GAcG;AACH;IAA2C,iCAAiC;IAC3E,uBAAY,OAAgB;eAC3B,kBAAM;YACL,OAAO,SAAA;YACP,UAAU,EAAE,SAAS;YACrB,WAAW,EAAE,iBAAiB;SAC9B,CAAC;IACH,CAAC;IAED,2FAA2F;IACrF,mCAAW,GAAjB;;;;;4BACiB,qBAAM,IAAI,CAAC,OAAO,CAAC,cAAc;6BAC/C,GAAG,CAAC,uBAAM,CAAC,OAAO,CAAC;6BACnB,YAAY,CAAC,sCAAsC,CAAC;6BACpD,MAAM,EAA4D,EAAA;;wBAH9D,OAAO,GAAG,SAGoD;wBAEpE,sBAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EAAC;;;;KACrB;IAED;;;;;OAKG;IACG,iCAAS,GAAf,UAAgB,QAAgB;;;gBAC/B,sBAAO,IAAI,CAAC,OAAO,CAAC,cAAc;yBAChC,GAAG,CAAC,uBAAM,CAAC,MAAM,CAAC;yBAClB,eAAe,CAAC,EAAE,QAAQ,UAAA,EAAE,CAAC;yBAC7B,YAAY,CAAC,qCAAqC,CAAC;yBACnD,MAAM,EAAsD,EAAC;;;KAC/D;IAED;;;;;;OAMG;IACG,iCAAS,GAAf,UAAgB,QAAgB;;;;gBACzB,OAAO,GAAiC,EAAE,QAAQ,UAAA,EAAE,CAAC;gBAE3D,sBAAO,IAAI,CAAC,OAAO,CAAC,cAAc;yBAChC,IAAI,CAAC,uBAAM,CAAC,UAAU,CAAC;yBACvB,WAAW,CAAC,OAAO,CAAC;yBACpB,YAAY,CAAC,uCAAuC,CAAC;yBACrD,MAAM,EAAgE,EAAC;;;KACzE;IACF,oBAAC;AAAD,CAAC,AAjDD,CAA2C,gBAAM,GAiDhD"}
@@ -0,0 +1 @@
1
+ export * from './Analyst';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Analyst"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Analyst/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
@@ -1,6 +1,7 @@
1
1
  import { OTPActions, SendOTPResponse, TaskRejectReasonResponse, WorkflowResponse } from '@bringg/types';
2
2
  import AddonsApi from './Addons/AddonsApi';
3
3
  import AlertsApi from './Alerts/AlertsApi';
4
+ import { Analyst } from './Analyst';
4
5
  import AnalyticsReportsApi from './AnalyticsReports/AnalyticsReportsApi';
5
6
  import ApplicationApi from './Application/ApplicationApi';
6
7
  import ApplicationMerchantConfigurationApi from './ApplicationMerchantConfiguration/ApplicationMerchantConfigurationApi';
@@ -215,6 +216,7 @@ export declare class BringgDashboardSDK {
215
216
  parkingSpotApi: ParkingSpotApi;
216
217
  customAttributesApi: CustomAttributesApi;
217
218
  asyncOperationStatus: AsyncOperationStatus;
219
+ analyst: Analyst;
218
220
  addons: AddonsApi;
219
221
  supportTicket: SupportTicketApi;
220
222
  orderExecutionActions: OrderExecutionActionsApi;
@@ -91,6 +91,7 @@ exports.newConfigurationProvider = exports.getFullConfiguration = exports.setEnv
91
91
  var mobx = __importStar(require("mobx"));
92
92
  var AddonsApi_1 = __importDefault(require("./Addons/AddonsApi"));
93
93
  var AlertsApi_1 = __importDefault(require("./Alerts/AlertsApi"));
94
+ var Analyst_1 = require("./Analyst");
94
95
  var AnalyticsReportsApi_1 = __importDefault(require("./AnalyticsReports/AnalyticsReportsApi"));
95
96
  var ApplicationApi_1 = __importDefault(require("./Application/ApplicationApi"));
96
97
  var ApplicationMerchantConfigurationApi_1 = __importDefault(require("./ApplicationMerchantConfiguration/ApplicationMerchantConfigurationApi"));
@@ -611,6 +612,7 @@ function init(session) {
611
612
  bringg.parkingSpotApi = new ParkingSpotApi_1.default(session);
612
613
  bringg.customAttributesApi = new CustomAttributesApi_1.default(session);
613
614
  bringg.asyncOperationStatus = new AsyncOperationStatus_1.AsyncOperationStatus(session);
615
+ bringg.analyst = new Analyst_1.Analyst(session);
614
616
  bringg.addons = new AddonsApi_1.default(session);
615
617
  bringg.supportTicket = new SupportTicketApi_1.default(session);
616
618
  bringg.optimizationKpi = new OptimizationKpiApi_1.default(session);