deepline 0.3.506 → 0.3.507

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.
Files changed (142) hide show
  1. package/dist/bundling-sources/sdk/src/client-core.ts +27 -6
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/monitors/deactivation-reasons.ts +38 -1
  4. package/dist/bundling-sources/shared_libs/monitors/fleets/verdict.ts +4 -2
  5. package/dist/bundling-sources/shared_libs/monitors/package.json +2 -0
  6. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-errors.ts +15 -0
  7. package/dist/bundling-sources/shared_libs/monitors/provider-monitor-state.ts +24 -4
  8. package/dist/bundling-sources/shared_libs/monitors/provider-resource-failure.ts +405 -0
  9. package/dist/bundling-sources/shared_libs/play-runtime/durable-runs-rollout.ts +6 -1
  10. package/dist/cli/auth-6PJ4G5PC.js +43 -0
  11. package/dist/cli/{auth-ZHFONT2D.mjs → auth-BNP3M27C.mjs} +5 -5
  12. package/dist/cli/{billing-3Z7N4WTL.js → billing-7HIVX4YJ.js} +79 -79
  13. package/dist/cli/{billing-B2YEMNHE.mjs → billing-JKJ2AEZ6.mjs} +6 -6
  14. package/dist/cli/{chunk-YEX6RPUO.mjs → chunk-2OKEMB5A.mjs} +1 -1
  15. package/dist/cli/{chunk-LRSRJJPD.js → chunk-2ZINJVWW.js} +16 -16
  16. package/dist/cli/{chunk-HINTYT5H.js → chunk-3D5ZNYYI.js} +44 -44
  17. package/dist/cli/{chunk-SUJIVF6L.js → chunk-56SRWY5F.js} +16 -16
  18. package/dist/cli/{chunk-TEMORCEE.mjs → chunk-5A66OJZD.mjs} +1 -1
  19. package/dist/cli/{chunk-CHGRURBN.mjs → chunk-5I2XKXLS.mjs} +5 -5
  20. package/dist/cli/{chunk-FWSEGIT6.js → chunk-5PXGAA2M.js} +4 -4
  21. package/dist/cli/{chunk-75NAFY36.js → chunk-6AQO5OJ5.js} +7 -7
  22. package/dist/cli/{chunk-5ARG7J7A.js → chunk-76R5I7HR.js} +6 -6
  23. package/dist/cli/{chunk-2IXXB7OA.mjs → chunk-7TZA6LJI.mjs} +5 -5
  24. package/dist/cli/{chunk-OD6TASBP.js → chunk-AXYLMDU3.js} +8 -8
  25. package/dist/cli/{chunk-FFGQR5J3.mjs → chunk-D2T4W5LR.mjs} +2 -2
  26. package/dist/cli/{chunk-OHNMJ5XQ.js → chunk-E5HGDYU3.js} +41 -41
  27. package/dist/cli/{chunk-3F676QXJ.js → chunk-E7YIIEZU.js} +11 -11
  28. package/dist/cli/{chunk-6RYVIZRP.mjs → chunk-EEJLV77L.mjs} +2 -2
  29. package/dist/cli/{chunk-BQBPVUFJ.mjs → chunk-EYZJDHXA.mjs} +3 -3
  30. package/dist/cli/{chunk-Z7EHY2MF.mjs → chunk-GMRWVXU2.mjs} +2 -2
  31. package/dist/cli/{chunk-2CFTDVEP.mjs → chunk-H334EFON.mjs} +2 -2
  32. package/dist/cli/{chunk-QAY5AS2H.mjs → chunk-H6PABDS4.mjs} +10 -10
  33. package/dist/cli/{chunk-F53SGS3C.js → chunk-HPZONIDF.js} +5 -5
  34. package/dist/cli/{chunk-O4DZG4VA.mjs → chunk-IBKWVFWP.mjs} +2 -2
  35. package/dist/cli/{chunk-ZZDTWVCQ.js → chunk-ILUZ7IHP.js} +21 -21
  36. package/dist/cli/{chunk-YVOS5KSG.mjs → chunk-IWZRQ6YW.mjs} +1 -1
  37. package/dist/cli/{chunk-GJNIC2CO.mjs → chunk-JCE2JNGD.mjs} +5 -5
  38. package/dist/cli/{chunk-2OY5DXTC.js → chunk-JPN6OBPW.js} +1 -1
  39. package/dist/cli/{chunk-OUGJUM5X.mjs → chunk-LSONU2E2.mjs} +6 -6
  40. package/dist/cli/{chunk-PRIHD5XS.js → chunk-MN5HO2PN.js} +9 -9
  41. package/dist/cli/{chunk-N7G36GXB.js → chunk-MQRT5NYP.js} +26 -26
  42. package/dist/cli/{chunk-YWZEBPXK.mjs → chunk-NJRJGXVF.mjs} +2 -2
  43. package/dist/cli/{chunk-AD2WJUZA.js → chunk-OBATCFZO.js} +7 -7
  44. package/dist/cli/{chunk-XUY7WQ2R.mjs → chunk-OPEJASMJ.mjs} +2 -2
  45. package/dist/cli/{chunk-QP333GFE.js → chunk-QWRSWQ7Z.js} +6 -6
  46. package/dist/cli/{chunk-E554XCJI.js → chunk-REFT4DMJ.js} +96 -96
  47. package/dist/cli/{chunk-GRESJ3H3.js → chunk-RFJANXCC.js} +14 -14
  48. package/dist/cli/{chunk-ONBXTEFQ.mjs → chunk-RTLWYERT.mjs} +1 -1
  49. package/dist/cli/{chunk-3BFZEHBH.mjs → chunk-T6FUNWXX.mjs} +1 -1
  50. package/dist/cli/{chunk-D7OCORZ7.mjs → chunk-TVR4R2E6.mjs} +1 -1
  51. package/dist/cli/{chunk-MHRR47VQ.js → chunk-TZ7APOBM.js} +3 -3
  52. package/dist/cli/{chunk-F7IQQYKV.js → chunk-V2K34NAO.js} +2 -2
  53. package/dist/cli/{chunk-YJKKOSXS.js → chunk-V4GGTOCX.js} +3 -3
  54. package/dist/cli/{chunk-EN7GXLFX.mjs → chunk-VGEBRTHF.mjs} +4 -4
  55. package/dist/cli/{chunk-BJ5OX62J.mjs → chunk-VQLD5M43.mjs} +5 -5
  56. package/dist/cli/{chunk-ZM5BJ5MP.js → chunk-WOPWSAGS.js} +53 -53
  57. package/dist/cli/{chunk-ND4WPLTE.mjs → chunk-WQAHMVBT.mjs} +2 -2
  58. package/dist/cli/{chunk-DB54ROPH.js → chunk-WTY2R4R3.js} +5 -5
  59. package/dist/cli/{chunk-OPBXKB57.mjs → chunk-XKGNEN4P.mjs} +1 -1
  60. package/dist/cli/{chunk-TS4KFQKS.mjs → chunk-YAAJHS6W.mjs} +1 -1
  61. package/dist/cli/{chunk-26DJ4BDY.js → chunk-ZCNGMQVD.js} +2 -2
  62. package/dist/cli/{csv-ARHQ54HA.mjs → csv-LZTQOPP2.mjs} +4 -4
  63. package/dist/cli/{csv-7K7LK63Y.js → csv-WYJVU5HV.js} +13 -13
  64. package/dist/cli/{db-JBX24NJY.mjs → db-D6XFOQP3.mjs} +6 -6
  65. package/dist/cli/{db-V4Z2I6DY.js → db-UCUXPY7S.js} +27 -27
  66. package/dist/cli/{describe-RBDSGSZ7.mjs → describe-HKL2XK67.mjs} +18 -18
  67. package/dist/cli/describe-XS4OIASD.js +50 -0
  68. package/dist/cli/describe-core.d.mts +2 -2
  69. package/dist/cli/describe-core.d.ts +2 -2
  70. package/dist/cli/{executions-XEZKV5QU.js → executions-5CF5NM7V.js} +8 -8
  71. package/dist/cli/{executions-BAZEU63W.mjs → executions-AFHYXH73.mjs} +6 -6
  72. package/dist/cli/{feedback-LOERESRU.js → feedback-GJAX3JZE.js} +8 -8
  73. package/dist/cli/{feedback-YDSWBHCO.mjs → feedback-MLKQ572F.mjs} +4 -4
  74. package/dist/cli/{git-4Z3W2CQU.mjs → git-BMLROZOU.mjs} +5 -5
  75. package/dist/cli/git-RIXUHRDL.js +25 -0
  76. package/dist/cli/index.js +138 -138
  77. package/dist/cli/index.mjs +41 -41
  78. package/dist/cli/{legacy-noops-4QIQPVE5.js → legacy-noops-FHRDF7MC.js} +8 -8
  79. package/dist/cli/{legacy-noops-E4HH7S5O.mjs → legacy-noops-Y7JSQVLQ.mjs} +5 -5
  80. package/dist/cli/{monitors-QBHDSDA7.js → monitors-Z6RPIQIH.js} +127 -112
  81. package/dist/cli/{monitors-FPDW5DDM.mjs → monitors-ZEVK3UD7.mjs} +34 -19
  82. package/dist/cli/{org-UCDHIHAD.mjs → org-PFLVANIN.mjs} +6 -6
  83. package/dist/cli/{org-JO4GGSAH.js → org-TXJ3RES5.js} +72 -72
  84. package/dist/cli/{pages-6V52IZXY.mjs → pages-BKEMQ2J7.mjs} +6 -6
  85. package/dist/cli/{pages-FJAAXAWO.js → pages-ESKKBK5Y.js} +18 -18
  86. package/dist/cli/{play-MF4DWROJ.mjs → play-4Z6Z7KVY.mjs} +18 -18
  87. package/dist/cli/{play-F3AENS6W.js → play-AAFOZJKQ.js} +317 -317
  88. package/dist/cli/{providers-NJJLTECA.mjs → providers-KYP2UWDV.mjs} +6 -6
  89. package/dist/cli/{providers-XXOQLPX7.js → providers-WEU4UNKY.js} +9 -9
  90. package/dist/cli/{quickstart-Z5MSMI7S.mjs → quickstart-7EUDF4IL.mjs} +4 -4
  91. package/dist/cli/{quickstart-JCE3XGQG.js → quickstart-DXYZCOJY.js} +6 -6
  92. package/dist/cli/{run-X2DNIW3F.js → run-3YN6P26W.js} +41 -41
  93. package/dist/cli/{run-56UGPIRL.mjs → run-MB2R5PQ7.mjs} +23 -23
  94. package/dist/cli/{search-SZYI4NBB.mjs → search-MIFBESRE.mjs} +8 -8
  95. package/dist/cli/search-Z7GUKVFE.js +33 -0
  96. package/dist/cli/{search-output-T35QNZUF.mjs → search-output-2IR3UA4W.mjs} +4 -4
  97. package/dist/cli/{search-output-7UNT6EMP.js → search-output-NUWL47SR.js} +6 -6
  98. package/dist/cli/{secrets-JMUAVIVC.js → secrets-6UT6BIDJ.js} +15 -15
  99. package/dist/cli/{secrets-Q36VC35L.mjs → secrets-E6WIYONW.mjs} +6 -6
  100. package/dist/cli/{sessions-HG6I3HMY.mjs → sessions-AP7L6YCL.mjs} +5 -5
  101. package/dist/cli/{sessions-SUXU7OM7.js → sessions-NF2RBXMJ.js} +6 -6
  102. package/dist/cli/{settings-UIELQ5CV.js → settings-FZWXYP4W.js} +82 -82
  103. package/dist/cli/{settings-Z76XW4KF.mjs → settings-MMLHJ5E5.mjs} +12 -12
  104. package/dist/cli/{setup-OXNYAOQ4.mjs → setup-WJNN2CZZ.mjs} +10 -10
  105. package/dist/cli/{setup-2L7H5P2O.js → setup-YHXAAJNZ.js} +50 -50
  106. package/dist/cli/skills-4YYUFNMS.js +37 -0
  107. package/dist/cli/{skills-XSNLXJGI.mjs → skills-KXZ5PJU2.mjs} +8 -8
  108. package/dist/cli/{tools-SUSFAYFH.mjs → tools-K6S7RX7B.mjs} +17 -17
  109. package/dist/cli/tools-OCYEMMUP.js +57 -0
  110. package/dist/cli/{update-ENSTG3QO.mjs → update-2SFWEVM6.mjs} +10 -10
  111. package/dist/cli/update-WQIPUQ4K.js +35 -0
  112. package/dist/cli/{workflow-Z33QE6VT.mjs → workflow-IR3RCVHZ.mjs} +7 -7
  113. package/dist/cli/{workflow-FMBZNY4F.js → workflow-SM3Q45X5.js} +17 -17
  114. package/dist/{client-Cx0420fs.d.ts → client-BlwD-G4v.d.ts} +1 -1
  115. package/dist/{client-BDbouy3Y.d.mts → client-DMpsMNH9.d.mts} +1 -1
  116. package/dist/{client-core-CwiVaMZ5.d.mts → client-core-CITtRTbB.d.mts} +27 -8
  117. package/dist/{client-core-B4hq0-m2.d.ts → client-core-DwBLuEkm.d.ts} +27 -8
  118. package/dist/index.d.mts +3 -3
  119. package/dist/index.d.ts +3 -3
  120. package/dist/index.js +9 -9
  121. package/dist/index.mjs +6 -6
  122. package/dist/install-integrity.json +105 -104
  123. package/dist/plays/play-description.d.mts +1 -1
  124. package/dist/plays/play-description.d.ts +1 -1
  125. package/dist/plays/run-request.d.mts +1 -1
  126. package/dist/plays/run-request.d.ts +1 -1
  127. package/dist/release.d.mts +1 -1
  128. package/dist/release.d.ts +1 -1
  129. package/dist/release.js +2 -2
  130. package/dist/release.mjs +1 -1
  131. package/dist/server.d.mts +2 -2
  132. package/dist/server.d.ts +2 -2
  133. package/dist/server.js +5 -5
  134. package/dist/server.mjs +3 -3
  135. package/package.json +1 -1
  136. package/dist/cli/auth-MMHG2OFE.js +0 -43
  137. package/dist/cli/describe-AYXVS6DZ.js +0 -50
  138. package/dist/cli/git-T6WKO7EA.js +0 -25
  139. package/dist/cli/search-B753RTKC.js +0 -33
  140. package/dist/cli/skills-DEVXYGYH.js +0 -37
  141. package/dist/cli/tools-SCGHABDL.js +0 -57
  142. package/dist/cli/update-BSIILGO3.js +0 -35
