@webiny/app-admin 6.6.0-alpha.10 → 6.6.0-alpha.12
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/base/Admin.js +2 -0
- package/base/Admin.js.map +1 -1
- package/base/createRootContainer.js +2 -0
- package/base/createRootContainer.js.map +1 -1
- package/base/resolveApiUrl.js +3 -2
- package/base/resolveApiUrl.js.map +1 -1
- package/components/SimpleForm/SimpleForm.js +2 -2
- package/components/SimpleForm/SimpleForm.js.map +1 -1
- package/features/accessManagement/roles/roleEvents/ApplyRoleChangeToCache.d.ts +17 -0
- package/features/accessManagement/roles/roleEvents/ApplyRoleChangeToCache.js +26 -0
- package/features/accessManagement/roles/roleEvents/ApplyRoleChangeToCache.js.map +1 -0
- package/features/accessManagement/roles/roleEvents/RefreshRoleInCacheRepository.d.ts +18 -0
- package/features/accessManagement/roles/roleEvents/RefreshRoleInCacheRepository.js +26 -0
- package/features/accessManagement/roles/roleEvents/RefreshRoleInCacheRepository.js.map +1 -0
- package/features/accessManagement/roles/roleEvents/abstractions.d.ts +8 -0
- package/features/accessManagement/roles/roleEvents/abstractions.js +5 -0
- package/features/accessManagement/roles/roleEvents/abstractions.js.map +1 -0
- package/features/accessManagement/roles/roleEvents/feature.d.ts +5 -0
- package/features/accessManagement/roles/roleEvents/feature.js +13 -0
- package/features/accessManagement/roles/roleEvents/feature.js.map +1 -0
- package/features/accessManagement/roles/roleEvents/index.d.ts +1 -0
- package/features/accessManagement/roles/roleEvents/index.js +1 -0
- package/features/accessManagement/teams/teamEvents/ApplyTeamChangeToCache.d.ts +17 -0
- package/features/accessManagement/teams/teamEvents/ApplyTeamChangeToCache.js +26 -0
- package/features/accessManagement/teams/teamEvents/ApplyTeamChangeToCache.js.map +1 -0
- package/features/accessManagement/teams/teamEvents/RefreshTeamInCacheRepository.d.ts +18 -0
- package/features/accessManagement/teams/teamEvents/RefreshTeamInCacheRepository.js +26 -0
- package/features/accessManagement/teams/teamEvents/RefreshTeamInCacheRepository.js.map +1 -0
- package/features/accessManagement/teams/teamEvents/abstractions.d.ts +8 -0
- package/features/accessManagement/teams/teamEvents/abstractions.js +5 -0
- package/features/accessManagement/teams/teamEvents/abstractions.js.map +1 -0
- package/features/accessManagement/teams/teamEvents/feature.d.ts +5 -0
- package/features/accessManagement/teams/teamEvents/feature.js +13 -0
- package/features/accessManagement/teams/teamEvents/feature.js.map +1 -0
- package/features/accessManagement/teams/teamEvents/index.d.ts +1 -0
- package/features/accessManagement/teams/teamEvents/index.js +1 -0
- package/features/adminAssistant/AdminAssistantGateway.js +4 -3
- package/features/adminAssistant/AdminAssistantGateway.js.map +1 -1
- package/features/adminAssistant/AdminAssistantPresenter.d.ts +16 -13
- package/features/adminAssistant/AdminAssistantPresenter.js +57 -91
- package/features/adminAssistant/AdminAssistantPresenter.js.map +1 -1
- package/features/adminAssistant/abstractions.d.ts +31 -23
- package/features/adminAssistant/abstractions.js.map +1 -1
- package/features/adminAssistant/turnsFromMessages.d.ts +4 -7
- package/features/adminAssistant/turnsFromMessages.js +0 -2
- package/features/adminAssistant/turnsFromMessages.js.map +1 -1
- package/features/adminUsers/users/userEvents/MarkUsersChanged.d.ts +16 -0
- package/features/adminUsers/users/userEvents/MarkUsersChanged.js +23 -0
- package/features/adminUsers/users/userEvents/MarkUsersChanged.js.map +1 -0
- package/features/adminUsers/users/userEvents/UsersRevision.d.ts +13 -0
- package/features/adminUsers/users/userEvents/UsersRevision.js +25 -0
- package/features/adminUsers/users/userEvents/UsersRevision.js.map +1 -0
- package/features/adminUsers/users/userEvents/abstractions.d.ts +17 -0
- package/features/adminUsers/users/userEvents/abstractions.js +5 -0
- package/features/adminUsers/users/userEvents/abstractions.js.map +1 -0
- package/features/adminUsers/users/userEvents/feature.d.ts +4 -0
- package/features/adminUsers/users/userEvents/feature.js +19 -0
- package/features/adminUsers/users/userEvents/feature.js.map +1 -0
- package/features/adminUsers/users/userEvents/index.d.ts +1 -0
- package/features/adminUsers/users/userEvents/index.js +1 -0
- package/features/aiChats/AiChatsGateway.d.ts +0 -3
- package/features/aiChats/AiChatsGateway.js +1 -26
- package/features/aiChats/AiChatsGateway.js.map +1 -1
- package/features/aiChats/AiChatsRepository.d.ts +1 -3
- package/features/aiChats/AiChatsRepository.js +9 -28
- package/features/aiChats/AiChatsRepository.js.map +1 -1
- package/features/aiChats/abstractions.d.ts +7 -19
- package/features/aiChats/abstractions.js.map +1 -1
- package/features/aiChats/index.d.ts +0 -2
- package/features/aiChats/index.js +0 -1
- package/features/assistantPageContext/AssistantPageContext.d.ts +12 -0
- package/features/assistantPageContext/AssistantPageContext.js +32 -0
- package/features/assistantPageContext/AssistantPageContext.js.map +1 -0
- package/features/assistantPageContext/abstractions.d.ts +33 -0
- package/features/assistantPageContext/abstractions.js +5 -0
- package/features/assistantPageContext/abstractions.js.map +1 -0
- package/features/assistantPageContext/feature.d.ts +3 -0
- package/features/assistantPageContext/feature.js +17 -0
- package/features/assistantPageContext/feature.js.map +1 -0
- package/features/assistantPageContext/index.d.ts +2 -0
- package/features/assistantPageContext/index.js +2 -0
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/modules/AccessManagementExtension.js +6 -0
- package/modules/AccessManagementExtension.js.map +1 -1
- package/package.json +20 -20
- package/presentation/accessManagement/apiKeys/ApiKeysDataSource.d.ts +5 -6
- package/presentation/accessManagement/apiKeys/ApiKeysDataSource.js +12 -13
- package/presentation/accessManagement/apiKeys/ApiKeysDataSource.js.map +1 -1
- package/presentation/accessManagement/apiKeys/ApiKeysPresenter.d.ts +5 -0
- package/presentation/accessManagement/apiKeys/ApiKeysPresenter.js +32 -2
- package/presentation/accessManagement/apiKeys/ApiKeysPresenter.js.map +1 -1
- package/presentation/accessManagement/apiKeys/ApiKeysPresenter.test.d.ts +1 -0
- package/presentation/accessManagement/apiKeys/ApiKeysPresenter.test.js +87 -0
- package/presentation/accessManagement/apiKeys/ApiKeysPresenter.test.js.map +1 -0
- package/presentation/accessManagement/apiKeys/abstractions.d.ts +2 -0
- package/presentation/accessManagement/apiKeys/abstractions.js.map +1 -1
- package/presentation/accessManagement/apiKeys/components/ApiKeysView.js +13 -37
- package/presentation/accessManagement/apiKeys/components/ApiKeysView.js.map +1 -1
- package/presentation/accessManagement/roles/RolesDataSource.d.ts +5 -6
- package/presentation/accessManagement/roles/RolesDataSource.js +12 -13
- package/presentation/accessManagement/roles/RolesDataSource.js.map +1 -1
- package/presentation/accessManagement/roles/RolesPresenter.d.ts +5 -0
- package/presentation/accessManagement/roles/RolesPresenter.js +32 -2
- package/presentation/accessManagement/roles/RolesPresenter.js.map +1 -1
- package/presentation/accessManagement/roles/RolesPresenter.test.d.ts +1 -0
- package/presentation/accessManagement/roles/RolesPresenter.test.js +168 -0
- package/presentation/accessManagement/roles/RolesPresenter.test.js.map +1 -0
- package/presentation/accessManagement/roles/abstractions.d.ts +2 -0
- package/presentation/accessManagement/roles/abstractions.js.map +1 -1
- package/presentation/accessManagement/roles/components/RolesDataList.js +12 -37
- package/presentation/accessManagement/roles/components/RolesDataList.js.map +1 -1
- package/presentation/accessManagement/roles/components/RolesView.js +1 -0
- package/presentation/accessManagement/roles/components/RolesView.js.map +1 -1
- package/presentation/accessManagement/teams/TeamsDataSource.d.ts +5 -6
- package/presentation/accessManagement/teams/TeamsDataSource.js +12 -13
- package/presentation/accessManagement/teams/TeamsDataSource.js.map +1 -1
- package/presentation/accessManagement/teams/TeamsPresenter.d.ts +5 -0
- package/presentation/accessManagement/teams/TeamsPresenter.js +33 -2
- package/presentation/accessManagement/teams/TeamsPresenter.js.map +1 -1
- package/presentation/accessManagement/teams/TeamsPresenter.test.d.ts +1 -0
- package/presentation/accessManagement/teams/TeamsPresenter.test.js +97 -0
- package/presentation/accessManagement/teams/TeamsPresenter.test.js.map +1 -0
- package/presentation/accessManagement/teams/abstractions.d.ts +2 -0
- package/presentation/accessManagement/teams/abstractions.js.map +1 -1
- package/presentation/accessManagement/teams/components/TeamsDataList.js +12 -37
- package/presentation/accessManagement/teams/components/TeamsDataList.js.map +1 -1
- package/presentation/accessManagement/teams/components/TeamsView.js +1 -0
- package/presentation/accessManagement/teams/components/TeamsView.js.map +1 -1
- package/presentation/adminUsers/AdminUsers.js +3 -0
- package/presentation/adminUsers/AdminUsers.js.map +1 -1
- package/presentation/adminUsers/views/Users/UsersDataList.js +22 -1
- package/presentation/adminUsers/views/Users/UsersDataList.js.map +1 -1
- package/presentation/adminUsers/views/Users/hooks/useUserForm.js +39 -9
- package/presentation/adminUsers/views/Users/hooks/useUserForm.js.map +1 -1
- package/presentation/adminUsers/views/Users/hooks/useUserForm.test.d.ts +1 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.test.js +149 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.test.js.map +1 -0
- package/presentation/listPresenter/ListPresenter.d.ts +12 -1
- package/presentation/listPresenter/ListPresenter.js +60 -4
- package/presentation/listPresenter/ListPresenter.js.map +1 -1
- package/presentation/listPresenter/ListPresenter.test.js +82 -0
- package/presentation/listPresenter/ListPresenter.test.js.map +1 -1
- package/presentation/listPresenter/LocalDataSource.d.ts +34 -0
- package/presentation/listPresenter/LocalDataSource.js +75 -0
- package/presentation/listPresenter/LocalDataSource.js.map +1 -0
- package/presentation/listPresenter/LocalDataSource.test.d.ts +1 -0
- package/presentation/listPresenter/LocalDataSource.test.js +124 -0
- package/presentation/listPresenter/LocalDataSource.test.js.map +1 -0
- package/presentation/listPresenter/QueryMatcher.js +1 -12
- package/presentation/listPresenter/QueryMatcher.js.map +1 -1
- package/presentation/listPresenter/abstractions.d.ts +21 -0
- package/presentation/listPresenter/abstractions.js.map +1 -1
- package/presentation/listPresenter/compareValues.d.ts +7 -0
- package/presentation/listPresenter/compareValues.js +15 -0
- package/presentation/listPresenter/compareValues.js.map +1 -0
- package/presentation/listPresenter/index.d.ts +2 -0
- package/presentation/listPresenter/index.js +2 -0
- package/presentation/listPresenter/sortOption.d.ts +7 -0
- package/presentation/listPresenter/sortOption.js +16 -0
- package/presentation/listPresenter/sortOption.js.map +1 -0
- package/presentation/listPresenter/sortOption.test.d.ts +1 -0
- package/presentation/listPresenter/sortOption.test.js +26 -0
- package/presentation/listPresenter/sortOption.test.js.map +1 -0
- package/presentation/trashBin/TrashBinPresenter.js +9 -0
- package/presentation/trashBin/TrashBinPresenter.js.map +1 -1
- package/presentation/trashBin/TrashBinPresenter.test.js +75 -0
- package/presentation/trashBin/TrashBinPresenter.test.js.map +1 -1
- package/presentation/trashBin/abstractions.d.ts +9 -0
- package/presentation/trashBin/abstractions.js.map +1 -1
- package/features/aiChats/AiChatSaveError.d.ts +0 -6
- package/features/aiChats/AiChatSaveError.js +0 -8
- package/features/aiChats/AiChatSaveError.js.map +0 -1
- package/features/aiChats/AiChatsRequestError.d.ts +0 -9
- package/features/aiChats/AiChatsRequestError.js +0 -8
- package/features/aiChats/AiChatsRequestError.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/adminAssistant/turnsFromMessages.js","sources":["../../../src/features/adminAssistant/turnsFromMessages.ts"],"sourcesContent":["import type { AdminAssistantMessage } from \"./abstractions.js\";\nimport type { AiTurnViewModel } from \"./abstractions.js\";\n\n/** A rebuilt turn
|
|
1
|
+
{"version":3,"file":"features/adminAssistant/turnsFromMessages.js","sources":["../../../src/features/adminAssistant/turnsFromMessages.ts"],"sourcesContent":["import type { AdminAssistantMessage } from \"./abstractions.js\";\nimport type { AiTurnViewModel } from \"./abstractions.js\";\n\n/** A rebuilt turn. The server keeps the messages, so carrying on needs none of them here. */\nexport type RestoredTurn = Omit<AiTurnViewModel, \"needsSetup\">;\n\ninterface Part {\n type?: unknown;\n text?: unknown;\n toolName?: unknown;\n input?: { questions?: unknown };\n output?: { type?: unknown };\n}\n\n/*\n * The tool the server's assistant calls to hand over follow-up questions. It is how the answer\n * ends, not work the user asked for, so the live stream never reports it as a tool, and neither does\n * a reopened chat. Mirrors `FOLLOW_UPS_TOOL` in `@webiny/ai-powerups`, which the admin cannot import.\n */\nconst FOLLOW_UPS_TOOL = \"suggestFollowUps\";\nconst MAX_FOLLOW_UPS = 3;\n\nconst followUpsOf = (part: Part): string[] => {\n const questions = part.input?.questions;\n if (!Array.isArray(questions)) {\n return [];\n }\n\n const result: string[] = [];\n for (const question of questions) {\n if (typeof question === \"string\" && question.trim()) {\n result.push(question.trim());\n }\n }\n return result.slice(0, MAX_FOLLOW_UPS);\n};\n\nconst partsOf = (message: AdminAssistantMessage): Part[] => {\n if (!Array.isArray(message.content)) {\n return [];\n }\n return message.content.filter(\n (part): part is Part => typeof part === \"object\" && part !== null\n );\n};\n\nconst textOf = (message: AdminAssistantMessage): string => {\n if (typeof message.content === \"string\") {\n return message.content;\n }\n\n const texts: string[] = [];\n for (const part of partsOf(message)) {\n if (part.type === \"text\" && typeof part.text === \"string\") {\n texts.push(part.text);\n }\n }\n return texts.join(\"\");\n};\n\nconst FAILED_OUTPUTS = new Set([\"error-text\", \"error-json\"]);\n\nconst startTurn = (question: string): RestoredTurn => ({\n question,\n text: \"\",\n answerStart: 0,\n tools: [],\n completed: [],\n failed: [],\n running: false,\n pendingApprovals: [],\n followUps: [],\n settled: true\n});\n\n/** Reads what an assistant or tool message adds to the turn it belongs to. */\nconst addToTurn = (turn: RestoredTurn, message: AdminAssistantMessage): void => {\n if (message.role === \"assistant\") {\n // Each assistant message is a step. Steps were streamed as one answer, a paragraph apart.\n const text = textOf(message);\n if (text) {\n turn.text = turn.text ? `${turn.text}\\n\\n${text}` : text;\n }\n\n for (const part of partsOf(message)) {\n if (part.type !== \"tool-call\" || typeof part.toolName !== \"string\") {\n continue;\n }\n if (part.toolName === FOLLOW_UPS_TOOL) {\n turn.followUps = followUpsOf(part);\n continue;\n }\n turn.tools.push(part.toolName);\n turn.answerStart = turn.text.length;\n }\n return;\n }\n\n if (message.role !== \"tool\") {\n return;\n }\n\n for (const part of partsOf(message)) {\n if (part.type !== \"tool-result\" || typeof part.toolName !== \"string\") {\n continue;\n }\n if (part.toolName === FOLLOW_UPS_TOOL) {\n continue;\n }\n const outputType = String(part.output?.type);\n if (FAILED_OUTPUTS.has(outputType)) {\n turn.failed.push(part.toolName);\n } else {\n turn.completed.push(part.toolName);\n }\n }\n};\n\n/**\n * Turns a saved conversation back into the turns the palette shows.\n *\n * The inverse of how the assistant replays a conversation: every user message starts a turn, and\n * the assistant and tool messages after it are that turn's. The follow-up questions come from the\n * call that suggested them, so a reopened chat offers the same ones it ended with.\n */\nexport const turnsFromMessages = (messages: AdminAssistantMessage[]): RestoredTurn[] => {\n const turns: RestoredTurn[] = [];\n\n for (const message of messages) {\n if (message.role === \"user\") {\n const question = textOf(message);\n const turn = startTurn(question);\n turns.push(turn);\n continue;\n }\n\n const current = turns[turns.length - 1];\n if (current) {\n addToTurn(current, message);\n }\n }\n\n return turns;\n};\n"],"names":["FOLLOW_UPS_TOOL","MAX_FOLLOW_UPS","followUpsOf","part","questions","Array","result","question","partsOf","message","textOf","texts","FAILED_OUTPUTS","Set","startTurn","addToTurn","turn","text","outputType","String","turnsFromMessages","messages","turns","current"],"mappings":"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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RecordChangedEventHandler } from "@webiny/app/features/recordChanges/index.js";
|
|
2
|
+
import { UsersRevision } from "./abstractions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Every change moves the list. An update also moves the user, so an open form for it reads it again.
|
|
5
|
+
* A deleted user's open form is left alone: reading it back would fail, and the form already handles
|
|
6
|
+
* a failed read by going back to the list with an error.
|
|
7
|
+
*/
|
|
8
|
+
declare class MarkUsersChangedImpl implements RecordChangedEventHandler.Interface {
|
|
9
|
+
private revision;
|
|
10
|
+
constructor(revision: UsersRevision.Interface);
|
|
11
|
+
handle(event: RecordChangedEventHandler.Event): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare const MarkUsersChanged: typeof MarkUsersChangedImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/app/features/eventPublisher/abstractions.js").IEventHandler<import("@webiny/app/features/recordChanges/RecordChangedEvent.js").RecordChangedEvent>>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RecordChangedEventHandler } from "@webiny/app/features/recordChanges/index.js";
|
|
2
|
+
import { UsersRevision } from "./abstractions.js";
|
|
3
|
+
const USER_RECORD_TYPE = "adminUsers.user";
|
|
4
|
+
class MarkUsersChangedImpl {
|
|
5
|
+
constructor(revision){
|
|
6
|
+
this.revision = revision;
|
|
7
|
+
}
|
|
8
|
+
async handle(event) {
|
|
9
|
+
const { type, id, change } = event.payload;
|
|
10
|
+
if (type !== USER_RECORD_TYPE) return;
|
|
11
|
+
this.revision.listChanged();
|
|
12
|
+
if ("updated" === change) this.revision.userChanged(id);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const MarkUsersChanged = RecordChangedEventHandler.createImplementation({
|
|
16
|
+
implementation: MarkUsersChangedImpl,
|
|
17
|
+
dependencies: [
|
|
18
|
+
UsersRevision
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
export { MarkUsersChanged };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=MarkUsersChanged.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/adminUsers/users/userEvents/MarkUsersChanged.js","sources":["../../../../../src/features/adminUsers/users/userEvents/MarkUsersChanged.ts"],"sourcesContent":["import { RecordChangedEventHandler } from \"@webiny/app/features/recordChanges/index.js\";\nimport { UsersRevision } from \"./abstractions.js\";\n\n// Sent by the api for admin users; see `USER_RECORD_TYPE` in @webiny/api-core.\nconst USER_RECORD_TYPE = \"adminUsers.user\";\n\n/**\n * Every change moves the list. An update also moves the user, so an open form for it reads it again.\n * A deleted user's open form is left alone: reading it back would fail, and the form already handles\n * a failed read by going back to the list with an error.\n */\nclass MarkUsersChangedImpl implements RecordChangedEventHandler.Interface {\n constructor(private revision: UsersRevision.Interface) {}\n\n async handle(event: RecordChangedEventHandler.Event): Promise<void> {\n const { type, id, change } = event.payload;\n if (type !== USER_RECORD_TYPE) {\n return;\n }\n\n this.revision.listChanged();\n if (change === \"updated\") {\n this.revision.userChanged(id);\n }\n }\n}\n\nexport const MarkUsersChanged = RecordChangedEventHandler.createImplementation({\n implementation: MarkUsersChangedImpl,\n dependencies: [UsersRevision]\n});\n"],"names":["USER_RECORD_TYPE","MarkUsersChangedImpl","revision","event","type","id","change","MarkUsersChanged","RecordChangedEventHandler","UsersRevision"],"mappings":";;AAIA,MAAMA,mBAAmB;AAOzB,MAAMC;IACF,YAAoBC,QAAiC,CAAE;aAAnCA,QAAQ,GAARA;IAAoC;IAExD,MAAM,OAAOC,KAAsC,EAAiB;QAChE,MAAM,EAAEC,IAAI,EAAEC,EAAE,EAAEC,MAAM,EAAE,GAAGH,MAAM,OAAO;QAC1C,IAAIC,SAASJ,kBACT;QAGJ,IAAI,CAAC,QAAQ,CAAC,WAAW;QACzB,IAAIM,AAAW,cAAXA,QACA,IAAI,CAAC,QAAQ,CAAC,WAAW,CAACD;IAElC;AACJ;AAEO,MAAME,mBAAmBC,0BAA0B,oBAAoB,CAAC;IAC3E,gBAAgBP;IAChB,cAAc;QAACQ;KAAc;AACjC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UsersRevision as Abstraction } from "./abstractions.js";
|
|
2
|
+
declare class UsersRevisionImpl implements Abstraction.Interface {
|
|
3
|
+
list: number;
|
|
4
|
+
private users;
|
|
5
|
+
constructor();
|
|
6
|
+
user(id: string): number;
|
|
7
|
+
listChanged(): void;
|
|
8
|
+
userChanged(id: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const UsersRevision: typeof UsersRevisionImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUsersRevision>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { makeAutoObservable } from "mobx";
|
|
2
|
+
import { UsersRevision } from "./abstractions.js";
|
|
3
|
+
class UsersRevisionImpl {
|
|
4
|
+
constructor(){
|
|
5
|
+
this.list = 0;
|
|
6
|
+
this.users = new Map();
|
|
7
|
+
makeAutoObservable(this);
|
|
8
|
+
}
|
|
9
|
+
user(id) {
|
|
10
|
+
return this.users.get(id) ?? 0;
|
|
11
|
+
}
|
|
12
|
+
listChanged() {
|
|
13
|
+
this.list++;
|
|
14
|
+
}
|
|
15
|
+
userChanged(id) {
|
|
16
|
+
this.users.set(id, this.user(id) + 1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const UsersRevision_UsersRevision = UsersRevision.createImplementation({
|
|
20
|
+
implementation: UsersRevisionImpl,
|
|
21
|
+
dependencies: []
|
|
22
|
+
});
|
|
23
|
+
export { UsersRevision_UsersRevision as UsersRevision };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=UsersRevision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/adminUsers/users/userEvents/UsersRevision.js","sources":["../../../../../src/features/adminUsers/users/userEvents/UsersRevision.ts"],"sourcesContent":["import { makeAutoObservable } from \"mobx\";\nimport { UsersRevision as Abstraction } from \"./abstractions.js\";\n\nclass UsersRevisionImpl implements Abstraction.Interface {\n list = 0;\n private users = new Map<string, number>();\n\n constructor() {\n makeAutoObservable(this);\n }\n\n user(id: string): number {\n return this.users.get(id) ?? 0;\n }\n\n listChanged(): void {\n this.list++;\n }\n\n userChanged(id: string): void {\n this.users.set(id, this.user(id) + 1);\n }\n}\n\nexport const UsersRevision = Abstraction.createImplementation({\n implementation: UsersRevisionImpl,\n dependencies: []\n});\n"],"names":["UsersRevisionImpl","Map","makeAutoObservable","id","UsersRevision","Abstraction"],"mappings":";;AAGA,MAAMA;IAIF,aAAc;aAHd,IAAI,GAAG;aACC,KAAK,GAAG,IAAIC;QAGhBC,mBAAmB,IAAI;IAC3B;IAEA,KAAKC,EAAU,EAAU;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAACA,OAAO;IACjC;IAEA,cAAoB;QAChB,IAAI,CAAC,IAAI;IACb;IAEA,YAAYA,EAAU,EAAQ;QAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAACA,IAAI,IAAI,CAAC,IAAI,CAACA,MAAM;IACvC;AACJ;AAEO,MAAMC,8BAAgBC,cAAAA,oBAAgC,CAAC;IAC1D,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface IUsersRevision {
|
|
2
|
+
/** Changes whenever a user is created, updated or deleted. */
|
|
3
|
+
readonly list: number;
|
|
4
|
+
/** Changes whenever the given user is updated. */
|
|
5
|
+
user(id: string): number;
|
|
6
|
+
listChanged(): void;
|
|
7
|
+
userChanged(id: string): void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Tells the Users view when what it loaded is out of date. The view keeps the users list and the
|
|
11
|
+
* open user in component state rather than in a shared cache, so it watches these numbers and reads
|
|
12
|
+
* again when one moves.
|
|
13
|
+
*/
|
|
14
|
+
export declare const UsersRevision: import("@webiny/di").Abstraction<IUsersRevision>;
|
|
15
|
+
export declare namespace UsersRevision {
|
|
16
|
+
type Interface = IUsersRevision;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/adminUsers/users/userEvents/abstractions.js","sources":["../../../../../src/features/adminUsers/users/userEvents/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\n\nexport interface IUsersRevision {\n /** Changes whenever a user is created, updated or deleted. */\n readonly list: number;\n /** Changes whenever the given user is updated. */\n user(id: string): number;\n listChanged(): void;\n userChanged(id: string): void;\n}\n\n/**\n * Tells the Users view when what it loaded is out of date. The view keeps the users list and the\n * open user in component state rather than in a shared cache, so it watches these numbers and reads\n * again when one moves.\n */\nexport const UsersRevision = createAbstraction<IUsersRevision>(\"AdminUsers/UsersRevision\");\n\nexport namespace UsersRevision {\n export type Interface = IUsersRevision;\n}\n"],"names":["UsersRevision","createAbstraction"],"mappings":";AAgBO,MAAMA,gBAAgBC,kBAAkC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/admin";
|
|
2
|
+
import { UsersRevision } from "./abstractions.js";
|
|
3
|
+
import { UsersRevision as external_UsersRevision_js_UsersRevision } from "./UsersRevision.js";
|
|
4
|
+
import { MarkUsersChanged } from "./MarkUsersChanged.js";
|
|
5
|
+
const UserEventsFeature = createFeature({
|
|
6
|
+
name: "AdminUsers/UserEvents",
|
|
7
|
+
register (container) {
|
|
8
|
+
container.register(external_UsersRevision_js_UsersRevision).inSingletonScope();
|
|
9
|
+
container.register(MarkUsersChanged);
|
|
10
|
+
},
|
|
11
|
+
resolve (container) {
|
|
12
|
+
return {
|
|
13
|
+
revision: container.resolve(UsersRevision)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
export { UserEventsFeature };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/adminUsers/users/userEvents/feature.js","sources":["../../../../../src/features/adminUsers/users/userEvents/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { UsersRevision as RevisionAbstraction } from \"./abstractions.js\";\nimport { UsersRevision } from \"./UsersRevision.js\";\nimport { MarkUsersChanged } from \"./MarkUsersChanged.js\";\n\n/** Keeps the Users view current when admin users are created, updated or deleted on the server. */\nexport const UserEventsFeature = createFeature({\n name: \"AdminUsers/UserEvents\",\n register(container) {\n container.register(UsersRevision).inSingletonScope();\n container.register(MarkUsersChanged);\n },\n resolve(container) {\n return {\n revision: container.resolve(RevisionAbstraction)\n };\n }\n});\n"],"names":["UserEventsFeature","createFeature","container","UsersRevision","MarkUsersChanged","RevisionAbstraction"],"mappings":";;;;AAMO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,yCAAe,gBAAgB;QAClDD,UAAU,QAAQ,CAACE;IACvB;IACA,SAAQF,SAAS;QACb,OAAO;YACH,UAAUA,UAAU,OAAO,CAACG;QAChC;IACJ;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UserEventsFeature } from "./feature.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UserEventsFeature } from "./feature.js";
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { MainGraphQLClient } from "@webiny/app/features/mainGraphQLClient/index.js";
|
|
2
2
|
import { AiChatsGateway as GatewayAbstraction } from "./abstractions.js";
|
|
3
3
|
import type { AiChat } from "./abstractions.js";
|
|
4
|
-
import type { AiChatSummary } from "./abstractions.js";
|
|
5
4
|
import type { AiChatsPage } from "./abstractions.js";
|
|
6
|
-
import type { SaveAiChatInput } from "./abstractions.js";
|
|
7
5
|
declare class AiChatsGatewayImpl implements GatewayAbstraction.Interface {
|
|
8
6
|
private client;
|
|
9
7
|
constructor(client: MainGraphQLClient.Interface);
|
|
10
8
|
list(after?: string): Promise<AiChatsPage>;
|
|
11
9
|
get(id: string): Promise<AiChat>;
|
|
12
|
-
save(input: SaveAiChatInput): Promise<AiChatSummary>;
|
|
13
10
|
delete(id: string): Promise<void>;
|
|
14
11
|
}
|
|
15
12
|
export declare const AiChatsGateway: typeof AiChatsGatewayImpl & {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MainGraphQLClient } from "@webiny/app/features/mainGraphQLClient/index.js";
|
|
2
2
|
import { AiChatsGateway } from "./abstractions.js";
|
|
3
|
-
import { AiChatsRequestError } from "./AiChatsRequestError.js";
|
|
4
3
|
const ERROR_FIELDS = `
|
|
5
4
|
error {
|
|
6
5
|
code
|
|
@@ -42,21 +41,6 @@ const GET_AI_CHAT = `
|
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
`;
|
|
45
|
-
const SAVE_AI_CHAT = `
|
|
46
|
-
mutation SaveAiChat($data: AiChatInput!) {
|
|
47
|
-
aiPowerUps {
|
|
48
|
-
saveAiChat(data: $data) {
|
|
49
|
-
data {
|
|
50
|
-
id
|
|
51
|
-
title
|
|
52
|
-
createdOn
|
|
53
|
-
savedOn
|
|
54
|
-
}
|
|
55
|
-
${ERROR_FIELDS}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
60
44
|
const DELETE_AI_CHAT = `
|
|
61
45
|
mutation DeleteAiChat($id: ID!) {
|
|
62
46
|
aiPowerUps {
|
|
@@ -68,7 +52,7 @@ const DELETE_AI_CHAT = `
|
|
|
68
52
|
}
|
|
69
53
|
`;
|
|
70
54
|
function unwrap(response) {
|
|
71
|
-
if (response.error) throw new
|
|
55
|
+
if (response.error) throw new Error(response.error.message);
|
|
72
56
|
if (null === response.data) throw new Error("The API returned no data.");
|
|
73
57
|
return response.data;
|
|
74
58
|
}
|
|
@@ -102,15 +86,6 @@ class AiChatsGatewayImpl {
|
|
|
102
86
|
});
|
|
103
87
|
return unwrap(response.aiPowerUps.getAiChat);
|
|
104
88
|
}
|
|
105
|
-
async save(input) {
|
|
106
|
-
const response = await this.client.execute({
|
|
107
|
-
query: SAVE_AI_CHAT,
|
|
108
|
-
variables: {
|
|
109
|
-
data: input
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return unwrap(response.aiPowerUps.saveAiChat);
|
|
113
|
-
}
|
|
114
89
|
async delete(id) {
|
|
115
90
|
const response = await this.client.execute({
|
|
116
91
|
query: DELETE_AI_CHAT,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/aiChats/AiChatsGateway.js","sources":["../../../src/features/aiChats/AiChatsGateway.ts"],"sourcesContent":["import { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport { AiChatsGateway as GatewayAbstraction } from \"./abstractions.js\";\nimport type { AiChat } from \"./abstractions.js\";\nimport type { AiChatSummary } from \"./abstractions.js\";\nimport type { AiChatsPage } from \"./abstractions.js\";\
|
|
1
|
+
{"version":3,"file":"features/aiChats/AiChatsGateway.js","sources":["../../../src/features/aiChats/AiChatsGateway.ts"],"sourcesContent":["import { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport { AiChatsGateway as GatewayAbstraction } from \"./abstractions.js\";\nimport type { AiChat } from \"./abstractions.js\";\nimport type { AiChatSummary } from \"./abstractions.js\";\nimport type { AiChatsPage } from \"./abstractions.js\";\n\nconst ERROR_FIELDS = /* GraphQL */ `\n error {\n code\n message\n }\n`;\n\nconst LIST_AI_CHATS = /* GraphQL */ `\n query ListAiChats($after: String) {\n aiPowerUps {\n listAiChats(after: $after) {\n data {\n id\n title\n createdOn\n savedOn\n }\n meta {\n cursor\n hasMoreItems\n }\n ${ERROR_FIELDS}\n }\n }\n }\n`;\n\nconst GET_AI_CHAT = /* GraphQL */ `\n query GetAiChat($id: ID!) {\n aiPowerUps {\n getAiChat(id: $id) {\n data {\n id\n title\n createdOn\n savedOn\n messages\n }\n ${ERROR_FIELDS}\n }\n }\n }\n`;\n\nconst DELETE_AI_CHAT = /* GraphQL */ `\n mutation DeleteAiChat($id: ID!) {\n aiPowerUps {\n deleteAiChat(id: $id) {\n data\n ${ERROR_FIELDS}\n }\n }\n }\n`;\n\ninterface GraphQLError {\n code: string;\n message: string;\n}\n\ninterface Response<TData, TMeta = undefined> {\n data: TData | null;\n meta?: TMeta;\n error: GraphQLError | null;\n}\n\ninterface ListResponse {\n aiPowerUps: {\n listAiChats: Response<AiChatSummary[], { cursor: string | null; hasMoreItems: boolean }>;\n };\n}\n\ninterface GetResponse {\n aiPowerUps: { getAiChat: Response<AiChat> };\n}\n\ninterface DeleteResponse {\n aiPowerUps: { deleteAiChat: Response<boolean> };\n}\n\n/**\n * Every operation answers `{ data, error }`; a missing `data` without an error is still a failure.\n */\nfunction unwrap<TData, TMeta>(response: Response<TData, TMeta>): TData {\n if (response.error) {\n throw new Error(response.error.message);\n }\n if (response.data === null) {\n throw new Error(\"The API returned no data.\");\n }\n return response.data;\n}\n\nclass AiChatsGatewayImpl implements GatewayAbstraction.Interface {\n constructor(private client: MainGraphQLClient.Interface) {}\n\n async list(after?: string): Promise<AiChatsPage> {\n const response = await this.client.execute<ListResponse>({\n query: LIST_AI_CHATS,\n variables: { after }\n });\n\n const result = response.aiPowerUps.listAiChats;\n const chats = unwrap(result);\n const meta = result.meta;\n\n let cursor: string | null = null;\n if (meta?.hasMoreItems) {\n cursor = meta.cursor;\n }\n\n return { chats, cursor };\n }\n\n async get(id: string): Promise<AiChat> {\n const response = await this.client.execute<GetResponse>({\n query: GET_AI_CHAT,\n variables: { id }\n });\n\n return unwrap(response.aiPowerUps.getAiChat);\n }\n\n async delete(id: string): Promise<void> {\n const response = await this.client.execute<DeleteResponse>({\n query: DELETE_AI_CHAT,\n variables: { id }\n });\n\n unwrap(response.aiPowerUps.deleteAiChat);\n }\n}\n\nexport const AiChatsGateway = GatewayAbstraction.createImplementation({\n implementation: AiChatsGatewayImpl,\n dependencies: [MainGraphQLClient]\n});\n"],"names":["ERROR_FIELDS","LIST_AI_CHATS","GET_AI_CHAT","DELETE_AI_CHAT","unwrap","response","Error","AiChatsGatewayImpl","client","after","result","chats","meta","cursor","id","AiChatsGateway","GatewayAbstraction","MainGraphQLClient"],"mappings":";;AAMA,MAAMA,eAA6B,CAAC;;;;;AAKpC,CAAC;AAED,MAAMC,gBAA8B,CAAC;;;;;;;;;;;;;;gBAcrB,EAAED,aAAa;;;;AAI/B,CAAC;AAED,MAAME,cAA4B,CAAC;;;;;;;;;;;gBAWnB,EAAEF,aAAa;;;;AAI/B,CAAC;AAED,MAAMG,iBAA+B,CAAC;;;;;gBAKtB,EAAEH,aAAa;;;;AAI/B,CAAC;AA8BD,SAASI,OAAqBC,QAAgC;IAC1D,IAAIA,SAAS,KAAK,EACd,MAAM,IAAIC,MAAMD,SAAS,KAAK,CAAC,OAAO;IAE1C,IAAIA,AAAkB,SAAlBA,SAAS,IAAI,EACb,MAAM,IAAIC,MAAM;IAEpB,OAAOD,SAAS,IAAI;AACxB;AAEA,MAAME;IACF,YAAoBC,MAAmC,CAAE;aAArCA,MAAM,GAANA;IAAsC;IAE1D,MAAM,KAAKC,KAAc,EAAwB;QAC7C,MAAMJ,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAe;YACrD,OAAOJ;YACP,WAAW;gBAAEQ;YAAM;QACvB;QAEA,MAAMC,SAASL,SAAS,UAAU,CAAC,WAAW;QAC9C,MAAMM,QAAQP,OAAOM;QACrB,MAAME,OAAOF,OAAO,IAAI;QAExB,IAAIG,SAAwB;QAC5B,IAAID,MAAM,cACNC,SAASD,KAAK,MAAM;QAGxB,OAAO;YAAED;YAAOE;QAAO;IAC3B;IAEA,MAAM,IAAIC,EAAU,EAAmB;QACnC,MAAMT,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAc;YACpD,OAAOH;YACP,WAAW;gBAAEY;YAAG;QACpB;QAEA,OAAOV,OAAOC,SAAS,UAAU,CAAC,SAAS;IAC/C;IAEA,MAAM,OAAOS,EAAU,EAAiB;QACpC,MAAMT,WAAW,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAiB;YACvD,OAAOF;YACP,WAAW;gBAAEW;YAAG;QACpB;QAEAV,OAAOC,SAAS,UAAU,CAAC,YAAY;IAC3C;AACJ;AAEO,MAAMU,gCAAiBC,eAAAA,oBAAuC,CAAC;IAClE,gBAAgBT;IAChB,cAAc;QAACU;KAAkB;AACrC"}
|
|
@@ -2,7 +2,6 @@ import { AiChatsGateway } from "./abstractions.js";
|
|
|
2
2
|
import { AiChatsRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
3
3
|
import type { AiChat } from "./abstractions.js";
|
|
4
4
|
import type { AiChatSummary } from "./abstractions.js";
|
|
5
|
-
import type { SaveAiChatInput } from "./abstractions.js";
|
|
6
5
|
/**
|
|
7
6
|
* Registered as a singleton, so the assistant and the chats panel see one list.
|
|
8
7
|
*
|
|
@@ -21,13 +20,12 @@ declare class AiChatsRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
|
21
20
|
load(): Promise<void>;
|
|
22
21
|
loadMore(): Promise<void>;
|
|
23
22
|
get(id: string): Promise<AiChat>;
|
|
24
|
-
|
|
23
|
+
remember(chat: AiChatSummary): void;
|
|
25
24
|
delete(id: string): Promise<void>;
|
|
26
25
|
private read;
|
|
27
26
|
private startReading;
|
|
28
27
|
private addPage;
|
|
29
28
|
private failReading;
|
|
30
|
-
private upsert;
|
|
31
29
|
private remove;
|
|
32
30
|
}
|
|
33
31
|
export declare const AiChatsRepository: typeof AiChatsRepositoryImpl & {
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { makeAutoObservable } from "mobx";
|
|
2
2
|
import { AiChatsGateway, AiChatsRepository } from "./abstractions.js";
|
|
3
3
|
import { messageOf } from "./messageOf.js";
|
|
4
|
-
import { AiChatSaveError } from "./AiChatSaveError.js";
|
|
5
|
-
import { AiChatsRequestError } from "./AiChatsRequestError.js";
|
|
6
|
-
const CHAT_TOO_LARGE = "AiChat/TooLarge";
|
|
7
|
-
const saveFailureOf = (error)=>{
|
|
8
|
-
if (!(error instanceof AiChatsRequestError)) return "unreachable";
|
|
9
|
-
return error.code === CHAT_TOO_LARGE ? "too-large" : "rejected";
|
|
10
|
-
};
|
|
11
4
|
class AiChatsRepositoryImpl {
|
|
12
5
|
constructor(gateway){
|
|
13
6
|
this.gateway = gateway;
|
|
@@ -33,17 +26,16 @@ class AiChatsRepositoryImpl {
|
|
|
33
26
|
get(id) {
|
|
34
27
|
return this.gateway.get(id);
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
29
|
+
remember(chat) {
|
|
30
|
+
const known = this.chats.some((existing)=>existing.id === chat.id);
|
|
31
|
+
if (!known) {
|
|
32
|
+
this.chats = [
|
|
33
|
+
chat,
|
|
34
|
+
...this.chats
|
|
35
|
+
];
|
|
36
|
+
return;
|
|
44
37
|
}
|
|
45
|
-
this.
|
|
46
|
-
return summary;
|
|
38
|
+
this.chats = this.chats.map((existing)=>existing.id === chat.id ? chat : existing);
|
|
47
39
|
}
|
|
48
40
|
async delete(id) {
|
|
49
41
|
await this.gateway.delete(id);
|
|
@@ -84,17 +76,6 @@ class AiChatsRepositoryImpl {
|
|
|
84
76
|
this.error = message;
|
|
85
77
|
this.loading = false;
|
|
86
78
|
}
|
|
87
|
-
upsert(summary) {
|
|
88
|
-
const known = this.chats.some((chat)=>chat.id === summary.id);
|
|
89
|
-
if (!known) {
|
|
90
|
-
this.chats = [
|
|
91
|
-
summary,
|
|
92
|
-
...this.chats
|
|
93
|
-
];
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
this.chats = this.chats.map((chat)=>chat.id === summary.id ? summary : chat);
|
|
97
|
-
}
|
|
98
79
|
remove(id) {
|
|
99
80
|
this.chats = this.chats.filter((chat)=>chat.id !== id);
|
|
100
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/aiChats/AiChatsRepository.js","sources":["../../../src/features/aiChats/AiChatsRepository.ts"],"sourcesContent":["import { makeAutoObservable } from \"mobx\";\nimport { AiChatsGateway } from \"./abstractions.js\";\nimport { AiChatsRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport type { AiChat } from \"./abstractions.js\";\nimport type { AiChatSummary } from \"./abstractions.js\";\nimport type { AiChatsPage } from \"./abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/aiChats/AiChatsRepository.js","sources":["../../../src/features/aiChats/AiChatsRepository.ts"],"sourcesContent":["import { makeAutoObservable } from \"mobx\";\nimport { AiChatsGateway } from \"./abstractions.js\";\nimport { AiChatsRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport type { AiChat } from \"./abstractions.js\";\nimport type { AiChatSummary } from \"./abstractions.js\";\nimport type { AiChatsPage } from \"./abstractions.js\";\nimport { messageOf } from \"./messageOf.js\";\n\n/**\n * Registered as a singleton, so the assistant and the chats panel see one list.\n *\n * Each mutation after an `await` is its own method, because `makeAutoObservable` makes those\n * actions and a bare assignment after an `await` would have left the one it started in.\n */\nclass AiChatsRepositoryImpl implements RepositoryAbstraction.Interface {\n chats: AiChatSummary[] = [];\n loading = false;\n error: string | null = null;\n private cursor: string | null = null;\n // Counts reads, so a read that a later one replaced cannot write its result over the newer one.\n private reads = 0;\n\n constructor(private gateway: AiChatsGateway.Interface) {\n makeAutoObservable<AiChatsRepositoryImpl, \"gateway\">(this, { gateway: false });\n }\n\n get hasMore(): boolean {\n return this.cursor !== null;\n }\n\n async load(): Promise<void> {\n await this.read(undefined, true);\n }\n\n async loadMore(): Promise<void> {\n if (this.cursor === null || this.loading) {\n return;\n }\n await this.read(this.cursor, false);\n }\n\n get(id: string): Promise<AiChat> {\n return this.gateway.get(id);\n }\n\n /*\n * The server lists chats by when they were created, so a chat saved again keeps its place. Only\n * a new chat goes first, which is also where the server puts it.\n */\n remember(chat: AiChatSummary): void {\n const known = this.chats.some(existing => existing.id === chat.id);\n if (!known) {\n this.chats = [chat, ...this.chats];\n return;\n }\n this.chats = this.chats.map(existing => (existing.id === chat.id ? chat : existing));\n }\n\n async delete(id: string): Promise<void> {\n await this.gateway.delete(id);\n this.remove(id);\n }\n\n /*\n * `load()` can start while a read is still in flight, since opening the history view reads the\n * first page again. Only the newest read updates the list, `loading` and `error`; an older one\n * finishing late is dropped.\n */\n private async read(after: string | undefined, replace: boolean): Promise<void> {\n const read = this.startReading();\n\n try {\n const page = await this.gateway.list(after);\n if (read === this.reads) {\n this.addPage(page, replace);\n }\n } catch (error) {\n if (read === this.reads) {\n const message = messageOf(error);\n this.failReading(message);\n }\n }\n }\n\n private startReading(): number {\n this.loading = true;\n this.error = null;\n this.reads++;\n return this.reads;\n }\n\n private addPage(page: AiChatsPage, replace: boolean): void {\n if (replace) {\n this.chats = page.chats;\n } else {\n // A chat created since the first page shifts the server's pages, so the next can repeat one.\n const known = new Set(this.chats.map(chat => chat.id));\n const fresh = page.chats.filter(chat => !known.has(chat.id));\n this.chats = [...this.chats, ...fresh];\n }\n this.cursor = page.cursor;\n this.loading = false;\n }\n\n private failReading(message: string): void {\n this.error = message;\n this.loading = false;\n }\n\n private remove(id: string): void {\n this.chats = this.chats.filter(chat => chat.id !== id);\n }\n}\n\nexport const AiChatsRepository = RepositoryAbstraction.createImplementation({\n implementation: AiChatsRepositoryImpl,\n dependencies: [AiChatsGateway]\n});\n"],"names":["AiChatsRepositoryImpl","gateway","makeAutoObservable","undefined","id","chat","known","existing","after","replace","read","page","error","message","messageOf","Set","fresh","AiChatsRepository","RepositoryAbstraction","AiChatsGateway"],"mappings":"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"}
|
|
@@ -16,16 +16,10 @@ export interface AiChatsPage {
|
|
|
16
16
|
cursor: string | null;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
* or the
|
|
19
|
+
* What fixes a run the assistant could not save: asking again, when the store itself failed, or
|
|
20
|
+
* only a new chat, when the chat is too large or the run cannot be repeated safely.
|
|
21
21
|
*/
|
|
22
|
-
export type AiChatSaveFailure = "
|
|
23
|
-
export interface SaveAiChatInput {
|
|
24
|
-
/** Omit it to start a new chat. */
|
|
25
|
-
id?: string;
|
|
26
|
-
/** The whole conversation so far, not only the newest turn. */
|
|
27
|
-
messages: AdminAssistantMessage[];
|
|
28
|
-
}
|
|
22
|
+
export type AiChatSaveFailure = "retryable" | "final";
|
|
29
23
|
/**
|
|
30
24
|
* Calls the `aiPowerUps` chat operations. The api registers them only with the admin assistant
|
|
31
25
|
* licensed, the same condition the palette checks before offering the assistant at all.
|
|
@@ -33,20 +27,18 @@ export interface SaveAiChatInput {
|
|
|
33
27
|
export interface IAiChatsGateway {
|
|
34
28
|
list(after?: string): Promise<AiChatsPage>;
|
|
35
29
|
get(id: string): Promise<AiChat>;
|
|
36
|
-
save(input: SaveAiChatInput): Promise<AiChatSummary>;
|
|
37
30
|
delete(id: string): Promise<void>;
|
|
38
31
|
}
|
|
39
32
|
export declare const AiChatsGateway: import("@webiny/di").Abstraction<IAiChatsGateway>;
|
|
40
33
|
export declare namespace AiChatsGateway {
|
|
41
34
|
type Interface = IAiChatsGateway;
|
|
42
35
|
type Page = AiChatsPage;
|
|
43
|
-
type SaveInput = SaveAiChatInput;
|
|
44
36
|
}
|
|
45
37
|
/**
|
|
46
38
|
* The signed-in identity's saved chats, as one list everything shares.
|
|
47
39
|
*
|
|
48
|
-
* The assistant
|
|
49
|
-
* shows up in the panel without the panel asking the server again.
|
|
40
|
+
* The assistant tells it what it saved and the chats panel reads from it, so a chat the assistant
|
|
41
|
+
* creates shows up in the panel without the panel asking the server again.
|
|
50
42
|
*/
|
|
51
43
|
export interface IAiChatsRepository {
|
|
52
44
|
/** Newest created first, as the server lists them. Holds the pages read so far. */
|
|
@@ -60,11 +52,8 @@ export interface IAiChatsRepository {
|
|
|
60
52
|
/** Read the page after the last one read. Does nothing on the last page. */
|
|
61
53
|
loadMore(): Promise<void>;
|
|
62
54
|
get(id: string): Promise<AiChat>;
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
* `AiChatSaveError` that says why.
|
|
66
|
-
*/
|
|
67
|
-
save(input: SaveAiChatInput): Promise<AiChatSummary>;
|
|
55
|
+
/** A chat the server saved: updated in the list, or put first if it is new. */
|
|
56
|
+
remember(chat: AiChatSummary): void;
|
|
68
57
|
delete(id: string): Promise<void>;
|
|
69
58
|
}
|
|
70
59
|
export declare const AiChatsRepository: import("@webiny/di").Abstraction<IAiChatsRepository>;
|
|
@@ -72,5 +61,4 @@ export declare namespace AiChatsRepository {
|
|
|
72
61
|
type Interface = IAiChatsRepository;
|
|
73
62
|
type Summary = AiChatSummary;
|
|
74
63
|
type Chat = AiChat;
|
|
75
|
-
type SaveInput = SaveAiChatInput;
|
|
76
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/aiChats/abstractions.js","sources":["../../../src/features/aiChats/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { AdminAssistantMessage } from \"~/features/adminAssistant/abstractions.js\";\n\n/** A row in the chats panel. The messages stay on the server until the chat is opened. */\nexport interface AiChatSummary {\n id: string;\n title: string;\n createdOn: string;\n savedOn: string;\n}\n\n/** A saved conversation, with the messages the assistant replays to continue it. */\nexport interface AiChat extends AiChatSummary {\n messages: AdminAssistantMessage[];\n}\n\nexport interface AiChatsPage {\n chats: AiChatSummary[];\n /** Pass it back to read the next page; `null` on the last one. */\n cursor: string | null;\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"features/aiChats/abstractions.js","sources":["../../../src/features/aiChats/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { AdminAssistantMessage } from \"~/features/adminAssistant/abstractions.js\";\n\n/** A row in the chats panel. The messages stay on the server until the chat is opened. */\nexport interface AiChatSummary {\n id: string;\n title: string;\n createdOn: string;\n savedOn: string;\n}\n\n/** A saved conversation, with the messages the assistant replays to continue it. */\nexport interface AiChat extends AiChatSummary {\n messages: AdminAssistantMessage[];\n}\n\nexport interface AiChatsPage {\n chats: AiChatSummary[];\n /** Pass it back to read the next page; `null` on the last one. */\n cursor: string | null;\n}\n\n/**\n * What fixes a run the assistant could not save: asking again, when the store itself failed, or\n * only a new chat, when the chat is too large or the run cannot be repeated safely.\n */\nexport type AiChatSaveFailure = \"retryable\" | \"final\";\n\n/**\n * Calls the `aiPowerUps` chat operations. The api registers them only with the admin assistant\n * licensed, the same condition the palette checks before offering the assistant at all.\n */\nexport interface IAiChatsGateway {\n list(after?: string): Promise<AiChatsPage>;\n get(id: string): Promise<AiChat>;\n delete(id: string): Promise<void>;\n}\n\nexport const AiChatsGateway = createAbstraction<IAiChatsGateway>(\"AiChatsGateway\");\n\nexport namespace AiChatsGateway {\n export type Interface = IAiChatsGateway;\n export type Page = AiChatsPage;\n}\n\n/**\n * The signed-in identity's saved chats, as one list everything shares.\n *\n * The assistant tells it what it saved and the chats panel reads from it, so a chat the assistant\n * creates shows up in the panel without the panel asking the server again.\n */\nexport interface IAiChatsRepository {\n /** Newest created first, as the server lists them. Holds the pages read so far. */\n readonly chats: AiChatSummary[];\n readonly hasMore: boolean;\n readonly loading: boolean;\n /** Why the last read failed, until the next one starts. */\n readonly error: string | null;\n /** Read the first page again, dropping what was read before. */\n load(): Promise<void>;\n /** Read the page after the last one read. Does nothing on the last page. */\n loadMore(): Promise<void>;\n get(id: string): Promise<AiChat>;\n /** A chat the server saved: updated in the list, or put first if it is new. */\n remember(chat: AiChatSummary): void;\n delete(id: string): Promise<void>;\n}\n\nexport const AiChatsRepository = createAbstraction<IAiChatsRepository>(\"AiChatsRepository\");\n\nexport namespace AiChatsRepository {\n export type Interface = IAiChatsRepository;\n export type Summary = AiChatSummary;\n export type Chat = AiChat;\n}\n"],"names":["AiChatsGateway","createAbstraction","AiChatsRepository"],"mappings":";AAsCO,MAAMA,iBAAiBC,kBAAmC;AA8B1D,MAAMC,oBAAoBD,kBAAsC"}
|
|
@@ -3,7 +3,5 @@ export { AiChatsRepository } from "./abstractions.js";
|
|
|
3
3
|
export type { AiChat } from "./abstractions.js";
|
|
4
4
|
export type { AiChatSummary } from "./abstractions.js";
|
|
5
5
|
export type { AiChatsPage } from "./abstractions.js";
|
|
6
|
-
export type { SaveAiChatInput } from "./abstractions.js";
|
|
7
6
|
export type { AiChatSaveFailure } from "./abstractions.js";
|
|
8
|
-
export { AiChatSaveError } from "./AiChatSaveError.js";
|
|
9
7
|
export { AiChatsFeature } from "./feature.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AssistantPageContext as Abstraction } from "./abstractions.js";
|
|
2
|
+
declare class AssistantPageContextImpl implements Abstraction.Interface {
|
|
3
|
+
private entries;
|
|
4
|
+
set(context: Abstraction.Data): Abstraction.Owner;
|
|
5
|
+
update(owner: Abstraction.Owner, context: Abstraction.Data): void;
|
|
6
|
+
clear(owner: Abstraction.Owner): void;
|
|
7
|
+
get(): Abstraction.Data | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const AssistantPageContext: typeof AssistantPageContextImpl & {
|
|
10
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IAssistantPageContext>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AssistantPageContext } from "./abstractions.js";
|
|
2
|
+
class AssistantPageContextImpl {
|
|
3
|
+
set(context) {
|
|
4
|
+
const owner = Symbol("AssistantPageContextOwner");
|
|
5
|
+
this.entries.push({
|
|
6
|
+
owner,
|
|
7
|
+
context
|
|
8
|
+
});
|
|
9
|
+
return owner;
|
|
10
|
+
}
|
|
11
|
+
update(owner, context) {
|
|
12
|
+
const entry = this.entries.find((entry)=>entry.owner === owner);
|
|
13
|
+
if (entry) entry.context = context;
|
|
14
|
+
}
|
|
15
|
+
clear(owner) {
|
|
16
|
+
this.entries = this.entries.filter((entry)=>entry.owner !== owner);
|
|
17
|
+
}
|
|
18
|
+
get() {
|
|
19
|
+
const newest = this.entries[this.entries.length - 1];
|
|
20
|
+
return newest?.context ?? null;
|
|
21
|
+
}
|
|
22
|
+
constructor(){
|
|
23
|
+
this.entries = [];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const AssistantPageContext_AssistantPageContext = AssistantPageContext.createImplementation({
|
|
27
|
+
implementation: AssistantPageContextImpl,
|
|
28
|
+
dependencies: []
|
|
29
|
+
});
|
|
30
|
+
export { AssistantPageContext_AssistantPageContext as AssistantPageContext };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=AssistantPageContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/assistantPageContext/AssistantPageContext.js","sources":["../../../src/features/assistantPageContext/AssistantPageContext.ts"],"sourcesContent":["import { AssistantPageContext as Abstraction } from \"./abstractions.js\";\n\ninterface Entry {\n owner: Abstraction.Owner;\n context: Abstraction.Data;\n}\n\n/*\n * A stack, newest last: a drawer that describes itself over a page that does too is what the user\n * is looking at, and closing it hands the page's context back. Not observable, since nothing renders\n * it; the assistant reads it at the moment a question is asked.\n */\nclass AssistantPageContextImpl implements Abstraction.Interface {\n private entries: Entry[] = [];\n\n set(context: Abstraction.Data): Abstraction.Owner {\n const owner = Symbol(\"AssistantPageContextOwner\");\n this.entries.push({ owner, context });\n return owner;\n }\n\n update(owner: Abstraction.Owner, context: Abstraction.Data): void {\n const entry = this.entries.find(entry => entry.owner === owner);\n if (entry) {\n entry.context = context;\n }\n }\n\n clear(owner: Abstraction.Owner): void {\n this.entries = this.entries.filter(entry => entry.owner !== owner);\n }\n\n get(): Abstraction.Data | null {\n const newest = this.entries[this.entries.length - 1];\n return newest?.context ?? null;\n }\n}\n\nexport const AssistantPageContext = Abstraction.createImplementation({\n implementation: AssistantPageContextImpl,\n dependencies: []\n});\n"],"names":["AssistantPageContextImpl","context","owner","Symbol","entry","newest","AssistantPageContext","Abstraction"],"mappings":";AAYA,MAAMA;IAGF,IAAIC,OAAyB,EAAqB;QAC9C,MAAMC,QAAQC,OAAO;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAAED;YAAOD;QAAQ;QACnC,OAAOC;IACX;IAEA,OAAOA,KAAwB,EAAED,OAAyB,EAAQ;QAC9D,MAAMG,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,CAACA,CAAAA,QAASA,MAAM,KAAK,KAAKF;QACzD,IAAIE,OACAA,MAAM,OAAO,GAAGH;IAExB;IAEA,MAAMC,KAAwB,EAAQ;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAACE,CAAAA,QAASA,MAAM,KAAK,KAAKF;IAChE;IAEA,MAA+B;QAC3B,MAAMG,SAAS,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE;QACpD,OAAOA,QAAQ,WAAW;IAC9B;;aAtBQ,OAAO,GAAY,EAAE;;AAuBjC;AAEO,MAAMC,4CAAuBC,qBAAAA,oBAAgC,CAAC;IACjE,gBAAgBP;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the user has on screen, sent to the assistant with each question so it can resolve "this
|
|
3
|
+
* folder", "Archive" or "these entries" without searching for them. `view` says what the screen is
|
|
4
|
+
* ("Entries of the Product content model"); `details` holds the ids and titles a question might
|
|
5
|
+
* refer to. Keep it to ids, titles and types: never record contents. The server drops details over
|
|
6
|
+
* a few kilobytes.
|
|
7
|
+
*/
|
|
8
|
+
export interface AssistantPageContextData {
|
|
9
|
+
view: string;
|
|
10
|
+
details: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/** Identifies one `set`, so each view clears only the context it set. */
|
|
13
|
+
export type AssistantPageContextOwner = symbol;
|
|
14
|
+
export interface IAssistantPageContext {
|
|
15
|
+
/** Put a context in front of any earlier one. Returns the owner to pass to `clear`. */
|
|
16
|
+
set(context: AssistantPageContextData): AssistantPageContextOwner;
|
|
17
|
+
/** Replace what this owner set without moving it, so a context set over it stays on top. */
|
|
18
|
+
update(owner: AssistantPageContextOwner, context: AssistantPageContextData): void;
|
|
19
|
+
/** Remove the context this owner set. The one before it, if any, is current again. */
|
|
20
|
+
clear(owner: AssistantPageContextOwner): void;
|
|
21
|
+
/** The newest context still set. */
|
|
22
|
+
get(): AssistantPageContextData | null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The screen the user is on, as the assistant should know it. A view's presenter sets it when the
|
|
26
|
+
* view starts and clears it when the view is disposed.
|
|
27
|
+
*/
|
|
28
|
+
export declare const AssistantPageContext: import("@webiny/di").Abstraction<IAssistantPageContext>;
|
|
29
|
+
export declare namespace AssistantPageContext {
|
|
30
|
+
type Interface = IAssistantPageContext;
|
|
31
|
+
type Data = AssistantPageContextData;
|
|
32
|
+
type Owner = AssistantPageContextOwner;
|
|
33
|
+
}
|