@thinkai/tai-api-contract 2.185.0 → 2.187.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.
@@ -1,7 +1,7 @@
1
1
  openapi: 3.0.3
2
2
  info:
3
3
  title: ThinkAI API
4
- version: 2.185.0
4
+ version: 2.187.0
5
5
  description: >
6
6
  Contract surface for the AI Driven SDLC backend used by ThinkAI.
7
7
  Workspace-scoped routes use `/workspaces/{workspaceId}/...`.
@@ -1069,6 +1069,269 @@ paths:
1069
1069
  error: Forbidden
1070
1070
  code: forbidden
1071
1071
 
1072
+ /admin/automation-cost/summary:
1073
+ get:
1074
+ tags: [PlatformAdmin]
1075
+ summary: Estimated Agent automation spend by workspace and operation
1076
+ operationId: adminGetAutomationCostSummary
1077
+ description: >
1078
+ Rolls up `tai_readiness_token_usage` for the given UTC range (defaults to the current
1079
+ UTC calendar month when `from`/`to` are omitted). Each row is one
1080
+ `(workspaceId, operation)` with token totals, invocation count, and
1081
+ `estimatedSpendCents` from `workers.automationCost.pricing` (Cursor Auto pool list-rate
1082
+ defaults when keys are missing). Portfolio `totals` are sums of the returned rows.
1083
+
1084
+ **Authorization:** Bearer JWT required. Caller email must appear in `PLATFORM_ADMIN_EMAILS`.
1085
+ Separate from customer Insights AI Usage & Spend / `ai_cost_budget`.
1086
+ parameters:
1087
+ - name: workspaceId
1088
+ in: query
1089
+ required: false
1090
+ schema:
1091
+ type: string
1092
+ format: uuid
1093
+ description: Filter by workspace UUID.
1094
+ - name: from
1095
+ in: query
1096
+ required: false
1097
+ schema:
1098
+ type: string
1099
+ format: date-time
1100
+ description: Inclusive start (ISO-8601). Defaults to start of current UTC month.
1101
+ - name: to
1102
+ in: query
1103
+ required: false
1104
+ schema:
1105
+ type: string
1106
+ format: date-time
1107
+ description: Inclusive end (ISO-8601). Defaults to end of current UTC month.
1108
+ responses:
1109
+ "200":
1110
+ description: Summary rows and portfolio totals (empty rows / zero totals when no usage).
1111
+ content:
1112
+ application/json:
1113
+ schema:
1114
+ $ref: "#/components/schemas/AutomationCostSummaryDto"
1115
+ "401":
1116
+ description: Missing or invalid JWT.
1117
+ content:
1118
+ application/json:
1119
+ schema:
1120
+ $ref: "#/components/schemas/ErrorMessageDto"
1121
+ "403":
1122
+ description: Caller is not a platform admin.
1123
+ content:
1124
+ application/json:
1125
+ schema:
1126
+ $ref: "#/components/schemas/ErrorMessageDto"
1127
+ example:
1128
+ error: Forbidden
1129
+ code: forbidden
1130
+
1131
+ /admin/workspaces/{workspaceId}/automation-cost/budget:
1132
+ get:
1133
+ tags: [PlatformAdmin]
1134
+ summary: Get automation-cost budget and month status for a workspace
1135
+ operationId: adminGetAutomationCostBudget
1136
+ description: >
1137
+ Returns budget rows for `readiness_analysis` and/or `readiness_fix` with
1138
+ `monthSpendCents` (estimated from token rows in the current UTC month) and
1139
+ `status` (`ok` | `warn` | `hard_stopped` | `paused`). When no budget is configured,
1140
+ `monthlyBudgetCents` is null and status is `ok` (unlimited) unless paused.
1141
+
1142
+ **Authorization:** Bearer JWT + `PLATFORM_ADMIN_EMAILS`.
1143
+ parameters:
1144
+ - $ref: "#/components/parameters/WorkspaceId"
1145
+ - name: operation
1146
+ in: query
1147
+ required: false
1148
+ schema:
1149
+ type: string
1150
+ enum: [readiness_analysis, readiness_fix]
1151
+ description: Limit to one operation; omit for both.
1152
+ responses:
1153
+ "200":
1154
+ description: Budget views for the requested operations.
1155
+ content:
1156
+ application/json:
1157
+ schema:
1158
+ $ref: "#/components/schemas/AutomationCostBudgetListDto"
1159
+ "401":
1160
+ description: Missing or invalid JWT.
1161
+ content:
1162
+ application/json:
1163
+ schema:
1164
+ $ref: "#/components/schemas/ErrorMessageDto"
1165
+ "403":
1166
+ description: Caller is not a platform admin.
1167
+ content:
1168
+ application/json:
1169
+ schema:
1170
+ $ref: "#/components/schemas/ErrorMessageDto"
1171
+ example:
1172
+ error: Forbidden
1173
+ code: forbidden
1174
+ "404":
1175
+ description: Workspace not found.
1176
+ content:
1177
+ application/json:
1178
+ schema:
1179
+ $ref: "#/components/schemas/ErrorMessageDto"
1180
+ example:
1181
+ error: Workspace not found
1182
+ code: workspace_not_found
1183
+ put:
1184
+ tags: [PlatformAdmin]
1185
+ summary: Upsert automation-cost budget for one operation
1186
+ operationId: adminPutAutomationCostBudget
1187
+ description: >
1188
+ Upserts `{ operation, monthlyBudgetCents, warnThresholdPct, hardEnabled }` into
1189
+ workspace `automation_cost_budget` (not `ai_cost_budget`). Default `warnThresholdPct`
1190
+ is 80. `monthlyBudgetCents: 0` with `hardEnabled: true` is an immediate hard stop.
1191
+ Returns the refreshed budget view for that operation.
1192
+
1193
+ **Authorization:** Bearer JWT + `PLATFORM_ADMIN_EMAILS`.
1194
+ parameters:
1195
+ - $ref: "#/components/parameters/WorkspaceId"
1196
+ requestBody:
1197
+ required: true
1198
+ content:
1199
+ application/json:
1200
+ schema:
1201
+ $ref: "#/components/schemas/AutomationCostBudgetUpsertDto"
1202
+ responses:
1203
+ "200":
1204
+ description: Updated budget view(s).
1205
+ content:
1206
+ application/json:
1207
+ schema:
1208
+ $ref: "#/components/schemas/AutomationCostBudgetListDto"
1209
+ "400":
1210
+ description: Invalid body.
1211
+ content:
1212
+ application/json:
1213
+ schema:
1214
+ $ref: "#/components/schemas/ErrorMessageDto"
1215
+ "401":
1216
+ description: Missing or invalid JWT.
1217
+ content:
1218
+ application/json:
1219
+ schema:
1220
+ $ref: "#/components/schemas/ErrorMessageDto"
1221
+ "403":
1222
+ description: Caller is not a platform admin.
1223
+ content:
1224
+ application/json:
1225
+ schema:
1226
+ $ref: "#/components/schemas/ErrorMessageDto"
1227
+ example:
1228
+ error: Forbidden
1229
+ code: forbidden
1230
+ "404":
1231
+ description: Workspace not found.
1232
+ content:
1233
+ application/json:
1234
+ schema:
1235
+ $ref: "#/components/schemas/ErrorMessageDto"
1236
+ example:
1237
+ error: Workspace not found
1238
+ code: workspace_not_found
1239
+
1240
+ /admin/workspaces/{workspaceId}/automation-cost/pause:
1241
+ post:
1242
+ tags: [PlatformAdmin]
1243
+ summary: Pause Agent automation for selected operations
1244
+ operationId: adminPostAutomationCostPause
1245
+ description: >
1246
+ Sets a per-workspace pause kill-switch for the listed operations. Workers honor pause
1247
+ the same as a hard budget stop (enforcement is a follow-up slice). Empty `operations`
1248
+ → `400`.
1249
+
1250
+ **Authorization:** Bearer JWT + `PLATFORM_ADMIN_EMAILS`.
1251
+ parameters:
1252
+ - $ref: "#/components/parameters/WorkspaceId"
1253
+ requestBody:
1254
+ required: true
1255
+ content:
1256
+ application/json:
1257
+ schema:
1258
+ $ref: "#/components/schemas/AutomationCostPauseBodyDto"
1259
+ responses:
1260
+ "200":
1261
+ description: Pause state stored.
1262
+ content:
1263
+ application/json:
1264
+ schema:
1265
+ $ref: "#/components/schemas/AutomationCostPauseResponseDto"
1266
+ "400":
1267
+ description: Empty or invalid operations list.
1268
+ content:
1269
+ application/json:
1270
+ schema:
1271
+ $ref: "#/components/schemas/ErrorMessageDto"
1272
+ "401":
1273
+ description: Missing or invalid JWT.
1274
+ content:
1275
+ application/json:
1276
+ schema:
1277
+ $ref: "#/components/schemas/ErrorMessageDto"
1278
+ "403":
1279
+ description: Caller is not a platform admin.
1280
+ content:
1281
+ application/json:
1282
+ schema:
1283
+ $ref: "#/components/schemas/ErrorMessageDto"
1284
+ example:
1285
+ error: Forbidden
1286
+ code: forbidden
1287
+ "404":
1288
+ description: Workspace not found.
1289
+ content:
1290
+ application/json:
1291
+ schema:
1292
+ $ref: "#/components/schemas/ErrorMessageDto"
1293
+ example:
1294
+ error: Workspace not found
1295
+ code: workspace_not_found
1296
+ delete:
1297
+ tags: [PlatformAdmin]
1298
+ summary: Clear automation-cost pause for a workspace
1299
+ operationId: adminDeleteAutomationCostPause
1300
+ description: >
1301
+ Clears `automation_cost_pause` for the workspace so workers may resume when under hard
1302
+ cap.
1303
+
1304
+ **Authorization:** Bearer JWT + `PLATFORM_ADMIN_EMAILS`.
1305
+ parameters:
1306
+ - $ref: "#/components/parameters/WorkspaceId"
1307
+ responses:
1308
+ "204":
1309
+ description: Pause cleared.
1310
+ "401":
1311
+ description: Missing or invalid JWT.
1312
+ content:
1313
+ application/json:
1314
+ schema:
1315
+ $ref: "#/components/schemas/ErrorMessageDto"
1316
+ "403":
1317
+ description: Caller is not a platform admin.
1318
+ content:
1319
+ application/json:
1320
+ schema:
1321
+ $ref: "#/components/schemas/ErrorMessageDto"
1322
+ example:
1323
+ error: Forbidden
1324
+ code: forbidden
1325
+ "404":
1326
+ description: Workspace not found.
1327
+ content:
1328
+ application/json:
1329
+ schema:
1330
+ $ref: "#/components/schemas/ErrorMessageDto"
1331
+ example:
1332
+ error: Workspace not found
1333
+ code: workspace_not_found
1334
+
1072
1335
  /privacy-requests:
