@zeniai/client-epic-state 5.2.4 → 5.2.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.
- package/lib/epic.js +12 -0
- package/lib/esm/epic.js +12 -0
- package/lib/esm/index.js +2 -2
- package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +411 -9
- package/lib/esm/view/aiCfoView/aiCfoViewSelector.js +49 -0
- package/lib/esm/view/aiCfoView/epics/deleteSkillEpic.js +23 -0
- package/lib/esm/view/aiCfoView/epics/fetchSkillDetailEpic.js +35 -0
- package/lib/esm/view/aiCfoView/epics/fetchSkillVersionBodyEpic.js +45 -0
- package/lib/esm/view/aiCfoView/epics/fetchSkillVersionsEpic.js +37 -0
- package/lib/esm/view/aiCfoView/epics/fetchSkillsEpic.js +11 -6
- package/lib/esm/view/aiCfoView/epics/saveSkillEpic.js +72 -0
- package/lib/esm/view/aiCfoView/epics/setSkillVisibilityEpic.js +32 -0
- package/lib/esm/view/aiCfoView/epics/toSkillDetail.js +102 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +26 -11
- package/lib/view/aiCfoView/aiCfoViewPayload.d.ts +85 -0
- package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +67 -2
- package/lib/view/aiCfoView/aiCfoViewReducer.js +413 -10
- package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +7 -1
- package/lib/view/aiCfoView/aiCfoViewSelector.js +54 -0
- package/lib/view/aiCfoView/aiCfoViewState.d.ts +143 -1
- package/lib/view/aiCfoView/epics/deleteSkillEpic.d.ts +8 -0
- package/lib/view/aiCfoView/epics/deleteSkillEpic.js +27 -0
- package/lib/view/aiCfoView/epics/fetchSkillDetailEpic.d.ts +8 -0
- package/lib/view/aiCfoView/epics/fetchSkillDetailEpic.js +39 -0
- package/lib/view/aiCfoView/epics/fetchSkillVersionBodyEpic.d.ts +13 -0
- package/lib/view/aiCfoView/epics/fetchSkillVersionBodyEpic.js +49 -0
- package/lib/view/aiCfoView/epics/fetchSkillVersionsEpic.d.ts +8 -0
- package/lib/view/aiCfoView/epics/fetchSkillVersionsEpic.js +41 -0
- package/lib/view/aiCfoView/epics/fetchSkillsEpic.js +11 -6
- package/lib/view/aiCfoView/epics/saveSkillEpic.d.ts +14 -0
- package/lib/view/aiCfoView/epics/saveSkillEpic.js +76 -0
- package/lib/view/aiCfoView/epics/setSkillVisibilityEpic.d.ts +14 -0
- package/lib/view/aiCfoView/epics/setSkillVisibilityEpic.js +36 -0
- package/lib/view/aiCfoView/epics/toSkillDetail.d.ts +88 -0
- package/lib/view/aiCfoView/epics/toSkillDetail.js +110 -0
- package/lib/view/taskManager/taskListView/taskList.d.ts +1 -1
- package/package.json +1 -1
|
@@ -29,7 +29,56 @@ const EMPTY_SKILLS_STATE = {
|
|
|
29
29
|
fetchState: 'Not-Started',
|
|
30
30
|
error: undefined,
|
|
31
31
|
skills: [],
|
|
32
|
+
// false, so the Skills entry stays hidden until the server confirms the feature
|
|
33
|
+
// is on. Defaulting true would flash a menu at tenants who never get one.
|
|
34
|
+
skillsEnabled: false,
|
|
35
|
+
// false, for the same reason as skillsEnabled: withhold the publish control until the
|
|
36
|
+
// server says this user may use it.
|
|
37
|
+
canPublish: false,
|
|
38
|
+
deletedMacroIds: [],
|
|
39
|
+
};
|
|
40
|
+
const EMPTY_SKILL_DETAIL_STATE = {
|
|
41
|
+
fetchState: 'Not-Started',
|
|
42
|
+
error: undefined,
|
|
43
|
+
detail: undefined,
|
|
44
|
+
macroId: undefined,
|
|
45
|
+
};
|
|
46
|
+
// Same stable-fallback reason as the two above: a selector that built a fresh object
|
|
47
|
+
// each call would re-render every subscriber on every unrelated state change.
|
|
48
|
+
const EMPTY_SKILL_VERSIONS_STATE = {
|
|
49
|
+
fetchState: 'Not-Started',
|
|
50
|
+
error: undefined,
|
|
51
|
+
versions: [],
|
|
52
|
+
macroId: undefined,
|
|
53
|
+
};
|
|
54
|
+
const EMPTY_SKILL_VERSION_BODY_STATE = {
|
|
55
|
+
fetchState: 'Not-Started',
|
|
56
|
+
error: undefined,
|
|
57
|
+
instructions: undefined,
|
|
58
|
+
macroId: undefined,
|
|
59
|
+
version: undefined,
|
|
60
|
+
};
|
|
61
|
+
const EMPTY_SKILL_MUTATION_STATE = {
|
|
62
|
+
fetchState: 'Not-Started',
|
|
63
|
+
error: undefined,
|
|
64
|
+
savedMacroId: undefined,
|
|
32
65
|
};
|
|
33
66
|
export function getSkills(state) {
|
|
34
67
|
return state.aiCfoViewState?.skills ?? EMPTY_SKILLS_STATE;
|
|
35
68
|
}
|
|
69
|
+
export function getSkillDetail(state) {
|
|
70
|
+
return state.aiCfoViewState?.skillDetail ?? EMPTY_SKILL_DETAIL_STATE;
|
|
71
|
+
}
|
|
72
|
+
export function getSkillVersions(state) {
|
|
73
|
+
return state.aiCfoViewState?.skillVersions ?? EMPTY_SKILL_VERSIONS_STATE;
|
|
74
|
+
}
|
|
75
|
+
export function getSkillVersionBody(state) {
|
|
76
|
+
return (state.aiCfoViewState?.skillVersionBody ?? EMPTY_SKILL_VERSION_BODY_STATE);
|
|
77
|
+
}
|
|
78
|
+
export function getSkillMutation(state) {
|
|
79
|
+
return state.aiCfoViewState?.skillMutation ?? EMPTY_SKILL_MUTATION_STATE;
|
|
80
|
+
}
|
|
81
|
+
/** True only when the server says the feature is on for this tenant. */
|
|
82
|
+
export function getSkillsEnabled(state) {
|
|
83
|
+
return getSkills(state).skillsEnabled;
|
|
84
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessStatus } from '../../../responsePayload';
|
|
4
|
+
import { deleteSkill, deleteSkillFailure, deleteSkillSuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
/** DELETE /1.0/skills/{macroId} — soft-deletes every version, frees the name. */
|
|
6
|
+
export const deleteSkillEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(deleteSkill.match),
|
|
7
|
+
// mergeMap for the same reason as the save: cancelling a delete does not un-delete
|
|
8
|
+
// it, and two deletes are for different skills anyway.
|
|
9
|
+
mergeMap((action) => {
|
|
10
|
+
const { macroId } = action.payload;
|
|
11
|
+
const url = `${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/skills/${encodeURIComponent(macroId)}`;
|
|
12
|
+
return zeniAPI.deleteAndGetJSON(url).pipe(mergeMap((response) => {
|
|
13
|
+
// isSuccessStatus, NOT isSuccessResponse: the latter also requires a non-null
|
|
14
|
+
// `data`, and a successful DELETE here is a 204 with no body. Using it reported
|
|
15
|
+
// every completed delete as a failure — the row stayed on screen and a retry
|
|
16
|
+
// 404'd on a skill that was already gone. deleteChatSessionEpic uses the status
|
|
17
|
+
// check for the same reason.
|
|
18
|
+
if (isSuccessStatus(response)) {
|
|
19
|
+
return of(deleteSkillSuccess({ macroId }));
|
|
20
|
+
}
|
|
21
|
+
return of(deleteSkillFailure(response.status));
|
|
22
|
+
}), catchError((error) => of(deleteSkillFailure(createZeniAPIStatus('Unexpected Error', 'Delete skill REST API call failed', error instanceof Error ? { message: error.message } : undefined)))));
|
|
23
|
+
}));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
4
|
+
import { fetchSkillDetail, fetchSkillDetailFailure, fetchSkillDetailSuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
import { isSkillDetailPayload, toSkillDetail } from './toSkillDetail';
|
|
6
|
+
// Deliberately minimal: the browser already holds the full Skill from the list, and
|
|
7
|
+
// this response's `skill` block exists so a deep link can open a detail view without
|
|
8
|
+
// the list ever having been fetched.
|
|
9
|
+
/** GET {aiCfoMicroServiceBaseUrl}/1.0/skills/{macroId} — one skill's prompt + card. */
|
|
10
|
+
export const fetchSkillDetailEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchSkillDetail.match),
|
|
11
|
+
// switchMap: clicking through the list fires one of these per skill, and only the
|
|
12
|
+
// one the user is currently looking at matters. The reducer also drops responses
|
|
13
|
+
// whose macroId no longer matches, so a cancelled-but-in-flight request cannot
|
|
14
|
+
// render the wrong prompt under the right title.
|
|
15
|
+
switchMap((action) => {
|
|
16
|
+
const { macroId } = action.payload;
|
|
17
|
+
const url = `${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/skills/${encodeURIComponent(macroId)}`;
|
|
18
|
+
return zeniAPI.getJSON(url).pipe(mergeMap((response) => {
|
|
19
|
+
// Shared mapper and shared guard. This epic used to keep its own `toSkill`
|
|
20
|
+
// and default a missing prompt to '', so the same malformed body showed an
|
|
21
|
+
// empty prompt here and failed the read elsewhere — and `isMine` was nearly
|
|
22
|
+
// added to only two of the three copies.
|
|
23
|
+
if (isSuccessResponse(response) &&
|
|
24
|
+
isSkillDetailPayload(response.data)) {
|
|
25
|
+
return of(fetchSkillDetailSuccess({
|
|
26
|
+
detail: toSkillDetail(response.data),
|
|
27
|
+
macroId,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
return of(fetchSkillDetailFailure({ error: response.status, macroId }));
|
|
31
|
+
}), catchError((error) => of(fetchSkillDetailFailure({
|
|
32
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch skill detail REST API call failed', error instanceof Error ? { message: error.message } : undefined),
|
|
33
|
+
macroId,
|
|
34
|
+
}))));
|
|
35
|
+
}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
4
|
+
import { fetchSkillVersionBody, fetchSkillVersionBodyFailure, fetchSkillVersionBodySuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
import { hasPromptBody } from './toSkillDetail';
|
|
6
|
+
/**
|
|
7
|
+
* GET /1.0/skills/{macroId}?version=N — one historical version's prompt.
|
|
8
|
+
*
|
|
9
|
+
* Only used to seed a restore. The history list carries metadata only, deliberately: a
|
|
10
|
+
* 20-version history would otherwise be a 240kB response for a panel that shows dates.
|
|
11
|
+
*/
|
|
12
|
+
export const fetchSkillVersionBodyEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchSkillVersionBody.match),
|
|
13
|
+
// switchMap: a read, and only the version the user last clicked matters. The reducer
|
|
14
|
+
// also drops a response whose (macroId, version) no longer matches, so a
|
|
15
|
+
// cancelled-but-in-flight request cannot seed the form with the wrong body.
|
|
16
|
+
switchMap((action) => {
|
|
17
|
+
const { macroId, version } = action.payload;
|
|
18
|
+
const url = `${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/skills/${encodeURIComponent(macroId)}?version=${encodeURIComponent(String(version))}`;
|
|
19
|
+
return zeniAPI.getJSON(url).pipe(mergeMap((response) => {
|
|
20
|
+
// `instructions` checked, not just `data`: the payload TYPE says the field is
|
|
21
|
+
// required, and the network is under no obligation to agree. Without this the
|
|
22
|
+
// epic reported success with `instructions: undefined`, and the browser — which
|
|
23
|
+
// holds the editor closed until a body arrives — showed "Loading this version…"
|
|
24
|
+
// for ever, with no error and no way forward.
|
|
25
|
+
if (isSuccessResponse(response) && hasPromptBody(response.data)) {
|
|
26
|
+
return of(fetchSkillVersionBodySuccess({
|
|
27
|
+
macroId,
|
|
28
|
+
version,
|
|
29
|
+
instructions: response.data.instructions,
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
// A malformed 2xx is a failure. An empty STRING is not malformed and is allowed
|
|
33
|
+
// through: the editor's own minimum-length rule refuses to save it, so the user
|
|
34
|
+
// sees a validation message on a form they can fix rather than a dead end.
|
|
35
|
+
return of(fetchSkillVersionBodyFailure({
|
|
36
|
+
macroId,
|
|
37
|
+
version,
|
|
38
|
+
error: response.status,
|
|
39
|
+
}));
|
|
40
|
+
}), catchError((error) => of(fetchSkillVersionBodyFailure({
|
|
41
|
+
macroId,
|
|
42
|
+
version,
|
|
43
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch skill version body REST API call failed', error instanceof Error ? { message: error.message } : undefined),
|
|
44
|
+
}))));
|
|
45
|
+
}));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
4
|
+
import { fetchSkillVersions, fetchSkillVersionsFailure, fetchSkillVersionsSuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
const toVersion = (payload) => ({
|
|
6
|
+
version: payload.version,
|
|
7
|
+
semver: payload.semver ?? null,
|
|
8
|
+
displayName: payload.display_name ?? null,
|
|
9
|
+
updatedAt: payload.updated_at ?? null,
|
|
10
|
+
// Defaulted defensively: these are booleans the server always sends, but a malformed
|
|
11
|
+
// 2xx should render a row as inactive-and-not-latest rather than as the live one.
|
|
12
|
+
isActive: payload.is_active === true,
|
|
13
|
+
isLatest: payload.is_latest === true,
|
|
14
|
+
instructionsCharCount: payload.instructions_char_count ?? 0,
|
|
15
|
+
});
|
|
16
|
+
/** GET /1.0/skills/{macroId}/versions — the history panel. */
|
|
17
|
+
export const fetchSkillVersionsEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchSkillVersions.match),
|
|
18
|
+
// switchMap: a read, and only the skill currently open matters. The reducer also
|
|
19
|
+
// drops responses whose macroId no longer matches, so a cancelled-but-in-flight
|
|
20
|
+
// request cannot render one skill's history under another's title.
|
|
21
|
+
switchMap((action) => {
|
|
22
|
+
const { macroId } = action.payload;
|
|
23
|
+
const url = `${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/skills/${encodeURIComponent(macroId)}/versions`;
|
|
24
|
+
return zeniAPI.getJSON(url).pipe(mergeMap((response) => {
|
|
25
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
26
|
+
return of(fetchSkillVersionsSuccess({
|
|
27
|
+
macroId,
|
|
28
|
+
// Guard the array: a malformed 2xx without `versions` must not crash .map.
|
|
29
|
+
versions: (response.data.versions ?? []).map(toVersion),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
return of(fetchSkillVersionsFailure({ macroId, error: response.status }));
|
|
33
|
+
}), catchError((error) => of(fetchSkillVersionsFailure({
|
|
34
|
+
macroId,
|
|
35
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch skill versions REST API call failed', error instanceof Error ? { message: error.message } : undefined),
|
|
36
|
+
}))));
|
|
37
|
+
}));
|
|
@@ -2,6 +2,7 @@ import { of } from 'rxjs';
|
|
|
2
2
|
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
3
|
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
4
4
|
import { fetchSkills, fetchSkillsFailure, fetchSkillsSuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
import { toBaseSkill } from './toSkillDetail';
|
|
5
6
|
const isNonBlankString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
6
7
|
// parameter_hints is a free-form {param: exampleValue(s)} map; flatten its non-blank
|
|
7
8
|
// string values (a single string or an array of them) into display-ready "try: …"
|
|
@@ -27,14 +28,12 @@ const toExampleHints = (parameterHints) => {
|
|
|
27
28
|
// a broken duplicate to the user — dedupe across parameter keys and array entries.
|
|
28
29
|
return Array.from(new Set(hints));
|
|
29
30
|
};
|
|
31
|
+
// Only the LIST route returns parameter_hints, so this is the one call site that has
|
|
32
|
+
// hints to spread in. Everything else about a summary comes from the shared base mapper,
|
|
33
|
+
// so a new `Skill` field cannot land here and be missed on the detail path.
|
|
30
34
|
const toSkill = (skillSummaryPayload) => ({
|
|
31
|
-
|
|
32
|
-
name: skillSummaryPayload.name,
|
|
33
|
-
displayName: skillSummaryPayload.display_name,
|
|
34
|
-
description: skillSummaryPayload.description,
|
|
35
|
-
semver: skillSummaryPayload.semver,
|
|
35
|
+
...toBaseSkill(skillSummaryPayload),
|
|
36
36
|
exampleHints: toExampleHints(skillSummaryPayload.parameter_hints),
|
|
37
|
-
hasScripts: skillSummaryPayload.has_scripts,
|
|
38
37
|
});
|
|
39
38
|
/** GET {aiCfoMicroServiceBaseUrl}/1.0/skills — chat-visible skills for the `/` menu. */
|
|
40
39
|
export const fetchSkillsEpic = (actions$,
|
|
@@ -52,6 +51,12 @@ switchMap(() => {
|
|
|
52
51
|
// Guard the array: a malformed 2xx body without `skills` must not crash .map.
|
|
53
52
|
return of(fetchSkillsSuccess({
|
|
54
53
|
skills: (response.data.skills ?? []).map(toSkill),
|
|
54
|
+
// === true, not a truthy check: a body missing the field entirely
|
|
55
|
+
// must read as "off" so the Skills entry stays hidden by default.
|
|
56
|
+
skillsEnabled: response.data.skills_enabled === true,
|
|
57
|
+
// Same discipline: a body without the field must withhold the publish
|
|
58
|
+
// control, not grant it.
|
|
59
|
+
canPublish: response.data.can_publish === true,
|
|
55
60
|
}));
|
|
56
61
|
}
|
|
57
62
|
return of(fetchSkillsFailure(response.status));
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
4
|
+
import { fetchSkillVersions, fetchSkills, saveSkill, saveSkillFailure, saveSkillSuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
import { getSkillDetail } from '../aiCfoViewSelector';
|
|
6
|
+
import { isSkillDetailPayload, toSkillDetail } from './toSkillDetail';
|
|
7
|
+
/**
|
|
8
|
+
* POST /1.0/skills (create) or PUT /1.0/skills/{macroId} (new version).
|
|
9
|
+
*
|
|
10
|
+
* One epic for both because they are the same action to a user — "save what I wrote" —
|
|
11
|
+
* and the server answers both with the detail payload. Splitting them would duplicate
|
|
12
|
+
* the payload mapping and the error handling for a difference the form does not have.
|
|
13
|
+
*/
|
|
14
|
+
export const saveSkillEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(saveSkill.match),
|
|
15
|
+
// mergeMap, NOT switchMap: a save is a write. Cancelling an in-flight one because
|
|
16
|
+
// another started does not un-send it, it just hides the outcome — and for a
|
|
17
|
+
// create that means a skill exists that the user was never told about.
|
|
18
|
+
mergeMap((action) => {
|
|
19
|
+
const { draft, macroId } = action.payload;
|
|
20
|
+
const base = `${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/skills`;
|
|
21
|
+
const body = {
|
|
22
|
+
name: draft.name,
|
|
23
|
+
instructions: draft.instructions,
|
|
24
|
+
description: draft.description,
|
|
25
|
+
// Sent as the menu name too. The server derives the unique `/` slug from it, so
|
|
26
|
+
// letting the two drift would make the command stop matching the row's title.
|
|
27
|
+
display_name: draft.name,
|
|
28
|
+
// Spread, not `visibility: draft.visibility`: the server distinguishes an ABSENT
|
|
29
|
+
// visibility ("leave it alone") from an explicit null or 'private' ("make it
|
|
30
|
+
// private"). Sending the key with a null value would unpublish a tenant-wide
|
|
31
|
+
// skill on any edit by someone who cannot publish.
|
|
32
|
+
//
|
|
33
|
+
// `!= null`, not `!== null`: the type says this is always present, but the value
|
|
34
|
+
// arrives from a component, and an untyped caller omitting it would spread
|
|
35
|
+
// `{visibility: undefined}` — a key present with no value, which is the one shape
|
|
36
|
+
// the rule above is about. The looser check costs nothing and closes it.
|
|
37
|
+
...(draft.visibility != null && { visibility: draft.visibility }),
|
|
38
|
+
};
|
|
39
|
+
const request$ = macroId != null && macroId !== ''
|
|
40
|
+
? zeniAPI.putAndGetJSON(`${base}/${encodeURIComponent(macroId)}`, body)
|
|
41
|
+
: zeniAPI.postAndGetJSON(base, body);
|
|
42
|
+
return request$.pipe(mergeMap((response) => {
|
|
43
|
+
if (isSuccessResponse(response) &&
|
|
44
|
+
isSkillDetailPayload(response.data)) {
|
|
45
|
+
const saved = response.data;
|
|
46
|
+
const savedMacroId = saved.skill.macro_id;
|
|
47
|
+
const emitted = [
|
|
48
|
+
saveSkillSuccess({
|
|
49
|
+
macroId: savedMacroId,
|
|
50
|
+
// The response is a full detail read — carried through so an editor left
|
|
51
|
+
// on this skill shows what it just saved rather than the previous prompt.
|
|
52
|
+
detail: toSkillDetail(saved),
|
|
53
|
+
}),
|
|
54
|
+
// Refetch rather than splice the response in: a create changes the list's
|
|
55
|
+
// ordering and an update can change the name it is sorted by, so a local
|
|
56
|
+
// insert would put the row somewhere the next load moves it away from.
|
|
57
|
+
fetchSkills(),
|
|
58
|
+
];
|
|
59
|
+
// A save adds a version, so the history panel is one behind — but only
|
|
60
|
+
// refetch when this skill is still the one on screen. `fetchSkillVersions`
|
|
61
|
+
// takes ownership of the versions slice, so firing it for a skill the user
|
|
62
|
+
// has already left would cancel the history of whatever they opened next.
|
|
63
|
+
if (getSkillDetail(state$.value).macroId === savedMacroId) {
|
|
64
|
+
emitted.push(fetchSkillVersions({ macroId: savedMacroId }));
|
|
65
|
+
}
|
|
66
|
+
return of(...emitted);
|
|
67
|
+
}
|
|
68
|
+
// A malformed 2xx is a failure, not a silent success: reporting "saved" when
|
|
69
|
+
// no skill came back leaves the user believing work was persisted.
|
|
70
|
+
return of(saveSkillFailure(response.status));
|
|
71
|
+
}), catchError((error) => of(saveSkillFailure(createZeniAPIStatus('Unexpected Error', 'Save skill REST API call failed', error instanceof Error ? { message: error.message } : undefined)))));
|
|
72
|
+
}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
4
|
+
import { fetchSkills, setSkillVisibility, setSkillVisibilityFailure, setSkillVisibilitySuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
import { isSkillDetailPayload, toSkillDetail } from './toSkillDetail';
|
|
6
|
+
/**
|
|
7
|
+
* PUT /1.0/skills/{macroId}/visibility — publish or unpublish, without a new version.
|
|
8
|
+
*
|
|
9
|
+
* Its own route rather than the prompt PUT: that one requires name and instructions, so a
|
|
10
|
+
* visibility-only change cannot be expressed through it, and sending the whole prompt back
|
|
11
|
+
* to flip one field would create a version whose prompt is identical to its parent's.
|
|
12
|
+
*/
|
|
13
|
+
export const setSkillVisibilityEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(setSkillVisibility.match),
|
|
14
|
+
// mergeMap, like the other writes: cancelling a write in flight does not un-send it,
|
|
15
|
+
// it only hides the outcome — and for a publish that means a skill sitting in every
|
|
16
|
+
// colleague's menu with nobody told it got there.
|
|
17
|
+
mergeMap((action) => {
|
|
18
|
+
const { macroId, visibility } = action.payload;
|
|
19
|
+
const url = `${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/skills/${encodeURIComponent(macroId)}/visibility`;
|
|
20
|
+
return zeniAPI.putAndGetJSON(url, { visibility }).pipe(mergeMap((response) => {
|
|
21
|
+
if (isSuccessResponse(response) &&
|
|
22
|
+
isSkillDetailPayload(response.data)) {
|
|
23
|
+
return of(setSkillVisibilitySuccess({
|
|
24
|
+
macroId,
|
|
25
|
+
detail: toSkillDetail(response.data),
|
|
26
|
+
}),
|
|
27
|
+
// The list carries the badge that shows the audience, so it is now stale.
|
|
28
|
+
fetchSkills());
|
|
29
|
+
}
|
|
30
|
+
return of(setSkillVisibilityFailure(response.status));
|
|
31
|
+
}), catchError((error) => of(setSkillVisibilityFailure(createZeniAPIStatus('Unexpected Error', 'Set skill visibility REST API call failed', error instanceof Error ? { message: error.message } : undefined)))));
|
|
32
|
+
}));
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every value `SkillVisibility` admits, as data so the converter below cannot drift from
|
|
3
|
+
* the type. Adding a tier to the union without adding it here is a compile error.
|
|
4
|
+
*/
|
|
5
|
+
const SKILL_VISIBILITIES = ['private', 'tenant'];
|
|
6
|
+
/**
|
|
7
|
+
* A wire string narrowed to {@link SkillVisibility}, or null.
|
|
8
|
+
*
|
|
9
|
+
* A converter rather than passing the raw string through, because `Skill.visibility` is a
|
|
10
|
+
* union on the state type and this is the boundary where an unvalidated payload becomes
|
|
11
|
+
* it — the repo's rule about explicit converters at scalar boundaries instead of a bare
|
|
12
|
+
* cast.
|
|
13
|
+
*
|
|
14
|
+
* Unrecognised maps to NULL, not to `'private'`. Null already means "does not apply" for a
|
|
15
|
+
* Zeni default, and consumers show no audience badge for it — so an unknown tier renders
|
|
16
|
+
* as no badge. Defaulting to `'private'` would instead label a skill the whole tenant can
|
|
17
|
+
* run as author-only, which is a confident lie rather than a visible gap.
|
|
18
|
+
*/
|
|
19
|
+
export const toSkillVisibility = (raw) => SKILL_VISIBILITIES.find((known) => known === raw) ?? null;
|
|
20
|
+
/**
|
|
21
|
+
* Everything about a skill summary EXCEPT `exampleHints`, which no shared mapper can
|
|
22
|
+
* honestly supply.
|
|
23
|
+
*
|
|
24
|
+
* Only the LIST route returns `parameter_hints`; the detail and write routes do not. A
|
|
25
|
+
* shared mapper hardcoding `exampleHints: []` would put a "try: …" line under a skill
|
|
26
|
+
* that has hints, or drop them from the menu — so the field is `Omit`ted and each caller
|
|
27
|
+
* spreads in what its own route actually knows.
|
|
28
|
+
*
|
|
29
|
+
* Returning `Omit<Skill, 'exampleHints'>` rather than duplicating the mapper is what
|
|
30
|
+
* makes a new `Skill` field land in one place: this function stops compiling until the
|
|
31
|
+
* field is mapped, and both callers inherit it. The previous shape — two full copies —
|
|
32
|
+
* is how `isMine` was nearly added to only one of them, which would have silently
|
|
33
|
+
* withheld the edit and delete controls on whichever surface was missed.
|
|
34
|
+
*/
|
|
35
|
+
export const toBaseSkill = (payload) => ({
|
|
36
|
+
macroId: payload.macro_id,
|
|
37
|
+
name: payload.name,
|
|
38
|
+
displayName: payload.display_name,
|
|
39
|
+
description: payload.description,
|
|
40
|
+
semver: payload.semver,
|
|
41
|
+
hasScripts: payload.has_scripts === true,
|
|
42
|
+
// === true, so an absent field withholds the write controls rather than offering ones
|
|
43
|
+
// the API refuses.
|
|
44
|
+
isMine: payload.is_mine === true,
|
|
45
|
+
isOwnedByTenant: payload.is_owned_by_tenant === true,
|
|
46
|
+
updatedAt: payload.updated_at ?? null,
|
|
47
|
+
visibility: toSkillVisibility(payload.visibility),
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Whether a 2xx body carries a prompt.
|
|
51
|
+
*
|
|
52
|
+
* Narrows to {@link PromptBody} and NOT to the whole payload, because the only consumer —
|
|
53
|
+
* the version-body read — dereferences `instructions` and nothing else. Asserting the
|
|
54
|
+
* whole shape here would claim `skill` was checked when it was not, and tying the read to
|
|
55
|
+
* it would fail a response whose prompt was fine and whose `skill` block was malformed,
|
|
56
|
+
* which is exactly what happened when this was one predicate instead of two.
|
|
57
|
+
*
|
|
58
|
+
* Takes `unknown`: the input is an unvalidated network body, and typing the parameter as
|
|
59
|
+
* the payload interface would assume the very thing being checked.
|
|
60
|
+
*/
|
|
61
|
+
export const hasPromptBody = (data) => typeof data?.instructions ===
|
|
62
|
+
'string';
|
|
63
|
+
/**
|
|
64
|
+
* Whether a 2xx body can build a whole {@link SkillDetail}.
|
|
65
|
+
*
|
|
66
|
+
* Narrows to the payload type itself, which is now truthful: the two fields this checks
|
|
67
|
+
* are the two the interface still declares required, and the other three are optional
|
|
68
|
+
* there. Stricter than {@link hasPromptBody} by exactly one field. Four epics read this shape
|
|
69
|
+
* and each used to guard it differently — `data != null`, `data?.skill != null`, and a
|
|
70
|
+
* real `instructions` check — so one malformed response became a failure in one place, an
|
|
71
|
+
* empty prompt in another, and `undefined` in a third.
|
|
72
|
+
*/
|
|
73
|
+
export const isSkillDetailPayload = (data) => hasPromptBody(data) && data.skill != null;
|
|
74
|
+
/**
|
|
75
|
+
* The detail payload every write route answers with.
|
|
76
|
+
*
|
|
77
|
+
* Shared because three epics need it — save, visibility, and the detail read — and a
|
|
78
|
+
* fourth copy is how one of them quietly stops carrying a field the others do.
|
|
79
|
+
*
|
|
80
|
+
* The coercions are not defensive habit; the payload type makes them mandatory — the
|
|
81
|
+
* three optional fields cannot be assigned to a non-optional `SkillDetail` without one.
|
|
82
|
+
* Which fields get coerced and which do not is the deliberate part:
|
|
83
|
+
*
|
|
84
|
+
* - `instructions` is load-bearing and already proven, so it passes through. Defaulting a
|
|
85
|
+
* missing prompt to `''` is the one thing this module exists to prevent: the user
|
|
86
|
+
* cannot tell an empty prompt from a skill that has one, and may save over the real
|
|
87
|
+
* thing.
|
|
88
|
+
* - `instructionsCharCount` falls back to the prompt's own length, NOT to 0. A 12,000
|
|
89
|
+
* character prompt displayed as "0 characters" is a lie the user can see, and the
|
|
90
|
+
* prompt is right here to measure. Approximate only for astral-plane characters, where
|
|
91
|
+
* UTF-16 units and the server's count differ — a rounding error, against a guaranteed
|
|
92
|
+
* wrong answer.
|
|
93
|
+
* - `artifact` and `artifactTitle` degrade to empty. They render a preview card, so
|
|
94
|
+
* losing them costs a card; failing the whole read would cost the user the skill.
|
|
95
|
+
*/
|
|
96
|
+
export const toSkillDetail = (payload) => ({
|
|
97
|
+
skill: { ...toBaseSkill(payload.skill), exampleHints: [] },
|
|
98
|
+
instructions: payload.instructions,
|
|
99
|
+
instructionsCharCount: payload.instructions_char_count ?? payload.instructions.length,
|
|
100
|
+
artifact: payload.artifact ?? '',
|
|
101
|
+
artifactTitle: payload.artifact_title ?? '',
|
|
102
|
+
});
|
package/lib/index.d.ts
CHANGED
|
@@ -968,12 +968,12 @@ export { AiAccountantCustomerViewState, AiAccountantSortKey, AiAccountantUIState
|
|
|
968
968
|
export { AiAccountantFilterCategoryField } from './view/companyView/types/cockpitTypes';
|
|
969
969
|
export { cancelAiAccountantOnboarding, fetchAiAccountantCustomers, fetchAiAccountantJobs, setSelectedTenantIdsForJobTrigger, triggerAiAccountantJob, updateAiAccountantUIState, } from './view/aiAccountantView/aiAccountantViewReducer';
|
|
970
970
|
export { AiAccountantCockpitView, getAiAccountantCockpitView, } from './view/aiAccountantView/aiAccountantViewSelector';
|
|
971
|
-
export { fetchChatSessionsForUser, createSession, submitQuestion, updateAiCfoViewScrollPosition, updateCurrentInput, updateCotCollapsedState, setSession, clearCurrentSessionId, clearDeleteChatSessionStatus, clearLastContextMessage, createSessionAndSubmit, stopSubmit, stopSubmitQuestion, fetchChatHistory, acceptMasterTOS, deleteChatSession, submitFeedback, updateResponseState, fetchSuggestedQuestions, fetchSuggestedQuestionsSuccess, fetchSuggestedQuestionsFailure, fetchSkills, fetchSkillsSuccess, fetchSkillsFailure, applyAiCfoSidePanelHostPageTransition, clearAiCfoSidePanelHostPageContext, } from './view/aiCfoView/aiCfoViewReducer';
|
|
972
|
-
export { AiCfoViewState, AiCfoViewUIState, Skill, SkillsState, SuggestedQuestionsForPageContext, } from './view/aiCfoView/aiCfoViewState';
|
|
971
|
+
export { fetchChatSessionsForUser, createSession, submitQuestion, updateAiCfoViewScrollPosition, updateCurrentInput, updateCotCollapsedState, setSession, clearCurrentSessionId, clearDeleteChatSessionStatus, clearLastContextMessage, createSessionAndSubmit, stopSubmit, stopSubmitQuestion, fetchChatHistory, acceptMasterTOS, deleteChatSession, submitFeedback, updateResponseState, fetchSuggestedQuestions, fetchSuggestedQuestionsSuccess, fetchSuggestedQuestionsFailure, fetchSkills, fetchSkillsSuccess, fetchSkillsFailure, fetchSkillDetail, clearSkillDetail, clearSkillMutation, deleteSkill, fetchSkillVersionBody, fetchSkillVersions, saveSkill, setSkillVisibility, openSkillsBrowser, closeSkillsBrowser, applyAiCfoSidePanelHostPageTransition, clearAiCfoSidePanelHostPageContext, } from './view/aiCfoView/aiCfoViewReducer';
|
|
972
|
+
export { AiCfoViewState, AiCfoViewUIState, Skill, SkillDetail, SkillDetailState, SkillDraft, SkillMutationState, SkillVersion, SkillVersionBodyState, SkillVersionsState, SkillVisibility, SkillsState, SuggestedQuestionsForPageContext, } from './view/aiCfoView/aiCfoViewState';
|
|
973
973
|
export { FetchSuggestedQuestionsResponse, SuggestedQuestionsDataPayload, FetchSkillsResponse, SkillSummaryPayload, SkillListDataPayload, } from './view/aiCfoView/aiCfoViewPayload';
|
|
974
974
|
export type { FeedbackType, SubmitFeedbackPayload, } from './view/aiCfoView/aiCfoViewPayload';
|
|
975
975
|
export type { AiCfoSuggestedQuestionsPageContext } from './common/aiCfo/aiCfoSuggestedQuestionsPageContext';
|
|
976
|
-
export { AiCfoViewSelector, getAiCfoView, getSuggestedQuestionsForPageContext, getSkills, } from './view/aiCfoView/aiCfoViewSelector';
|
|
976
|
+
export { AiCfoViewSelector, getAiCfoView, getSuggestedQuestionsForPageContext, getSkills, getSkillDetail, getSkillMutation, getSkillVersionBody, getSkillVersions, getSkillsEnabled, } from './view/aiCfoView/aiCfoViewSelector';
|
|
977
977
|
export { MessagePayload, ChatSessionPayload, AiCfoAnswerPayload, } from './entity/aiCfo/aiCfoPayload';
|
|
978
978
|
export { setNewSession, setSessions, updateAiCfoAnswerCardPolicyWizardPlan, upsertAnswerPayload, upsertOrAddQuestionAnswerPayload, addQuestionPayload, clearSession, toAiCfoExports, toAiCfoVisualization, appendSyntheticAiCfoAnswer, updateSyntheticAiCfoAnswer, removeSyntheticAiCfoAnswer, } from './entity/aiCfo/aiCfoReducer';
|
|
979
979
|
export { AiCfoSelectorView, getAllQuestionAnswersForChatSession, getQuestionAnswerByIdForChatSession, getAllQuestionsForChatSession, getAiCfoSelectorView, getSyntheticAiCfoAnswersForChatSession, getSyntheticAiCfoAnswerByQuestionAnswerId, ChatSessionWithOrderedQuestionAnswers, } from './entity/aiCfo/aiCfoSelector';
|