@epam/ai-dial-chat-hooks 1.3.0-dev.296 → 1.3.0-dev.305

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.
Files changed (58) hide show
  1. package/catalog/application-credentials.d.ts.map +1 -1
  2. package/catalog/application-credentials.js +20 -25
  3. package/catalog/use-publish-history.d.ts +19 -0
  4. package/catalog/use-publish-history.d.ts.map +1 -0
  5. package/catalog/use-publish-history.js +25 -0
  6. package/catalog/useCatalogToolsetCredentials/useCatalogToolsetCredentials.d.ts.map +1 -1
  7. package/catalog/useCatalogToolsetCredentials/useCatalogToolsetCredentials.js +72 -77
  8. package/catalog.js +19 -18
  9. package/conversation/conversation-data-source.d.ts +47 -0
  10. package/conversation/conversation-data-source.d.ts.map +1 -0
  11. package/conversation/conversation-data-source.js +11 -0
  12. package/conversation/useConversationExport/useConversationExport.d.ts.map +1 -1
  13. package/conversation/useConversationExport/useConversationExport.js +76 -84
  14. package/conversation/useConversationScroll/useConversationScroll.d.ts.map +1 -1
  15. package/conversation/useConversationScroll/useConversationScroll.js +64 -63
  16. package/conversation.js +33 -32
  17. package/entry-points/catalog.d.ts +1 -0
  18. package/entry-points/catalog.d.ts.map +1 -1
  19. package/entry-points/conversation.d.ts +1 -0
  20. package/entry-points/conversation.d.ts.map +1 -1
  21. package/entry-points/project.d.ts +5 -0
  22. package/entry-points/project.d.ts.map +1 -1
  23. package/external-services/useExternalServiceLogin.d.ts +3 -13
  24. package/external-services/useExternalServiceLogin.d.ts.map +1 -1
  25. package/external-services/useExternalServiceLogin.js +49 -58
  26. package/index.d.ts +7 -0
  27. package/index.d.ts.map +1 -1
  28. package/index.js +189 -182
  29. package/mcp-apps/useMcpAppTools/useMcpAppTools.d.ts.map +1 -1
  30. package/mcp-apps/useMcpAppTools/useMcpAppTools.js +42 -39
  31. package/oauth/authorize-url.d.ts +7 -1
  32. package/oauth/authorize-url.d.ts.map +1 -1
  33. package/oauth/authorize-url.js +13 -3
  34. package/oauth/models.d.ts +25 -0
  35. package/oauth/models.d.ts.map +1 -1
  36. package/oauth/useToolsetLogin/useToolsetLogin.d.ts.map +1 -1
  37. package/oauth/useToolsetLogin/useToolsetLogin.js +45 -56
  38. package/oauth.js +7 -7
  39. package/package.json +17 -17
  40. package/project/create-project-chat.d.ts +34 -0
  41. package/project/create-project-chat.d.ts.map +1 -0
  42. package/project/create-project-chat.js +27 -0
  43. package/project/project-conversation-data-source.d.ts +36 -0
  44. package/project/project-conversation-data-source.d.ts.map +1 -0
  45. package/project/project-conversation-data-source.js +67 -0
  46. package/project/project-file-preview.d.ts +28 -0
  47. package/project/project-file-preview.d.ts.map +1 -0
  48. package/project/project-file-preview.js +20 -0
  49. package/project/use-project-draft.d.ts +46 -0
  50. package/project/use-project-draft.d.ts.map +1 -0
  51. package/project/use-project-draft.js +54 -0
  52. package/project/use-project-file-preview.d.ts +42 -0
  53. package/project/use-project-file-preview.d.ts.map +1 -0
  54. package/project/use-project-file-preview.js +46 -0
  55. package/project.js +15 -10
  56. package/shared/sleep.d.ts +3 -0
  57. package/shared/sleep.d.ts.map +1 -0
  58. package/shared/sleep.js +13 -0
