@esri/hub-web-components 0.0.5

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 (70) hide show
  1. package/LICENSE.md +13 -0
  2. package/README.md +35 -0
  3. package/dist/cdn/2NFBUAOJ.js +4 -0
  4. package/dist/cdn/3ZRJV7VD.js +3 -0
  5. package/dist/cdn/CADUTR4A.js +4 -0
  6. package/dist/cdn/E5QHKHGG.js +41 -0
  7. package/dist/cdn/IDWXUFCL.js +6 -0
  8. package/dist/cdn/MNXAWZSB.js +9 -0
  9. package/dist/cdn/YBCM3RPB.js +4 -0
  10. package/dist/cdn/assets/hub-ai-assistant/t9n/messages.en.json +1 -0
  11. package/dist/cdn/assets/hub-ai-assistant/t9n/messages.es.json +1 -0
  12. package/dist/cdn/index.js +4 -0
  13. package/dist/chunks/chat-action.js +41 -0
  14. package/dist/chunks/runtime.js +12 -0
  15. package/dist/components/arcgis-chat-shell/customElement.d.ts +27 -0
  16. package/dist/components/arcgis-chat-shell/customElement.js +44 -0
  17. package/dist/components/arcgis-chat-shell/index.d.ts +5 -0
  18. package/dist/components/arcgis-chat-shell/index.js +5 -0
  19. package/dist/components/arcgis-chat-ui/components/chat-action/customElement.d.ts +9 -0
  20. package/dist/components/arcgis-chat-ui/components/chat-action/customElement.js +9 -0
  21. package/dist/components/arcgis-chat-ui/components/chat-action/index.d.ts +2 -0
  22. package/dist/components/arcgis-chat-ui/components/chat-action/index.js +2 -0
  23. package/dist/components/arcgis-chat-ui/components/chat-response/customElement.d.ts +9 -0
  24. package/dist/components/arcgis-chat-ui/components/chat-response/customElement.js +42 -0
  25. package/dist/components/arcgis-chat-ui/components/chat-response/index.d.ts +8 -0
  26. package/dist/components/arcgis-chat-ui/components/chat-response/index.js +8 -0
  27. package/dist/components/arcgis-chat-ui/components/chat-status/customElement.d.ts +6 -0
  28. package/dist/components/arcgis-chat-ui/components/chat-status/customElement.js +8 -0
  29. package/dist/components/arcgis-chat-ui/components/chat-status/index.d.ts +1 -0
  30. package/dist/components/arcgis-chat-ui/components/chat-status/index.js +1 -0
  31. package/dist/components/arcgis-chat-ui/customElement.d.ts +58 -0
  32. package/dist/components/arcgis-chat-ui/customElement.js +127 -0
  33. package/dist/components/arcgis-chat-ui/index.d.ts +3 -0
  34. package/dist/components/arcgis-chat-ui/index.js +3 -0
  35. package/dist/components/arcgis-chat-ui/util/constants.d.ts +4 -0
  36. package/dist/components/arcgis-chat-ui/util/customElement.d.ts +3 -0
  37. package/dist/components/arcgis-chat-ui/util/types.d.ts +27 -0
  38. package/dist/components/arcgis-hub-ai-assistant/customElement.d.ts +90 -0
  39. package/dist/components/arcgis-hub-ai-assistant/customElement.js +210 -0
  40. package/dist/components/arcgis-hub-ai-assistant/index.d.ts +9 -0
  41. package/dist/components/arcgis-hub-ai-assistant/index.js +9 -0
  42. package/dist/components/arcgis-hub-ai-assistant/util/api.d.ts +25 -0
  43. package/dist/components/arcgis-hub-ai-assistant/util/customElement.d.ts +18 -0
  44. package/dist/components/arcgis-hub-ai-assistant/util/customElement.js +33 -0
  45. package/dist/components/arcgis-hub-ai-assistant/util/framework.d.ts +184 -0
  46. package/dist/components/arcgis-hub-ai-assistant/util/index.d.ts +1 -0
  47. package/dist/components/arcgis-hub-ai-assistant/util/index.js +1 -0
  48. package/dist/components/arcgis-hub-ai-assistant/util/test.d.ts +1387 -0
  49. package/dist/controllers/useT9n.d.ts +1 -0
  50. package/dist/docs/api.json +1113 -0
  51. package/dist/docs/docs.json +1010 -0
  52. package/dist/docs/vscode.css-custom-data.json +6 -0
  53. package/dist/docs/vscode.html-custom-data.json +133 -0
  54. package/dist/docs/web-types.json +413 -0
  55. package/dist/embed-config.d.ts +18 -0
  56. package/dist/embed-config.js +24 -0
  57. package/dist/enums.d.ts +10 -0
  58. package/dist/index.d.ts +74 -0
  59. package/dist/index.js +8 -0
  60. package/dist/loader.d.ts +2 -0
  61. package/dist/loader.js +13 -0
  62. package/dist/main.css +1 -0
  63. package/dist/runtime.d.ts +6 -0
  64. package/dist/types/components.d.ts +1 -0
  65. package/dist/types/lumina.d.ts +28 -0
  66. package/dist/types/preact.d.ts +36 -0
  67. package/dist/types/react.d.ts +47 -0
  68. package/dist/types/stencil.d.ts +35 -0
  69. package/dist/util/configuration.d.ts +16 -0
  70. package/package.json +99 -0
