@herbertgao/pi-extensions 2026.11.19 → 2026.11.21

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 (185) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +10 -10
  3. package/THIRD_PARTY_NOTICES.md +3 -3
  4. package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +8 -0
  5. package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +9 -5
  6. package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +11 -1
  7. package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +1 -1
  8. package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +71 -13
  9. package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +148 -47
  10. package/node_modules/@narumitw/pi-btw/CHANGELOG.md +7 -0
  11. package/node_modules/@narumitw/pi-btw/dist/chunks/{main-tree-picker-3PXJARQW.ts → main-tree-picker-WMTVRTR2.ts} +1 -1
  12. package/node_modules/@narumitw/pi-btw/dist/chunks/main-tree-picker-WMTVRTR2.ts.map +7 -0
  13. package/node_modules/@narumitw/pi-btw/dist/index.ts +1 -1
  14. package/node_modules/@narumitw/pi-btw/docs/core-alignment.md +6 -0
  15. package/node_modules/@narumitw/pi-btw/package.json +5 -5
  16. package/node_modules/@narumitw/pi-btw/src/main-tree-picker.ts +1 -1
  17. package/node_modules/@narumitw/pi-caffeinate/CHANGELOG.md +7 -0
  18. package/node_modules/@narumitw/pi-caffeinate/package.json +3 -3
  19. package/node_modules/pi-lens/CHANGELOG-USER.md +6 -6
  20. package/node_modules/pi-lens/CHANGELOG.md +121 -0
  21. package/node_modules/pi-lens/README.md +9 -2
  22. package/node_modules/pi-lens/dist/{chunk-ZVQUYCBU.js → chunk-2ERVW2UF.js} +161 -100
  23. package/node_modules/pi-lens/dist/{chunk-AFSG6YUB.js → chunk-2K7BUOKS.js} +13 -13
  24. package/node_modules/pi-lens/dist/{chunk-BJGWP4UX.js → chunk-3JJ4OAJI.js} +10 -10
  25. package/node_modules/pi-lens/dist/{chunk-GIK6VUCY.js → chunk-3UHGSUVL.js} +1 -1
  26. package/node_modules/pi-lens/dist/{chunk-EKQDQPX6.js → chunk-463WN3VP.js} +1 -1
  27. package/node_modules/pi-lens/dist/{chunk-F7BFIENK.js → chunk-4X3ML2UQ.js} +29 -32
  28. package/node_modules/pi-lens/dist/{chunk-7JMEPY6P.js → chunk-5BI5YP57.js} +10 -10
  29. package/node_modules/pi-lens/dist/{chunk-MKW7ZUTT.js → chunk-5Z4XLUFF.js} +3 -3
  30. package/node_modules/pi-lens/dist/{chunk-NIZKGBOU.js → chunk-62AJH3IN.js} +12 -14
  31. package/node_modules/pi-lens/dist/{chunk-4GLSO2EM.js → chunk-6F34GMP7.js} +12 -12
  32. package/node_modules/pi-lens/dist/{chunk-35UJUF27.js → chunk-6LIUVGOR.js} +13 -3
  33. package/node_modules/pi-lens/dist/{chunk-WJ7GY5WJ.js → chunk-6REF4GCO.js} +1 -1
  34. package/node_modules/pi-lens/dist/{chunk-HFIFEH46.js → chunk-7KRR24GO.js} +3 -3
  35. package/node_modules/pi-lens/dist/{chunk-WAK2AXQQ.js → chunk-7OMOMBEQ.js} +9 -9
  36. package/node_modules/pi-lens/dist/{chunk-S7KUDW73.js → chunk-7ZFXICNN.js} +15 -15
  37. package/node_modules/pi-lens/dist/{chunk-VEF3GFOL.js → chunk-ABKRQVOY.js} +28 -52
  38. package/node_modules/pi-lens/dist/{chunk-Y2LIOCA7.js → chunk-ANSLRJBG.js} +1 -1
  39. package/node_modules/pi-lens/dist/{chunk-ARTCVE6I.js → chunk-AWMFBPGJ.js} +9 -9
  40. package/node_modules/pi-lens/dist/{chunk-H6DNTQ4V.js → chunk-BG7KHGNX.js} +2 -2
  41. package/node_modules/pi-lens/dist/{chunk-FD4LJQ6Y.js → chunk-BK2R2223.js} +10 -8
  42. package/node_modules/pi-lens/dist/{chunk-TWAQFMLW.js → chunk-BXXC6KRR.js} +31 -34
  43. package/node_modules/pi-lens/dist/{chunk-S247BOH2.js → chunk-CKJS2AUI.js} +4 -4
  44. package/node_modules/pi-lens/dist/{chunk-GNK2IHVG.js → chunk-COGU5KQJ.js} +15 -15
  45. package/node_modules/pi-lens/dist/{chunk-P7EV5ISR.js → chunk-CQNXALZJ.js} +12 -6
  46. package/node_modules/pi-lens/dist/{chunk-IO6P3NBP.js → chunk-CSZESDPP.js} +1 -1
  47. package/node_modules/pi-lens/dist/chunk-CZ5TCJPB.js +98 -0
  48. package/node_modules/pi-lens/dist/{chunk-DLGJYQML.js → chunk-D2LFEA5U.js} +9 -2
  49. package/node_modules/pi-lens/dist/chunk-D3KLF5CD.js +50 -0
  50. package/node_modules/pi-lens/dist/{chunk-W2JPGW7Q.js → chunk-ENJ2M76Y.js} +20 -20
  51. package/node_modules/pi-lens/dist/{chunk-2DWNYVUN.js → chunk-EQKF6BAK.js} +3 -3
  52. package/node_modules/pi-lens/dist/{chunk-KIQSNH3F.js → chunk-F2SAP2FM.js} +38 -45
  53. package/node_modules/pi-lens/dist/{chunk-BYIEU4E4.js → chunk-F6QAJXQV.js} +2 -2
  54. package/node_modules/pi-lens/dist/chunk-GR2QDWH5.js +25 -0
  55. package/node_modules/pi-lens/dist/{chunk-T2D2WWP6.js → chunk-GVE5VZYQ.js} +5 -5
  56. package/node_modules/pi-lens/dist/{chunk-HMXWZUQW.js → chunk-GWZZOJD2.js} +1 -1
  57. package/node_modules/pi-lens/dist/chunk-GZS6VPIE.js +27 -0
  58. package/node_modules/pi-lens/dist/chunk-H4B4SC7I.js +71 -0
  59. package/node_modules/pi-lens/dist/{chunk-2RQREVGO.js → chunk-HA6TUJOE.js} +1 -1
  60. package/node_modules/pi-lens/dist/{chunk-NAACKIKT.js → chunk-HKPJTI47.js} +2 -2
  61. package/node_modules/pi-lens/dist/{chunk-NHHS5T52.js → chunk-HPKC55MA.js} +1 -1
  62. package/node_modules/pi-lens/dist/{chunk-B2QO7GHY.js → chunk-I65CQLCG.js} +1 -1
  63. package/node_modules/pi-lens/dist/{chunk-BQ72NQQM.js → chunk-IDKLWVKY.js} +11 -11
  64. package/node_modules/pi-lens/dist/chunk-IUM2Q7NF.js +25 -0
  65. package/node_modules/pi-lens/dist/{chunk-PVV27TOX.js → chunk-J24IS3KZ.js} +5 -5
  66. package/node_modules/pi-lens/dist/{chunk-DKXIUGNA.js → chunk-J2DAHH4T.js} +2 -2
  67. package/node_modules/pi-lens/dist/{chunk-CDAJQBKJ.js → chunk-JBDZVOFL.js} +11 -11
  68. package/node_modules/pi-lens/dist/{chunk-T7KHGEJ5.js → chunk-JC6NFC57.js} +3 -3
  69. package/node_modules/pi-lens/dist/{chunk-BWGNVM33.js → chunk-JTHEUTW7.js} +11 -11
  70. package/node_modules/pi-lens/dist/{chunk-WWZLT6AM.js → chunk-JWW3ODBN.js} +2 -2
  71. package/node_modules/pi-lens/dist/{chunk-Q32RJDYC.js → chunk-K3ZIYLHT.js} +4 -4
  72. package/node_modules/pi-lens/dist/{chunk-LDPY22FS.js → chunk-KDPZA2UE.js} +2 -3
  73. package/node_modules/pi-lens/dist/{chunk-YIEHUKX2.js → chunk-KMY2OU4T.js} +489 -285
  74. package/node_modules/pi-lens/dist/{chunk-WH6O4IFD.js → chunk-KQF7VT26.js} +10 -10
  75. package/node_modules/pi-lens/dist/{chunk-OG3UCAHV.js → chunk-KVGA7X76.js} +3 -3
  76. package/node_modules/pi-lens/dist/{chunk-TABDCX35.js → chunk-KW7O72AK.js} +2 -2
  77. package/node_modules/pi-lens/dist/{chunk-AOEVZXR6.js → chunk-LEQTVRSV.js} +9 -9
  78. package/node_modules/pi-lens/dist/{chunk-7BWPQZHE.js → chunk-LKPSBM6S.js} +3 -3
  79. package/node_modules/pi-lens/dist/{chunk-WA6U2URH.js → chunk-LKW2HFSZ.js} +6 -6
  80. package/node_modules/pi-lens/dist/{chunk-M3QGXGY4.js → chunk-LURFD4HD.js} +624 -97
  81. package/node_modules/pi-lens/dist/{chunk-2YQ5LI7R.js → chunk-M6ELTECW.js} +4 -4
  82. package/node_modules/pi-lens/dist/{chunk-OHTHVILU.js → chunk-MGVVYYKW.js} +12 -12
  83. package/node_modules/pi-lens/dist/{chunk-W2YHHNY3.js → chunk-MQBKGRSB.js} +7 -7
  84. package/node_modules/pi-lens/dist/{chunk-MET776XM.js → chunk-MVG2ZEAO.js} +6 -6
  85. package/node_modules/pi-lens/dist/{chunk-2XALJI2K.js → chunk-MY4XNNTX.js} +39 -41
  86. package/node_modules/pi-lens/dist/{chunk-GFCPPCNR.js → chunk-N4AJVFRF.js} +11 -11
  87. package/node_modules/pi-lens/dist/{chunk-UARVPNAU.js → chunk-OFKKMXWM.js} +31 -36
  88. package/node_modules/pi-lens/dist/{chunk-DHFJS2I4.js → chunk-OFZE4ANN.js} +8 -8
  89. package/node_modules/pi-lens/dist/chunk-OLXBUTJR.js +61 -0
  90. package/node_modules/pi-lens/dist/{chunk-SJ2SR432.js → chunk-OZGEHOSG.js} +38 -17
  91. package/node_modules/pi-lens/dist/{chunk-6MDWNZ7E.js → chunk-PKGOROPQ.js} +40 -2
  92. package/node_modules/pi-lens/dist/{chunk-3IWMNN2S.js → chunk-Q6D5QKRG.js} +17 -17
  93. package/node_modules/pi-lens/dist/{chunk-JGCBMCCS.js → chunk-QECLJFHI.js} +12 -17
  94. package/node_modules/pi-lens/dist/{chunk-KXKM2DFP.js → chunk-QJA33VD5.js} +4 -4
  95. package/node_modules/pi-lens/dist/{chunk-YV7XVYSJ.js → chunk-R5XVJ6AN.js} +11 -11
  96. package/node_modules/pi-lens/dist/{chunk-62PIU4TO.js → chunk-REZL4OM4.js} +1 -1
  97. package/node_modules/pi-lens/dist/{chunk-NNDZ7DOP.js → chunk-RK5RBREN.js} +74 -107
  98. package/node_modules/pi-lens/dist/chunk-RP5ZQTHO.js +86 -0
  99. package/node_modules/pi-lens/dist/{chunk-HKRESBMC.js → chunk-RURPX2YV.js} +23 -23
  100. package/node_modules/pi-lens/dist/chunk-TB5MGZLS.js +53 -0
  101. package/node_modules/pi-lens/dist/chunk-TC63XRYP.js +27 -0
  102. package/node_modules/pi-lens/dist/chunk-TJOYHAXJ.js +69 -0
  103. package/node_modules/pi-lens/dist/{chunk-NZ7NSKIW.js → chunk-TRXKDCBP.js} +13 -13
  104. package/node_modules/pi-lens/dist/{chunk-7WAQ3K26.js → chunk-TTK37D7R.js} +22 -23
  105. package/node_modules/pi-lens/dist/{chunk-ALTHJUZO.js → chunk-UH3QHLR5.js} +2 -2
  106. package/node_modules/pi-lens/dist/{chunk-6MZLS6CK.js → chunk-UNTJJ7GN.js} +7 -7
  107. package/node_modules/pi-lens/dist/{chunk-XRLZ75YY.js → chunk-UPAFSETJ.js} +54 -59
  108. package/node_modules/pi-lens/dist/{chunk-N2U644ZW.js → chunk-UX75PTQW.js} +50 -17
  109. package/node_modules/pi-lens/dist/{chunk-EXHSWN3P.js → chunk-V353PYMK.js} +423 -233
  110. package/node_modules/pi-lens/dist/{chunk-SL4G67AP.js → chunk-V4TFQY5G.js} +2 -2
  111. package/node_modules/pi-lens/dist/{chunk-YOMLAKU6.js → chunk-VC3W54G3.js} +289 -138
  112. package/node_modules/pi-lens/dist/{chunk-KSQJBGRO.js → chunk-VSBCJVPC.js} +5 -5
  113. package/node_modules/pi-lens/dist/{chunk-EBXCYEII.js → chunk-WAQQGXVV.js} +3 -3
  114. package/node_modules/pi-lens/dist/{chunk-7ORBRDFY.js → chunk-WLEVWR7Y.js} +2 -2
  115. package/node_modules/pi-lens/dist/{chunk-Q4UQNTLB.js → chunk-WPMPVP5I.js} +4 -4
  116. package/node_modules/pi-lens/dist/{chunk-TQKWR5AZ.js → chunk-WXNLFOC2.js} +7 -7
  117. package/node_modules/pi-lens/dist/{chunk-HOWHAKXO.js → chunk-Y3ZNOZZS.js} +6 -6
  118. package/node_modules/pi-lens/dist/{chunk-DNJJVKJZ.js → chunk-YL6JQTWC.js} +29 -32
  119. package/node_modules/pi-lens/dist/{chunk-HUWW77QY.js → chunk-YVE5Q2UU.js} +86 -217
  120. package/node_modules/pi-lens/dist/{chunk-25CAONWT.js → chunk-YZNARDMM.js} +12 -9
  121. package/node_modules/pi-lens/dist/{chunk-HERQPNY6.js → chunk-ZDWNFZJ2.js} +8 -8
  122. package/node_modules/pi-lens/dist/{chunk-MKQFSW2Q.js → chunk-ZEUF7BIN.js} +2 -2
  123. package/node_modules/pi-lens/dist/{chunk-AB26NAHA.js → chunk-ZIF4WLWR.js} +45 -25
  124. package/node_modules/pi-lens/dist/{chunk-6MWX2J5H.js → chunk-ZSPVF7KI.js} +227 -24
  125. package/node_modules/pi-lens/dist/{chunk-QQGZY2BR.js → chunk-ZX6OKBVO.js} +2 -2
  126. package/node_modules/pi-lens/dist/index.js +6455 -5243
  127. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +8 -8
  128. package/node_modules/pi-lens/dist/mcp/cli.js +39 -41
  129. package/node_modules/pi-lens/dist/mcp/server.js +870 -559
  130. package/node_modules/pi-lens/dist/mcp/worker.js +68 -59
  131. package/node_modules/pi-lens/dist/probes/installer.js +19 -20
  132. package/node_modules/pi-lens/docs/configuration.md +24 -10
  133. package/node_modules/pi-lens/docs/defect-shapes.md +18 -2
  134. package/node_modules/pi-lens/docs/environment-variables.md +18 -9
  135. package/node_modules/pi-lens/docs/globalconfig.md +16 -0
  136. package/node_modules/pi-lens/docs/invariants/dispatch-runners.md +7 -0
  137. package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +33 -3
  138. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +23 -10
  139. package/node_modules/pi-lens/docs/lsp-idle-eviction.md +8 -3
  140. package/node_modules/pi-lens/docs/release-qa-baseline.md +22 -17
  141. package/node_modules/pi-lens/docs/servercapabilities.md +1 -1
  142. package/node_modules/pi-lens/docs/settings.md +9 -2
  143. package/node_modules/pi-lens/docs/tools.md +1 -1
  144. package/node_modules/pi-lens/package.json +3 -3
  145. package/node_modules/pi-typesafe/README.md +1 -1
  146. package/node_modules/pi-typesafe/dist/ask.js +6 -3
  147. package/node_modules/pi-typesafe/dist/auth.d.ts +31 -7
  148. package/node_modules/pi-typesafe/dist/auth.js +159 -55
  149. package/node_modules/pi-typesafe/dist/batch.d.ts +16 -2
  150. package/node_modules/pi-typesafe/dist/batch.js +62 -22
  151. package/node_modules/pi-typesafe/dist/calibrate.d.ts +38 -11
  152. package/node_modules/pi-typesafe/dist/calibrate.js +56 -24
  153. package/node_modules/pi-typesafe/dist/client.d.ts +13 -0
  154. package/node_modules/pi-typesafe/dist/client.js +67 -27
  155. package/node_modules/pi-typesafe/dist/errors.d.ts +20 -0
  156. package/node_modules/pi-typesafe/dist/errors.js +105 -2
  157. package/node_modules/pi-typesafe/dist/extension.d.ts +106 -0
  158. package/node_modules/pi-typesafe/dist/extension.js +206 -106
  159. package/node_modules/pi-typesafe/dist/index.d.ts +8 -8
  160. package/node_modules/pi-typesafe/dist/index.js +3 -3
  161. package/node_modules/pi-typesafe/dist/key-prompt.d.ts +20 -0
  162. package/node_modules/pi-typesafe/dist/key-prompt.js +23 -3
  163. package/node_modules/pi-typesafe/dist/login.d.ts +58 -1
  164. package/node_modules/pi-typesafe/dist/login.js +167 -13
  165. package/node_modules/pi-typesafe/dist/schema.d.ts +3 -0
  166. package/node_modules/pi-typesafe/dist/schema.js +47 -13
  167. package/node_modules/pi-typesafe/dist/ui.d.ts +2 -1
  168. package/node_modules/pi-typesafe/dist/usage.d.ts +53 -0
  169. package/node_modules/pi-typesafe/dist/usage.js +79 -40
  170. package/node_modules/pi-typesafe/package.json +3 -3
  171. package/package.json +8 -8
  172. package/node_modules/@narumitw/pi-btw/dist/chunks/main-tree-picker-3PXJARQW.ts.map +0 -7
  173. package/node_modules/pi-lens/dist/chunk-3UTDLQWO.js +0 -88
  174. package/node_modules/pi-lens/dist/chunk-3Z7Z3B7V.js +0 -27
  175. package/node_modules/pi-lens/dist/chunk-4E4OCW3L.js +0 -38
  176. package/node_modules/pi-lens/dist/chunk-5HVDD7IA.js +0 -17
  177. package/node_modules/pi-lens/dist/chunk-BKJ6WZKP.js +0 -255
  178. package/node_modules/pi-lens/dist/chunk-D3UQWOCB.js +0 -46
  179. package/node_modules/pi-lens/dist/chunk-EH6EHFW2.js +0 -73
  180. package/node_modules/pi-lens/dist/chunk-J7VNGHLN.js +0 -69
  181. package/node_modules/pi-lens/dist/chunk-L3Q72QGQ.js +0 -25
  182. package/node_modules/pi-lens/dist/chunk-TFSBHRL2.js +0 -25
  183. package/node_modules/pi-lens/dist/chunk-UWBD3JMH.js +0 -56
  184. package/node_modules/pi-lens/dist/chunk-XWWFESYZ.js +0 -27
  185. package/node_modules/pi-lens/dist/chunk-XZSXSM4K.js +0 -27