@@ -1218,17 +1218,36 @@ export type MonitorsAvailableOptions = {
1218
1218
  *
1219
1219
  * `provisioning` is a monitor whose create was recorded but that the provider
1220
1220
  * has not confirmed yet; it delivers no events and does not bill until it
1221
- * becomes `active`. A Fleet is never `provisioning`. Provider cleanup,
1222
- * retries, and failures are Monitor Job progress and must never be added to
1223
- * this union. The `status` and `active` fields below are retained only as
1224
- * deprecated compatibility aliases for older API responses.
1221
+ * becomes `active`. A Fleet is never `provisioning`.
1222
+ *
1223
+ * `errored` is a monitor the provider stopped after it was created, in a way
1224
+ * that resubmitting the same definition cannot fix (for example its LinkedIn
1225
+ * URL no longer resolves). `failure` says why and what to do: update the
1226
+ * monitor's payload, which creates a fresh resource, or delete it. A Fleet is
1227
+ * never `errored`; its member monitors are.
1228
+ *
1229
+ * Provider cleanup and retries are Monitor Job progress and must never be
1230
+ * added to this union. The `status` and `active` fields below are retained
1231
+ * only as deprecated compatibility aliases for older API responses.
1225
1232
  */
1226
1233
  export type MonitorState =
1227
1234
  | 'active'
1228
1235
  | 'provisioning'
1229
1236
  | 'billing_suspended'
1237
+ | 'errored'
1230
1238
  | 'disabled';
1231
1239
 
1240
+ /** Why an `errored` monitor stopped, and what fixes it. */
1241
+ export type MonitorFailure = {
1242
+ /** The provider's reason code, e.g. `source_inaccessible`. */
1243
+ reason: string;
1244
+ /** What the customer does about it. */
1245
+ message: string;
1246
+ failed_at: string;
1247
+ /** Failures of resources created from the current payload. */
1248
+ failure_count: number;
1249
+ };
1250
+
1232
1251
  /** List filters accepted by the canonical state surface. */
1233
1252
  export type MonitorStateFilter = MonitorState | 'all';
1234
1253
 
@@ -1243,6 +1262,8 @@ export type MonitorListEntry = {
1243
1262
  state?: MonitorState;
1244
1263
  /** @deprecated Use state. `inactive` is projected as `disabled`. */
1245
1264
  status?: string;
1265
+ /** Present only while `state` is `errored`. */
1266
+ failure?: MonitorFailure;
1246
1267
  tool?: string;
1247
1268
  /** Generic provider-authored event category for this deployed monitor. */
1248
1269
  type?: string;
@@ -1997,8 +2018,8 @@ export type MonitorsNamespace = {
1997
2018
  options?: MonitorLifecycleOptions,
1998
2019
  ) => Promise<MonitorJobResult | MonitorDeployResult>;
1999
2020
  /** List deployed monitors (active by default). Use `state` to filter the
2000
- * four customer states (`active`, `provisioning`, `billing_suspended`,
2001
- * `disabled`); `status` is retained for older servers.
2021
+ * five customer states (`active`, `provisioning`, `billing_suspended`,
2022
+ * `errored`, `disabled`); `status` is retained for older servers.
2002
2023
  * `includeConsumers` requires a limit of 20 or fewer. */
2003
2024
  list: (options?: MonitorsListOptions) => Promise<MonitorsListResult>;
2004
2025
  /** Fetch one deployed monitor by public key with bounded current listener health. */
@@ -205,7 +205,7 @@ export const SDK_RELEASE = {
205
205
  // getters keep their established compatibility behavior.
206
206
  // 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
207
207
  // 0.3.90 is the first deliberately versioned SDK release for API v3.
208
- version: '0.3.506',
208
+ version: '0.3.507',
209
209
  updateSummary: {
210
210
  introducedIn: '0.3.90',
211
211
  summary:
@@ -23,7 +23,17 @@ import {
23
23
  * this off" and "we did, and here is why" must not be the same state.
24
24
  */
25
25
 
26
- export type MonitorDeactivationOwner = 'policy' | 'fleet' | 'admin';
26
+ /**
27
+ * `provider` means the provider itself stopped running the monitor's resource
28
+ * (a TamRadar `radar_failure` after a successful create, KAR-193). The monitor
29
+ * is `errored`: nothing automatic revives it, and only a changed payload, which
30
+ * creates a fresh resource, clears it.
31
+ */
32
+ export type MonitorDeactivationOwner =
33
+ | 'policy'
34
+ | 'fleet'
35
+ | 'admin'
36
+ | 'provider';
27
37
 
28
38
  /**
29
39
  * The delivery window, in days, that `monitors health` reports against.
@@ -92,6 +102,22 @@ export const MONITOR_DEACTIVATION_REASONS: readonly MonitorDeactivationReasonDef
92
102
  resolution:
93
103
  'Re-add the source row and re-sync the fleet, or leave it deactivated.',
94
104
  },
105
+ {
106
+ id: 'provider_source_inaccessible',
107
+ owner: 'provider',
108
+ summary:
109
+ 'Errored because the provider could not reach the source this monitor watches (source_inaccessible).',
110
+ resolution:
111
+ "Update the monitor with the source's current URL, or remove it. Resubmitting the same payload leaves it errored.",
112
+ },
113
+ {
114
+ id: 'provider_resource_failed',
115
+ owner: 'provider',
116
+ summary:
117
+ 'Errored because the provider failed this monitor twice in a row.',
118
+ resolution:
119
+ 'Update or remove the monitor. Resubmitting the same payload leaves it errored.',
120
+ },
95
121
  ];
96
122
 
97
123
  const BY_ID = new Map(
@@ -132,6 +158,17 @@ export function isPolicyDeactivation(id: string | undefined | null): boolean {
132
158
  return monitorDeactivationReason(id)?.owner === 'policy';
133
159
  }
134
160
 
161
+ /**
162
+ * True when the provider failed the monitor's resource and the monitor is
163
+ * `errored` (KAR-193). Automatic audit, repair and policy recovery leave it
164
+ * alone; a payload change is the only way back.
165
+ */
166
+ export function isProviderErroredDeactivation(
167
+ id: string | undefined | null,
168
+ ): boolean {
169
+ return monitorDeactivationReason(id)?.owner === 'provider';
170
+ }
171
+
135
172
  /** Both policy and admin shutdown retain the definition; only policy owns recovery. */
136
173
  export function isMonitorSuspension(id: string | undefined | null): boolean {
137
174
  const owner = monitorDeactivationReason(id)?.owner;
@@ -65,11 +65,13 @@ export const FLEET_SETTLED_VERDICTS = [
65
65
  /**
66
66
  * A Fleet's customer state. A Fleet has no `provisioning` state: its first
67
67
  * convergence is reported by the durable Fleet operation, while each member
68
- * monitor still pending its create reports `provisioning` itself.
68
+ * monitor still pending its create reports `provisioning` itself. Nor is a
69
+ * Fleet `errored`: the provider fails one member's resource, and that member
70
+ * reports `errored` itself.
69
71
  */
70
72
  export type FleetCustomerState = Exclude<
71
73
  ProviderMonitorCustomerState,
72
- 'provisioning'
74
+ 'provisioning' | 'errored'
73
75
  >;
74
76
 
75
77
  /**
@@ -93,6 +93,8 @@
93
93
  "./provider-monitor-status.js": "./provider-monitor-status.ts",
94
94
  "./provider-monitor-upstream-identity": "./provider-monitor-upstream-identity.ts",
95
95
  "./provider-monitor-upstream-identity.js": "./provider-monitor-upstream-identity.ts",
96
+ "./provider-resource-failure": "./provider-resource-failure.ts",
97
+ "./provider-resource-failure.js": "./provider-resource-failure.ts",
96
98
  "./provider-webhook-monitor-runtime": "./provider-webhook-monitor-runtime.ts",
97
99
  "./provider-webhook-monitor-runtime.js": "./provider-webhook-monitor-runtime.ts",
98
100
  "./quickstart-prompts": "./quickstart-prompts.ts",
@@ -130,3 +130,18 @@ export class ProviderMonitorStoppedAfterSubmitError extends Error {
130
130
  this.name = 'ProviderMonitorStoppedAfterSubmitError';
131
131
  }
132
132
  }
133
+
134
+ /**
135
+ * The provider failed this monitor's resource and only a payload change fixes
136
+ * it (`errored`, KAR-193). Nothing else may recreate it from the same payload:
137
+ * not a repair (a forced replacement), including one whose batch selected the
138
+ * monitor before the failure webhook landed, and not a priority-only update.
139
+ */
140
+ export class ProviderMonitorErroredRepairRefusedError extends Error {
141
+ constructor(readonly monitorKey: string) {
142
+ super(
143
+ `Monitor "${monitorKey}" is errored: the provider failed its resource. Change its payload or delete it; only a payload change recreates it.`,
144
+ );
145
+ this.name = 'ProviderMonitorErroredRepairRefusedError';
146
+ }
147
+ }
@@ -1,3 +1,5 @@
1
+ import { isProviderErroredDeactivationReason } from './provider-resource-failure';
2
+
1
3
  /** Provider evidence carried only by an exact, fenced terminal deletion. */
2
4
  export type ProviderMonitorDeletionObservation = {
3
5
  providerResourceId: string;
@@ -11,6 +13,11 @@ export type ProviderMonitorDeletionObservation = {
11
13
  * has not yet confirmed that it exists: it does not deliver events or bill
12
14
  * until the create commits and the monitor becomes `active`.
13
15
  *
16
+ * `errored` means the provider failed the monitor's resource after it was
17
+ * created, in a way recreating the same payload cannot fix (KAR-193). It is a
18
+ * customer state, not operation progress: it lasts until the customer changes
19
+ * the payload or removes the monitor, and the fix is theirs to make.
20
+ *
14
21
  * Provider work, retries, and audit evidence intentionally live on separate
15
22
  * axes. They must never become additional values in this union.
16
23
  */
@@ -18,6 +25,7 @@ export type ProviderMonitorCustomerState =
18
25
  | 'active'
19
26
  | 'provisioning'
20
27
  | 'billing_suspended'
28
+ | 'errored'
21
29
  | 'disabled';
22
30
 
23
31
  /**
@@ -159,21 +167,32 @@ export function providerMonitorCustomerStateForBillingState(
159
167
  /**
160
168
  * The single public monitor-state projection. A billing suspension owns the
161
169
  * off state. A `pending_create` lifecycle is `provisioning`: the create was
162
- * recorded but the provider has not confirmed the resource. Otherwise `active`
163
- * is operational proof: a committed active lifecycle and a non-empty provider
170
+ * recorded but the provider has not confirmed the resource. A provider-owned
171
+ * deactivation on a live lifecycle is `errored`. Otherwise `active` is
172
+ * operational proof: a committed active lifecycle and a non-empty provider
164
173
  * resource binding. Internal billing bookkeeping such as an unresolved usage
165
174
  * charge must not make a usable provider resource look disabled.
175
+ *
176
+ * Callers that omit `deactivationReason` never see `errored`; every public
177
+ * list/get projection passes it.
166
178
  */
167
179
  export function providerMonitorCustomerState(input: {
168
180
  lifecycleStatus?: string | null;
169
181
  billingState?: unknown;
170
182
  providerResourceId?: string | null | undefined;
183
+ deactivationReason?: string | null | undefined;
171
184
  }): ProviderMonitorCustomerState {
172
185
  const billingState = providerMonitorCustomerStateForBillingState(
173
186
  input.billingState,
174
187
  );
175
188
  if (billingState === 'billing_suspended') return billingState;
176
189
  if (input.lifecycleStatus === 'pending_create') return 'provisioning';
190
+ if (
191
+ input.lifecycleStatus === 'active' &&
192
+ isProviderErroredDeactivationReason(input.deactivationReason)
193
+ ) {
194
+ return 'errored';
195
+ }
177
196
 
178
197
  const providerResourceId = providerMonitorResourceId(
179
198
  input.providerResourceId,
@@ -186,8 +205,9 @@ export function providerMonitorCustomerState(input: {
186
205
 
187
206
  /**
188
207
  * Deprecated compatibility projection for the old `status`/`active` keys. The
189
- * alias stays two-valued: every non-active state, including `provisioning`,
190
- * is `inactive`.
208
+ * alias stays two-valued: every non-active state, including `provisioning`
209
+ * and `errored`, is `inactive`. An installed CLI that predates `errored`
210
+ * falls back to this alias and shows such a monitor as `disabled`.
191
211
  */
192
212
  export function providerMonitorStatusAlias(
193
213
  state: ProviderMonitorCustomerState,
@@ -0,0 +1,405 @@
1
+ /**
2
+ * Provider resource failures: the `errored` monitor state (KAR-193).
3
+ *
4
+ * TamRadar can fail a radar hours or days after its create returned success,
5
+ * with a `radar_failure` webhook naming the radar and a reason. Before this
6
+ * module Deepline only refunded the create: the monitor stayed desired-active,
7
+ * the daily global audit saw "active vs inactive" and recreated the radar,
8
+ * TamRadar failed it again, and the loop repeated every day.
9
+ *
10
+ * The rule, decided by Karl on 2026-11-11:
11
+ *
12
+ * - `source_inaccessible` (the profile URL is dead or renamed) errors the
13
+ * monitor at once. Recreating the same URL cannot succeed.
14
+ * - Any other reason gets one automatic recreate. A second failure on the same
15
+ * payload errors the monitor.
16
+ * - An errored monitor stays errored until its payload changes. Changing the
17
+ * payload creates a fresh resource and clears it; resubmitting the same
18
+ * payload does not. Delete removes it. Nothing automatic revives it.
19
+ *
20
+ * The decision is pure so every direction can be driven without Convex. The
21
+ * Convex owner (`providerMonitorRegistry.recordProviderResourceFailure`)
22
+ * applies it, and the inbound processor raises the alerts.
23
+ */
24
+
25
+ export const TAMRADAR_SOURCE_INACCESSIBLE_REASON = 'source_inaccessible';
26
+
27
+ /**
28
+ * Stored when a failure webhook names no reason. Never a known reason, so it
29
+ * always raises the unknown-reason alert.
30
+ */
31
+ export const UNSPECIFIED_PROVIDER_FAILURE_REASON = 'unspecified';
32
+
33
+ /**
34
+ * Every `radar_failure` reason Deepline has seen in Production.
35
+ *
36
+ * A reason outside this set raises a Slack alert each time it arrives, so a
37
+ * new provider failure mode cannot slip through as one more refund. When the
38
+ * alert fires, decide how the reason should be treated and add it here.
39
+ *
40
+ * Evidence (KAR-193 fleet-wide journal scan, 2026-11-11): Prove's 72
41
+ * `contact_social_posts` failures and three August company radars were
42
+ * `source_inaccessible`; one September `company_new_hires` failure was
43
+ * `missing_prerequisites`.
44
+ */
45
+ export const KNOWN_TAMRADAR_RADAR_FAILURE_REASONS: ReadonlySet<string> =
46
+ new Set([TAMRADAR_SOURCE_INACCESSIBLE_REASON, 'missing_prerequisites']);
47
+
48
+ export function isKnownTamradarRadarFailureReason(reason: string): boolean {
49
+ return KNOWN_TAMRADAR_RADAR_FAILURE_REASONS.has(reason);
50
+ }
51
+
52
+ /**
53
+ * The `provider`-owned deactivation reasons that mean `errored`. Declared in
54
+ * `deactivation-reasons.ts`; repeated here, import-free, so the customer state
55
+ * projection can read them without a module cycle. A unit test keeps the two
56
+ * in step.
57
+ */
58
+ export const PROVIDER_ERRORED_DEACTIVATION_REASON_IDS: ReadonlySet<string> =
59
+ new Set(['provider_source_inaccessible', 'provider_resource_failed']);
60
+
61
+ export function isProviderErroredDeactivationReason(
62
+ id: string | null | undefined,
63
+ ): boolean {
64
+ return (
65
+ typeof id === 'string' && PROVIDER_ERRORED_DEACTIVATION_REASON_IDS.has(id)
66
+ );
67
+ }
68
+
69
+ /** Failures on one payload before a non-`source_inaccessible` reason errors. */
70
+ export const PROVIDER_RESOURCE_FAILURES_BEFORE_ERRORED = 2;
71
+
72
+ /** The stored failure record on a monitor definition. */
73
+ export type ProviderResourceFailureRecord = {
74
+ /** The provider's reason code, e.g. `source_inaccessible`. */
75
+ reason: string;
76
+ /** The resource the provider failed. */
77
+ providerResourceId: string;
78
+ /** The provider's id for this failure event (TamRadar `update_id`). */
79
+ providerEventId: string;
80
+ /** The provider's error id, kept for support conversations. */
81
+ errorId?: string;
82
+ failedAt: number;
83
+ /**
84
+ * Failures of resources created from the same payload. A changed payload
85
+ * starts again at 1.
86
+ */
87
+ failureCount: number;
88
+ /** Fingerprint of the payload the failed resource was created from. */
89
+ payloadFingerprint: string;
90
+ };
91
+
92
+ export type ProviderResourceFailureEvent = {
93
+ reason: string;
94
+ providerResourceId: string;
95
+ providerEventId: string;
96
+ errorId?: string;
97
+ failedAt: number;
98
+ };
99
+
100
+ export type ProviderResourceFailureDecision =
101
+ /** This exact failure event was already recorded. */
102
+ | { kind: 'duplicate' }
103
+ /** Record the failure and let one automatic recreate run. */
104
+ | { kind: 'retry'; failure: ProviderResourceFailureRecord }
105
+ /** Record the failure and move the monitor to `errored`. */
106
+ | {
107
+ kind: 'errored';
108
+ failure: ProviderResourceFailureRecord;
109
+ deactivationReason:
110
+ | 'provider_source_inaccessible'
111
+ | 'provider_resource_failed';
112
+ };
113
+
114
+ export function decideProviderResourceFailure(input: {
115
+ previous: ProviderResourceFailureRecord | undefined | null;
116
+ event: ProviderResourceFailureEvent;
117
+ payloadFingerprint: string;
118
+ }): ProviderResourceFailureDecision {
119
+ const { previous, event } = input;
120
+ if (previous && previous.providerEventId === event.providerEventId) {
121
+ return { kind: 'duplicate' };
122
+ }
123
+ const samePayload =
124
+ previous !== null &&
125
+ previous !== undefined &&
126
+ previous.payloadFingerprint === input.payloadFingerprint;
127
+ // A second webhook about a resource already counted is the same failure,
128
+ // not a new one: only a recreate earns another count.
129
+ const failureCount = !samePayload
130
+ ? 1
131
+ : previous.providerResourceId === event.providerResourceId
132
+ ? previous.failureCount
133
+ : previous.failureCount + 1;
134
+ const failure: ProviderResourceFailureRecord = {
135
+ reason: event.reason,
136
+ providerResourceId: event.providerResourceId,
137
+ providerEventId: event.providerEventId,
138
+ ...(event.errorId ? { errorId: event.errorId } : {}),
139
+ failedAt: event.failedAt,
140
+ failureCount,
141
+ payloadFingerprint: input.payloadFingerprint,
142
+ };
143
+ if (event.reason === TAMRADAR_SOURCE_INACCESSIBLE_REASON) {
144
+ return {
145
+ kind: 'errored',
146
+ failure,
147
+ deactivationReason: 'provider_source_inaccessible',
148
+ };
149
+ }
150
+ if (failureCount >= PROVIDER_RESOURCE_FAILURES_BEFORE_ERRORED) {
151
+ return {
152
+ kind: 'errored',
153
+ failure,
154
+ deactivationReason: 'provider_resource_failed',
155
+ };
156
+ }
157
+ return { kind: 'retry', failure };
158
+ }
159
+
160
+ /**
161
+ * True when a payload being committed with a fresh resource differs from the
162
+ * one the recorded failure was created from. That is the customer's fix: it
163
+ * clears `errored` and the failure count.
164
+ */
165
+ export function providerResourceFailureClearedByPayload(input: {
166
+ failure: Pick<ProviderResourceFailureRecord, 'payloadFingerprint'>;
167
+ payloadFingerprint: string;
168
+ }): boolean {
169
+ return input.failure.payloadFingerprint !== input.payloadFingerprint;
170
+ }
171
+
172
+ function stableJson(value: unknown): string {
173
+ if (value === null || typeof value !== 'object') {
174
+ return JSON.stringify(value ?? null);
175
+ }
176
+ if (Array.isArray(value)) {
177
+ return `[${value.map((entry) => stableJson(entry)).join(',')}]`;
178
+ }
179
+ return `{${Object.keys(value as Record<string, unknown>)
180
+ .filter((key) => (value as Record<string, unknown>)[key] !== undefined)
181
+ .sort()
182
+ .map(
183
+ (key) =>
184
+ `${JSON.stringify(key)}:${stableJson((value as Record<string, unknown>)[key])}`,
185
+ )
186
+ .join(',')}}`;
187
+ }
188
+
189
+ /**
190
+ * SHA-256 of the payload's stable JSON. Runs in Convex and in Node, both of
191
+ * which provide Web Crypto.
192
+ */
193
+ export async function providerMonitorPayloadFingerprint(
194
+ payload: unknown,
195
+ ): Promise<string> {
196
+ const digest = await crypto.subtle.digest(
197
+ 'SHA-256',
198
+ new TextEncoder().encode(stableJson(payload ?? {})),
199
+ );
200
+ return Array.from(new Uint8Array(digest), (byte) =>
201
+ byte.toString(16).padStart(2, '0'),
202
+ ).join('');
203
+ }
204
+
205
+ /**
206
+ * The customer-facing fix prompt for an errored monitor. The wording is
207
+ * Karl's (KAR-193), with "the provider" where he wrote the upstream's name:
208
+ * customers and agents only ever see `deepline_native`
209
+ * (`scripts/check-deepline-native-no-tamradar-leak.ts` scans these strings).
210
+ * A contact radar watches a LinkedIn profile URL, which is what
211
+ * `source_inaccessible` means for it; a company radar's source is not a
212
+ * LinkedIn URL, so it gets the same instruction without that claim.
213
+ */
214
+ export function providerResourceFailureMessage(input: {
215
+ reason: string;
216
+ sourceCapability?: string | null;
217
+ }): string {
218
+ if (input.reason === TAMRADAR_SOURCE_INACCESSIBLE_REASON) {
219
+ return input.sourceCapability?.startsWith('contact_')
220
+ ? "This LinkedIn URL no longer resolves (the provider could not reach it). Update the monitor with the person's current URL, or remove it."
221
+ : 'The provider could not reach the source this monitor watches (reason: source_inaccessible). Update the monitor with a source that resolves, or remove it.';
222
+ }
223
+ return `The provider could not run this monitor (reason: ${input.reason}). Update or remove the monitor.`;
224
+ }
225
+
226
+ /**
227
+ * The public shape of a failure on `monitors list/get` (snake_case API). It
228
+ * never names the provider resource id: the customer API exposes Deepline's
229
+ * own identities, not upstream ones.
230
+ */
231
+ export type ProviderMonitorFailureSummary = {
232
+ reason: string;
233
+ message: string;
234
+ failed_at: string;
235
+ failure_count: number;
236
+ };
237
+
238
+ export function providerMonitorFailureSummary(input: {
239
+ failure: ProviderResourceFailureRecord;
240
+ sourceCapability?: string | null;
241
+ }): ProviderMonitorFailureSummary {
242
+ return {
243
+ reason: input.failure.reason,
244
+ message: providerResourceFailureMessage({
245
+ reason: input.failure.reason,
246
+ sourceCapability: input.sourceCapability,
247
+ }),
248
+ failed_at: new Date(input.failure.failedAt).toISOString(),
249
+ failure_count: input.failure.failureCount,
250
+ };
251
+ }
252
+
253
+ /** Read a stored record defensively; null when absent or malformed. */
254
+ export function parseProviderResourceFailureRecord(
255
+ value: unknown,
256
+ ): ProviderResourceFailureRecord | null {
257
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
258
+ const row = value as Record<string, unknown>;
259
+ const text = (key: string) =>
260
+ typeof row[key] === 'string' && (row[key] as string).trim()
261
+ ? (row[key] as string)
262
+ : null;
263
+ const reason = text('reason');
264
+ const providerResourceId = text('providerResourceId');
265
+ const providerEventId = text('providerEventId');
266
+ const payloadFingerprint = text('payloadFingerprint');
267
+ const failedAt = row.failedAt;
268
+ const failureCount = row.failureCount;
269
+ if (
270
+ !reason ||
271
+ !providerResourceId ||
272
+ !providerEventId ||
273
+ !payloadFingerprint ||
274
+ typeof failedAt !== 'number' ||
275
+ !Number.isFinite(failedAt) ||
276
+ typeof failureCount !== 'number' ||
277
+ !Number.isInteger(failureCount) ||
278
+ failureCount < 1
279
+ ) {
280
+ return null;
281
+ }
282
+ const errorId = text('errorId');
283
+ return {
284
+ reason,
285
+ providerResourceId,
286
+ providerEventId,
287
+ ...(errorId ? { errorId } : {}),
288
+ failedAt,
289
+ failureCount,
290
+ payloadFingerprint,
291
+ };
292
+ }
293
+
294
+ /**
295
+ * The Slack alert a recorded failure raises, or null for none.
296
+ *
297
+ * Two things must never pass silently (KAR-193): a monitor going `errored`,
298
+ * and a failure reason Deepline has not classified. A first failure with a
299
+ * known, retryable reason is the automatic recreate working as designed and
300
+ * raises nothing; its second failure errors the monitor and alerts then.
301
+ * A redelivered event alerts nothing the first delivery did not.
302
+ */
303
+ export function providerResourceFailureAlert(input: {
304
+ outcome: string;
305
+ reason: string;
306
+ providerResourceId: string;
307
+ failureCount?: number | null;
308
+ errorId?: string | null;
309
+ sourceCapability?: string | null;
310
+ }): { reason: string; detail: string } | null {
311
+ if (input.outcome === 'duplicate') return null;
312
+ const unknownReason = !isKnownTamradarRadarFailureReason(input.reason);
313
+ const errored = input.outcome === 'errored';
314
+ if (!errored && !unknownReason) return null;
315
+ const parts = [
316
+ `radar_failure reason=${input.reason} on radar ${input.providerResourceId}`,
317
+ `outcome=${input.outcome}`,
318
+ ...(input.failureCount ? [`failure ${input.failureCount}`] : []),
319
+ ...(input.errorId ? [`error_id=${input.errorId}`] : []),
320
+ ];
321
+ if (unknownReason) {
322
+ parts.push(
323
+ `Deepline has never classified reason '${input.reason}': decide how it should be treated and add it to the known radar failure reasons in packages/monitors/provider-resource-failure.ts`,
324
+ );
325
+ }
326
+ if (errored) {
327
+ parts.push(
328
+ `Customer sees: ${providerResourceFailureMessage({
329
+ reason: input.reason,
330
+ sourceCapability: input.sourceCapability,
331
+ })}`,
332
+ );
333
+ }
334
+ return {
335
+ reason: errored
336
+ ? unknownReason
337
+ ? 'monitor_errored_unknown_provider_failure_reason'
338
+ : 'monitor_errored'
339
+ : 'unknown_provider_failure_reason',
340
+ detail: parts.join(' | '),
341
+ };
342
+ }
343
+
344
+ /**
345
+ * Read the failure facts from an unwrapped TamRadar `radar_failure` payload.
346
+ *
347
+ * Real shape (Prove, 2026-11-11): `{code: 400, status: 'error', message,
348
+ * errors: [{field: 'radar', reason: 'source_inaccessible'}], error_id,
349
+ * update_id, update_type: 'radar_failure', refund_amount_usd,
350
+ * data: {radar_id, radar_type, ...}}`. A payload without `errors[].reason`
351
+ * reads as `unspecified`, which is never a known reason and so alerts.
352
+ */
353
+ export function readTamradarRadarFailure(payload: Record<string, unknown>): {
354
+ reason: string;
355
+ providerEventId: string | null;
356
+ errorId: string | null;
357
+ radarId: string | null;
358
+ } | null {
359
+ if (payload.update_type !== 'radar_failure') return null;
360
+ const text = (value: unknown) =>
361
+ typeof value === 'string' && value.trim() ? value.trim() : null;
362
+ const errors = Array.isArray(payload.errors) ? payload.errors : [];
363
+ const firstReason = errors
364
+ .map((entry) =>
365
+ entry && typeof entry === 'object'
366
+ ? text((entry as Record<string, unknown>).reason)
367
+ : null,
368
+ )
369
+ .find((reason): reason is string => reason !== null);
370
+ const data =
371
+ payload.data && typeof payload.data === 'object'
372
+ ? (payload.data as Record<string, unknown>)
373
+ : {};
374
+ return {
375
+ reason: firstReason ?? UNSPECIFIED_PROVIDER_FAILURE_REASON,
376
+ providerEventId: text(payload.update_id) ?? text(payload.event_id),
377
+ errorId: text(payload.error_id),
378
+ radarId: text(data.radar_id),
379
+ };
380
+ }
381
+
382
+ /**
383
+ * True when Deepline wants a monitor running, the provider holds its resource
384
+ * inactive or missing, and no recorded failure of THAT resource explains it.
385
+ *
386
+ * Repair recreates such a monitor. Before KAR-193 that happened silently;
387
+ * this drift has no webhook behind it, so its cause is unknown and a person
388
+ * should hear about it. A recorded failure of the current resource is the
389
+ * one automatic retry working as designed and is not reported again.
390
+ */
391
+ export function isUnexplainedProviderDrift(row: {
392
+ desired: 'active' | 'inactive';
393
+ observed?: 'active' | 'inactive' | 'missing' | 'unknown' | null;
394
+ providerResourceId?: string | null;
395
+ providerFailure?: unknown;
396
+ }): boolean {
397
+ if (row.desired !== 'active') return false;
398
+ if (row.observed !== 'inactive' && row.observed !== 'missing') return false;
399
+ const failure = parseProviderResourceFailureRecord(row.providerFailure);
400
+ return (
401
+ failure === null ||
402
+ !row.providerResourceId ||
403
+ failure.providerResourceId !== row.providerResourceId
404
+ );
405
+ }
@@ -27,8 +27,13 @@ export const DURABLE_RUNS_ROLLOUT = {
27
27
  * stamped by the database clock. Readers of
28
28
  * that key already ship; a gateway without `publish_latest_cache_result`
29
29
  * turns the write into a no-op.
30
+ *
31
+ * On since rollout switch 1. A hit on the shared result stays unbilled,
32
+ * exactly as every cache hit was before (founder decision, 2026-11-11).
33
+ * Off again stops new writes; entries age out by each caller's own
34
+ * `staleAfterSeconds`.
30
35
  */
31
- sharedReadCacheWrites: false,
36
+ sharedReadCacheWrites: true,
32
37
  /**
33
38
  * A provider's 5xx is retried inside the attempt with exponential backoff
34
39
  * and jitter, sending the same provider idempotency key, even for an