@anyshift/backstage-plugin-anyshift 0.1.0-beta.2 → 0.1.0-beta.20
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/CHANGELOG.md +76 -0
- package/README.md +14 -1
- package/dist/api/AnyshiftApi.esm.js +61 -7
- package/dist/api/AnyshiftApi.esm.js.map +1 -1
- package/dist/components/ask/AskAnyshiftCard.esm.js +348 -0
- package/dist/components/ask/AskAnyshiftCard.esm.js.map +1 -0
- package/dist/components/ask/askPresenters.esm.js +1203 -0
- package/dist/components/ask/askPresenters.esm.js.map +1 -0
- package/dist/components/ask/askScope.esm.js +27 -0
- package/dist/components/ask/askScope.esm.js.map +1 -0
- package/dist/components/ask/askSuggestions.esm.js +41 -0
- package/dist/components/ask/askSuggestions.esm.js.map +1 -0
- package/dist/components/cloud/CloudImpactSection.esm.js +54 -0
- package/dist/components/cloud/CloudImpactSection.esm.js.map +1 -0
- package/dist/components/cloud/CloudPage.esm.js +104 -0
- package/dist/components/cloud/CloudPage.esm.js.map +1 -0
- package/dist/components/cloud/CloudRelationshipSections.esm.js +43 -0
- package/dist/components/cloud/CloudRelationshipSections.esm.js.map +1 -0
- package/dist/components/cloud/CloudResourceContent.esm.js +495 -0
- package/dist/components/cloud/CloudResourceContent.esm.js.map +1 -0
- package/dist/components/entity/AnyshiftEntityContent.esm.js +128 -23
- package/dist/components/entity/AnyshiftEntityContent.esm.js.map +1 -1
- package/dist/components/entity/ArchitectureOperationDetails.esm.js +107 -0
- package/dist/components/entity/ArchitectureOperationDetails.esm.js.map +1 -0
- package/dist/components/entity/BriefSections.esm.js +24 -4
- package/dist/components/entity/BriefSections.esm.js.map +1 -1
- package/dist/components/entity/DatadogLiveSignal.esm.js +85 -23
- package/dist/components/entity/DatadogLiveSignal.esm.js.map +1 -1
- package/dist/components/entity/MermaidArchitecture.esm.js +202 -43
- package/dist/components/entity/MermaidArchitecture.esm.js.map +1 -1
- package/dist/components/entity/SectionPresenters.esm.js +145 -82
- package/dist/components/entity/SectionPresenters.esm.js.map +1 -1
- package/dist/components/entity/architectureDiagram.esm.js +48 -15
- package/dist/components/entity/architectureDiagram.esm.js.map +1 -1
- package/dist/components/entity/architectureGraph.esm.js +145 -0
- package/dist/components/entity/architectureGraph.esm.js.map +1 -0
- package/dist/components/entity/entityIdentity.esm.js +40 -0
- package/dist/components/entity/entityIdentity.esm.js.map +1 -0
- package/dist/components/entity/relatedCatalogEntities.esm.js +60 -0
- package/dist/components/entity/relatedCatalogEntities.esm.js.map +1 -0
- package/dist/components/explorer/AnyshiftExplorerPage.esm.js +222 -21
- package/dist/components/explorer/AnyshiftExplorerPage.esm.js.map +1 -1
- package/dist/components/explorer/DatadogOperationsRadar.esm.js +92 -31
- package/dist/components/explorer/DatadogOperationsRadar.esm.js.map +1 -1
- package/dist/index.d.ts +26 -102
- package/dist/index.esm.js +1 -1
- package/dist/package.json.esm.js +10 -10
- package/dist/plugin.esm.js +51 -8
- package/dist/plugin.esm.js.map +1 -1
- package/dist/routes.esm.js +2 -1
- package/dist/routes.esm.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.0-beta.16
|
|
6
|
+
|
|
7
|
+
- Retry unresolved cloud-change evidence with the provider-native ARN while keeping the stable
|
|
8
|
+
catalog identity and existing entity URLs unchanged.
|
|
9
|
+
|
|
10
|
+
## 0.1.0-beta.15
|
|
11
|
+
|
|
12
|
+
- Resolve Affected footprint entries against one Backstage catalog snapshot and link only entities
|
|
13
|
+
that are proven to exist.
|
|
14
|
+
- Repair stale runtime-namespace links, de-duplicate logical names, and keep unresolved graph
|
|
15
|
+
evidence visible as plain text instead of dead links.
|
|
16
|
+
|
|
17
|
+
## 0.1.0-beta.14
|
|
18
|
+
|
|
19
|
+
- Expose available APM HTTP methods and templated paths from service `CALLS_TO` edges through a compact architecture-diagram affordance and source-grouped evidence inspector.
|
|
20
|
+
- Keep missing operation or observation metadata explicitly unknown without changing legacy edge rendering or adding per-edge Graph API requests.
|
|
21
|
+
|
|
22
|
+
## 0.1.0-beta.13
|
|
23
|
+
|
|
24
|
+
- Keep zero-event cloud-resource pages quiet: identity-completeness codes do not become alerts
|
|
25
|
+
without a returned event, while source and status limits remain one evidence caveat.
|
|
26
|
+
|
|
27
|
+
## 0.1.0-beta.12
|
|
28
|
+
|
|
29
|
+
- Render cloud Resources through shared Cloud and Anyshift evidence cards, with direct catalog
|
|
30
|
+
dependencies, typed potential impact, cloud changes, IaC evidence, and ARN-scoped Ask.
|
|
31
|
+
- Keep cloud evidence separate from workload/Kubernetes safeguards and make absent catalog, change,
|
|
32
|
+
IaC, or impact evidence explicitly unknown rather than healthy.
|
|
33
|
+
|
|
34
|
+
## 0.1.0-beta.11
|
|
35
|
+
|
|
36
|
+
- Add one reusable Ask Anyshift card to the estate dashboard and supported entity pages.
|
|
37
|
+
- Render bounded typed evidence, visible entity scope, effective interpretation, uncertainty, and safe error states.
|
|
38
|
+
- Keep viewer Ask availability independent from operator-only Advanced Query.
|
|
39
|
+
|
|
40
|
+
## 0.1.0-beta.10
|
|
41
|
+
|
|
42
|
+
- Render why-now evidence immediately after the entity overview without claiming causality.
|
|
43
|
+
- Link affected service footprints to related Backstage catalog entities.
|
|
44
|
+
- Add estate evidence coverage, blind spots, freshness, and scoped retry to the Anyshift dashboard.
|
|
45
|
+
|
|
46
|
+
## 0.1.0-beta.9
|
|
47
|
+
|
|
48
|
+
- Render configured callers and dependencies separately from observed APM traffic.
|
|
49
|
+
- Resolve ECS configuration evidence through a dedicated runtime identity annotation.
|
|
50
|
+
|
|
51
|
+
## 0.1.0-beta.8
|
|
52
|
+
|
|
53
|
+
- Render cloud evidence timestamps with bracketed time-zone identifiers without
|
|
54
|
+
displaying `Invalid Date`.
|
|
55
|
+
- Preserve unrecognized timestamp evidence as its original value instead of
|
|
56
|
+
inventing a time.
|
|
57
|
+
|
|
58
|
+
## 0.1.0-beta.7
|
|
59
|
+
|
|
60
|
+
- Load normalized cloud changes, Terraform provenance, and drift evidence on cloud Resource pages.
|
|
61
|
+
- Resolve stable Anyshift resource identity before provider-native ARN fallback.
|
|
62
|
+
- Preserve successful evidence sections across partial upstream failures and render unknown drift neutrally.
|
|
63
|
+
|
|
64
|
+
## 0.1.0-beta.6
|
|
65
|
+
|
|
66
|
+
- Add a discoverable global Cloud inventory page.
|
|
67
|
+
- Add generic cloud Resource content with identity, ownership, relations, ARN, and console links.
|
|
68
|
+
|
|
69
|
+
## 0.1.0-beta.5
|
|
70
|
+
|
|
71
|
+
- Hide entity content for catalog resources without a supported Anyshift brief kind.
|
|
72
|
+
- Preserve the default workload view for GitHub-owned Components.
|
|
73
|
+
|
|
74
|
+
## 0.1.0-beta.3
|
|
75
|
+
|
|
76
|
+
- Show durable catalog reconciliation status on the global dashboard.
|
|
77
|
+
- Add a permission-aware **Reconcile now** operator action.
|
|
78
|
+
|
|
3
79
|
## 0.1.0-beta.2
|
|
4
80
|
|
|
5
81
|
- Coordinate the frontend package with the trusted catalog synchronization beta.
|
package/README.md
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
New-frontend-system plugin for the Anyshift infrastructure graph. Installing the package in an app
|
|
4
4
|
created with `@backstage/frontend-defaults` and configured with `app.packages: all` discovers its
|
|
5
|
-
dashboard, navigation
|
|
5
|
+
dashboard, Cloud inventory page, navigation items, API factory, and entity content automatically.
|
|
6
|
+
|
|
7
|
+
The Cloud page lists provider-managed infrastructure Resources with searchable type, account,
|
|
8
|
+
region, and ownership metadata. Cloud Resource entities receive read-only normalized change,
|
|
9
|
+
Terraform provenance, and drift evidence alongside their stable identity, provider console link,
|
|
10
|
+
and catalog relationships. Evidence sections degrade independently, and an unknown drift verdict
|
|
11
|
+
is not presented as drift.
|
|
12
|
+
|
|
13
|
+
When `anyshift.ask.enabled` is true, the same Ask Anyshift card appears on the estate dashboard and
|
|
14
|
+
supported entity pages for every viewer with `anyshift.view`. It is a single-question experience,
|
|
15
|
+
not a chat history. Entity scope is visible and removable, and the effective `For <target>: ...`
|
|
16
|
+
interpretation is shown with each answer. Typed presenters render only supported evidence; missing
|
|
17
|
+
timestamps and missing evidence remain explicitly unknown. Advanced Query stays independently
|
|
18
|
+
controlled by `anyshift.query.enabled` and `anyshift.query`.
|
|
6
19
|
|
|
7
20
|
The package has no legacy frontend entry point. Add the corresponding
|
|
8
21
|
`@anyshift/backstage-plugin-anyshift-backend` package to the Backstage backend and configure one
|
|
@@ -3,6 +3,18 @@ import { createApiRef } from '@backstage/frontend-plugin-api';
|
|
|
3
3
|
const anyshiftApiRef = createApiRef({
|
|
4
4
|
id: "plugin.anyshift.service"
|
|
5
5
|
});
|
|
6
|
+
class AnyshiftRequestError extends Error {
|
|
7
|
+
constructor(status, code, message, retryAfterSeconds) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
12
|
+
this.name = "AnyshiftRequestError";
|
|
13
|
+
}
|
|
14
|
+
status;
|
|
15
|
+
code;
|
|
16
|
+
retryAfterSeconds;
|
|
17
|
+
}
|
|
6
18
|
class AnyshiftClient {
|
|
7
19
|
discoveryApi;
|
|
8
20
|
fetchApi;
|
|
@@ -10,6 +22,13 @@ class AnyshiftClient {
|
|
|
10
22
|
this.discoveryApi = options.discoveryApi;
|
|
11
23
|
this.fetchApi = options.fetchApi;
|
|
12
24
|
}
|
|
25
|
+
async ask(request) {
|
|
26
|
+
return this.request("/ask", {
|
|
27
|
+
method: "POST",
|
|
28
|
+
headers: { "content-type": "application/json" },
|
|
29
|
+
body: JSON.stringify(request)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
13
32
|
async capabilities() {
|
|
14
33
|
return this.get("/capabilities");
|
|
15
34
|
}
|
|
@@ -27,12 +46,22 @@ class AnyshiftClient {
|
|
|
27
46
|
)}/sections/${encodeURIComponent(section)}${briefQuery(options)}`
|
|
28
47
|
);
|
|
29
48
|
}
|
|
30
|
-
async insights() {
|
|
31
|
-
return this.get(
|
|
49
|
+
async insights(options = {}) {
|
|
50
|
+
return this.get(`/insights${options.refresh ? "?refresh=1" : ""}`);
|
|
32
51
|
}
|
|
33
52
|
async datadogSignals(options = {}) {
|
|
34
53
|
return this.get(`/signals/datadog${options.refresh ? "?refresh=1" : ""}`);
|
|
35
54
|
}
|
|
55
|
+
async cloudResourceBrief(resource, options = {}) {
|
|
56
|
+
const params = new URLSearchParams({ resource });
|
|
57
|
+
if (options.fallbackResource)
|
|
58
|
+
params.set("fallbackResource", options.fallbackResource);
|
|
59
|
+
if (options.since) params.set("since", options.since);
|
|
60
|
+
if (options.cursor) params.set("cursor", options.cursor);
|
|
61
|
+
if (options.diff !== void 0) params.set("diff", String(options.diff));
|
|
62
|
+
if (options.refresh) params.set("refresh", "1");
|
|
63
|
+
return this.get(`/cloud/resources/brief?${params}`);
|
|
64
|
+
}
|
|
36
65
|
async inventory(type, options = {}) {
|
|
37
66
|
const params = new URLSearchParams({ type });
|
|
38
67
|
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
@@ -47,11 +76,14 @@ class AnyshiftClient {
|
|
|
47
76
|
body: JSON.stringify({ sql })
|
|
48
77
|
});
|
|
49
78
|
}
|
|
79
|
+
async reconcileCatalog() {
|
|
80
|
+
return this.request("/anyshift/reconcile", { method: "POST" }, "catalog");
|
|
81
|
+
}
|
|
50
82
|
async get(path) {
|
|
51
83
|
return this.request(path, { method: "GET" });
|
|
52
84
|
}
|
|
53
|
-
async request(path, init) {
|
|
54
|
-
const baseUrl = await this.discoveryApi.getBaseUrl(
|
|
85
|
+
async request(path, init, pluginId = "anyshift") {
|
|
86
|
+
const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);
|
|
55
87
|
const response = await this.fetchApi.fetch(`${baseUrl}${path}`, init);
|
|
56
88
|
const text = await response.text();
|
|
57
89
|
let payload;
|
|
@@ -61,20 +93,42 @@ class AnyshiftClient {
|
|
|
61
93
|
payload = {};
|
|
62
94
|
}
|
|
63
95
|
if (!response.ok) {
|
|
64
|
-
|
|
65
|
-
|
|
96
|
+
const error = errorEnvelope(payload);
|
|
97
|
+
throw new AnyshiftRequestError(
|
|
98
|
+
response.status,
|
|
99
|
+
error.code,
|
|
100
|
+
error.message ?? `Anyshift request failed (${response.status})`,
|
|
101
|
+
error.retryAfterSeconds
|
|
66
102
|
);
|
|
67
103
|
}
|
|
68
104
|
return payload;
|
|
69
105
|
}
|
|
70
106
|
}
|
|
107
|
+
function errorEnvelope(payload) {
|
|
108
|
+
const error = payload && typeof payload === "object" && "error" in payload ? payload.error : void 0;
|
|
109
|
+
if (!error || typeof error !== "object") {
|
|
110
|
+
return { code: "request_failed" };
|
|
111
|
+
}
|
|
112
|
+
const { code, message, retryAfterSeconds } = error;
|
|
113
|
+
return {
|
|
114
|
+
code: typeof code === "string" ? code : "request_failed",
|
|
115
|
+
message: typeof message === "string" && message ? message : void 0,
|
|
116
|
+
retryAfterSeconds: typeof retryAfterSeconds === "number" && Number.isFinite(retryAfterSeconds) ? retryAfterSeconds : void 0
|
|
117
|
+
};
|
|
118
|
+
}
|
|
71
119
|
function briefQuery(options) {
|
|
72
120
|
const params = new URLSearchParams();
|
|
73
121
|
if (options.namespace) params.set("namespace", options.namespace);
|
|
74
122
|
if (options.refresh) params.set("refresh", "1");
|
|
123
|
+
if (options.configurationEndpoints)
|
|
124
|
+
params.set("configurationEndpoints", options.configurationEndpoints);
|
|
125
|
+
if (options.configurationDependencies)
|
|
126
|
+
params.set("configurationDependencies", options.configurationDependencies);
|
|
127
|
+
if (options.configurationTarget)
|
|
128
|
+
params.set("configurationTarget", options.configurationTarget);
|
|
75
129
|
const query = params.toString();
|
|
76
130
|
return query ? `?${query}` : "";
|
|
77
131
|
}
|
|
78
132
|
|
|
79
|
-
export { AnyshiftClient, anyshiftApiRef };
|
|
133
|
+
export { AnyshiftClient, AnyshiftRequestError, anyshiftApiRef };
|
|
80
134
|
//# sourceMappingURL=AnyshiftApi.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnyshiftApi.esm.js","sources":["../../src/api/AnyshiftApi.ts"],"sourcesContent":["import {\n createApiRef,\n type DiscoveryApi,\n type FetchApi,\n} from '@backstage/frontend-plugin-api';\nimport type {\n BriefSectionName,\n BriefSectionResponse,\n AnyshiftCapabilities,\n CatalogSummary,\n DatadogSignals,\n EstateInsights,\n QueryResult,\n ServiceBrief,\n} from './types';\n\nexport interface AnyshiftApi {\n capabilities(): Promise<AnyshiftCapabilities>;\n brief(\n kind: string,\n target: string,\n options?: BriefRequestOptions,\n ): Promise<ServiceBrief>;\n briefSection(\n kind: string,\n target: string,\n section: BriefSectionName,\n options?: BriefRequestOptions,\n ): Promise<BriefSectionResponse>;\n insights(): Promise<EstateInsights>;\n datadogSignals(options?: { refresh?: boolean }): Promise<DatadogSignals>;\n inventory(\n type: string,\n options?: { limit?: number; offset?: number },\n ): Promise<CatalogSummary>;\n query(sql: string): Promise<QueryResult>;\n}\n\nexport interface BriefRequestOptions {\n namespace?: string;\n refresh?: boolean;\n}\n\nexport const anyshiftApiRef = createApiRef<AnyshiftApi>({\n id: 'plugin.anyshift.service',\n});\n\nexport class AnyshiftClient implements AnyshiftApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: { discoveryApi: DiscoveryApi; fetchApi: FetchApi }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n }\n\n async capabilities(): Promise<AnyshiftCapabilities> {\n return this.get('/capabilities');\n }\n\n async brief(\n kind: string,\n target: string,\n options: BriefRequestOptions = {},\n ): Promise<ServiceBrief> {\n return this.get(\n `/brief/${encodeURIComponent(kind)}/${encodeURIComponent(\n target,\n )}${briefQuery(options)}`,\n );\n }\n\n async briefSection(\n kind: string,\n target: string,\n section: BriefSectionName,\n options: BriefRequestOptions = {},\n ): Promise<BriefSectionResponse> {\n return this.get(\n `/brief/${encodeURIComponent(kind)}/${encodeURIComponent(\n target,\n )}/sections/${encodeURIComponent(section)}${briefQuery(options)}`,\n );\n }\n\n async insights(): Promise<EstateInsights> {\n return this.get('/insights');\n }\n\n async datadogSignals(\n options: { refresh?: boolean } = {},\n ): Promise<DatadogSignals> {\n return this.get(`/signals/datadog${options.refresh ? '?refresh=1' : ''}`);\n }\n\n async inventory(\n type: string,\n options: { limit?: number; offset?: number } = {},\n ): Promise<CatalogSummary> {\n const params = new URLSearchParams({ type });\n if (options.limit !== undefined) params.set('limit', String(options.limit));\n if (options.offset !== undefined)\n params.set('offset', String(options.offset));\n return this.get(`/inventory?${params}`);\n }\n\n async query(sql: string): Promise<QueryResult> {\n return this.request('/query', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ sql }),\n });\n }\n\n private async get<T>(path: string): Promise<T> {\n return this.request(path, { method: 'GET' });\n }\n\n private async request<T>(path: string, init: RequestInit): Promise<T> {\n const baseUrl = await this.discoveryApi.getBaseUrl('anyshift');\n const response = await this.fetchApi.fetch(`${baseUrl}${path}`, init);\n const text = await response.text();\n let payload: any;\n try {\n payload = text ? JSON.parse(text) : {};\n } catch {\n payload = {};\n }\n if (!response.ok) {\n throw new Error(\n payload?.error?.message ||\n `Anyshift request failed (${response.status})`,\n );\n }\n return payload as T;\n }\n}\n\nfunction briefQuery(options: BriefRequestOptions): string {\n const params = new URLSearchParams();\n if (options.namespace) params.set('namespace', options.namespace);\n if (options.refresh) params.set('refresh', '1');\n const query = params.toString();\n return query ? `?${query}` : '';\n}\n"],"names":[],"mappings":";;AA2CO,MAAM,iBAAiB,YAAA,CAA0B;AAAA,EACtD,EAAA,EAAI;AACN,CAAC;AAEM,MAAM,cAAA,CAAsC;AAAA,EAChC,YAAA;AAAA,EACA,QAAA;AAAA,EAEjB,YAAY,OAAA,EAA6D;AACvE,IAAA,IAA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IACb;AACA,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,OAAA,EAAS,KAAA,EAAO,OAAA,IACd,CAAA,yBAAA,EAA4B,SAAS,MAAM,CAAA,CAAA;AAAA,OAC/C;AAAA,IACF;AACA,IAAA,OAAO,OAAA;AAAA,EACT;AACF;AAEA,SAAS,WAAW,OAAA,EAAsC;AACxD,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AACnC,EAAA,IAAI,QAAQ,SAAA,EAAW,MAAA,CAAO,GAAA,CAAI,WAAA,EAAa,QAAQ,SAAS,CAAA;AAChE,EAAA,IAAI,OAAA,CAAQ,OAAA,EAAS,MAAA,CAAO,GAAA,CAAI,WAAW,GAAG,CAAA;AAC9C,EAAA,MAAM,KAAA,GAAQ,OAAO,QAAA,EAAS;AAC9B,EAAA,OAAO,KAAA,GAAQ,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,GAAK,EAAA;AAC/B;;;;"}
|
|
1
|
+
{"version":3,"file":"AnyshiftApi.esm.js","sources":["../../src/api/AnyshiftApi.ts"],"sourcesContent":["import {\n createApiRef,\n type DiscoveryApi,\n type FetchApi,\n} from '@backstage/frontend-plugin-api';\nimport type {\n BriefSectionName,\n BriefSectionResponse,\n AnyshiftCapabilities,\n AskAnyshiftRequest,\n AskAnyshiftResponse,\n CatalogSummary,\n CatalogSyncReport,\n CloudResourceBrief,\n DatadogSignals,\n EstateInsights,\n QueryResult,\n ServiceBrief,\n} from './types';\n\nexport interface AnyshiftApi {\n ask(request: AskAnyshiftRequest): Promise<AskAnyshiftResponse>;\n capabilities(): Promise<AnyshiftCapabilities>;\n brief(\n kind: string,\n target: string,\n options?: BriefRequestOptions,\n ): Promise<ServiceBrief>;\n briefSection(\n kind: string,\n target: string,\n section: BriefSectionName,\n options?: BriefRequestOptions,\n ): Promise<BriefSectionResponse>;\n insights(options?: { refresh?: boolean }): Promise<EstateInsights>;\n datadogSignals(options?: { refresh?: boolean }): Promise<DatadogSignals>;\n cloudResourceBrief(\n resource: string,\n options?: CloudResourceBriefRequestOptions,\n ): Promise<CloudResourceBrief>;\n inventory(\n type: string,\n options?: { limit?: number; offset?: number },\n ): Promise<CatalogSummary>;\n query(sql: string): Promise<QueryResult>;\n reconcileCatalog(): Promise<CatalogSyncAccepted>;\n}\n\nexport interface BriefRequestOptions {\n namespace?: string;\n refresh?: boolean;\n configurationEndpoints?: string;\n configurationDependencies?: string;\n configurationTarget?: string;\n}\n\nexport interface CloudResourceBriefRequestOptions {\n fallbackResource?: string;\n since?: string;\n cursor?: string;\n diff?: boolean;\n refresh?: boolean;\n}\n\nexport interface CatalogSyncAccepted {\n accepted: true;\n acceptedAt: string;\n previous?: CatalogSyncReport;\n}\n\nexport const anyshiftApiRef = createApiRef<AnyshiftApi>({\n id: 'plugin.anyshift.service',\n});\n\nexport class AnyshiftRequestError extends Error {\n constructor(\n readonly status: number,\n readonly code: string,\n message: string,\n readonly retryAfterSeconds?: number,\n ) {\n super(message);\n this.name = 'AnyshiftRequestError';\n }\n}\n\nexport class AnyshiftClient implements AnyshiftApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: { discoveryApi: DiscoveryApi; fetchApi: FetchApi }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n }\n\n async ask(request: AskAnyshiftRequest): Promise<AskAnyshiftResponse> {\n return this.request('/ask', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(request),\n });\n }\n\n async capabilities(): Promise<AnyshiftCapabilities> {\n return this.get('/capabilities');\n }\n\n async brief(\n kind: string,\n target: string,\n options: BriefRequestOptions = {},\n ): Promise<ServiceBrief> {\n return this.get(\n `/brief/${encodeURIComponent(kind)}/${encodeURIComponent(\n target,\n )}${briefQuery(options)}`,\n );\n }\n\n async briefSection(\n kind: string,\n target: string,\n section: BriefSectionName,\n options: BriefRequestOptions = {},\n ): Promise<BriefSectionResponse> {\n return this.get(\n `/brief/${encodeURIComponent(kind)}/${encodeURIComponent(\n target,\n )}/sections/${encodeURIComponent(section)}${briefQuery(options)}`,\n );\n }\n\n async insights(options: { refresh?: boolean } = {}): Promise<EstateInsights> {\n return this.get(`/insights${options.refresh ? '?refresh=1' : ''}`);\n }\n\n async datadogSignals(\n options: { refresh?: boolean } = {},\n ): Promise<DatadogSignals> {\n return this.get(`/signals/datadog${options.refresh ? '?refresh=1' : ''}`);\n }\n\n async cloudResourceBrief(\n resource: string,\n options: CloudResourceBriefRequestOptions = {},\n ): Promise<CloudResourceBrief> {\n const params = new URLSearchParams({ resource });\n if (options.fallbackResource)\n params.set('fallbackResource', options.fallbackResource);\n if (options.since) params.set('since', options.since);\n if (options.cursor) params.set('cursor', options.cursor);\n if (options.diff !== undefined) params.set('diff', String(options.diff));\n if (options.refresh) params.set('refresh', '1');\n return this.get(`/cloud/resources/brief?${params}`);\n }\n\n async inventory(\n type: string,\n options: { limit?: number; offset?: number } = {},\n ): Promise<CatalogSummary> {\n const params = new URLSearchParams({ type });\n if (options.limit !== undefined) params.set('limit', String(options.limit));\n if (options.offset !== undefined)\n params.set('offset', String(options.offset));\n return this.get(`/inventory?${params}`);\n }\n\n async query(sql: string): Promise<QueryResult> {\n return this.request('/query', {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ sql }),\n });\n }\n\n async reconcileCatalog(): Promise<CatalogSyncAccepted> {\n return this.request('/anyshift/reconcile', { method: 'POST' }, 'catalog');\n }\n\n private async get<T>(path: string): Promise<T> {\n return this.request(path, { method: 'GET' });\n }\n\n private async request<T>(\n path: string,\n init: RequestInit,\n pluginId = 'anyshift',\n ): Promise<T> {\n const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);\n const response = await this.fetchApi.fetch(`${baseUrl}${path}`, init);\n const text = await response.text();\n let payload: unknown;\n try {\n payload = text ? JSON.parse(text) : {};\n } catch {\n payload = {};\n }\n if (!response.ok) {\n const error = errorEnvelope(payload);\n throw new AnyshiftRequestError(\n response.status,\n error.code,\n error.message ?? `Anyshift request failed (${response.status})`,\n error.retryAfterSeconds,\n );\n }\n return payload as T;\n }\n}\n\nfunction errorEnvelope(payload: unknown): {\n code: string;\n message?: string;\n retryAfterSeconds?: number;\n} {\n const error =\n payload && typeof payload === 'object' && 'error' in payload\n ? (payload as { error?: unknown }).error\n : undefined;\n if (!error || typeof error !== 'object') {\n return { code: 'request_failed' };\n }\n\n const { code, message, retryAfterSeconds } = error as {\n code?: unknown;\n message?: unknown;\n retryAfterSeconds?: unknown;\n };\n return {\n code: typeof code === 'string' ? code : 'request_failed',\n message: typeof message === 'string' && message ? message : undefined,\n retryAfterSeconds:\n typeof retryAfterSeconds === 'number' &&\n Number.isFinite(retryAfterSeconds)\n ? retryAfterSeconds\n : undefined,\n };\n}\n\nfunction briefQuery(options: BriefRequestOptions): string {\n const params = new URLSearchParams();\n if (options.namespace) params.set('namespace', options.namespace);\n if (options.refresh) params.set('refresh', '1');\n if (options.configurationEndpoints)\n params.set('configurationEndpoints', options.configurationEndpoints);\n if (options.configurationDependencies)\n params.set('configurationDependencies', options.configurationDependencies);\n if (options.configurationTarget)\n params.set('configurationTarget', options.configurationTarget);\n const query = params.toString();\n return query ? `?${query}` : '';\n}\n"],"names":[],"mappings":";;AAsEO,MAAM,iBAAiB,YAAA,CAA0B;AAAA,EACtD,EAAA,EAAI;AACN,CAAC;AAEM,MAAM,6BAA6B,KAAA,CAAM;AAAA,EAC9C,WAAA,CACW,MAAA,EACA,IAAA,EACT,OAAA,EACS,iBAAA,EACT;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AALJ,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAEA,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA;AAGT,IAAA,IAAA,CAAK,IAAA,GAAO,sBAAA;AAAA,EACd;AAAA,EAPW,MAAA;AAAA,EAC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nC,EAAA,IAAI,QAAQ,SAAA,EAAW,MAAA,CAAO,GAAA,CAAI,WAAA,EAAa,QAAQ,SAAS,CAAA;AAChE,EAAA,IAAI,OAAA,CAAQ,OAAA,EAAS,MAAA,CAAO,GAAA,CAAI,WAAW,GAAG,CAAA;AAC9C,EAAA,IAAI,OAAA,CAAQ,sBAAA;AACV,IAAA,MAAA,CAAO,GAAA,CAAI,wBAAA,EAA0B,OAAA,CAAQ,sBAAsB,CAAA;AACrE,EAAA,IAAI,OAAA,CAAQ,yBAAA;AACV,IAAA,MAAA,CAAO,GAAA,CAAI,2BAAA,EAA6B,OAAA,CAAQ,yBAAyB,CAAA;AAC3E,EAAA,IAAI,OAAA,CAAQ,mBAAA;AACV,IAAA,MAAA,CAAO,GAAA,CAAI,qBAAA,EAAuB,OAAA,CAAQ,mBAAmB,CAAA;AAC/D,EAAA,MAAM,KAAA,GAAQ,OAAO,QAAA,EAAS;AAC9B,EAAA,OAAO,KAAA,GAAQ,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,GAAK,EAAA;AAC/B;;;;"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { Card, CardContent, Typography, Box, Chip, Button, TextField, CircularProgress } from '@material-ui/core';
|
|
3
|
+
import { useApi } from '@backstage/frontend-plugin-api';
|
|
4
|
+
import { useRef, useState, useLayoutEffect } from 'react';
|
|
5
|
+
import { anyshiftApiRef, AnyshiftRequestError } from '../../api/AnyshiftApi.esm.js';
|
|
6
|
+
import { scopedSuggestions, estateSuggestions, followUpsForIntent } from './askSuggestions.esm.js';
|
|
7
|
+
import { presentAskResult, AskResultPresenter } from './askPresenters.esm.js';
|
|
8
|
+
|
|
9
|
+
const MAX_QUESTION_CODE_POINTS = 500;
|
|
10
|
+
const MAX_SCOPE_TARGET_CODE_POINTS = 200;
|
|
11
|
+
const IDLE_HELPER_TEXT = "Read-only answers from your connected graph. Do not include secrets.";
|
|
12
|
+
const AskAnyshiftCard = ({
|
|
13
|
+
context,
|
|
14
|
+
scope,
|
|
15
|
+
scopeLabel
|
|
16
|
+
}) => {
|
|
17
|
+
const api = useApi(anyshiftApiRef);
|
|
18
|
+
const validPropScope = context === "entity" && isValidScope(scope) ? scope : void 0;
|
|
19
|
+
const propScopeIdentity = context === "entity" && scope?.entityRef.trim() ? scope.entityRef : void 0;
|
|
20
|
+
const mountedIdentity = context === "estate" ? "estate" : `entity:${propScopeIdentity ?? ""}`;
|
|
21
|
+
const previousMountedIdentity = useRef(mountedIdentity);
|
|
22
|
+
const requestGeneration = useRef(0);
|
|
23
|
+
const activeRequest = useRef();
|
|
24
|
+
const [question, setQuestion] = useState("");
|
|
25
|
+
const [validationError, setValidationError] = useState();
|
|
26
|
+
const [state, setState] = useState({ status: "idle" });
|
|
27
|
+
const [scopeRemoved, setScopeRemoved] = useState(false);
|
|
28
|
+
const localScope = scopeRemoved ? void 0 : validPropScope;
|
|
29
|
+
const restorableScope = validPropScope;
|
|
30
|
+
const visibleScopeLabel = scopeLabel?.trim() || localScope?.target;
|
|
31
|
+
const restorableScopeLabel = scopeLabel?.trim() || restorableScope?.target;
|
|
32
|
+
const requestContext = requestContextKey(
|
|
33
|
+
context,
|
|
34
|
+
propScopeIdentity,
|
|
35
|
+
localScope
|
|
36
|
+
);
|
|
37
|
+
const previousRequestContext = useRef(requestContext);
|
|
38
|
+
useLayoutEffect(() => {
|
|
39
|
+
if (previousMountedIdentity.current === mountedIdentity) return;
|
|
40
|
+
previousMountedIdentity.current = mountedIdentity;
|
|
41
|
+
requestGeneration.current += 1;
|
|
42
|
+
activeRequest.current = void 0;
|
|
43
|
+
setState({ status: "idle" });
|
|
44
|
+
setValidationError(void 0);
|
|
45
|
+
setScopeRemoved(false);
|
|
46
|
+
}, [mountedIdentity]);
|
|
47
|
+
useLayoutEffect(() => {
|
|
48
|
+
if (previousRequestContext.current === requestContext) return;
|
|
49
|
+
previousRequestContext.current = requestContext;
|
|
50
|
+
requestGeneration.current += 1;
|
|
51
|
+
if (!activeRequest.current) return;
|
|
52
|
+
activeRequest.current = void 0;
|
|
53
|
+
setState(
|
|
54
|
+
(current) => current.status === "loading" ? { status: "idle" } : current
|
|
55
|
+
);
|
|
56
|
+
setValidationError(void 0);
|
|
57
|
+
}, [requestContext]);
|
|
58
|
+
const loading = state.status === "loading";
|
|
59
|
+
const examples = localScope ? scopedSuggestions : estateSuggestions;
|
|
60
|
+
const visibleAnswer = answerForState(state);
|
|
61
|
+
const previousAnswer = state.status === "loading" || state.status === "error" ? state.previous : void 0;
|
|
62
|
+
const submitQuestion = async (explicitQuestion = question) => {
|
|
63
|
+
if (activeRequest.current?.requestContext === requestContext) return;
|
|
64
|
+
const clientError = validateQuestion(explicitQuestion);
|
|
65
|
+
if (clientError) {
|
|
66
|
+
setValidationError(clientError);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
setValidationError(void 0);
|
|
70
|
+
const generation = requestGeneration.current + 1;
|
|
71
|
+
requestGeneration.current = generation;
|
|
72
|
+
activeRequest.current = { generation, requestContext };
|
|
73
|
+
const previous = visibleAnswer;
|
|
74
|
+
setState({ status: "loading", previous });
|
|
75
|
+
try {
|
|
76
|
+
const request = localScope ? { question: explicitQuestion, scope: localScope } : { question: explicitQuestion };
|
|
77
|
+
const answer = await api.ask(request);
|
|
78
|
+
if (ownsActiveRequest(activeRequest.current, generation, requestContext)) {
|
|
79
|
+
setState({ status: "success", answer });
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (ownsActiveRequest(activeRequest.current, generation, requestContext)) {
|
|
83
|
+
setState({
|
|
84
|
+
status: "error",
|
|
85
|
+
error: safeRequestError(error),
|
|
86
|
+
previous
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
if (ownsActiveRequest(activeRequest.current, generation, requestContext)) {
|
|
91
|
+
activeRequest.current = void 0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const submitExplicitQuestion = (nextQuestion) => {
|
|
96
|
+
if (activeRequest.current?.requestContext === requestContext) return;
|
|
97
|
+
setQuestion(nextQuestion);
|
|
98
|
+
void submitQuestion(nextQuestion);
|
|
99
|
+
};
|
|
100
|
+
const onSubmit = (event) => {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
void submitQuestion();
|
|
103
|
+
};
|
|
104
|
+
const onQuestionKeyDown = (event) => {
|
|
105
|
+
if (event.key !== "Enter" || !event.metaKey && !event.ctrlKey) return;
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
void submitQuestion();
|
|
108
|
+
};
|
|
109
|
+
return /* @__PURE__ */ jsx(Card, { variant: "outlined", children: /* @__PURE__ */ jsxs(CardContent, { children: [
|
|
110
|
+
/* @__PURE__ */ jsx(Typography, { component: "h2", variant: "h6", gutterBottom: true, children: "Ask Anyshift" }),
|
|
111
|
+
context === "entity" && /* @__PURE__ */ jsx(
|
|
112
|
+
Box,
|
|
113
|
+
{
|
|
114
|
+
mb: 2,
|
|
115
|
+
display: "flex",
|
|
116
|
+
alignItems: "center",
|
|
117
|
+
flexWrap: "wrap",
|
|
118
|
+
gridGap: 8,
|
|
119
|
+
children: localScope ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
120
|
+
/* @__PURE__ */ jsx(
|
|
121
|
+
Chip,
|
|
122
|
+
{
|
|
123
|
+
size: "small",
|
|
124
|
+
color: "primary",
|
|
125
|
+
variant: "outlined",
|
|
126
|
+
label: `Scope \xB7 ${visibleScopeLabel}`
|
|
127
|
+
}
|
|
128
|
+
),
|
|
129
|
+
/* @__PURE__ */ jsx(
|
|
130
|
+
Button,
|
|
131
|
+
{
|
|
132
|
+
type: "button",
|
|
133
|
+
size: "small",
|
|
134
|
+
disabled: loading,
|
|
135
|
+
onClick: () => setScopeRemoved(true),
|
|
136
|
+
"aria-label": `Remove ${visibleScopeLabel} scope`,
|
|
137
|
+
children: "Remove"
|
|
138
|
+
}
|
|
139
|
+
)
|
|
140
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
141
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "Searching the whole connected project" }),
|
|
142
|
+
restorableScope && /* @__PURE__ */ jsx(
|
|
143
|
+
Button,
|
|
144
|
+
{
|
|
145
|
+
type: "button",
|
|
146
|
+
size: "small",
|
|
147
|
+
disabled: loading,
|
|
148
|
+
onClick: () => setScopeRemoved(false),
|
|
149
|
+
"aria-label": `Restore ${restorableScopeLabel} scope`,
|
|
150
|
+
children: "Restore scope"
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
] })
|
|
154
|
+
}
|
|
155
|
+
),
|
|
156
|
+
/* @__PURE__ */ jsxs("form", { onSubmit, noValidate: true, children: [
|
|
157
|
+
/* @__PURE__ */ jsx(
|
|
158
|
+
TextField,
|
|
159
|
+
{
|
|
160
|
+
id: "ask-anyshift-question",
|
|
161
|
+
label: "Question",
|
|
162
|
+
value: question,
|
|
163
|
+
onChange: (event) => {
|
|
164
|
+
setQuestion(event.target.value);
|
|
165
|
+
if (validationError) setValidationError(void 0);
|
|
166
|
+
},
|
|
167
|
+
onKeyDown: onQuestionKeyDown,
|
|
168
|
+
disabled: loading,
|
|
169
|
+
error: Boolean(validationError),
|
|
170
|
+
helperText: validationError ?? IDLE_HELPER_TEXT,
|
|
171
|
+
multiline: true,
|
|
172
|
+
minRows: 2,
|
|
173
|
+
fullWidth: true,
|
|
174
|
+
variant: "outlined"
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
/* @__PURE__ */ jsx(Box, { mt: 1, display: "flex", justifyContent: "flex-end", children: /* @__PURE__ */ jsx(
|
|
178
|
+
Button,
|
|
179
|
+
{
|
|
180
|
+
type: "submit",
|
|
181
|
+
color: "primary",
|
|
182
|
+
variant: "contained",
|
|
183
|
+
disabled: loading,
|
|
184
|
+
startIcon: loading ? /* @__PURE__ */ jsx(CircularProgress, { size: 16 }) : void 0,
|
|
185
|
+
children: loading ? "Asking\u2026" : "Ask"
|
|
186
|
+
}
|
|
187
|
+
) })
|
|
188
|
+
] }),
|
|
189
|
+
/* @__PURE__ */ jsx(
|
|
190
|
+
QuestionChoices,
|
|
191
|
+
{
|
|
192
|
+
title: "Try an example",
|
|
193
|
+
questions: examples,
|
|
194
|
+
disabled: loading,
|
|
195
|
+
onQuestion: submitExplicitQuestion
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
state.status === "error" && /* @__PURE__ */ jsxs(Box, { mt: 2, role: "alert", "aria-live": "polite", children: [
|
|
199
|
+
/* @__PURE__ */ jsx(Typography, { color: "error", children: errorCopy(state.error) }),
|
|
200
|
+
isRetryable(state.error) && /* @__PURE__ */ jsx(Box, { mt: 1, children: /* @__PURE__ */ jsx(
|
|
201
|
+
Button,
|
|
202
|
+
{
|
|
203
|
+
type: "button",
|
|
204
|
+
size: "small",
|
|
205
|
+
variant: "outlined",
|
|
206
|
+
onClick: () => void submitQuestion(),
|
|
207
|
+
children: "Retry"
|
|
208
|
+
}
|
|
209
|
+
) })
|
|
210
|
+
] }),
|
|
211
|
+
loading && /* @__PURE__ */ jsx(Typography, { role: "status", variant: "body2", color: "textSecondary", children: "Searching the connected graph\u2026" }),
|
|
212
|
+
visibleAnswer && /* @__PURE__ */ jsxs(Box, { mt: 3, children: [
|
|
213
|
+
previousAnswer && /* @__PURE__ */ jsx(Typography, { component: "h3", variant: "subtitle2", gutterBottom: true, children: "Previous answer" }),
|
|
214
|
+
/* @__PURE__ */ jsx(
|
|
215
|
+
SafeAnswer,
|
|
216
|
+
{
|
|
217
|
+
answer: visibleAnswer,
|
|
218
|
+
onQuestion: loading ? void 0 : submitExplicitQuestion
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
!loading && /* @__PURE__ */ jsx(
|
|
222
|
+
QuestionChoices,
|
|
223
|
+
{
|
|
224
|
+
title: "Ask another question",
|
|
225
|
+
questions: followUpsForIntent(
|
|
226
|
+
visibleAnswer.result.intent,
|
|
227
|
+
Boolean(localScope)
|
|
228
|
+
),
|
|
229
|
+
disabled: false,
|
|
230
|
+
onQuestion: submitExplicitQuestion
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
] })
|
|
234
|
+
] }) });
|
|
235
|
+
};
|
|
236
|
+
const QuestionChoices = ({
|
|
237
|
+
title,
|
|
238
|
+
questions,
|
|
239
|
+
disabled,
|
|
240
|
+
onQuestion
|
|
241
|
+
}) => /* @__PURE__ */ jsxs(Box, { mt: 2, children: [
|
|
242
|
+
/* @__PURE__ */ jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: title }),
|
|
243
|
+
/* @__PURE__ */ jsx(Box, { display: "flex", flexWrap: "wrap", gridGap: 8, children: questions.map((suggestion) => /* @__PURE__ */ jsx(
|
|
244
|
+
Button,
|
|
245
|
+
{
|
|
246
|
+
type: "button",
|
|
247
|
+
size: "small",
|
|
248
|
+
variant: "outlined",
|
|
249
|
+
disabled,
|
|
250
|
+
onClick: () => onQuestion(suggestion),
|
|
251
|
+
children: suggestion
|
|
252
|
+
},
|
|
253
|
+
suggestion
|
|
254
|
+
)) })
|
|
255
|
+
] });
|
|
256
|
+
const SafeAnswer = ({
|
|
257
|
+
answer,
|
|
258
|
+
onQuestion
|
|
259
|
+
}) => {
|
|
260
|
+
try {
|
|
261
|
+
presentAskResult(answer.result);
|
|
262
|
+
} catch {
|
|
263
|
+
return /* @__PURE__ */ jsxs(Box, { "aria-label": "Anyshift answer", children: [
|
|
264
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body1", children: answer.result.summary }),
|
|
265
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "Detailed evidence is not supported by this Backstage version." })
|
|
266
|
+
] });
|
|
267
|
+
}
|
|
268
|
+
return /* @__PURE__ */ jsx(
|
|
269
|
+
AskResultPresenter,
|
|
270
|
+
{
|
|
271
|
+
result: answer.result,
|
|
272
|
+
effectiveQuestion: answer.effectiveQuestion,
|
|
273
|
+
answeredAt: answer.answeredAt,
|
|
274
|
+
onQuestion
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
function answerForState(state) {
|
|
279
|
+
switch (state.status) {
|
|
280
|
+
case "success":
|
|
281
|
+
return state.answer;
|
|
282
|
+
case "loading":
|
|
283
|
+
case "error":
|
|
284
|
+
return state.previous;
|
|
285
|
+
case "idle":
|
|
286
|
+
return void 0;
|
|
287
|
+
default:
|
|
288
|
+
return assertNever(state);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function ownsActiveRequest(activeRequest, generation, requestContext) {
|
|
292
|
+
return activeRequest?.generation === generation && activeRequest.requestContext === requestContext;
|
|
293
|
+
}
|
|
294
|
+
function requestContextKey(context, entityRef, scope) {
|
|
295
|
+
if (context === "estate") return "estate";
|
|
296
|
+
const identity = entityRef?.trim() ?? "";
|
|
297
|
+
return scope ? `entity:${identity}:target:${scope.target.trim()}` : `entity:${identity}:unscoped`;
|
|
298
|
+
}
|
|
299
|
+
function validateQuestion(value) {
|
|
300
|
+
if (!value.trim()) return "Enter a question.";
|
|
301
|
+
if (Array.from(value).length > MAX_QUESTION_CODE_POINTS) {
|
|
302
|
+
return "Questions must be 500 characters or fewer.";
|
|
303
|
+
}
|
|
304
|
+
return void 0;
|
|
305
|
+
}
|
|
306
|
+
function isValidScope(scope) {
|
|
307
|
+
if (!scope?.entityRef.trim() || !scope.target.trim()) return false;
|
|
308
|
+
if (Array.from(scope.target).length > MAX_SCOPE_TARGET_CODE_POINTS) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
return !Array.from(scope.target).some((character) => {
|
|
312
|
+
const codePoint = character.codePointAt(0);
|
|
313
|
+
return codePoint !== void 0 && (codePoint <= 31 || codePoint >= 127 && codePoint <= 159);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
function safeRequestError(error) {
|
|
317
|
+
return error instanceof AnyshiftRequestError ? error : new AnyshiftRequestError(0, "unavailable", "Unavailable");
|
|
318
|
+
}
|
|
319
|
+
function errorCopy(error) {
|
|
320
|
+
if (error.status === 400 || error.code === "bad_request") {
|
|
321
|
+
return "Ask Anyshift could not answer that question. Try rephrasing it or choose an example.";
|
|
322
|
+
}
|
|
323
|
+
if (error.status === 403 || error.code === "forbidden") {
|
|
324
|
+
return "Ask Anyshift access is unavailable for your account.";
|
|
325
|
+
}
|
|
326
|
+
if (error.status === 413 || error.code === "payload_too_large") {
|
|
327
|
+
return "Questions must be 500 characters or fewer.";
|
|
328
|
+
}
|
|
329
|
+
if (error.status === 429 || error.code === "rate_limited") {
|
|
330
|
+
return typeof error.retryAfterSeconds === "number" ? `Ask Anyshift is temporarily rate limited. Try again in ${error.retryAfterSeconds} seconds.` : "Ask Anyshift is temporarily rate limited. Try again shortly.";
|
|
331
|
+
}
|
|
332
|
+
if (error.status === 504 || error.code === "timeout") {
|
|
333
|
+
return "The graph question timed out. Try again.";
|
|
334
|
+
}
|
|
335
|
+
if (error.status === 0 || error.status === 502 || error.status === 503 || error.code === "unavailable" || error.code === "upstream_unavailable" || error.code === "request_failed") {
|
|
336
|
+
return "Ask Anyshift is temporarily unavailable. Try again.";
|
|
337
|
+
}
|
|
338
|
+
return "Ask Anyshift could not complete the question. Try again.";
|
|
339
|
+
}
|
|
340
|
+
function isRetryable(error) {
|
|
341
|
+
return error.status === 0 || error.status === 429 || error.status === 502 || error.status === 503 || error.status === 504 || error.code === "timeout" || error.code === "unavailable" || error.code === "upstream_unavailable" || error.code === "request_failed";
|
|
342
|
+
}
|
|
343
|
+
function assertNever(value) {
|
|
344
|
+
throw new Error(`Unsupported Ask card state: ${String(value)}`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export { AskAnyshiftCard };
|
|
348
|
+
//# sourceMappingURL=AskAnyshiftCard.esm.js.map
|