1073
1336
  post:
1074
1337
  tags: [PrivacyRequests]
@@ -17165,20 +17428,107 @@ components:
17165
17428
  items:
17166
17429
  $ref: "#/components/schemas/AiUsageSpendAggregatedContributorRowDto"
17167
17430
 
17431
+ AiUsageSpendKeyInsightModelRightSizingEvidenceDto:
17432
+ type: object
17433
+ additionalProperties: false
17434
+ description: >
17435
+ Numeric evidence for `id=model_right_sizing` (Cost-to-Value insight #2).
17436
+ Premium share is `premiumSpendCents / totalModelSpendCents` against
17437
+ `thresholdPct` (Phase A default 40).
17438
+ required:
17439
+ - premiumSharePct
17440
+ - premiumSpendCents
17441
+ - totalModelSpendCents
17442
+ - thresholdPct
17443
+ - personCount
17444
+ properties:
17445
+ premiumSharePct:
17446
+ type: number
17447
+ description: Premium-model share of model spend in the window (0–100).
17448
+ premiumSpendCents:
17449
+ type: integer
17450
+ description: Sum of spend_cents on premium-classified models (cents).
17451
+ totalModelSpendCents:
17452
+ type: integer
17453
+ description: Sum of spend_cents across all models in the window (cents).
17454
+ thresholdPct:
17455
+ type: number
17456
+ description: Effective premium-share threshold used for this card (0–100).
17457
+ personCount:
17458
+ type: integer
17459
+ description: >
17460
+ Distinct mapped person_id rows contributing to this card's sample
17461
+ (workspace rollup or the single person for a person-scoped card).
17462
+
17463
+ AiUsageSpendKeyInsightDrilldownDto:
17464
+ type: object
17465
+ additionalProperties: false
17466
+ description: >
17467
+ Optional member drill-down for person-scoped `model_right_sizing` cards.
17468
+ Links to `GET …/integrations/ai-tool/{provider}/members/{externalId}`.
17469
+ required: [provider, externalId]
17470
+ properties:
17471
+ provider:
17472
+ type: string
17473
+ enum: [cursor, claude]
17474
+ description: AI tool provider for the member detail route.
17475
+ externalId:
17476
+ type: string
17477
+ description: Provider member external id for the member detail route.
17478
+
17168
17479
  AiUsageSpendKeyInsightItemDto:
17169
17480
  type: object
17170
17481
  additionalProperties: false
17171
17482
  required: [id, tone, text]
17483
+ description: >
17484
+ One Key Insights panel card. Base fields (`id`, `tone`, `text`) apply to
17485
+ all insights. When `id` is `model_right_sizing`, clients MUST treat
17486
+ `dataQuality`, `limitation`, `recommendedAction`, and `evidence` as
17487
+ required; `scope` and `drilldown` are optional (person cards may set both).
17172
17488
  properties:
17173
17489
  id:
17174
17490
  type: string
17175
- description: Stable insight key (e.g. spend-leader, spend-vs-output).
17491
+ description: >
17492
+ Stable insight key (e.g. spend-leader, spend-vs-output,
17493
+ model_right_sizing).
17176
17494
  tone:
17177
17495
  type: string
17178
17496
  enum: [positive, warning, neutral]
17179
17497
  text:
17180
17498
  type: string
17181
17499
  description: Human-readable insight sentence for the UI panel.
17500
+ dataQuality:
17501
+ allOf:
17502
+ - $ref: "#/components/schemas/AiAssistedCodeDataQuality"
17503
+ description: >
17504
+ Required when `id=model_right_sizing`. Phase A/B always `estimated`
17505
+ (model-mix heuristic; no task-complexity telemetry until Phase 3).
17506
+ limitation:
17507
+ type: string
17508
+ description: >
17509
+ Required when `id=model_right_sizing`. Fixed honesty string that the
17510
+ model mix is heuristic and does not encode task complexity.
17511
+ recommendedAction:
17512
+ type: string
17513
+ description: >
17514
+ Required when `id=model_right_sizing`. Coaching copy for the card CTA
17515
+ (advisory only; not vendor enforcement).
17516
+ evidence:
17517
+ allOf:
17518
+ - $ref: "#/components/schemas/AiUsageSpendKeyInsightModelRightSizingEvidenceDto"
17519
+ description: Required when `id=model_right_sizing`.
17520
+ scope:
17521
+ type: string
17522
+ enum: [workspace, person]
17523
+ description: >
17524
+ Optional scope for `model_right_sizing` cards. Workspace default vs
17525
+ per-person personalized item.
17526
+ drilldown:
17527
+ allOf:
17528
+ - $ref: "#/components/schemas/AiUsageSpendKeyInsightDrilldownDto"
17529
+ description: >
17530
+ Optional when `scope=person` for `model_right_sizing`; omitted on
17531
+ workspace cards.
17182
17532
 
17183
17533
  AiUsageSpendKeyInsightsDto:
17184
17534
  type: object
@@ -25400,6 +25750,186 @@ components:
25400
25750
  items:
25401
25751
  $ref: "#/components/schemas/ActivityLogEntryDto"
25402
25752
 
25753
+ AutomationCostOperationDto:
25754
+ type: string
25755
+ enum: [readiness_analysis, readiness_fix]
25756
+ description: Platform Agent job type in the readiness token ledger.
25757
+
25758
+ AutomationCostSummaryRowDto:
25759
+ type: object
25760
+ required:
25761
+ - workspaceId
25762
+ - operation
25763
+ - inputTokens
25764
+ - outputTokens
25765
+ - cacheReadTokens
25766
+ - cacheWriteTokens
25767
+ - estimatedSpendCents
25768
+ - invocationCount
25769
+ properties:
25770
+ workspaceId:
25771
+ type: string
25772
+ format: uuid
25773
+ operation:
25774
+ $ref: "#/components/schemas/AutomationCostOperationDto"
25775
+ inputTokens:
25776
+ type: integer
25777
+ format: int64
25778
+ outputTokens:
25779
+ type: integer
25780
+ format: int64
25781
+ cacheReadTokens:
25782
+ type: integer
25783
+ format: int64
25784
+ cacheWriteTokens:
25785
+ type: integer
25786
+ format: int64
25787
+ estimatedSpendCents:
25788
+ type: integer
25789
+ description: Ops estimate from token totals × runtime-config pricing (integer cents).
25790
+ invocationCount:
25791
+ type: integer
25792
+
25793
+ AutomationCostSummaryTotalsDto:
25794
+ type: object
25795
+ required:
25796
+ - inputTokens
25797
+ - outputTokens
25798
+ - cacheReadTokens
25799
+ - cacheWriteTokens
25800
+ - estimatedSpendCents
25801
+ - invocationCount
25802
+ properties:
25803
+ inputTokens:
25804
+ type: integer
25805
+ format: int64
25806
+ outputTokens:
25807
+ type: integer
25808
+ format: int64
25809
+ cacheReadTokens:
25810
+ type: integer
25811
+ format: int64
25812
+ cacheWriteTokens:
25813
+ type: integer
25814
+ format: int64
25815
+ estimatedSpendCents:
25816
+ type: integer
25817
+ invocationCount:
25818
+ type: integer
25819
+
25820
+ AutomationCostSummaryDto:
25821
+ type: object
25822
+ required: [rows, totals]
25823
+ properties:
25824
+ rows:
25825
+ type: array
25826
+ items:
25827
+ $ref: "#/components/schemas/AutomationCostSummaryRowDto"
25828
+ totals:
25829
+ $ref: "#/components/schemas/AutomationCostSummaryTotalsDto"
25830
+
25831
+ AutomationCostBudgetStatusDto:
25832
+ type: string
25833
+ enum: [ok, warn, hard_stopped, paused]
25834
+
25835
+ AutomationCostBudgetViewDto:
25836
+ type: object
25837
+ required:
25838
+ - operation
25839
+ - monthlyBudgetCents
25840
+ - warnThresholdPct
25841
+ - hardEnabled
25842
+ - monthSpendCents
25843
+ - status
25844
+ - paused
25845
+ properties:
25846
+ operation:
25847
+ $ref: "#/components/schemas/AutomationCostOperationDto"
25848
+ monthlyBudgetCents:
25849
+ type: integer
25850
+ nullable: true
25851
+ description: Null when no budget is configured (unlimited).
25852
+ warnThresholdPct:
25853
+ type: integer
25854
+ minimum: 0
25855
+ maximum: 100
25856
+ hardEnabled:
25857
+ type: boolean
25858
+ monthSpendCents:
25859
+ type: integer
25860
+ description: Estimated spend for this operation in the current UTC calendar month.
25861
+ status:
25862
+ $ref: "#/components/schemas/AutomationCostBudgetStatusDto"
25863
+ paused:
25864
+ type: boolean
25865
+ pauseReason:
25866
+ type: string
25867
+ nullable: true
25868
+
25869
+ AutomationCostBudgetListDto:
25870
+ type: object
25871
+ required: [budgets]
25872
+ properties:
25873
+ budgets:
25874
+ type: array
25875
+ items:
25876
+ $ref: "#/components/schemas/AutomationCostBudgetViewDto"
25877
+
25878
+ AutomationCostBudgetUpsertDto:
25879
+ type: object
25880
+ required: [operation, monthlyBudgetCents]
25881
+ properties:
25882
+ operation:
25883
+ $ref: "#/components/schemas/AutomationCostOperationDto"
25884
+ monthlyBudgetCents:
25885
+ type: integer
25886
+ minimum: 0
25887
+ warnThresholdPct:
25888
+ type: integer
25889
+ minimum: 0
25890
+ maximum: 100
25891
+ default: 80
25892
+ hardEnabled:
25893
+ type: boolean
25894
+ default: false
25895
+
25896
+ AutomationCostPauseBodyDto:
25897
+ type: object
25898
+ required: [operations, reason]
25899
+ properties:
25900
+ operations:
25901
+ type: array
25902
+ minItems: 1
25903
+ items:
25904
+ $ref: "#/components/schemas/AutomationCostOperationDto"
25905
+ reason:
25906
+ type: string
25907
+
25908
+ AutomationCostPauseStateDto:
25909
+ type: object
25910
+ required: [operations, reason, pausedAt]
25911
+ properties:
25912
+ operations:
25913
+ type: array
25914
+ items:
25915
+ $ref: "#/components/schemas/AutomationCostOperationDto"
25916
+ reason:
25917
+ type: string
25918
+ pausedAt:
25919
+ type: string
25920
+ format: date-time
25921
+ pausedBy:
25922
+ type: string
25923
+ nullable: true
25924
+ description: Platform admin email that set the pause, when known.
25925
+
25926
+ AutomationCostPauseResponseDto:
25927
+ type: object
25928
+ required: [pause]
25929
+ properties:
25930
+ pause:
25931
+ $ref: "#/components/schemas/AutomationCostPauseStateDto"
25932
+
25403
25933
  ReadinessTokenUsageRowDto:
25404
25934
  type: object
25405
25935
  required:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkai/tai-api-contract",
3
- "version": "2.185.0",
3
+ "version": "2.187.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",