@@ -1,3 +1,109 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import type { ResolvedBackend, TypeSafeBackend } from "./backends.js";
3
+ import type { SpendReport } from "./client.js";
4
+ import type { AuthReport, AuthState } from "./auth.js";
5
+ export interface RouteConsent {
6
+ readonly text: string;
7
+ readonly namesModel: boolean;
8
+ }
9
+ export interface ValidSessionRoute {
10
+ readonly status: "valid";
11
+ readonly backend: TypeSafeBackend;
12
+ readonly config: ResolvedBackend;
13
+ readonly model: string | undefined;
14
+ readonly sentModel: string;
15
+ readonly consent: RouteConsent;
16
+ }
17
+ export interface InvalidSessionRoute {
18
+ readonly status: "invalid";
19
+ readonly error: string;
20
+ }
21
+ export type SessionRoute = ValidSessionRoute | InvalidSessionRoute;
22
+ export type ConsentSource = "environment" | "command";
23
+ export type ConsentState = {
24
+ readonly status: "disabled";
25
+ } | {
26
+ readonly status: "enabled";
27
+ readonly source: ConsentSource;
28
+ };
29
+ export type ConsentEvent = {
30
+ readonly type: "session_start";
31
+ readonly envEnabled: boolean;
32
+ } | {
33
+ readonly type: "enable";
34
+ } | {
35
+ readonly type: "disable";
36
+ } | {
37
+ readonly type: "logout";
38
+ readonly isActive: boolean;
39
+ readonly hasEnvKey: boolean;
40
+ };
41
+ export type CalloutState = {
42
+ readonly status: "healthy";
43
+ } | {
44
+ readonly status: "degraded";
45
+ readonly key: string;
46
+ };
47
+ export type CalloutEvent = {
48
+ readonly type: "session_start";
49
+ } | {
50
+ readonly type: "login_succeeded";
51
+ } | {
52
+ readonly type: "evaluate_succeeded";
53
+ } | {
54
+ readonly type: "degrade";
55
+ readonly key: string;
56
+ };
57
+ export interface CalloutTransition {
58
+ readonly state: CalloutState;
59
+ readonly emit: boolean;
60
+ }
61
+ export interface BudgetBlock {
62
+ readonly reason: "session_cap" | "daily_cap";
63
+ readonly message: string;
64
+ }
65
+ export type SessionReadiness = {
66
+ readonly status: "invalid_backend";
67
+ readonly error: string;
68
+ } | {
69
+ readonly status: "disabled";
70
+ readonly route: ValidSessionRoute;
71
+ readonly auth: AuthState;
72
+ readonly authReport: AuthReport;
73
+ readonly budget?: BudgetBlock;
74
+ } | {
75
+ readonly status: "blocked_auth";
76
+ readonly route: ValidSessionRoute;
77
+ readonly auth: AuthState;
78
+ readonly authReport: AuthReport;
79
+ readonly budget?: BudgetBlock;
80
+ } | {
81
+ readonly status: "blocked_budget";
82
+ readonly route: ValidSessionRoute;
83
+ readonly auth: AuthState;
84
+ readonly authReport: AuthReport;
85
+ readonly budget: BudgetBlock;
86
+ } | {
87
+ readonly status: "ready";
88
+ readonly route: ValidSessionRoute;
89
+ readonly auth: AuthState;
90
+ readonly authReport: AuthReport;
91
+ };
92
+ export interface ReadinessInput {
93
+ readonly route: SessionRoute;
94
+ readonly consent: ConsentState;
95
+ readonly auth?: AuthState | undefined;
96
+ readonly spend?: SpendReport | undefined;
97
+ readonly maxRequests?: number | undefined;
98
+ }
99
+ /** Parse route once at load so an invalid PI_TYPESAFE_BACKEND carries no backend id and cannot fall back to api.typesafe.ai. */
100
+ export declare function resolveSessionRoute(env?: NodeJS.ProcessEnv): SessionRoute;
101
+ export declare function initialConsent(env?: NodeJS.ProcessEnv): ConsentState;
102
+ export declare function transitionConsent(state: ConsentState, event: ConsentEvent): ConsentState;
103
+ /** Deduplicate repeated callouts while degraded, and re-arm on session start or recovery so later degradations still surface. */
104
+ export declare function transitionCallout(state: CalloutState, event: CalloutEvent): CalloutTransition;
105
+ /** Client getSpend().blocked covers daily caps only, so surface the per-session attempt cap explicitly here too. */
106
+ export declare function budgetBlockFor(spend: SpendReport | undefined, maxRequests?: number): BudgetBlock | undefined;
107
+ export declare function deriveSessionReadiness(input: ReadinessInput): SessionReadiness;
2
108
  /** Native Pi registration; importing the root library does not load this module. */