@@ -0,0 +1,25 @@
1
+ import { CivicApiResponse } from '../../../types';
2
+ /**
3
+ * Call the Esri-managed GeoAI civic agent
4
+ * This currently handles the intent response.
5
+ * TODO: Move API to internally do both intent & actions
6
+ * */
7
+ /**
8
+ * Old method for fetching data from the AI model. Moving to fetchCivicInference
9
+ * @param message
10
+ * @param context
11
+ * @param history
12
+ * @returns
13
+ */
14
+ export declare function fetchIntent(message: string, context: string, history: string[]): Promise<CivicApiResponse>;
15
+ /**
16
+ * Call the Esri-managed GeoAI civic agent
17
+ * */
18
+ export declare function fetchInformation(message: string, history: string[], location: string, hub: string, informationSources: string[], allowChat: boolean, context?: string, language?: string): Promise<CivicApiResponse>;
19
+ /**
20
+ * Call the Esri-managed GeoAI civic agent
21
+ * */
22
+ export declare function fetchCivicInference(message: string, history: string[], location: string, hub: string, tools?: string[], language?: string): Promise<CivicApiResponse>;
23
+ /**
24
+ * Deprecated method for fetching data from the AI model. Moving to fetchCivicInference
25
+ * */
@@ -0,0 +1,18 @@
1
+ /// <reference types="../../index.d.ts" />
2
+ import { ChatSource } from '../../arcgis-chat-ui/util/types';
3
+ import { FinderSource, FinderResponseContext } from './framework';
4
+ /**
5
+ * When the "sources" come back from the AI, they do not have all the item properties. This function "enriches" them
6
+ * so they have all their item properties so we can display them down the component tree.
7
+ */
8
+ export declare const enrichSources: (sources: FinderSource[]) => Promise<ChatSource[]>;
9
+ export declare const getLocationCenter: (extent?: number[][]) => number[];
10
+ export declare const calculateZoom: (extent?: number[][]) => number;
11
+ /**
12
+ * Checks if the provided object is a FinderResponseContext by verifying its "kind" property.
13
+ * Returns true if the object matches the FinderResponseContext type, otherwise false.
14
+ *
15
+ * @param obj - The object to evaluate.
16
+ * @returns boolean indicating whether the object is a FinderResponseContext.
17
+ */
18
+ export declare function isFinderResponseContext(obj: unknown): obj is FinderResponseContext;
@@ -0,0 +1,33 @@
1
+ import { getItem as u } from "@esri/arcgis-rest-portal";
2
+ /*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
3
+ See https://js.arcgis.com/0.0/esri/copyright.txt for details.
4
+ v0.0.5 */
5
+ const m = async (o) => await Promise.all(o.map(h)), h = async (o) => {
6
+ const t = structuredClone(o);
7
+ try {
8
+ const n = await u(o.id);
9
+ return console.debug("Enriching source:", o.id, n), t.thumbnail = n.thumbnail, t.url = n.url, t.type = n.type, t;
10
+ } catch {
11
+ console.error("Could not enrich:", o);
12
+ }
13
+ return t;
14
+ }, g = (o) => {
15
+ if (!o)
16
+ return [0, 0];
17
+ const t = o[0][0], n = o[0][1], r = o[1][0], s = (o[1][1] + n) / 2;
18
+ return [(r + t) / 2, s];
19
+ }, p = (o) => {
20
+ if (!o)
21
+ return 5;
22
+ const t = o[0][0], n = o[0][1], r = o[1][0], c = o[1][1], s = Math.abs(r - t), e = Math.abs(c - n), i = Math.log2(360 / s), a = Math.log2(180 / e);
23
+ return Math.floor(Math.min(i, a)) + 2;
24
+ };
25
+ function f(o) {
26
+ return !!o && typeof o == "object" && "kind" in o && o.kind === "FinderResponse";
27
+ }
28
+ export {
29
+ p as calculateZoom,
30
+ m as enrichSources,
31
+ g as getLocationCenter,
32
+ f as isFinderResponseContext
33
+ };
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Developer interface to the ArcGIS AI framework and Hub skills
3
+ * "finder" is the Hub search assistant skill.
4
+ * In the future there will be more skills for content creation, moderation, and newsletter generation.
5
+ *
6
+ * Example usage:
7
+ *
8
+ * ```ts
9
+ * const response = await getFinderResponse({
10
+ * message: 'How many trees are in Ward 6?',
11
+ * conversationId: null // to use previous history include conversationId
12
+ * context: {
13
+ * kind: 'FinderRequest',
14
+ * item: '4ef...', // the item id of the Item with the assistant configuration (e.g. a Hub Site)
15
+ * },
16
+ * token: token, // Use the ArcGIS user token if available
17
+ * apiUrl: 'https://hub.arcgis.com/api/assistants/v1', // or your custom API URL
18
+ * });
19
+ * ```
20
+ *
21
+ * The API sequence looks like this:
22
+ * 1. Call getSkillResponse with the skillId, message, and context to get the initial response.
23
+ * 2. If the response has more messages (hasMore is true),
24
+ * continue calling getSkillResponse with the conversationId and inquiryId until hasMore is false.
25
+ * 3. The response will include the conversationId, inquiryId, and sequenceNumber for tracking the conversation.
26
+ * 4. The context can be used to pass additional information to the skill
27
+ *
28
+ * The ArcGIS AI API works by calling
29
+ * /api/skills/{skillId}/chat
30
+ * with a POST request containing the message and context.
31
+ *
32
+ * context is specific to a skill and must include the `kind` which is the skill-specific context type. (e.g. FinderRequestContext)
33
+ * and the additional properties required by the skill.
34
+ *
35
+ * The response will include the conversationId, inquiryId, and sequenceNumber for tracking the conversation.
36
+ * If hasMore is true, you can continue to call the same endpoint with the conversationId and inquiryId
37
+ * to get more messages until hasMore is false.
38
+ *
39
+ * Authentication is required and is done using a Bearer token in the Authorization header.
40
+ */
41
+ /**
42
+ * General Skill API response type (excluding context)
43
+ */
44
+ export interface SkillApiResponse<TContext = unknown> {
45
+ conversationId: string | null;
46
+ inquiryId: string;
47
+ hasMore: boolean;
48
+ sequenceNumber: number;
49
+ message?: string;
50
+ context: TContext;
51
+ }
52
+ /**
53
+ * FinderActionProperties defines the properties for actions in the Finder skill.
54
+ */
55
+ export interface FinderActionProperties {
56
+ kind: string;
57
+ topic: string;
58
+ datasets: string[] | null;
59
+ latitude: number | null;
60
+ longitude: number | null;
61
+ zoom: number | null;
62
+ }
63
+ /**
64
+ * FinderAction defines an action that is recommended as a follow-up user query
65
+ */
66
+ export interface FinderAction {
67
+ kind: string;
68
+ action: string;
69
+ text: string;
70
+ properties: FinderActionProperties;
71
+ }
72
+ /**
73
+ * FinderSource defines a source of information in a response such as a dataset, document, or app.
74
+ */
75
+ export interface FinderSource {
76
+ kind: string;
77
+ id: string;
78
+ type: string;
79
+ title: string;
80
+ description: string;
81
+ source: string;
82
+ }
83
+ /**
84
+ * FinderLocation defines the location of a response or source
85
+ */
86
+ export interface FinderLocation {
87
+ kind: string;
88
+ name: string;
89
+ latitude: number;
90
+ longitude: number;
91
+ zoom: number | null;
92
+ }
93
+ export declare enum FinderResponseContextKind {
94
+ RESPONSE = "FinderResponse",
95
+ WORKFLOW = "FinderWorkflow"
96
+ }
97
+ /**
98
+ * FinderTool defines a tool that can be used in the Finder skill, such as a search or geocode.
99
+ */
100
+ export interface FinderTool {
101
+ name: string;
102
+ parameters: Record<string, unknown>;
103
+ }
104
+ /**
105
+ * FinderRequestContext defines the information sent to the Finder skill API
106
+ */
107
+ export interface FinderRequestContext {
108
+ kind: string;
109
+ domain?: string;
110
+ location?: string;
111
+ item?: string;
112
+ }
113
+ /**
114
+ * FinderResponseContext defines the information sent back from the Finder skill API
115
+ */
116
+ export interface FinderResponseContext {
117
+ kind: string;
118
+ text: string;
119
+ actions: FinderAction[];
120
+ sources: FinderSource[];
121
+ location: FinderLocation;
122
+ features: unknown;
123
+ tools: FinderTool[];
124
+ }
125
+ export interface ArcgisErrorAsContext {
126
+ error: {
127
+ code: number;
128
+ messageCode: string;
129
+ details?: unknown[];
130
+ message: string;
131
+ subCode?: unknown;
132
+ };
133
+ kind: string;
134
+ }
135
+ export type SkillResponse = SkillApiResponse;
136
+ export type FinderSkillResponse = SkillApiResponse<FinderResponseContext>;
137
+ export type ArcgisErrorResponse = SkillApiResponse<ArcgisErrorAsContext>;
138
+ /**
139
+ * Calls a skill API endpoint with support for retries and pause between attempts.
140
+ *
141
+ * @template TContext - The type of the context object expected in the API response.
142
+ * @param apiUrl - The base API URL to the AI framework.
143
+ * @param payload - The request payload to send to the skill API.
144
+ * @param headers - The HTTP headers to include in the request.
145
+ * @param retries - The number of retry attempts if the request fails (default: 3).
146
+ * @param pauseMs - The pause duration in milliseconds between retry attempts (default: 1000).
147
+ * @returns A promise that resolves to the skill API response with the specified context type.
148
+ * @throws Will throw an error if all retry attempts fail.
149
+ */
150
+ export declare function getSkillResponse<TContext = unknown>(params: {
151
+ skillId: string;
152
+ message: string;
153
+ context: object;
154
+ token: string;
155
+ conversationId?: string;
156
+ apiUrl?: string;
157
+ pauseMs?: number;
158
+ retries?: number;
159
+ }): Promise<SkillApiResponse<TContext>[]>;
160
+ /**
161
+ * Parameters for the getFinderResponse function.
162
+ *
163
+ * @param message The user message/question.
164
+ * @param context The FinderRequest context object.
165
+ * @param token The bearer token for authentication.
166
+ * @param apiUrl The base API URL (default: 'https://api.example.com').
167
+ * @param pauseMs Pause in ms between retries (default: 1000).
168
+ * @param retries Number of retries for API calls (default: 50).
169
+ */
170
+ export interface GetFinderResponseParams {
171
+ message: string;
172
+ context: FinderRequestContext;
173
+ token: string;
174
+ conversationId?: string | null;
175
+ apiUrl?: string;
176
+ pauseMs?: number;
177
+ retries?: number;
178
+ }
179
+ /**
180
+ * Get a response from the 'finder' skill for a FinderRequest.
181
+ *
182
+ * @returns Array of SkillResponse objects from the skill API.
183
+ */
184
+ export declare function getFinderResponse({ message, context, token, conversationId, apiUrl, pauseMs, retries, }: GetFinderResponseParams): Promise<ArcgisErrorResponse[] | FinderSkillResponse[]>;
@@ -0,0 +1 @@
1
+ export * from "./customElement.js";
@@ -0,0 +1 @@
1
+ export * from "./customElement.js";