@app-vitals/agent-admin 1.45.0 → 1.47.0
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/openapi.platform.json +350 -0
- package/package.json +2 -2
- package/src/admin-boot.ts +11 -0
- package/src/admin-extension.ts +30 -0
- package/src/admin-extension.unit.test.ts +64 -1
- package/src/admin-ui-settings-layout.merge.unit.test.ts +66 -0
- package/src/admin-ui-settings-layout.ts +24 -0
- package/src/admin-ui.ts +5 -0
- package/src/agent-template-reconcile.ts +170 -32
- package/src/agent-template-triggers.integration.test.ts +368 -0
- package/src/agent-templates.ts +35 -3
- package/src/agents-api.ts +183 -0
- package/src/agents.integration.test.ts +226 -3
- package/src/agents.ts +70 -17
- package/src/openapi-schemas.ts +13 -0
- package/src/server.exports.unit.test.ts +35 -0
- package/src/server.ts +15 -0
package/openapi.platform.json
CHANGED
|
@@ -618,6 +618,19 @@
|
|
|
618
618
|
},
|
|
619
619
|
"anthropicApiKey": {
|
|
620
620
|
"type": "string"
|
|
621
|
+
},
|
|
622
|
+
"env": {
|
|
623
|
+
"type": "object",
|
|
624
|
+
"additionalProperties": {
|
|
625
|
+
"type": "string"
|
|
626
|
+
},
|
|
627
|
+
"example": {
|
|
628
|
+
"ANTHROPIC_MODEL": "claude-opus-4-1"
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
"templateDetached": {
|
|
632
|
+
"type": "boolean",
|
|
633
|
+
"example": false
|
|
621
634
|
}
|
|
622
635
|
},
|
|
623
636
|
"required": [
|
|
@@ -866,6 +879,217 @@
|
|
|
866
879
|
"prompt"
|
|
867
880
|
]
|
|
868
881
|
},
|
|
882
|
+
"TemplateReconcileResult": {
|
|
883
|
+
"type": "object",
|
|
884
|
+
"properties": {
|
|
885
|
+
"agentId": {
|
|
886
|
+
"type": "string"
|
|
887
|
+
},
|
|
888
|
+
"status": {
|
|
889
|
+
"type": "string",
|
|
890
|
+
"enum": [
|
|
891
|
+
"reconciled",
|
|
892
|
+
"detached",
|
|
893
|
+
"unknown_specialty"
|
|
894
|
+
]
|
|
895
|
+
},
|
|
896
|
+
"counts": {
|
|
897
|
+
"type": "object",
|
|
898
|
+
"properties": {
|
|
899
|
+
"env": {
|
|
900
|
+
"type": "object",
|
|
901
|
+
"properties": {
|
|
902
|
+
"created": {
|
|
903
|
+
"type": "integer"
|
|
904
|
+
},
|
|
905
|
+
"updated": {
|
|
906
|
+
"type": "integer"
|
|
907
|
+
},
|
|
908
|
+
"adopted": {
|
|
909
|
+
"type": "integer"
|
|
910
|
+
},
|
|
911
|
+
"deleted": {
|
|
912
|
+
"type": "integer"
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
"required": [
|
|
916
|
+
"created",
|
|
917
|
+
"updated",
|
|
918
|
+
"adopted",
|
|
919
|
+
"deleted"
|
|
920
|
+
]
|
|
921
|
+
},
|
|
922
|
+
"tool": {
|
|
923
|
+
"type": "object",
|
|
924
|
+
"properties": {
|
|
925
|
+
"created": {
|
|
926
|
+
"type": "integer"
|
|
927
|
+
},
|
|
928
|
+
"updated": {
|
|
929
|
+
"type": "integer"
|
|
930
|
+
},
|
|
931
|
+
"adopted": {
|
|
932
|
+
"type": "integer"
|
|
933
|
+
},
|
|
934
|
+
"deleted": {
|
|
935
|
+
"type": "integer"
|
|
936
|
+
}
|
|
937
|
+
},
|
|
938
|
+
"required": [
|
|
939
|
+
"created",
|
|
940
|
+
"updated",
|
|
941
|
+
"adopted",
|
|
942
|
+
"deleted"
|
|
943
|
+
]
|
|
944
|
+
},
|
|
945
|
+
"plugin": {
|
|
946
|
+
"type": "object",
|
|
947
|
+
"properties": {
|
|
948
|
+
"created": {
|
|
949
|
+
"type": "integer"
|
|
950
|
+
},
|
|
951
|
+
"updated": {
|
|
952
|
+
"type": "integer"
|
|
953
|
+
},
|
|
954
|
+
"adopted": {
|
|
955
|
+
"type": "integer"
|
|
956
|
+
},
|
|
957
|
+
"deleted": {
|
|
958
|
+
"type": "integer"
|
|
959
|
+
}
|
|
960
|
+
},
|
|
961
|
+
"required": [
|
|
962
|
+
"created",
|
|
963
|
+
"updated",
|
|
964
|
+
"adopted",
|
|
965
|
+
"deleted"
|
|
966
|
+
]
|
|
967
|
+
},
|
|
968
|
+
"cron": {
|
|
969
|
+
"type": "object",
|
|
970
|
+
"properties": {
|
|
971
|
+
"created": {
|
|
972
|
+
"type": "integer"
|
|
973
|
+
},
|
|
974
|
+
"updated": {
|
|
975
|
+
"type": "integer"
|
|
976
|
+
},
|
|
977
|
+
"adopted": {
|
|
978
|
+
"type": "integer"
|
|
979
|
+
},
|
|
980
|
+
"deleted": {
|
|
981
|
+
"type": "integer"
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
"required": [
|
|
985
|
+
"created",
|
|
986
|
+
"updated",
|
|
987
|
+
"adopted",
|
|
988
|
+
"deleted"
|
|
989
|
+
]
|
|
990
|
+
}
|
|
991
|
+
},
|
|
992
|
+
"required": [
|
|
993
|
+
"env",
|
|
994
|
+
"tool",
|
|
995
|
+
"plugin",
|
|
996
|
+
"cron"
|
|
997
|
+
]
|
|
998
|
+
},
|
|
999
|
+
"systemCrons": {
|
|
1000
|
+
"type": "object",
|
|
1001
|
+
"properties": {
|
|
1002
|
+
"created": {
|
|
1003
|
+
"type": "integer"
|
|
1004
|
+
},
|
|
1005
|
+
"updated": {
|
|
1006
|
+
"type": "integer"
|
|
1007
|
+
},
|
|
1008
|
+
"deleted": {
|
|
1009
|
+
"type": "integer"
|
|
1010
|
+
}
|
|
1011
|
+
},
|
|
1012
|
+
"required": [
|
|
1013
|
+
"created",
|
|
1014
|
+
"updated",
|
|
1015
|
+
"deleted"
|
|
1016
|
+
]
|
|
1017
|
+
},
|
|
1018
|
+
"conflicts": {
|
|
1019
|
+
"type": "array",
|
|
1020
|
+
"items": {
|
|
1021
|
+
"type": "object",
|
|
1022
|
+
"properties": {
|
|
1023
|
+
"kind": {
|
|
1024
|
+
"type": "string",
|
|
1025
|
+
"enum": [
|
|
1026
|
+
"env",
|
|
1027
|
+
"tool",
|
|
1028
|
+
"plugin",
|
|
1029
|
+
"cron"
|
|
1030
|
+
]
|
|
1031
|
+
},
|
|
1032
|
+
"key": {
|
|
1033
|
+
"type": "string"
|
|
1034
|
+
},
|
|
1035
|
+
"reason": {
|
|
1036
|
+
"type": "string",
|
|
1037
|
+
"enum": [
|
|
1038
|
+
"cron_name_conflict",
|
|
1039
|
+
"invalid_cron_schedule",
|
|
1040
|
+
"denylisted_env_key"
|
|
1041
|
+
]
|
|
1042
|
+
}
|
|
1043
|
+
},
|
|
1044
|
+
"required": [
|
|
1045
|
+
"kind",
|
|
1046
|
+
"key",
|
|
1047
|
+
"reason"
|
|
1048
|
+
]
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
"toolsEmptyGuarded": {
|
|
1052
|
+
"type": "boolean"
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
"required": [
|
|
1056
|
+
"agentId",
|
|
1057
|
+
"status",
|
|
1058
|
+
"counts",
|
|
1059
|
+
"systemCrons",
|
|
1060
|
+
"conflicts",
|
|
1061
|
+
"toolsEmptyGuarded"
|
|
1062
|
+
]
|
|
1063
|
+
},
|
|
1064
|
+
"TemplateDetachResult": {
|
|
1065
|
+
"type": "object",
|
|
1066
|
+
"properties": {
|
|
1067
|
+
"templateDetached": {
|
|
1068
|
+
"type": "boolean"
|
|
1069
|
+
}
|
|
1070
|
+
},
|
|
1071
|
+
"required": [
|
|
1072
|
+
"templateDetached"
|
|
1073
|
+
]
|
|
1074
|
+
},
|
|
1075
|
+
"ResetTemplateBody": {
|
|
1076
|
+
"type": "object",
|
|
1077
|
+
"properties": {
|
|
1078
|
+
"kind": {
|
|
1079
|
+
"type": "string",
|
|
1080
|
+
"enum": [
|
|
1081
|
+
"env",
|
|
1082
|
+
"tool",
|
|
1083
|
+
"plugin",
|
|
1084
|
+
"cron"
|
|
1085
|
+
]
|
|
1086
|
+
},
|
|
1087
|
+
"key": {
|
|
1088
|
+
"type": "string",
|
|
1089
|
+
"minLength": 1
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
},
|
|
869
1093
|
"ReconcileCronResult": {
|
|
870
1094
|
"type": "object",
|
|
871
1095
|
"properties": {
|
|
@@ -5141,6 +5365,132 @@
|
|
|
5141
5365
|
}
|
|
5142
5366
|
}
|
|
5143
5367
|
},
|
|
5368
|
+
"/agents/{id}/template/reconcile": {
|
|
5369
|
+
"post": {
|
|
5370
|
+
"summary": "Reconcile the agent against its template",
|
|
5371
|
+
"description": "Applies the agent's merged template (specialty defaults, deployment/account layers) to its env, tools, plugins and crons in one transaction: adds missing items, updates template-sourced rows, removes orphans, and leaves custom rows and tombstones alone. A detached agent is left untouched (status `detached`). Called automatically on agent startup and when a template changes.",
|
|
5372
|
+
"parameters": [
|
|
5373
|
+
{
|
|
5374
|
+
"schema": {
|
|
5375
|
+
"type": "string",
|
|
5376
|
+
"example": "clx1234567890"
|
|
5377
|
+
},
|
|
5378
|
+
"required": true,
|
|
5379
|
+
"name": "id",
|
|
5380
|
+
"in": "path"
|
|
5381
|
+
}
|
|
5382
|
+
],
|
|
5383
|
+
"responses": {
|
|
5384
|
+
"200": {
|
|
5385
|
+
"description": "Template reconcile summary",
|
|
5386
|
+
"content": {
|
|
5387
|
+
"application/json": {
|
|
5388
|
+
"schema": {
|
|
5389
|
+
"$ref": "#/components/schemas/TemplateReconcileResult"
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
},
|
|
5397
|
+
"/agents/{id}/template/detach": {
|
|
5398
|
+
"post": {
|
|
5399
|
+
"summary": "Detach the agent from its template",
|
|
5400
|
+
"description": "Stops applying template writes to the agent. Existing rows stay as they are. Admin or session member only.",
|
|
5401
|
+
"parameters": [
|
|
5402
|
+
{
|
|
5403
|
+
"schema": {
|
|
5404
|
+
"type": "string",
|
|
5405
|
+
"example": "clx1234567890"
|
|
5406
|
+
},
|
|
5407
|
+
"required": true,
|
|
5408
|
+
"name": "id",
|
|
5409
|
+
"in": "path"
|
|
5410
|
+
}
|
|
5411
|
+
],
|
|
5412
|
+
"responses": {
|
|
5413
|
+
"200": {
|
|
5414
|
+
"description": "Agent detached",
|
|
5415
|
+
"content": {
|
|
5416
|
+
"application/json": {
|
|
5417
|
+
"schema": {
|
|
5418
|
+
"$ref": "#/components/schemas/TemplateDetachResult"
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
}
|
|
5425
|
+
},
|
|
5426
|
+
"/agents/{id}/template/reattach": {
|
|
5427
|
+
"post": {
|
|
5428
|
+
"summary": "Reattach the agent to its template",
|
|
5429
|
+
"description": "Clears the detach flag and reconciles the agent against its template. Custom rows are kept. Admin or session member only.",
|
|
5430
|
+
"parameters": [
|
|
5431
|
+
{
|
|
5432
|
+
"schema": {
|
|
5433
|
+
"type": "string",
|
|
5434
|
+
"example": "clx1234567890"
|
|
5435
|
+
},
|
|
5436
|
+
"required": true,
|
|
5437
|
+
"name": "id",
|
|
5438
|
+
"in": "path"
|
|
5439
|
+
}
|
|
5440
|
+
],
|
|
5441
|
+
"responses": {
|
|
5442
|
+
"200": {
|
|
5443
|
+
"description": "Template reconcile summary",
|
|
5444
|
+
"content": {
|
|
5445
|
+
"application/json": {
|
|
5446
|
+
"schema": {
|
|
5447
|
+
"$ref": "#/components/schemas/TemplateReconcileResult"
|
|
5448
|
+
}
|
|
5449
|
+
}
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
}
|
|
5453
|
+
}
|
|
5454
|
+
},
|
|
5455
|
+
"/agents/{id}/template/reset": {
|
|
5456
|
+
"post": {
|
|
5457
|
+
"summary": "Reset the agent to its template",
|
|
5458
|
+
"description": "Drops the agent's custom rows (overrides and tombstones) for every key its template defines, or only the one `kind`/`key` given, then reconciles so the template values return as template-sourced rows. 409 when the agent is detached. Admin or session member only.",
|
|
5459
|
+
"parameters": [
|
|
5460
|
+
{
|
|
5461
|
+
"schema": {
|
|
5462
|
+
"type": "string",
|
|
5463
|
+
"example": "clx1234567890"
|
|
5464
|
+
},
|
|
5465
|
+
"required": true,
|
|
5466
|
+
"name": "id",
|
|
5467
|
+
"in": "path"
|
|
5468
|
+
}
|
|
5469
|
+
],
|
|
5470
|
+
"requestBody": {
|
|
5471
|
+
"required": false,
|
|
5472
|
+
"content": {
|
|
5473
|
+
"application/json": {
|
|
5474
|
+
"schema": {
|
|
5475
|
+
"$ref": "#/components/schemas/ResetTemplateBody"
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5478
|
+
}
|
|
5479
|
+
},
|
|
5480
|
+
"responses": {
|
|
5481
|
+
"200": {
|
|
5482
|
+
"description": "Template reconcile summary",
|
|
5483
|
+
"content": {
|
|
5484
|
+
"application/json": {
|
|
5485
|
+
"schema": {
|
|
5486
|
+
"$ref": "#/components/schemas/TemplateReconcileResult"
|
|
5487
|
+
}
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
}
|
|
5492
|
+
}
|
|
5493
|
+
},
|
|
5144
5494
|
"/agents/{id}/crons/reconcile": {
|
|
5145
5495
|
"post": {
|
|
5146
5496
|
"summary": "Reconcile system crons",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.47.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sdk": "0.135.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
45
|
+
"@app-vitals/agent-lib": "1.47.0",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
package/src/admin-boot.ts
CHANGED
|
@@ -83,6 +83,7 @@ import { AgentGitHubInstallationsService } from "./agent-github-installations.ts
|
|
|
83
83
|
import { AgentMarketplaceService } from "./agent-marketplaces.ts";
|
|
84
84
|
import { AgentMemberService } from "./agent-members.ts";
|
|
85
85
|
import { AgentPluginService } from "./agent-plugins.ts";
|
|
86
|
+
import { AgentTemplateReconcileService } from "./agent-template-reconcile.ts";
|
|
86
87
|
import { AgentTemplateService } from "./agent-templates.ts";
|
|
87
88
|
import { createAgentTemplatesApp } from "./agent-templates-api.ts";
|
|
88
89
|
import { AgentTokenService } from "./agent-tokens.ts";
|
|
@@ -213,6 +214,13 @@ export async function startAdmin(
|
|
|
213
214
|
undefined,
|
|
214
215
|
specialtyDefaults,
|
|
215
216
|
);
|
|
217
|
+
// ATP-2.2: applies the agent template at create, boot and on template change.
|
|
218
|
+
const templateReconcileService = new AgentTemplateReconcileService(
|
|
219
|
+
prisma,
|
|
220
|
+
crypto,
|
|
221
|
+
specialtyRegistry,
|
|
222
|
+
specialtyDefaults,
|
|
223
|
+
);
|
|
216
224
|
const agentCronRunService = new AgentCronRunService(prisma);
|
|
217
225
|
const agentToolService = new AgentToolService(prisma);
|
|
218
226
|
const agentTokenService = new AgentTokenService(prisma);
|
|
@@ -524,6 +532,7 @@ export async function startAdmin(
|
|
|
524
532
|
chatService: deletionChatService,
|
|
525
533
|
slack: slackClient,
|
|
526
534
|
decrypt: crypto.decrypt,
|
|
535
|
+
agentTemplateReconcileService: templateReconcileService,
|
|
527
536
|
sessionSecret,
|
|
528
537
|
adminApiKeys,
|
|
529
538
|
sentryClient: process.env.SENTRY_DSN ? Sentry : undefined,
|
|
@@ -582,6 +591,7 @@ export async function startAdmin(
|
|
|
582
591
|
prisma,
|
|
583
592
|
crypto,
|
|
584
593
|
specialtyRegistry,
|
|
594
|
+
templateReconcileService,
|
|
585
595
|
);
|
|
586
596
|
root.route(
|
|
587
597
|
"/",
|
|
@@ -641,6 +651,7 @@ export async function startAdmin(
|
|
|
641
651
|
specialtyRegistry,
|
|
642
652
|
specialtyDefaults,
|
|
643
653
|
templateService,
|
|
654
|
+
templateReconcile: templateReconcileService,
|
|
644
655
|
serviceIntegrations,
|
|
645
656
|
chatService: deletionChatService,
|
|
646
657
|
slack: slackClient,
|
package/src/admin-extension.ts
CHANGED
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
* agentDetailCards(ctx) — extra cards on the agent detail page, each placed
|
|
25
25
|
* in the header or the Configuration group
|
|
26
26
|
* backgroundPasses(ctx) — interval loops, started after the platform sweepers
|
|
27
|
+
* settingsNavItems(ctx) — extra settings-sidebar entries, each naming the
|
|
28
|
+
* section it joins (an unknown section is appended).
|
|
29
|
+
* Merged into the nav with mergeSettingsNavItems
|
|
30
|
+
* (admin-ui-settings-layout.ts, also exported from
|
|
31
|
+
* server.ts with renderSettingsLayout). A throwing
|
|
32
|
+
* hook is logged and contributes nothing
|
|
27
33
|
* specialtyDefaults(name) — a specialty's default crons/tools/plugins. Like
|
|
28
34
|
* serviceIntegrations it needs no context and is
|
|
29
35
|
* collected before the services are built; the cron
|
|
@@ -196,6 +202,15 @@ export interface AdminOpenApiContribution {
|
|
|
196
202
|
};
|
|
197
203
|
}
|
|
198
204
|
|
|
205
|
+
/** One settings-sidebar entry contributed by an extension. */
|
|
206
|
+
export interface SettingsNavContribution {
|
|
207
|
+
/** Label of the section to join; an unknown label appends a new section. */
|
|
208
|
+
section: string;
|
|
209
|
+
label: string;
|
|
210
|
+
path: string;
|
|
211
|
+
adminOnly?: boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
199
214
|
export interface AdminExtension {
|
|
200
215
|
name?: string;
|
|
201
216
|
/** See the header: env-only, resolved before the provisioner is built. */
|
|
@@ -209,6 +224,7 @@ export interface AdminExtension {
|
|
|
209
224
|
adminUiRoutes?(ctx: AdminExtensionContext): AdminRouteContribution[];
|
|
210
225
|
agentDetailCards?(ctx: AdminExtensionContext): AgentDetailCardSlot[];
|
|
211
226
|
backgroundPasses?(ctx: AdminExtensionContext): AdminBackgroundPass[];
|
|
227
|
+
settingsNavItems?(ctx: AdminExtensionContext): SettingsNavContribution[];
|
|
212
228
|
openApi?(): AdminOpenApiContribution;
|
|
213
229
|
}
|
|
214
230
|
|
|
@@ -219,6 +235,7 @@ export const ADMIN_EXTENSION_HOOK_ORDER = [
|
|
|
219
235
|
"adminUiRoutes",
|
|
220
236
|
"agentDetailCards",
|
|
221
237
|
"backgroundPasses",
|
|
238
|
+
"settingsNavItems",
|
|
222
239
|
] as const;
|
|
223
240
|
|
|
224
241
|
export interface ResolvedAdminExtensions {
|
|
@@ -230,6 +247,7 @@ export interface ResolvedAdminExtensions {
|
|
|
230
247
|
adminUiRoutes: AdminRouteContribution[];
|
|
231
248
|
agentDetailCards: AgentDetailCardSlot[];
|
|
232
249
|
backgroundPasses: AdminBackgroundPass[];
|
|
250
|
+
settingsNavItems: SettingsNavContribution[];
|
|
233
251
|
}
|
|
234
252
|
|
|
235
253
|
/**
|
|
@@ -248,6 +266,17 @@ export function resolveAdminExtensions(
|
|
|
248
266
|
const adminUiRoutes = collect((ext) => ext.adminUiRoutes?.(ctx));
|
|
249
267
|
const agentDetailCards = collect((ext) => ext.agentDetailCards?.(ctx));
|
|
250
268
|
const backgroundPasses = collect((ext) => ext.backgroundPasses?.(ctx));
|
|
269
|
+
const settingsNavItems = extensions.flatMap((ext) => {
|
|
270
|
+
try {
|
|
271
|
+
return ext.settingsNavItems?.(ctx) ?? [];
|
|
272
|
+
} catch (err) {
|
|
273
|
+
console.error(
|
|
274
|
+
`[admin] extension "${ext.name ?? "unnamed"}" settingsNavItems failed:`,
|
|
275
|
+
err,
|
|
276
|
+
);
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
});
|
|
251
280
|
const agentPhaseMethodologyService = services
|
|
252
281
|
.map((s) => s.agentPhaseMethodologyService)
|
|
253
282
|
.filter((svc) => svc !== undefined)
|
|
@@ -265,6 +294,7 @@ export function resolveAdminExtensions(
|
|
|
265
294
|
adminUiRoutes,
|
|
266
295
|
agentDetailCards,
|
|
267
296
|
backgroundPasses,
|
|
297
|
+
settingsNavItems,
|
|
268
298
|
};
|
|
269
299
|
}
|
|
270
300
|
|
|
@@ -53,6 +53,7 @@ describe("resolveAdminExtensions", () => {
|
|
|
53
53
|
adminUiRoutes: [],
|
|
54
54
|
agentDetailCards: [],
|
|
55
55
|
backgroundPasses: [],
|
|
56
|
+
settingsNavItems: [],
|
|
56
57
|
});
|
|
57
58
|
});
|
|
58
59
|
|
|
@@ -88,6 +89,10 @@ describe("resolveAdminExtensions", () => {
|
|
|
88
89
|
calls.push(`${id}:backgroundPasses:${c === ctx}`);
|
|
89
90
|
return [];
|
|
90
91
|
},
|
|
92
|
+
settingsNavItems: (c) => {
|
|
93
|
+
calls.push(`${id}:settingsNavItems:${c === ctx}`);
|
|
94
|
+
return [];
|
|
95
|
+
},
|
|
91
96
|
openApi: () => {
|
|
92
97
|
calls.push(`${id}:openApi`);
|
|
93
98
|
return {};
|
|
@@ -105,16 +110,74 @@ describe("resolveAdminExtensions", () => {
|
|
|
105
110
|
expect(calls.some((c) => c.endsWith(":openApi"))).toBe(false);
|
|
106
111
|
});
|
|
107
112
|
|
|
108
|
-
it("pins the hook order: services first,
|
|
113
|
+
it("pins the hook order: services first, settings nav items last", () => {
|
|
109
114
|
expect([...ADMIN_EXTENSION_HOOK_ORDER]).toEqual([
|
|
110
115
|
"services",
|
|
111
116
|
"apiRoutes",
|
|
112
117
|
"adminUiRoutes",
|
|
113
118
|
"agentDetailCards",
|
|
114
119
|
"backgroundPasses",
|
|
120
|
+
"settingsNavItems",
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("settingsNavItems: concatenates in extension order and passes adminOnly through", () => {
|
|
125
|
+
const resolved = resolveAdminExtensions(
|
|
126
|
+
[
|
|
127
|
+
{
|
|
128
|
+
settingsNavItems: () => [
|
|
129
|
+
{ section: "A", label: "a1", path: "/a1", adminOnly: true },
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
{},
|
|
133
|
+
{
|
|
134
|
+
settingsNavItems: (c) => [
|
|
135
|
+
{ section: c === ctx ? "B" : "?", label: "b1", path: "/b1" },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
ctx,
|
|
140
|
+
);
|
|
141
|
+
expect(resolved.settingsNavItems).toEqual([
|
|
142
|
+
{ section: "A", label: "a1", path: "/a1", adminOnly: true },
|
|
143
|
+
{ section: "B", label: "b1", path: "/b1" },
|
|
115
144
|
]);
|
|
116
145
|
});
|
|
117
146
|
|
|
147
|
+
it("settingsNavItems: a throwing hook is logged and skipped, others unaffected", () => {
|
|
148
|
+
const errSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
149
|
+
try {
|
|
150
|
+
const resolved = resolveAdminExtensions(
|
|
151
|
+
[
|
|
152
|
+
{
|
|
153
|
+
settingsNavItems: () => {
|
|
154
|
+
throw new Error("boom");
|
|
155
|
+
},
|
|
156
|
+
backgroundPasses: () => [
|
|
157
|
+
{
|
|
158
|
+
name: "p",
|
|
159
|
+
logPrefix: "[p]",
|
|
160
|
+
intervalMs: 1,
|
|
161
|
+
tick: async () => {},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
settingsNavItems: () => [{ section: "S", label: "l", path: "/l" }],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
ctx,
|
|
170
|
+
);
|
|
171
|
+
expect(resolved.settingsNavItems).toEqual([
|
|
172
|
+
{ section: "S", label: "l", path: "/l" },
|
|
173
|
+
]);
|
|
174
|
+
expect(resolved.backgroundPasses).toHaveLength(1);
|
|
175
|
+
expect(errSpy).toHaveBeenCalledTimes(1);
|
|
176
|
+
} finally {
|
|
177
|
+
errSpy.mockRestore();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
118
181
|
it("concatenates list contributions in extension order", () => {
|
|
119
182
|
const app = new Hono();
|
|
120
183
|
const pass = (name: string): AdminBackgroundPass => ({
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
mergeSettingsNavItems,
|
|
4
|
+
renderSettingsLayout,
|
|
5
|
+
type SettingsNav,
|
|
6
|
+
} from "./admin-ui-settings-layout.ts";
|
|
7
|
+
|
|
8
|
+
const base = (): SettingsNav => ({
|
|
9
|
+
sections: [
|
|
10
|
+
{ label: "General", items: [{ label: "Profile", path: "/p" }] },
|
|
11
|
+
{ label: "Org", items: [{ label: "Members", path: "/m" }] },
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("mergeSettingsNavItems", () => {
|
|
16
|
+
it("appends into the section with a matching label", () => {
|
|
17
|
+
const out = mergeSettingsNavItems(base(), [
|
|
18
|
+
{ section: "General", label: "Extra", path: "/x" },
|
|
19
|
+
]);
|
|
20
|
+
expect(out.sections.map((s) => s.label)).toEqual(["General", "Org"]);
|
|
21
|
+
expect(out.sections[0]?.items).toEqual([
|
|
22
|
+
{ label: "Profile", path: "/p" },
|
|
23
|
+
{ label: "Extra", path: "/x" },
|
|
24
|
+
]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("appends a new section at the end for an unknown label", () => {
|
|
28
|
+
const out = mergeSettingsNavItems(base(), [
|
|
29
|
+
{ section: "Coding", label: "A", path: "/a" },
|
|
30
|
+
{ section: "Coding", label: "B", path: "/b" },
|
|
31
|
+
]);
|
|
32
|
+
expect(out.sections.map((s) => s.label)).toEqual([
|
|
33
|
+
"General",
|
|
34
|
+
"Org",
|
|
35
|
+
"Coding",
|
|
36
|
+
]);
|
|
37
|
+
expect(out.sections[2]?.items.map((i) => i.label)).toEqual(["A", "B"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("does not mutate the input", () => {
|
|
41
|
+
const nav = base();
|
|
42
|
+
const snapshot = structuredClone(nav);
|
|
43
|
+
mergeSettingsNavItems(nav, [
|
|
44
|
+
{ section: "General", label: "Extra", path: "/x" },
|
|
45
|
+
{ section: "New", label: "N", path: "/n" },
|
|
46
|
+
]);
|
|
47
|
+
expect(nav).toEqual(snapshot);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("preserves adminOnly so non-admins do not see the item", () => {
|
|
51
|
+
const nav = mergeSettingsNavItems(base(), [
|
|
52
|
+
{ section: "Coding", label: "Secret", path: "/s", adminOnly: true },
|
|
53
|
+
]);
|
|
54
|
+
const render = (isAdmin: boolean) =>
|
|
55
|
+
renderSettingsLayout({
|
|
56
|
+
userName: "u",
|
|
57
|
+
title: "T",
|
|
58
|
+
nav,
|
|
59
|
+
active: "/p",
|
|
60
|
+
body: "",
|
|
61
|
+
isAdmin,
|
|
62
|
+
});
|
|
63
|
+
expect(render(false)).not.toContain("Secret");
|
|
64
|
+
expect(render(true)).toContain("Secret");
|
|
65
|
+
});
|
|
66
|
+
});
|