3
109
  export default function typesafeExtension(pi: ExtensionAPI): void;
@@ -2,7 +2,7 @@ import { Text } from "@earendil-works/pi-tui";
2
2
  import { BACKEND_ENV, DEFAULT_BACKEND, DECISIONS_BACKENDS, MODEL_ENV, backendFromEnvironment, backendHost, modelFromEnvironment, resolveBackend, sentModelId } from "./backends.js";
3
3
  import { createTypeSafe, DEFAULT_MAX_REQUESTS } from "./client.js";
4
4
  import { authState, clearAuthState, describeAuth, isKeyRejection } from "./auth.js";
5
- import { clearStoredApiKey, credentialsPath, keySituation, keySourceLabel } from "./credentials.js";
5
+ import { clearStoredApiKey, credentialsPath } from "./credentials.js";
6
6
  import { TypeSafeIntegrationError, safeError } from "./errors.js";
7
7
  import { loginWithPrompt } from "./login.js";
8
8
  import { DEFAULT_MAX_INPUT_BYTES, evaluationSchema, normalizeEvaluationRequest, prepareEvaluationRequest } from "./schema.js";
@@ -23,10 +23,98 @@ function consentFor(backend, model) {
23
23
  namesModel,
24
24
  };
25
25
  }
26
+ /** Parse route once at load so an invalid PI_TYPESAFE_BACKEND carries no backend id and cannot fall back to api.typesafe.ai. */
27
+ export function resolveSessionRoute(env = process.env) {
28
+ try {
29
+ const backend = backendFromEnvironment(env);
30
+ const model = modelFromEnvironment(env);
31
+ const config = resolveBackend(backend);
32
+ const sentModel = sentModelId(backend, model);
33
+ return {
34
+ status: "valid",
35
+ backend,
36
+ config,
37
+ model,
38
+ sentModel,
39
+ consent: consentFor(backend, model),
40
+ };
41
+ }
42
+ catch (error) {
43
+ return { status: "invalid", error: safeError(error).message };
44
+ }
45
+ }
46
+ export function initialConsent(env = process.env) {
47
+ return env.PI_TYPESAFE_ENABLED === "1"
48
+ ? { status: "enabled", source: "environment" }
49
+ : { status: "disabled" };
50
+ }
51
+ export function transitionConsent(state, event) {
52
+ switch (event.type) {
53
+ case "session_start":
54
+ return event.envEnabled ? { status: "enabled", source: "environment" } : { status: "disabled" };
55
+ case "enable":
56
+ return { status: "enabled", source: "command" };
57
+ case "disable":
58
+ return { status: "disabled" };
59
+ case "logout":
60
+ // Removing a shadowed or non-active backend key does not invalidate the session's active credentials.
61
+ return event.isActive && !event.hasEnvKey ? { status: "disabled" } : state;
62
+ }
63
+ }
64
+ /** Deduplicate repeated callouts while degraded, and re-arm on session start or recovery so later degradations still surface. */
65
+ export function transitionCallout(state, event) {
66
+ switch (event.type) {
67
+ case "session_start":
68
+ case "login_succeeded":
69
+ case "evaluate_succeeded":
70
+ return { state: { status: "healthy" }, emit: false };
71
+ case "degrade":
72
+ if (state.status === "degraded" && state.key === event.key) {
73
+ return { state, emit: false };
74
+ }
75
+ return { state: { status: "degraded", key: event.key }, emit: true };
76
+ }
77
+ }
78
+ /** Client getSpend().blocked covers daily caps only, so surface the per-session attempt cap explicitly here too. */
79
+ export function budgetBlockFor(spend, maxRequests = DEFAULT_MAX_REQUESTS) {
80
+ if (spend === undefined)
81
+ return undefined;
82
+ const sessionLimit = spend.caps.maxRequests ?? maxRequests;
83
+ if (spend.session.requestsStarted >= sessionLimit) {
84
+ return {
85
+ reason: "session_cap",
86
+ message: `Session cap reached: ${spend.session.requestsStarted}/${sessionLimit} attempts in this session; no request will be submitted until session start/reload.`,
87
+ };
88
+ }
89
+ if (spend.blocked !== undefined) {
90
+ return {
91
+ reason: "daily_cap",
92
+ message: `Cap reached: ${spend.blocked.cap} ${spend.blocked.used}/${spend.blocked.limit} on ${spend.blocked.day}; no request will be submitted until the local day rolls over.`,
93
+ };
94
+ }
95
+ return undefined;
96
+ }
97
+ export function deriveSessionReadiness(input) {
98
+ if (input.route.status === "invalid") {
99
+ return { status: "invalid_backend", error: input.route.error };
100
+ }
101
+ const auth = input.auth ?? authState({ backend: input.route.backend });
102
+ const authReport = describeAuth(auth);
103
+ const budget = budgetBlockFor(input.spend, input.maxRequests);
104
+ if (input.consent.status === "disabled") {
105
+ return { status: "disabled", route: input.route, auth, authReport, ...(budget === undefined ? {} : { budget }) };
106
+ }
107
+ if (authReport.level === "error") {
108
+ return { status: "blocked_auth", route: input.route, auth, authReport, ...(budget === undefined ? {} : { budget }) };
109
+ }
110
+ if (budget !== undefined) {
111
+ return { status: "blocked_budget", route: input.route, auth, authReport, budget };
112
+ }
113
+ return { status: "ready", route: input.route, auth, authReport };
114
+ }
26
115
  /** The status line naming the backend, its host, and its key variable; the model is stated once, by `Model:` or the consent sentence. */