@@ -1,52 +1,55 @@
1
- import { useEffect as e, useMemo as t, useRef as n, useState as r } from "react";
2
- import { collectToolCallNames as i, sanitizeToolName as a } from "@epam/ai-dial-mcp-apps";
1
+ import { isPublicToolsetId as e } from "../../oauth/toolset-id.js";
2
+ import { useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
3
+ import { collectToolCallNames as a, sanitizeToolName as o } from "@epam/ai-dial-mcp-apps";
3
4
  //#region src/mcp-apps/useMcpAppTools/useMcpAppTools.ts
4
- var o = (o, s, c, l) => {
5
- let [u, d] = r([]), [f, p] = r([]), m = n(/* @__PURE__ */ new Set());
6
- e(() => {
7
- if (m.current = /* @__PURE__ */ new Set(), p([]), s?.features?.mcp !== !0 || s.type !== "toolset" && s.type !== "application") {
8
- d([]);
5
+ var s = (t) => {
6
+ let n = (e) => o(`${e.displayName ?? e.id}`), r = new Set(t.filter((t) => e(t.id)).map(n));
7
+ return t.filter((t) => e(t.id) || !r.has(n(t)));
8
+ }, c = (e, c, l, u) => {
9
+ let [d, f] = i([]), [p, m] = i([]), h = r(/* @__PURE__ */ new Set());
10
+ t(() => {
11
+ if (h.current = /* @__PURE__ */ new Set(), m([]), c?.features?.mcp !== !0 || c.type !== "toolset" && c.type !== "application") {
12
+ f([]);
9
13
  return;
10
14
  }
11
- let e = s.id, t = s.type;
15
+ let t = c.id, n = c.type;
12
16
  (async () => {
13
17
  try {
14
- let n = await o.listAppTools(e, t);
15
- d(n.map(({ resourceUri: n, toolName: r }) => ({
16
- toolsetId: e,
17
- resourceUri: n,
18
+ let r = await e.listAppTools(t, n);
19
+ f(r.map(({ resourceUri: e, toolName: r }) => ({
20
+ toolsetId: t,
21
+ resourceUri: e,
18
22
  toolName: r,
19
23
  mcpToolName: r,
20
- kind: t,
24
+ kind: n,
21
25
  discovery: "direct"
22
26
  })));
23
27
  } catch {
24
- d([]);
28
+ f([]);
25
29
  }
26
30
  })();
27
31
  }, [
28
- s?.id,
29
- s?.type,
30
- s?.features?.mcp,
31
- o
32
+ c?.id,
33
+ c?.type,
34
+ c?.features?.mcp,
35
+ e
32
36
  ]);
33
- let h = t(() => i(c), [c]);
34
- return e(() => {
35
- if (h.size === 0) return;
36
- let e = l.filter((e) => {
37
- if (m.current.has(e.id)) return !1;
38
- let t = a(`${e.displayName ?? e.id}_`);
39
- return [...h].some((e) => e.startsWith(t));
40
- });
41
- if (e.length !== 0) {
42
- for (let t of e) m.current.add(t.id);
37
+ let g = n(() => a(l), [l]);
38
+ return t(() => {
39
+ if (g.size === 0) return;
40
+ let t = s(u.filter((e) => {
41
+ let t = o(`${e.displayName ?? e.id}_`);
42
+ return [...g].some((e) => e.startsWith(t));
43
+ })).filter((e) => !h.current.has(e.id));
44
+ if (t.length !== 0) {
45
+ for (let e of t) h.current.add(e.id);
43
46
  (async () => {
44
- let t = await Promise.all(e.map(async (e) => {
47
+ let n = await Promise.all(t.map(async (t) => {
45
48
  try {
46
- return (await o.listAppTools(e.id, "toolset")).map(({ resourceUri: t, toolName: n }) => ({
47
- toolsetId: e.id,
48
- resourceUri: t,
49
- toolName: a(`${e.displayName ?? e.id}_${n}`),
49
+ return (await e.listAppTools(t.id, "toolset")).map(({ resourceUri: e, toolName: n }) => ({
50
+ toolsetId: t.id,
51
+ resourceUri: e,
52
+ toolName: o(`${t.displayName ?? t.id}_${n}`),
50
53
  mcpToolName: n,
51
54
  kind: "toolset",
52
55
  discovery: "indirect"
@@ -55,14 +58,14 @@ var o = (o, s, c, l) => {
55
58
  return [];
56
59
  }
57
60
  }));
58
- p((e) => [...e, ...t.flat()]);
61
+ m((e) => [...e, ...n.flat()]);
59
62
  })();
60
63
  }
61
64
  }, [
62
- h,
63
- l,
64
- o
65
- ]), t(() => [...u, ...f], [u, f]);
65
+ g,
66
+ u,
67
+ e
68
+ ]), n(() => [...d, ...p], [d, p]);
66
69
  };
67
70
  //#endregion
68
- export { o as useMcpAppTools };
71
+ export { c as useMcpAppTools };
@@ -1,4 +1,4 @@
1
- import { ToolsetOAuthSettings } from './models';
1
+ import { ToolsetOAuthSettings, ToolsetOAuthSettingsSource } from './models';
2
2
  /**
3
3
  * Resolves the OAuth callback location against the current origin. The
4
4
  * callback path is supplied by the host: this module owns no application
@@ -13,4 +13,10 @@ export declare const getToolsetRedirectUri: (callbackPath: string) => string;
13
13
  * `http:`/`https:` URL.
14
14
  */
15
15
  export declare const buildToolsetAuthorizeUrl: (auth: ToolsetOAuthSettings, redirectUri: string, state: string) => string | null;
16
+ /**
17
+ * Maps the public OAuth client fields of a DIAL Core auth-settings DTO onto
18
+ * the settings `buildToolsetAuthorizeUrl` reads, so every login entry point
19
+ * copies the same fields. An absent source yields all-`undefined` settings.
20
+ */
21
+ export declare const toToolsetOAuthSettings: (source?: ToolsetOAuthSettingsSource) => ToolsetOAuthSettings;
16
22
  //# sourceMappingURL=authorize-url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authorize-url.d.ts","sourceRoot":"","sources":["../../src/oauth/authorize-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,cAAc,MAAM,KAAG,MACjB,CAAC;AAU7C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,oBAAoB,EAC1B,aAAa,MAAM,EACnB,OAAO,MAAM,KACZ,MAAM,GAAG,IA0BX,CAAC"}
1
+ {"version":3,"file":"authorize-url.d.ts","sourceRoot":"","sources":["../../src/oauth/authorize-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAElB;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,cAAc,MAAM,KAAG,MACjB,CAAC;AAU7C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,oBAAoB,EAC1B,aAAa,MAAM,EACnB,OAAO,MAAM,KACZ,MAAM,GAAG,IAmCX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,0BAA0B,KAClC,oBAOD,CAAC"}
@@ -3,10 +3,20 @@ var e = (e) => `${window.location.origin}${e}`, t = /* @__PURE__ */ new Set(["ht
3
3
  if (!e.authorizationEndpoint?.trim() || !e.clientId?.trim()) return null;
4
4
  try {
5
5
  let i = new URL(e.authorizationEndpoint.trim());
6
- return t.has(i.protocol) ? (i.searchParams.set("response_type", "code"), i.searchParams.set("client_id", e.clientId.trim()), i.searchParams.set("redirect_uri", n), e.codeChallenge && i.searchParams.set("code_challenge", e.codeChallenge), e.codeChallengeMethod && i.searchParams.set("code_challenge_method", e.codeChallengeMethod), i.searchParams.set("state", r), e.scopes && e.scopes.length > 0 && i.searchParams.set("scope", e.scopes.join(" ")), i.toString()) : null;
6
+ if (!t.has(i.protocol)) return null;
7
+ i.searchParams.set("response_type", "code"), i.searchParams.set("client_id", e.clientId.trim()), i.searchParams.set("redirect_uri", n), e.codeChallenge && i.searchParams.set("code_challenge", e.codeChallenge), e.codeChallengeMethod && i.searchParams.set("code_challenge_method", e.codeChallengeMethod), i.searchParams.set("state", r), e.scopes && e.scopes.length > 0 && i.searchParams.set("scope", e.scopes.join(" "));
8
+ let a = e.resource?.trim();
9
+ return a && i.searchParams.set("resource", a), i.toString();
7
10
  } catch {
8
11
  return null;
9
12
  }
10
- };
13
+ }, r = (e) => ({
14
+ clientId: e?.clientId,
15
+ authorizationEndpoint: e?.authorizationEndpoint,
16
+ scopes: e?.scopesSupported,
17
+ codeChallenge: e?.codeChallenge,
18
+ codeChallengeMethod: e?.codeChallengeMethod,
19
+ resource: e?.resource
20
+ });
11
21
  //#endregion
12
- export { n as buildToolsetAuthorizeUrl, e as getToolsetRedirectUri };
22
+ export { n as buildToolsetAuthorizeUrl, e as getToolsetRedirectUri, r as toToolsetOAuthSettings };
package/oauth/models.d.ts CHANGED
@@ -11,6 +11,31 @@ export interface ToolsetOAuthSettings {
11
11
  scopes?: string[];
12
12
  codeChallenge?: string;
13
13
  codeChallengeMethod?: string;
14
+ /**
15
+ * RFC 8707 resource indicator DIAL Core stored for the client and sends on
16
+ * the token exchange; the authorize URL must carry the same value.
17
+ */
18
+ resource?: string;
19
+ }
20
+ /**
21
+ * Public OAuth client fields of a DIAL Core auth-settings DTO, as both a
22
+ * toolset's `authSettings` and an external service's metadata carry them.
23
+ * Declared structurally so `toToolsetOAuthSettings` accepts either without
24
+ * this module importing the generated client.
25
+ */
26
+ export interface ToolsetOAuthSettingsSource {
27
+ /** OAuth client id. */
28
+ clientId?: string;
29
+ /** Authorization endpoint the popup is sent to. */
30
+ authorizationEndpoint?: string;
31
+ /** Scopes the client may request. */
32
+ scopesSupported?: string[];
33
+ /** PKCE challenge. */
34
+ codeChallenge?: string;
35
+ /** PKCE challenge method. */
36
+ codeChallengeMethod?: string;
37
+ /** RFC 8707 resource indicator. */
38
+ resource?: string;
14
39
  }
15
40
  /**
16
41
  * Redirect state for an OAuth login flow. The flow writes this into the
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/oauth/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,8BAA8B,EAC9B,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,MAAM,4BAA4B,GACpC;IACE,IAAI,EAAE,gCAAgC,CAAC,OAAO,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,GACD;IAAE,IAAI,EAAE,gCAAgC,CAAC,OAAO,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,gCAAgC,CAAC,aAAa,CAAA;CAAE,CAAC;AAE7D,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,sBAAsB,CAAC,OAAO,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,uBAAuB,CAAC;CAC3C;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,sBAAsB,CAAC,OAAO,CAAC;IACrC,MAAM,EAAE,yBAAyB,CAAC;CACnC;AAED,qEAAqE;AACrE,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,8BAA8B,CAAC,kBAAkB,CAAC;CACzD;AAED;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GACpC,0BAA0B,GAAG,0BAA0B,CAAC;AAE1D,0FAA0F;AAC1F,MAAM,MAAM,kBAAkB,GAC1B,0BAA0B,GAC1B,0BAA0B,GAC1B;IAAE,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAA;CAAE,CAAC"}
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/oauth/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,8BAA8B,EAC9B,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,0BAA0B;IACzC,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,qCAAqC;IACrC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,sBAAsB;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6BAA6B;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,MAAM,4BAA4B,GACpC;IACE,IAAI,EAAE,gCAAgC,CAAC,OAAO,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,GACD;IAAE,IAAI,EAAE,gCAAgC,CAAC,OAAO,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,gCAAgC,CAAC,aAAa,CAAA;CAAE,CAAC;AAE7D,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,sBAAsB,CAAC,OAAO,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,uBAAuB,CAAC;CAC3C;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,sBAAsB,CAAC,OAAO,CAAC;IACrC,MAAM,EAAE,yBAAyB,CAAC;CACnC;AAED,qEAAqE;AACrE,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,8BAA8B,CAAC,kBAAkB,CAAC;CACzD;AAED;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GACpC,0BAA0B,GAAG,0BAA0B,CAAC;AAE1D,0FAA0F;AAC1F,MAAM,MAAM,kBAAkB,GAC1B,0BAA0B,GAC1B,0BAA0B,GAC1B;IAAE,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAA;CAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useToolsetLogin.d.ts","sourceRoot":"","sources":["../../../src/oauth/useToolsetLogin/useToolsetLogin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAOtD,OAAO,EAGL,gBAAgB,EAChB,uBAAuB,EAGxB,MAAM,UAAU,CAAC;AAElB,kDAAkD;AAClD,oBAAY,uBAAuB;IACjC,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,YAAY,kBAAkB;IAC9B,SAAS,cAAc;CACxB;AAED,kDAAkD;AAClD,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,IAAI,EAAE,uBAAuB,CAAC;CAC/B;AAED,sCAAsC;AACtC,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,qDAAqD;IACrD,kBAAkB,EAAE,gBAAgB,CAAC;IACrC,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,8CAA8C;AAC9C,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,YAAY,EAAE,CACZ,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,mBAAmB,KACtB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,0EAA0E;IAC1E,aAAa,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,oBAAoB,KACvB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,wFAAwF;IACxF,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3D;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,KAAK,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACrE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,sFAM7B,qBAAqB,KAAG,qBA2M1B,CAAC"}
1
+ {"version":3,"file":"useToolsetLogin.d.ts","sourceRoot":"","sources":["../../../src/oauth/useToolsetLogin/useToolsetLogin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AAKvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAOtD,OAAO,EAGL,gBAAgB,EAChB,uBAAuB,EAGxB,MAAM,UAAU,CAAC;AAElB,kDAAkD;AAClD,oBAAY,uBAAuB;IACjC,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,YAAY,kBAAkB;IAC9B,SAAS,cAAc;CACxB;AAED,kDAAkD;AAClD,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,IAAI,EAAE,uBAAuB,CAAC;CAC/B;AAED,sCAAsC;AACtC,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,qDAAqD;IACrD,kBAAkB,EAAE,gBAAgB,CAAC;IACrC,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,8CAA8C;AAC9C,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,YAAY,EAAE,CACZ,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,mBAAmB,KACtB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,0EAA0E;IAC1E,aAAa,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,oBAAoB,KACvB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,wFAAwF;IACxF,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3D;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,KAAK,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACrE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,sFAM7B,qBAAqB,KAAG,qBA+L1B,CAAC"}
@@ -1,93 +1,82 @@
1
1
  import { OAuthResourceKind as e, ToolsetAuthStatus as t, ToolsetAuthTypes as n, ToolsetOAuthInitiationResultType as r, ToolsetOAuthResultType as i } from "../types.js";
2
2
  import { selectToolsetAuthStatus as a } from "../toolset-id.js";
3
- import { emitToolsetLoginSuccess as o } from "../../shared/toolset-login-events.js";
4
- import { waitForToolsetOAuthResult as s } from "../handshake.js";
5
- import { initiateOAuthLogin as c, navigateToolsetOAuthPopup as l, openToolsetOAuthPopup as u } from "../popup.js";
6
- import { useCallback as d } from "react";
3
+ import { toToolsetOAuthSettings as o } from "../authorize-url.js";
4
+ import { emitToolsetLoginSuccess as s } from "../../shared/toolset-login-events.js";
5
+ import { waitForToolsetOAuthResult as c } from "../handshake.js";
6
+ import { initiateOAuthLogin as l, navigateToolsetOAuthPopup as u, openToolsetOAuthPopup as d } from "../popup.js";
7
+ import { useCallback as f } from "react";
7
8
  //#region src/oauth/useToolsetLogin/useToolsetLogin.ts
8
- var f = /* @__PURE__ */ function(e) {
9
+ var p = /* @__PURE__ */ function(e) {
9
10
  return e.Success = "success", e.Failure = "failure", e.PopupBlocked = "popup-blocked", e.Cancelled = "cancelled", e;
10
- }({}), p = ({ callbackPath: f, loginToolset: p, logoutToolset: m, getToolset: h, shouldFetchOAuthSettings: g = !1 }) => {
11
- let _ = d(async (e, t, n) => {
11
+ }({}), m = ({ callbackPath: p, loginToolset: m, logoutToolset: h, getToolset: g, shouldFetchOAuthSettings: _ = !1 }) => {
12
+ let v = f(async (e, t, n) => {
12
13
  try {
13
- await m(e, {
14
+ await h(e, {
14
15
  url: e,
15
16
  credentialsLevel: t,
16
17
  authenticationType: n
17
18
  });
18
19
  } catch {}
19
- }, [m]), v = d(async (d) => {
20
- let { toolsetId: p, credentialsLevel: m, oauthSettings: v, forceStale: y, offlineUsageConsent: b } = d, x = {
21
- clientId: v?.clientId,
22
- authorizationEndpoint: v?.authorizationEndpoint,
23
- scopes: v?.scopes,
24
- codeChallenge: v?.codeChallenge,
25
- codeChallengeMethod: v?.codeChallengeMethod
26
- }, S;
27
- if (y || g) {
28
- let t = u();
20
+ }, [h]), y = f(async (f) => {
21
+ let { toolsetId: m, credentialsLevel: h, oauthSettings: y, forceStale: b, offlineUsageConsent: x } = f, S = y ?? {}, C;
22
+ if (b || _) {
23
+ let t = d();
29
24
  if (!t) return { type: "popup-blocked" };
30
- y && await _(p, m, n.OAuth);
31
- let r = x;
32
- if (g) try {
33
- let { authSettings: e } = await h(p);
25
+ b && await v(m, h, n.OAuth);
26
+ let r = S;
27
+ if (_) try {
28
+ let { authSettings: e } = await g(m);
34
29
  if (t.closed) return { type: "cancelled" };
35
30
  if (e?.authenticationType !== n.OAuth) return t.close(), { type: "failure" };
36
- r = {
37
- clientId: e.clientId,
38
- authorizationEndpoint: e.authorizationEndpoint,
39
- scopes: e.scopesSupported,
40
- codeChallenge: e.codeChallenge,
41
- codeChallengeMethod: e.codeChallengeMethod
42
- };
31
+ r = o(e);
43
32
  } catch {
44
33
  return t.close(), { type: "failure" };
45
34
  }
46
- S = l(t, r, p, f, m, e.Toolset, b);
47
- } else S = c(x, p, f, m, b);
48
- if (S.type === r.Blocked) return { type: "popup-blocked" };
49
- if (S.type !== r.Started) return { type: "failure" };
50
- let C = await s(S.popup, S.flowId, {
51
- toolsetId: p,
52
- credentialsLevel: m,
53
- callbackPath: f
35
+ C = u(t, r, m, p, h, e.Toolset, x);
36
+ } else C = l(S, m, p, h, x);
37
+ if (C.type === r.Blocked) return { type: "popup-blocked" };
38
+ if (C.type !== r.Started) return { type: "failure" };
39
+ let w = await c(C.popup, C.flowId, {
40
+ toolsetId: m,
41
+ credentialsLevel: h,
42
+ callbackPath: p
54
43
  });
55
- if (C.type === i.Success) return o({
56
- toolsetId: p,
57
- credentialsLevel: m
44
+ if (w.type === i.Success) return s({
45
+ toolsetId: m,
46
+ credentialsLevel: h
58
47
  }), { type: "success" };
59
- if (C.type === i.Failure) return { type: "failure" };
48
+ if (w.type === i.Failure) return { type: "failure" };
60
49
  try {
61
- let e = await h(p);
62
- if (a(e.authSettings, m) === t.SignedIn) return o({
63
- toolsetId: p,
64
- credentialsLevel: m
50
+ let e = await g(m);
51
+ if (a(e.authSettings, h) === t.SignedIn) return s({
52
+ toolsetId: m,
53
+ credentialsLevel: h
65
54
  }), { type: "success" };
66
55
  } catch {}
67
56
  return { type: "cancelled" };
68
57
  }, [
69
- f,
70
- h,
71
- _,
72
- g
73
- ]), y = d(async (e) => {
74
- let { toolsetId: t, credentialsLevel: n, authenticationType: r, apiKey: i, isCurrentlyFailed: a, forceStale: s, offlineUsageConsent: c } = e;
58
+ p,
59
+ g,
60
+ v,
61
+ _
62
+ ]), b = f(async (e) => {
63
+ let { toolsetId: t, credentialsLevel: n, authenticationType: r, apiKey: i, isCurrentlyFailed: a, forceStale: o, offlineUsageConsent: c } = e;
75
64
  try {
76
- return (s || a) && await _(t, n, r), await p(t, {
65
+ return (o || a) && await v(t, n, r), await m(t, {
77
66
  url: t,
78
67
  credentialsLevel: n,
79
68
  authenticationType: r,
80
69
  apiKey: i?.trim(),
81
70
  offlineUsageConsent: c
82
- }), o({
71
+ }), s({
83
72
  toolsetId: t,
84
73
  credentialsLevel: n
85
74
  }), { type: "success" };
86
75
  } catch {
87
76
  return { type: "failure" };
88
77
  }
89
- }, [p, _]);
90
- return { login: d((e) => e.authenticationType === n.OAuth ? v(e) : y(e), [v, y]) };
78
+ }, [m, v]);
79
+ return { login: f((e) => e.authenticationType === n.OAuth ? y(e) : b(e), [y, b]) };
91
80
  };
92
81
  //#endregion
93
- export { f as ToolsetLoginOutcomeType, p as useToolsetLogin };
82
+ export { p as ToolsetLoginOutcomeType, m as useToolsetLogin };
package/oauth.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { OAuthResourceKind as e, TOOLSET_REDIRECT_STATE_KEY as t, ToolsetAuthStatus as n, ToolsetAuthTypes as r, ToolsetCredentialsLevel as i, ToolsetOAuthCallbackQuery as a, ToolsetOAuthChannelControlType as o, ToolsetOAuthFailureReason as s, ToolsetOAuthInitiationResultType as c, ToolsetOAuthResultType as l, WithLogin as u } from "./oauth/types.js";
2
2
  import { decodeToolsetId as d, encodeToolsetId as f, getToolsetFallbackName as p, isPublicToolsetId as m, normalizeToolsetId as h, resolveToolsetCredentialsLevel as g, selectToolsetAuthStatus as _ } from "./oauth/toolset-id.js";
3
- import { emitToolsetLoginSuccess as v, subscribeToolsetLoginSuccess as y } from "./shared/toolset-login-events.js";
4
- import { getToolsetOAuthChannelName as b, waitForToolsetOAuthResult as x } from "./oauth/handshake.js";
5
- import { buildToolsetAuthorizeUrl as S, getToolsetRedirectUri as C } from "./oauth/authorize-url.js";
6
- import { initiateOAuthLogin as w, navigateToolsetOAuthPopup as T, openToolsetOAuthPopup as E } from "./oauth/popup.js";
7
- import { ToolsetLoginOutcomeType as D, useToolsetLogin as O } from "./oauth/useToolsetLogin/useToolsetLogin.js";
8
- import { useOAuthCallbackCompletion as k } from "./oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.js";
9
- export { e as OAuthResourceKind, t as TOOLSET_REDIRECT_STATE_KEY, n as ToolsetAuthStatus, r as ToolsetAuthTypes, i as ToolsetCredentialsLevel, D as ToolsetLoginOutcomeType, a as ToolsetOAuthCallbackQuery, o as ToolsetOAuthChannelControlType, s as ToolsetOAuthFailureReason, c as ToolsetOAuthInitiationResultType, l as ToolsetOAuthResultType, u as WithLogin, S as buildToolsetAuthorizeUrl, d as decodeToolsetId, v as emitToolsetLoginSuccess, f as encodeToolsetId, p as getToolsetFallbackName, b as getToolsetOAuthChannelName, C as getToolsetRedirectUri, w as initiateOAuthLogin, m as isPublicToolsetId, T as navigateToolsetOAuthPopup, h as normalizeToolsetId, E as openToolsetOAuthPopup, g as resolveToolsetCredentialsLevel, _ as selectToolsetAuthStatus, y as subscribeToolsetLoginSuccess, k as useOAuthCallbackCompletion, O as useToolsetLogin, x as waitForToolsetOAuthResult };
3
+ import { buildToolsetAuthorizeUrl as v, getToolsetRedirectUri as y, toToolsetOAuthSettings as b } from "./oauth/authorize-url.js";
4
+ import { emitToolsetLoginSuccess as x, subscribeToolsetLoginSuccess as S } from "./shared/toolset-login-events.js";
5
+ import { getToolsetOAuthChannelName as C, waitForToolsetOAuthResult as w } from "./oauth/handshake.js";
6
+ import { initiateOAuthLogin as T, navigateToolsetOAuthPopup as E, openToolsetOAuthPopup as D } from "./oauth/popup.js";
7
+ import { ToolsetLoginOutcomeType as O, useToolsetLogin as k } from "./oauth/useToolsetLogin/useToolsetLogin.js";
8
+ import { useOAuthCallbackCompletion as A } from "./oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.js";
9
+ export { e as OAuthResourceKind, t as TOOLSET_REDIRECT_STATE_KEY, n as ToolsetAuthStatus, r as ToolsetAuthTypes, i as ToolsetCredentialsLevel, O as ToolsetLoginOutcomeType, a as ToolsetOAuthCallbackQuery, o as ToolsetOAuthChannelControlType, s as ToolsetOAuthFailureReason, c as ToolsetOAuthInitiationResultType, l as ToolsetOAuthResultType, u as WithLogin, v as buildToolsetAuthorizeUrl, d as decodeToolsetId, x as emitToolsetLoginSuccess, f as encodeToolsetId, p as getToolsetFallbackName, C as getToolsetOAuthChannelName, y as getToolsetRedirectUri, T as initiateOAuthLogin, m as isPublicToolsetId, E as navigateToolsetOAuthPopup, h as normalizeToolsetId, D as openToolsetOAuthPopup, g as resolveToolsetCredentialsLevel, _ as selectToolsetAuthStatus, S as subscribeToolsetLoginSuccess, b as toToolsetOAuthSettings, A as useOAuthCallbackCompletion, k as useToolsetLogin, w as waitForToolsetOAuthResult };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@epam/ai-dial-chat-hooks",
3
3
  "description": "Framework-level React hooks extracted from AI DIAL Chat for building custom chat interfaces",
4
- "version": "1.3.0-dev.296",
4
+ "version": "1.3.0-dev.305",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "./index.js",
@@ -131,7 +131,7 @@
131
131
  }
132
132
  },
133
133
  "dependencies": {
134
- "@epam/ai-dial-chat-api-client": "1.3.0-dev.296",
134
+ "@epam/ai-dial-chat-api-client": "1.3.0-dev.305",
135
135
  "dompurify": "3.4.17",
136
136
  "fflate": "^0.8.3",
137
137
  "lru-cache": "^10.4.3",
@@ -140,23 +140,23 @@
140
140
  },
141
141
  "peerDependencies": {
142
142
  "react": "^19.2.8",
143
- "@epam/ai-dial-attachment-canvas": "1.3.0-dev.296",
144
- "@epam/ai-dial-attachment-input": "1.3.0-dev.296",
145
- "@epam/ai-dial-catalog": "1.3.0-dev.296",
146
- "@epam/ai-dial-chat-overlay": "1.3.0-dev.296",
147
- "@epam/ai-dial-chat-shared": "1.3.0-dev.296",
148
- "@epam/ai-dial-conversation-input": "1.3.0-dev.296",
149
- "@epam/ai-dial-mcp-apps": "1.3.0-dev.296",
150
- "@epam/ai-dial-projects": "1.3.0-dev.296",
151
- "@epam/ai-dial-publish-panel": "1.3.0-dev.296",
152
- "@epam/ai-dial-quotations": "1.3.0-dev.296",
143
+ "@epam/ai-dial-attachment-canvas": "1.3.0-dev.305",
144
+ "@epam/ai-dial-attachment-input": "1.3.0-dev.305",
145
+ "@epam/ai-dial-catalog": "1.3.0-dev.305",
146
+ "@epam/ai-dial-chat-overlay": "1.3.0-dev.305",
147
+ "@epam/ai-dial-chat-shared": "1.3.0-dev.305",
148
+ "@epam/ai-dial-conversation-input": "1.3.0-dev.305",
149
+ "@epam/ai-dial-mcp-apps": "1.3.0-dev.305",
150
+ "@epam/ai-dial-projects": "1.3.0-dev.305",
151
+ "@epam/ai-dial-publish-panel": "1.3.0-dev.305",
152
+ "@epam/ai-dial-quotations": "1.3.0-dev.305",
153
153
  "@epam/ai-dial-react-file-manager": "^0.4.0-dev.25",
154
- "@epam/ai-dial-scheduled-tasks": "1.3.0-dev.296",
155
- "@epam/ai-dial-share": "1.3.0-dev.296",
156
- "@epam/ai-dial-skill-editor": "1.3.0-dev.296",
157
- "@epam/ai-dial-source-panel": "1.3.0-dev.296",
154
+ "@epam/ai-dial-scheduled-tasks": "1.3.0-dev.305",
155
+ "@epam/ai-dial-share": "1.3.0-dev.305",
156
+ "@epam/ai-dial-skill-editor": "1.3.0-dev.305",
157
+ "@epam/ai-dial-source-panel": "1.3.0-dev.305",
158
158
  "@epam/ai-dial-ui-kit": "^0.16.0-dev.67",
159
- "@epam/ai-dial-usage-dashboard": "1.3.0-dev.296",
159
+ "@epam/ai-dial-usage-dashboard": "1.3.0-dev.305",
160
160
  "@modelcontextprotocol/sdk": "^1.32.2",
161
161
  "@epam/pdf-highlighter-kit": "^0.0.19"
162
162
  },
@@ -0,0 +1,34 @@
1
+ import { ConversationResponseDto } from '@epam/ai-dial-chat-api-client';
2
+ import { ChatSettingsValues } from '../useChatSettingsFormConfig/useChatSettingsFormConfig';
3
+ import { ConversationCreateRequest, ProjectsApiClient } from './projects-api-client';
4
+ /** Why creating a project chat failed, as the host explains it. */
5
+ export declare enum ProjectChatCreateFailure {
6
+ /** The project has no room left for another chat. */
7
+ StorageFull = "storage-full",
8
+ /** Any other failure. */
9
+ Failed = "failed"
10
+ }
11
+ /** A failed chat create, classified for the host's message. */
12
+ export interface ProjectChatCreateFailureDetails {
13
+ /** Why the create failed. */
14
+ failure: ProjectChatCreateFailure;
15
+ /** Trace id of the failed request, when the response carried one. */
16
+ requestId?: string;
17
+ }
18
+ /**
19
+ * Creates a project chat from its first message, saves the composer's chat
20
+ * settings onto it, and hands the saved chat to `onCreated` in every case where
21
+ * the chat exists, even when saving the settings fails (the chat exists either
22
+ * way, and opening it avoids a duplicate on retry). A failed save is rethrown
23
+ * after `onCreated` ran; a failed create rejects without calling it.
24
+ *
25
+ * @param client - Configured project requests, from `createProjectsApiClient`.
26
+ * @param projectId - The project's DIAL id.
27
+ * @param request - First message, deployment, attachments, tool configuration, form values and skills.
28
+ * @param settings - System prompt, temperature and response format saved onto the new chat.
29
+ * @param onCreated - Receives the chat with the settings applied, e.g. to open it.
30
+ */
31
+ export declare const createProjectChat: (client: Pick<ProjectsApiClient, "createProjectConversation" | "saveProjectConversation">, projectId: string, request: ConversationCreateRequest, settings: ChatSettingsValues, onCreated: (saved: ConversationResponseDto) => void) => Promise<ConversationResponseDto>;
32
+ /** Classifies a rejected project chat create as storage-full or a plain failure, with its trace id. */
33
+ export declare const classifyProjectChatCreateError: (error: unknown) => Promise<ProjectChatCreateFailureDetails>;
34
+ //# sourceMappingURL=create-project-chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-project-chat.d.ts","sourceRoot":"","sources":["../../src/project/create-project-chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wDAAwD,CAAC;AACjG,OAAO,KAAK,EACV,yBAAyB,EACzB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,mEAAmE;AACnE,oBAAY,wBAAwB;IAClC,qDAAqD;IACrD,WAAW,iBAAiB;IAC5B,yBAAyB;IACzB,MAAM,WAAW;CAClB;AAED,+DAA+D;AAC/D,MAAM,WAAW,+BAA+B;IAC9C,6BAA6B;IAC7B,OAAO,EAAE,wBAAwB,CAAC;IAClC,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,IAAI,CACV,iBAAiB,EACjB,2BAA2B,GAAG,yBAAyB,CACxD,EACD,WAAW,MAAM,EACjB,SAAS,yBAAyB,EAClC,UAAU,kBAAkB,EAC5B,WAAW,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,KAClD,OAAO,CAAC,uBAAuB,CAiBjC,CAAC;AAEF,uGAAuG;AACvG,eAAO,MAAM,8BAA8B,GACzC,OAAO,OAAO,KACb,OAAO,CAAC,+BAA+B,CASzC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { getApiErrorDetails as e } from "../api-error/api-error.js";
2
+ import { ProjectCreateErrorCode as t } from "@epam/ai-dial-chat-api-client";
3
+ //#region src/project/create-project-chat.ts
4
+ var n = /* @__PURE__ */ function(e) {
5
+ return e.StorageFull = "storage-full", e.Failed = "failed", e;
6
+ }({}), r = async (e, t, n, r, i) => {
7
+ let a = await e.createProjectConversation(t, n), o = {
8
+ ...a,
9
+ prompt: r.systemPrompt,
10
+ temperature: r.temperature,
11
+ responseFormat: r.responseFormat
12
+ };
13
+ try {
14
+ await e.saveProjectConversation(a.id, o);
15
+ } finally {
16
+ i(o);
17
+ }
18
+ return o;
19
+ }, i = async (n) => {
20
+ let { code: r, traceId: i } = await e(n);
21
+ return {
22
+ failure: r === t.ProjectStorageFull ? "storage-full" : "failed",
23
+ requestId: i
24
+ };
25
+ };
26
+ //#endregion
27
+ export { n as ProjectChatCreateFailure, i as classifyProjectChatCreateError, r as createProjectChat };
@@ -0,0 +1,36 @@
1
+ import { ConversationDataSource } from '../conversation/conversation-data-source';
2
+ import { CreateChatStreamApiDeps } from '../conversation/create-chat-stream-api';
3
+ import { SerializedKeyedWriter } from '../shared/serialized-writer';
4
+ import { ProjectsApiClient } from './projects-api-client';
5
+ /** Host ports of {@link createProjectConversationDataSource}. */
6
+ export interface ProjectConversationDataSourceOptions {
7
+ /** The project's DIAL id. */
8
+ projectId: string;
9
+ /** Whether the caller owns the project; a conversation opens read-only without it. */
10
+ canEdit: boolean;
11
+ /** Configured project requests, from `createProjectsApiClient`; only the conversation requests are used. */
12
+ client: Pick<ProjectsApiClient, 'getProjectConversation' | 'saveProjectConversation' | 'deleteProjectConversation' | 'attachToProjectGeneration'>;
13
+ /** Where and how the completion stream is sent: the host's base path under the project, and its CSRF token store. */
14
+ stream: Pick<CreateChatStreamApiDeps, 'getCsrfToken' | 'setCsrfToken' | 'completionsBasePath'>;
15
+ /** The host's routes: a project conversation's page, and where a deleted or missing one goes. */
16
+ routes: {
17
+ /** Returns the page route of a conversation. */
18
+ getConversationRoute: (id: string) => string;
19
+ /** Returns the route a deleted or missing conversation navigates to. */
20
+ getExitRoute: () => string;
21
+ };
22
+ /** The queue viewed marks go through, shared with the host's other pages so they write one at a time. */
23
+ viewedWriter: SerializedKeyedWriter;
24
+ /** Translation key of the toast shown when the conversation cannot be loaded; the host resolves it. */
25
+ notFoundMessageKey?: string;
26
+ }
27
+ /**
28
+ * Returns the data source of a conversation stored inside a project: the
29
+ * project conversation requests for loads, saves and streams, the host's
30
+ * routes, read-only from `canEdit`, no sidebar list side effects and no
31
+ * Duplicate. A project chat has no sidebar row, so the open chat is marked
32
+ * viewed through `viewedWriter`, and a generation starting drops a mark still
33
+ * waiting for its chat.
34
+ */
35
+ export declare const createProjectConversationDataSource: ({ projectId, canEdit, client, stream, routes, viewedWriter, notFoundMessageKey, }: ProjectConversationDataSourceOptions) => ConversationDataSource;
36
+ //# sourceMappingURL=project-conversation-data-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-conversation-data-source.d.ts","sourceRoot":"","sources":["../../src/project/project-conversation-data-source.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,wCAAwC,CAAC;AAGhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAU/D,iEAAiE;AACjE,MAAM,WAAW,oCAAoC;IACnD,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,OAAO,EAAE,OAAO,CAAC;IACjB,4GAA4G;IAC5G,MAAM,EAAE,IAAI,CACV,iBAAiB,EACf,wBAAwB,GACxB,yBAAyB,GACzB,2BAA2B,GAC3B,2BAA2B,CAC9B,CAAC;IACF,qHAAqH;IACrH,MAAM,EAAE,IAAI,CACV,uBAAuB,EACvB,cAAc,GAAG,cAAc,GAAG,qBAAqB,CACxD,CAAC;IACF,iGAAiG;IACjG,MAAM,EAAE;QACN,gDAAgD;QAChD,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;QAC7C,wEAAwE;QACxE,YAAY,EAAE,MAAM,MAAM,CAAC;KAC5B,CAAC;IACF,yGAAyG;IACzG,YAAY,EAAE,qBAAqB,CAAC;IACpC,uGAAuG;IACvG,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAsED;;;;;;;GAOG;AACH,eAAO,MAAM,mCAAmC,GAAI,mFAQjD,oCAAoC,KAAG,sBAiEzC,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { createChatStreamApi as e } from "../conversation/create-chat-stream-api.js";
2
+ import { NO_CONVERSATION_LIST_SYNC as t } from "../conversation/conversation-data-source.js";
3
+ import { getBrowserTimezone as n } from "../shared/browser-timezone.js";
4
+ import { sleep as r } from "../shared/sleep.js";
5
+ //#region src/project/project-conversation-data-source.ts
6
+ var i = "projects/", a = 5, o = 2e3, s = 5e3, c = "data: {\"action\":\"UPDATE\"}\n\n", l = (e) => e.startsWith(i) ? e : `${i}${e}`, u = (e) => {
7
+ let t = new TextEncoder().encode(c);
8
+ return new ReadableStream({ async pull(n) {
9
+ await r(s, e), e.aborted ? n.close() : n.enqueue(t);
10
+ } }, { highWaterMark: 0 });
11
+ }, d = (e, t, n, i) => {
12
+ let s = new AbortController();
13
+ return (async () => {
14
+ for (let c = 0; c < a; c++) {
15
+ if (await r(o, s.signal), s.signal.aborted) return;
16
+ try {
17
+ let { name: r } = await e(t, s.signal);
18
+ if (s.signal.aborted) return;
19
+ if (r && r !== n) {
20
+ i(r);
21
+ return;
22
+ }
23
+ } catch {
24
+ if (s.signal.aborted) return;
25
+ }
26
+ }
27
+ })(), () => s.abort();
28
+ }, f = ({ projectId: r, canEdit: i, client: a, stream: o, routes: s, viewedWriter: c, notFoundMessageKey: f }) => {
29
+ let { streamCompletion: p, stopCompletion: m } = e({
30
+ ...o,
31
+ getTimezone: n
32
+ }), h = {
33
+ ...t,
34
+ markUnread: (e) => c.drop(e),
35
+ markViewed: async (e) => {
36
+ try {
37
+ await c.enqueue(e);
38
+ } catch {}
39
+ },
40
+ shouldMarkOpenChatViewed: !0
41
+ }, g = (e, t) => a.saveProjectConversation(l(e), t);
42
+ return {
43
+ transport: {
44
+ streamCompletion: p,
45
+ stopCompletion: m,
46
+ watchConversation: async (e, t) => u(t),
47
+ attachToGeneration: (e, t) => a.attachToProjectGeneration(r, e, t),
48
+ getConversation: async (e, t) => await a.getProjectConversation(e, t),
49
+ saveConversation: async (e, t) => await g(e, t)
50
+ },
51
+ getConversation: a.getProjectConversation,
52
+ saveConversation: g,
53
+ handlersApi: {
54
+ saveConversation: ({ path: e, saveConversationBodyDto: t }) => g(e, t.conversation),
55
+ deleteConversation: ({ path: e }) => a.deleteProjectConversation(l(e))
56
+ },
57
+ watchTitle: (e, t, n) => d(a.getProjectConversation, e, t, n),
58
+ getConversationRoute: s.getConversationRoute,
59
+ getExitRoute: s.getExitRoute,
60
+ isReadOnly: () => !i,
61
+ listSync: h,
62
+ canDuplicate: !1,
63
+ notFoundMessageKey: f
64
+ };
65
+ };
66
+ //#endregion
67
+ export { f as createProjectConversationDataSource };