27
- function backendLine(backend) {
28
- const config = resolveBackend(backend);
29
- return `${config.label} backend: ${backendHost(backend)}, key from ${config.keyEnv}.`;
116
+ function backendLine(route) {
117
+ return `${route.config.label} backend: ${backendHost(route.backend)}, key from ${route.config.keyEnv}.`;
30
118
  }
31
119
  const sample = {
32
120
  state: { message: "I was charged twice for my subscription. Please help today." },
@@ -59,28 +147,17 @@ function format(result, expanded = false) {
59
147
  }
60
148
  /** Native Pi registration; importing the root library does not load this module. */
61
149
  export default function typesafeExtension(pi) {
62
- let enabled = process.env.PI_TYPESAFE_ENABLED === "1";
63
150
  // Resolved once per process: the backend names the host every request goes to, so it cannot change mid-session.
64
- let backend;
65
- let model;
66
- let backendError;
67
- try {
68
- backend = backendFromEnvironment();
69
- model = modelFromEnvironment();
70
- }
71
- catch (error) {
72
- backend = DEFAULT_BACKEND;
73
- backendError = safeError(error).message;
74
- }
75
- const consent = consentFor(backend, model);
151
+ const route = resolveSessionRoute();
152
+ let consent = initialConsent();
76
153
  let client;
77
- // One callout per distinct degradation per session: a long run must not bury the reason in repeated notices.
78
- let calledOut;
79
- const getClient = () => client ??= createTypeSafe({ backend, ...(model === undefined ? {} : { model }) });
154
+ let callout = { status: "healthy" };
155
+ const getClient = (valid) => client ??= createTypeSafe({ backend: valid.backend, ...(valid.model === undefined ? {} : { model: valid.model }) });
80
156
  const callOut = (ctx, key, text) => {
81
- if (calledOut === key)
157
+ const next = transitionCallout(callout, { type: "degrade", key });
158
+ callout = next.state;
159
+ if (!next.emit)
82
160
  return;
83
- calledOut = key;
84
161
  try {
85
162
  if (ctx?.hasUI)
86
163
  ctx.ui.notify(text, "warning");
@@ -92,24 +169,29 @@ export default function typesafeExtension(pi) {
92
169
  }
93
170
  };
94
171
  pi.on("session_start", async (_event, ctx) => {
95
- enabled = process.env.PI_TYPESAFE_ENABLED === "1";
172
+ consent = transitionConsent(consent, { type: "session_start", envEnabled: process.env.PI_TYPESAFE_ENABLED === "1" });
96
173
  client = undefined;
97
- calledOut = undefined;
174
+ callout = transitionCallout(callout, { type: "session_start" }).state;
98
175
  // An enabled extension with no usable key used to look exactly like a working one. Say it at startup; an
99
176
  // unverified-but-present key stays quiet, because the first request is what proves it.
100
- const auth = describeAuth(authState({ backend }));
101
- // A backend name the registry does not know means no judgment can be sent at all, whether or not it is enabled.
102
- if (backendError !== undefined)
103
- callOut(ctx, `start:backend`, `${backendError} Judgments will fail until ${BACKEND_ENV} names a valid backend or is unset.`);
104
- else if (enabled && auth.level === "error")
105
- callOut(ctx, `start:${auth.level}`, `TypeSafe is enabled but judgments will fail. ${auth.text}`);
177
+ const readiness = deriveSessionReadiness({ route, consent });
178
+ if (readiness.status === "invalid_backend") {
179
+ callOut(ctx, "start:backend", `${readiness.error} Judgments will fail until ${BACKEND_ENV} names a valid backend or is unset.`);
180
+ }
181
+ else if (readiness.status === "blocked_auth") {
182
+ callOut(ctx, `start:${readiness.authReport.level}`, `TypeSafe is enabled but judgments will fail. ${readiness.authReport.text}`);
183
+ }
106
184
  });
107
185
  pi.registerEntryRenderer("typesafe-result", (entry, { expanded }) => new Text(entry.data ? format(entry.data, expanded) : "TypeSafe · no result", 0, 0));
108
186
  pi.registerTool({
109
187
  name: "typesafe_evaluate",
110
188
  label: "TypeSafe",
111
- description: `Evaluate supplied state with independent Choice, Score, and Noul questions in one ${resolveBackend(backend).label} request. Each question judges the whole state, so when several items are involved, put each item in a named state field (e.g. \`reports.r1\`) and ask one question per item per dimension (e.g. \`r1_owner\`, \`r2_owner\`), naming the field in the instructions; never aggregate several items into one question. ${consent.text} Requires operator opt-in via /typesafe enable or PI_TYPESAFE_ENABLED=1. Limit: 32 questions, ${DEFAULT_MAX_INPUT_BYTES / 1024} KiB JSON, ${DEFAULT_MAX_REQUESTS} attempts per session; no retries.`,
112
- promptSnippet: `Ask batched structured questions with ${resolveBackend(backend).label} (external service; operator opt-in required)`,
189
+ description: route.status === "valid"
190
+ ? `Evaluate supplied state with independent Choice, Score, and Noul questions in one ${route.config.label} request. Each question judges the whole state, so when several items are involved, put each item in a named state field (e.g. \`reports.r1\`) and ask one question per item per dimension (e.g. \`r1_owner\`, \`r2_owner\`), naming the field in the instructions; never aggregate several items into one question. ${route.consent.text} Requires operator opt-in via /typesafe enable or PI_TYPESAFE_ENABLED=1. Limit: 32 questions, ${DEFAULT_MAX_INPUT_BYTES / 1024} KiB JSON, ${DEFAULT_MAX_REQUESTS} attempts per session; no retries.`
191
+ : `Evaluate supplied state with TypeSafe. Unavailable: ${route.error} Fix or unset ${BACKEND_ENV} before calling this tool.`,
192
+ promptSnippet: route.status === "valid"
193
+ ? `Ask batched structured questions with ${route.config.label} (external service; operator opt-in required)`
194
+ : `TypeSafe unavailable: invalid ${BACKEND_ENV} configuration`,
113
195
  promptGuidelines: [
114
196
  // The payload shape is what models get wrong on the first call; the same sample the playground edits is the cheapest way to show it.
115
197
  // Every session pays for this line on every tool listing, so the sample stays short.
@@ -123,26 +205,29 @@ export default function typesafeExtension(pi) {
123
205
  // Pi validates against `parameters` after this hook; the cast only names the schema's type.
124
206
  prepareArguments: args => normalizeEvaluationRequest(args),
125
207
  async execute(_id, params, signal, _onUpdate, ctx) {
126
- if (!enabled)
208
+ const readiness = deriveSessionReadiness({ route, consent, spend: client?.getSpend() });
209
+ if (readiness.status === "invalid_backend")
210
+ throw new TypeSafeIntegrationError("configuration", readiness.error);
211
+ if (readiness.status === "disabled")
127
212
  throw new TypeSafeIntegrationError("configuration", "TypeSafe is disabled. Ask the operator to run /typesafe enable; do not enable it by editing configuration or environment files.");
128
- if (backendError !== undefined)
129
- throw new TypeSafeIntegrationError("configuration", backendError);
213
+ const validRoute = readiness.route;
130
214
  // The tool admits through the same rule as the library; evaluate() re-runs it idempotently.
131
215
  const request = prepareEvaluationRequest(params);
132
216
  try {
133
- const result = await getClient().evaluate(request, signal ? { signal } : {});
217
+ const result = await getClient(validRoute).evaluate(request, signal ? { signal } : {});
218
+ callout = transitionCallout(callout, { type: "evaluate_succeeded" }).state;
134
219
  return { content: [{ type: "text", text: JSON.stringify(result) }], details: result };
135
220
  }
136
221
  catch (error) {
137
- const safe = safeError(error, backend);
222
+ const safe = safeError(error, validRoute.backend);
138
223
  // A 401 is about the key, so it outlives this call and is called out once; a 403 refuses one request and is
139
224
  // only thrown. The client recorded the failure before throwing, so describeAuth describes that failure.
140
225
  if (isKeyRejection(safe.status)) {
141
- const auth = describeAuth(authState({ backend }));
226
+ const auth = describeAuth(authState({ backend: validRoute.backend }));
142
227
  callOut(ctx, `run:${safe.code}:${safe.status ?? ""}`, `${auth.text} Judgments will fail until the key is fixed.`);
143
228
  }
144
229
  else if (safe.code === "configuration") {
145
- callOut(ctx, `run:configuration`, `${safe.message} Judgments will fail until that is fixed.`);
230
+ callOut(ctx, "run:configuration", `${safe.message} Judgments will fail until that is fixed.`);
146
231
  }
147
232
  throw safe;
148
233
  }
@@ -181,79 +266,89 @@ export default function typesafeExtension(pi) {
181
266
  else
182
267
  pi.sendMessage({ customType: "typesafe-status", content: text, display: true });
183
268
  };
184
- // No key change makes an unusable backend name work: decline instead of prompting for a key or deleting the
185
- // stored one a later valid run would want.
186
- if (backendError !== undefined && (action === "login" || action === "logout")) {
187
- report(`${backendError} No key change fixes that, so /typesafe ${action} does nothing: fix or unset ${BACKEND_ENV} first.`, "warning");
269
+ if (action === "disable") {
270
+ consent = transitionConsent(consent, { type: "disable" });
271
+ report("TypeSafe disabled for future agent calls. In-flight requests are not cancelled.");
188
272
  return;
189
273
  }
190
- try {
191
- // A backend the command names, or this session's own backend when it names none, so the commands act on
192
- // what judgments actually use. resolveBackend refuses a name the registry does not know.
193
- const spec = backendArg === undefined ? backend : backendArg;
194
- const config = resolveBackend(spec);
195
- const isActive = config.keyEnv === resolveBackend(backend).keyEnv;
196
- const situation = keySituation(backend);
197
- if (action === "status") {
198
- const spend = client?.getSpend();
199
- const auth = describeAuth(authState({ backend }));
200
- const session = spend
201
- ? `Session ${spend.session.requestsStarted}/${DEFAULT_MAX_REQUESTS} attempts, ${spend.session.requestsSucceeded} successful, ${spend.session.requestsFailed} failed, ${spend.session.inputTokens} input tokens (~$${spend.session.estimatedUsd.toFixed(4)}).`
202
- : `Session 0/${DEFAULT_MAX_REQUESTS} attempts; no client yet in this session.`;
203
- const today = spend
204
- ? `Today ${spend.today.requestsStarted} requests (${spend.today.requestsSucceeded} ok, ${spend.today.requestsFailed} failed), ${spend.today.inputTokens} input tokens, ~$${spend.today.estimatedUsd.toFixed(4)}.`
205
- : "";
206
- const blocked = spend?.blocked ? `Cap reached: ${spend.blocked.cap} ${spend.blocked.used}/${spend.blocked.limit} on ${spend.blocked.day}; no request will be submitted until the local day rolls over.` : "";
207
- // The backend, host, and key source lead, so a status line cannot describe the TypeSafe key while another
208
- // backend serves the requests. The model is named once: by `Model:` when the consent sentence is the fixed
209
- // one that names none, otherwise by the consent sentence itself. An unusable name sends nothing, so that
210
- // status names no model and quotes no consent.
211
- const route = backendError !== undefined
212
- ? `Backend: ${BACKEND_ENV} is invalid — ${backendError} Judgments will fail.`
213
- : backendLine(backend);
214
- const version = backendError === undefined && !consent.namesModel ? `Model: ${sentModelId(backend, model)}.` : "";
274
+ if (!actions.includes(action)) {
275
+ report(`Usage: /typesafe ${actions.join(" | ")}. login and logout take a backend name: ${backendChoices}.`, "warning");
276
+ return;
277
+ }
278
+ if (action === "status") {
279
+ const spend = client?.getSpend();
280
+ const readiness = deriveSessionReadiness({ route, consent, spend });
281
+ const session = spend
282
+ ? `Session ${spend.session.requestsStarted}/${DEFAULT_MAX_REQUESTS} attempts, ${spend.session.requestsSucceeded} successful, ${spend.session.requestsFailed} failed, ${spend.session.inputTokens} input tokens (~$${spend.session.estimatedUsd.toFixed(4)}).`
283
+ : `Session 0/${DEFAULT_MAX_REQUESTS} attempts; no client yet in this session.`;
284
+ const today = spend
285
+ ? `Today ${spend.today.requestsStarted} requests (${spend.today.requestsSucceeded} ok, ${spend.today.requestsFailed} failed), ${spend.today.inputTokens} input tokens, ~$${spend.today.estimatedUsd.toFixed(4)}.`
286
+ : "";
287
+ if (readiness.status === "invalid_backend") {
215
288
  report([
216
- `TypeSafe: ${enabled ? "enabled" : "disabled"}.`,
217
- route,
218
- auth.text,
289
+ `TypeSafe: ${consent.status}.`,
290
+ `Backend: ${BACKEND_ENV} is invalid — ${readiness.error} Judgments will fail.`,
219
291
  session,
220
- today,
221
- blocked,
222
- version,
223
- backend === DEFAULT_BACKEND ? "" : `Set ${MODEL_ENV} to send another model.`,
224
292
  "Session limits reset on session start/reload; daily counters persist and caps come from client options or PI_TYPESAFE_MAX_* environment variables.",
225
- backendError === undefined ? consent.text : "",
226
- ].filter((part) => part !== "").join(" "), (auth.level === "error" && enabled) || backendError !== undefined ? "warning" : "info");
293
+ ].join(" "), "warning");
227
294
  return;
228
295
  }
296
+ const budget = readiness.status === "ready" ? undefined : readiness.budget;
297
+ const version = !readiness.route.consent.namesModel ? `Model: ${readiness.route.sentModel}.` : "";
298
+ report([
299
+ `TypeSafe: ${consent.status}.`,
300
+ backendLine(readiness.route),
301
+ readiness.authReport.text,
302
+ session,
303
+ today,
304
+ budget?.message ?? "",
305
+ version,
306
+ readiness.route.backend === DEFAULT_BACKEND ? "" : `Set ${MODEL_ENV} to send another model.`,
307
+ "Session limits reset on session start/reload; daily counters persist and caps come from client options or PI_TYPESAFE_MAX_* environment variables.",
308
+ readiness.route.consent.text,
309
+ ].filter((part) => part !== "").join(" "), readiness.status === "blocked_auth" || readiness.status === "blocked_budget" ? "warning" : "info");
310
+ return;
311
+ }
312
+ // Invalid route carries no backend id: decline every command that would touch keys, consent, or the API.
313
+ if (route.status === "invalid") {
314
+ if (action === "login" || action === "logout") {
315
+ report(`${route.error} No key change fixes that, so /typesafe ${action} does nothing: fix or unset ${BACKEND_ENV} first.`, "warning");
316
+ }
317
+ else {
318
+ report(`${route.error} /typesafe ${action} cannot run until ${BACKEND_ENV} names a valid backend or is unset.`, "warning");
319
+ }
320
+ return;
321
+ }
322
+ try {
323
+ // A backend the command names, or this session's own backend when it names none, so the commands act on
324
+ // what judgments actually use. resolveBackend refuses a name the registry does not know.
325
+ const spec = backendArg === undefined ? route.backend : backendArg;
326
+ const config = resolveBackend(spec);
327
+ const isActive = config.keyEnv === route.config.keyEnv;
229
328
  if (action === "logout") {
230
329
  const removed = clearStoredApiKey(spec);
231
- clearAuthState();
232
- client = undefined;
233
330
  const env = process.env[config.keyEnv]?.trim();
234
- // A session with consent but no key can only fail the next call; logging out another backend's key changes nothing.
235
- if (isActive && !env)
236
- enabled = false;
331
+ clearAuthState(spec);
332
+ if (isActive) {
333
+ client = undefined;
334
+ }
335
+ consent = transitionConsent(consent, { type: "logout", isActive, hasEnvKey: Boolean(env) });
237
336
  const tail = env
238
337
  ? ` ${config.keyEnv} is still set in the environment and takes precedence over a stored key.`
239
338
  : (isActive ? " Judgments are off for this session." : "");
240
339
  report(`${removed ? `Removed the stored ${config.label} key at ${credentialsPath()}.` : `No stored ${config.label} key to remove.`}${tail}`);
241
340
  return;
242
341
  }
243
- if (action === "disable") {
244
- enabled = false;
245
- report("TypeSafe disabled for future agent calls. In-flight requests are not cancelled.");
246
- return;
247
- }
248
- if (!actions.includes(action)) {
249
- report(`Usage: /typesafe ${actions.join(" | ")}. login and logout take a backend name: ${backendChoices}.`, "warning");
250
- return;
251
- }
252
342
  if (!ctx.hasUI) {
253
343
  report(`This command needs interactive Pi. For headless tool use, explicitly set PI_TYPESAFE_ENABLED=1 and ${config.keyEnv} before launching Pi.`, "warning");
254
344
  return;
255
345
  }
256
- if (action === "login" || (action === "setup" && situation.kind === "missing")) {
346
+ const readiness = deriveSessionReadiness({ route, consent, spend: client?.getSpend() });
347
+ if (readiness.status === "invalid_backend") {
348
+ report(`${readiness.error} /typesafe ${action} cannot run until ${BACKEND_ENV} names a valid backend or is unset.`, "warning");
349
+ return;
350
+ }
351
+ if (action === "login" || (action === "setup" && readiness.auth.kind === "missing")) {
257
352
  // The one rule for every backend: the stored key is used unless the backend's variable is set, and then it wins.
258
353
  if (process.env[config.keyEnv]?.trim()) {
259
354
  report(`${config.keyEnv} is set in the environment and takes precedence over a stored key. Unset it before using /typesafe login.`, "warning");
@@ -264,32 +359,36 @@ export default function typesafeExtension(pi) {
264
359
  report("Login cancelled; nothing was saved.");
265
360
  return;
266
361
  }
267
- client = undefined;
362
+ if (isActive) {
363
+ client = undefined;
364
+ callout = transitionCallout(callout, { type: "login_succeeded" }).state;
365
+ }
268
366
  const proof = login.models === undefined ? "verified with one request" : `verified (${login.models} model${login.models === 1 ? "" : "s"} available)`;
269
367
  const hint = isActive
270
- ? (enabled ? "" : " Run /typesafe enable to allow agent tool calls.")
271
- : ` ${BACKEND_ENV} is ${backend}; set it to ${config.name} to send judgments there.`;
368
+ ? (consent.status === "enabled" ? "" : " Run /typesafe enable to allow agent tool calls.")
369
+ : ` ${BACKEND_ENV} is ${route.backend}; set it to ${config.name} to send judgments there.`;
272
370
  report(`${config.label} key ${proof} and saved to ${login.path} with owner-only permissions.${hint}`);
273
371
  return;
274
372
  }
275
373
  if (action === "setup") {
276
- const current = situation.kind === "environment" || situation.kind === "stored" ? `configured via ${keySourceLabel(situation)}`
277
- : situation.kind === "unusable" ? `unusable — ${situation.reason}`
374
+ const current = readiness.auth.kind === "environment" || readiness.auth.kind === "stored" ? `configured via ${readiness.auth.keyName}`
375
+ : readiness.auth.kind === "unusable" ? `unusable — ${readiness.auth.reason}`
278
376
  : "missing";
279
- report(`Key ${current}. Run /typesafe test for one sample request or /typesafe enable to allow agent tool calls.`);
377
+ const budget = readiness.status === "ready" ? undefined : readiness.budget;
378
+ report(`Key ${current}. Run /typesafe test for one sample request or /typesafe enable to allow agent tool calls.${budget ? ` ${budget.message}` : ""}`, budget ? "warning" : "info");
280
379
  return;
281
380
  }
282
381
  if (action === "enable") {
283
- if (situation.kind === "missing") {
382
+ if (readiness.auth.kind === "missing") {
284
383
  report("Run /typesafe login first: no API key is configured.", "warning");
285
384
  return;
286
385
  }
287
- if (situation.kind === "unusable") {
288
- report(`The stored key cannot be used. ${situation.reason}`, "warning");
386
+ if (readiness.auth.kind === "unusable") {
387
+ report(`The stored key cannot be used. ${readiness.auth.reason}`, "warning");
289
388
  return;
290
389
  }
291
- if (await ctx.ui.confirm("Enable TypeSafe for this session?", consent.text)) {
292
- enabled = true;
390
+ if (await ctx.ui.confirm("Enable TypeSafe for this session?", route.consent.text)) {
391
+ consent = transitionConsent(consent, { type: "enable" });
293
392
  report(`TypeSafe enabled. Up to ${DEFAULT_MAX_REQUESTS} attempts in this session; /typesafe disable stops future agent calls.`);
294
393
  }
295
394
  return;
@@ -308,14 +407,15 @@ export default function typesafeExtension(pi) {
308
407
  }
309
408
  }
310
409
  const validated = prepareEvaluationRequest(request);
311
- if (!await ctx.ui.confirm("Send this TypeSafe request?", consent.text))
410
+ if (!await ctx.ui.confirm("Send this TypeSafe request?", route.consent.text))
312
411
  return;
313
- const result = await getClient().evaluate(validated);
412
+ const result = await getClient(route).evaluate(validated);
413
+ callout = transitionCallout(callout, { type: "evaluate_succeeded" }).state;
314
414
  // Playground results stay out of LLM context; the agent tool returns its own results normally.
315
415
  pi.appendEntry("typesafe-result", result);
316
416
  }
317
417
  catch (error) {
318
- report(safeError(error, backend).message, "error");
418
+ report(safeError(error, route.backend).message, "error");
319
419
  }
320
420
  },
321
421
  });
@@ -1,18 +1,18 @@
1
1
  export { createTypeSafe, backendHost, backendPrice, backendFromEnvironment, modelFromEnvironment, resolveBackend, sentModelId, BACKEND_ENV, MODEL_ENV, DEFAULT_MAX_REQUESTS, DECISIONS_BACKENDS, DEFAULT_BACKEND } from "./client.js";
2
- export type { TypeSafe, TypeSafeOptions, EvaluationOptions, Evaluation, UsageSnapshot, SpendReport, TypeSafeBackend, BackendConfig, BackendEndpoint, BackendSpec, RegistryBackendConfig, ResolvedBackend, } from "./client.js";
2
+ export type { TypeSafe, TypeSafeOptions, EvaluationOptions, Evaluation, UsageSnapshot, SpendReport, BudgetState, TypeSafeBackend, BackendConfig, BackendEndpoint, BackendSpec, RegistryBackendConfig, ResolvedBackend, } from "./client.js";
3
3
  export { ask, DEFAULT_ASK_TIMEOUT_MS } from "./ask.js";
4
4
  export type { AskAnswer, AskOptions, Judge } from "./ask.js";
5
5
  export { fanOut, DEFAULT_CONCURRENCY, evaluateMany, evaluateAll, chunkEvaluationRequest } from "./batch.js";
6
- export type { BatchEvaluation, BatchOptions, FanOutOptions, Settled } from "./batch.js";
7
- export { authState, authStatePath, clearAuthState, describeAuth, recordAuthFailure, recordAuthVerified } from "./auth.js";
8
- export type { AuthFailure, AuthReport, AuthState } from "./auth.js";
6
+ export type { BatchEvaluation, BatchOptions, FanOutOptions, Settled, SettledStatus, SkipReason } from "./batch.js";
7
+ export { authState, authStatePath, clearAuthState, describeAuth, recordAuthFailure, recordAuthVerified, transitionAuthRecord } from "./auth.js";
8
+ export type { AuthEvent, AuthFailure, AuthRecord, AuthReport, AuthState, AuthStatus, AuthWriteOptions } from "./auth.js";
9
9
  export { clearStoredApiKey, credentialsPath, keySituation, keySourceLabel, normalizeApiKey, piTypesafeDir, resolveApiKey, storeApiKey, } from "./credentials.js";
10
10
  export type { KeySituation, KeySource } from "./credentials.js";
11
11
  export { capsFromEnvironment, DEFAULT_USD_PER_MTOK, emptyTotals, estimateUsd, localDay, mergeCaps, openUsageLedger, usagePath, } from "./usage.js";
12
12
  export type { BlockedCap, SpendCaps, UsageLedger, UsageLedgerOptions, UsageReport, UsageTotals } from "./usage.js";
13
- export { TypeSafeIntegrationError } from "./errors.js";
14
- export type { IntegrationErrorCode } from "./errors.js";
15
- export { DEFAULT_BACKEND_LIMITS, DEFAULT_MAX_INPUT_BYTES, DEFAULT_MAX_QUESTIONS, evaluationSchema, normalizeEvaluationRequest, parseEvaluationRequest, prepareEvaluationRequest, } from "./schema.js";
16
- export type { BackendLimits, PrepareEvaluationOptions } from "./schema.js";
13
+ export { TypeSafeIntegrationError, classifyError } from "./errors.js";
14
+ export type { ErrorDisposition, ErrorTarget, IntegrationErrorCode } from "./errors.js";
15
+ export { ADMISSION_STAGES, DEFAULT_BACKEND_LIMITS, DEFAULT_MAX_INPUT_BYTES, DEFAULT_MAX_QUESTIONS, evaluationSchema, normalizeEvaluationRequest, parseEvaluationRequest, prepareEvaluationRequest, } from "./schema.js";
16
+ export type { AdmissionStage, BackendLimits, PrepareEvaluationOptions } from "./schema.js";
17
17
  export { choice, noul, score } from "@typesafe-ai/sdk";
18
18
  export type { Questions, Question, SystemOneRequest, SystemOneResult, EntryType, JsonValue, ChoiceQuestion, ChoiceResponse, NoulQuestion, NoulResponse, ScoreQuestion, ScoreResponse, Usage, } from "@typesafe-ai/sdk";
@@ -1,9 +1,9 @@
1
1
  export { createTypeSafe, backendHost, backendPrice, backendFromEnvironment, modelFromEnvironment, resolveBackend, sentModelId, BACKEND_ENV, MODEL_ENV, DEFAULT_MAX_REQUESTS, DECISIONS_BACKENDS, DEFAULT_BACKEND } from "./client.js";
2
2
  export { ask, DEFAULT_ASK_TIMEOUT_MS } from "./ask.js";
3
3
  export { fanOut, DEFAULT_CONCURRENCY, evaluateMany, evaluateAll, chunkEvaluationRequest } from "./batch.js";
4
- export { authState, authStatePath, clearAuthState, describeAuth, recordAuthFailure, recordAuthVerified } from "./auth.js";
4
+ export { authState, authStatePath, clearAuthState, describeAuth, recordAuthFailure, recordAuthVerified, transitionAuthRecord } from "./auth.js";
5
5
  export { clearStoredApiKey, credentialsPath, keySituation, keySourceLabel, normalizeApiKey, piTypesafeDir, resolveApiKey, storeApiKey, } from "./credentials.js";
6
6
  export { capsFromEnvironment, DEFAULT_USD_PER_MTOK, emptyTotals, estimateUsd, localDay, mergeCaps, openUsageLedger, usagePath, } from "./usage.js";
7
- export { TypeSafeIntegrationError } from "./errors.js";
8
- export { DEFAULT_BACKEND_LIMITS, DEFAULT_MAX_INPUT_BYTES, DEFAULT_MAX_QUESTIONS, evaluationSchema, normalizeEvaluationRequest, parseEvaluationRequest, prepareEvaluationRequest, } from "./schema.js";
7
+ export { TypeSafeIntegrationError, classifyError } from "./errors.js";
8
+ export { ADMISSION_STAGES, DEFAULT_BACKEND_LIMITS, DEFAULT_MAX_INPUT_BYTES, DEFAULT_MAX_QUESTIONS, evaluationSchema, normalizeEvaluationRequest, parseEvaluationRequest, prepareEvaluationRequest, } from "./schema.js";
9
9
  export { choice, noul, score } from "@typesafe-ai/sdk";
@@ -1,3 +1,23 @@
1
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
+ export type KeyPromptState = {
3
+ readonly status: "editing";
4
+ } | {
5
+ readonly status: "submitted";
6
+ readonly value: string;
7
+ } | {
8
+ readonly status: "cancelled";
9
+ };
10
+ export type KeyPromptEvent = {
11
+ readonly type: "submit";
12
+ readonly value: string;
13
+ } | {
14
+ readonly type: "cancel";
15
+ };
16
+ export interface KeyPromptTransition {
17
+ readonly state: KeyPromptState;
18
+ readonly settledNow: boolean;
19
+ }
20
+ /** Terminal UIs can deliver trailing keystrokes after Enter or Escape; settle at most once. */
21
+ export declare function transitionKeyPrompt(state: KeyPromptState, event: KeyPromptEvent): KeyPromptTransition;
2
22
  /** Hidden input in the TUI; falls back to Pi's plain input dialog where custom components are unavailable. */
3
23
  export declare function promptForApiKey(ctx: ExtensionCommandContext, label?: string): Promise<string | undefined>;