@tokcalc/mcp-server 0.1.2 → 0.1.4

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 (192) hide show
  1. package/README.md +86 -406
  2. package/dist/index.js +21285 -0
  3. package/package.json +34 -91
  4. package/.zscripts/build.sh +0 -175
  5. package/.zscripts/database-runtime-build.sh +0 -33
  6. package/.zscripts/dev.pid +0 -1
  7. package/.zscripts/dev.sh +0 -154
  8. package/.zscripts/mini-services-build.sh +0 -78
  9. package/.zscripts/mini-services-install.sh +0 -65
  10. package/.zscripts/mini-services-start.sh +0 -123
  11. package/.zscripts/python-runtime-build.sh +0 -120
  12. package/.zscripts/start.sh +0 -145
  13. package/CAPACITY_STUDY.md +0 -283
  14. package/CODE_OF_CONDUCT.md +0 -55
  15. package/CONTRIBUTING.md +0 -177
  16. package/Caddyfile +0 -23
  17. package/LICENSE +0 -204
  18. package/bun.lock +0 -1965
  19. package/components.json +0 -21
  20. package/db/custom.db +0 -0
  21. package/download/README.md +0 -1
  22. package/download/tokcalc-dark-calculator.png +0 -0
  23. package/download/tokcalc-dark-default.png +0 -0
  24. package/download/tokcalc-demo.webm +0 -0
  25. package/download/tokcalc-github-link.png +0 -0
  26. package/download/tokcalc-hydration-fixed.png +0 -0
  27. package/download/tokcalc-issue-resolved.png +0 -0
  28. package/download/tokcalc-light-mode.png +0 -0
  29. package/download/tokcalc-light-reference.png +0 -0
  30. package/download/tokcalc-long-context-qwen.png +0 -0
  31. package/download/tokcalc-long-context.png +0 -0
  32. package/download/tokcalc-og-image-preview.png +0 -0
  33. package/download/tokcalc-phase2-3.png +0 -0
  34. package/download/tokcalc-plain-english.png +0 -0
  35. package/download/tokcalc-preview.png +0 -0
  36. package/download/tokcalc-share-bvb.png +0 -0
  37. package/download/tokcalc-share-feature.png +0 -0
  38. package/download/tokcalc-tab-build-vs-buy.png +0 -0
  39. package/download/tokcalc-tab-calculator.png +0 -0
  40. package/download/tokcalc-tab-reference.png +0 -0
  41. package/eslint.config.mjs +0 -50
  42. package/examples/websocket/frontend.tsx +0 -196
  43. package/examples/websocket/server.ts +0 -138
  44. package/mini-services/.gitkeep +0 -0
  45. package/mini-services/mcp-server/README.md +0 -86
  46. package/mini-services/mcp-server/bun.lock +0 -202
  47. package/mini-services/mcp-server/index.ts +0 -504
  48. package/mini-services/mcp-server/package.json +0 -40
  49. package/next.config.ts +0 -12
  50. package/postcss.config.mjs +0 -5
  51. package/prisma/schema.prisma +0 -32
  52. package/public/google6f58ca6be85fa903.html +0 -1
  53. package/public/logo.svg +0 -29
  54. package/public/manifest.json +0 -51
  55. package/public/og-icon-256.png +0 -0
  56. package/public/og.png +0 -0
  57. package/public/robots.txt +0 -25
  58. package/public/sitemap.xml +0 -23
  59. package/public/tokcalc-demo.gif +0 -0
  60. package/scripts/og-template.html +0 -120
  61. package/scripts/render-og.mjs +0 -43
  62. package/server.json +0 -21
  63. package/src/app/api/pricing/aws/route.ts +0 -186
  64. package/src/app/api/pricing/azure/route.ts +0 -168
  65. package/src/app/api/pricing/gcp/route.ts +0 -230
  66. package/src/app/api/pricing/vast-ai/route.ts +0 -164
  67. package/src/app/api/route.ts +0 -5
  68. package/src/app/compare/h100-vs-h200/layout.tsx +0 -30
  69. package/src/app/compare/h100-vs-h200/page.tsx +0 -328
  70. package/src/app/globals.css +0 -122
  71. package/src/app/layout.tsx +0 -276
  72. package/src/app/page.tsx +0 -2670
  73. package/src/components/azure-live-pricing.tsx +0 -185
  74. package/src/components/benchmark-import.tsx +0 -340
  75. package/src/components/confidence-badge.tsx +0 -116
  76. package/src/components/live-pricing-comparison.tsx +0 -241
  77. package/src/components/theme-provider.tsx +0 -11
  78. package/src/components/theme-toggle.tsx +0 -55
  79. package/src/components/ui/accordion.tsx +0 -66
  80. package/src/components/ui/alert-dialog.tsx +0 -157
  81. package/src/components/ui/alert.tsx +0 -66
  82. package/src/components/ui/aspect-ratio.tsx +0 -11
  83. package/src/components/ui/avatar.tsx +0 -53
  84. package/src/components/ui/badge.tsx +0 -46
  85. package/src/components/ui/breadcrumb.tsx +0 -109
  86. package/src/components/ui/button.tsx +0 -59
  87. package/src/components/ui/calendar.tsx +0 -213
  88. package/src/components/ui/card.tsx +0 -92
  89. package/src/components/ui/carousel.tsx +0 -241
  90. package/src/components/ui/chart.tsx +0 -353
  91. package/src/components/ui/checkbox.tsx +0 -32
  92. package/src/components/ui/collapsible.tsx +0 -33
  93. package/src/components/ui/command.tsx +0 -184
  94. package/src/components/ui/context-menu.tsx +0 -252
  95. package/src/components/ui/dialog.tsx +0 -143
  96. package/src/components/ui/drawer.tsx +0 -135
  97. package/src/components/ui/dropdown-menu.tsx +0 -257
  98. package/src/components/ui/form.tsx +0 -167
  99. package/src/components/ui/hover-card.tsx +0 -44
  100. package/src/components/ui/input-otp.tsx +0 -77
  101. package/src/components/ui/input.tsx +0 -21
  102. package/src/components/ui/label.tsx +0 -24
  103. package/src/components/ui/menubar.tsx +0 -276
  104. package/src/components/ui/navigation-menu.tsx +0 -168
  105. package/src/components/ui/pagination.tsx +0 -127
  106. package/src/components/ui/popover.tsx +0 -48
  107. package/src/components/ui/progress.tsx +0 -31
  108. package/src/components/ui/radio-group.tsx +0 -45
  109. package/src/components/ui/resizable.tsx +0 -56
  110. package/src/components/ui/scroll-area.tsx +0 -58
  111. package/src/components/ui/select.tsx +0 -185
  112. package/src/components/ui/separator.tsx +0 -28
  113. package/src/components/ui/sheet.tsx +0 -139
  114. package/src/components/ui/sidebar.tsx +0 -726
  115. package/src/components/ui/skeleton.tsx +0 -13
  116. package/src/components/ui/slider.tsx +0 -63
  117. package/src/components/ui/sonner.tsx +0 -25
  118. package/src/components/ui/switch.tsx +0 -31
  119. package/src/components/ui/table.tsx +0 -116
  120. package/src/components/ui/tabs.tsx +0 -66
  121. package/src/components/ui/textarea.tsx +0 -18
  122. package/src/components/ui/toast.tsx +0 -129
  123. package/src/components/ui/toaster.tsx +0 -35
  124. package/src/components/ui/toggle-group.tsx +0 -73
  125. package/src/components/ui/toggle.tsx +0 -47
  126. package/src/components/ui/tooltip.tsx +0 -61
  127. package/src/components/vast-ai-live-pricing.tsx +0 -176
  128. package/src/hooks/use-mobile.ts +0 -19
  129. package/src/hooks/use-toast.ts +0 -194
  130. package/src/lib/benchmark-parser-sglang.ts +0 -150
  131. package/src/lib/benchmark-parser-tokcalc.ts +0 -247
  132. package/src/lib/benchmark-parser-trtllm.ts +0 -152
  133. package/src/lib/benchmark-parser-vllm.ts +0 -198
  134. package/src/lib/benchmark-schema.ts +0 -263
  135. package/src/lib/db.ts +0 -13
  136. package/src/lib/engine-presets.ts +0 -183
  137. package/src/lib/price-schema.ts +0 -141
  138. package/src/lib/token-calc.ts +0 -808
  139. package/src/lib/track.ts +0 -31
  140. package/src/lib/url-state.ts +0 -256
  141. package/src/lib/utils.ts +0 -6
  142. package/tailwind.config.ts +0 -64
  143. package/tests/database-runtime-build.sh +0 -75
  144. package/tests/python-runtime-build.sh +0 -64
  145. package/tests/python-runtime-container.sh +0 -31
  146. package/tool-results/bash_1789888171144_2c5381860539.txt +0 -161
  147. package/tool-results/bash_1789888175925_49c53ba3c61b.txt +0 -191
  148. package/tool-results/bash_1789888181202_49c53ba3c61b.txt +0 -191
  149. package/tool-results/bash_1789888195219_4a86a5c91411.txt +0 -200
  150. package/tool-results/bash_1789888203128_6cca13c71b47.txt +0 -199
  151. package/tool-results/bash_1789929256963_2a52aff0d0a8.txt +0 -160
  152. package/tool-results/read_1789888151021_69f58eec6a5b.txt +0 -653
  153. package/tool-results/read_1789888153837_1d3a8bfc2a94.txt +0 -653
  154. package/tool-results/read_1789888163087_ccc406d47505.txt +0 -122
  155. package/tool-results/read_1789888167347_67d1d7c9830a.txt +0 -122
  156. package/tool-results/read_1789929252529_d90e8f383a25.txt +0 -285
  157. package/tsconfig.json +0 -42
  158. package/upload/Pasted Content_1789887800864.txt +0 -652
  159. package/upload/Pasted Content_1789887909561.txt +0 -652
  160. package/upload/Pasted Content_1789887918428.txt +0 -652
  161. package/upload/Pasted Content_1789887959420.txt +0 -652
  162. package/upload/Pasted Content_1789888020485.txt +0 -652
  163. package/upload/Pasted Content_1789888058079.txt +0 -652
  164. package/upload/Pasted Content_1789888885033.txt +0 -686
  165. package/upload/Pasted Content_1789928912741.txt +0 -285
  166. package/upload/Pasted Content_1789928938402.txt +0 -285
  167. package/upload/Pasted Content_1789929160389.txt +0 -285
  168. package/upload/Pasted Content_1789929176660.txt +0 -285
  169. package/upload/issue_vision.json +0 -28
  170. package/upload/pasted_image_1789883175209.png +0 -0
  171. package/upload/pasted_image_1789899056690.png +0 -0
  172. package/upload/pasted_image_1789900371483.png +0 -0
  173. package/upload/pasted_image_1789900472823.png +0 -0
  174. package/upload/pasted_image_1789900490374.png +0 -0
  175. package/upload/pasted_image_1789900585552.png +0 -0
  176. package/upload/pasted_image_1789900606519.png +0 -0
  177. package/upload/pasted_image_1789901598705.png +0 -0
  178. package/upload/pasted_image_1789901613545.png +0 -0
  179. package/upload/pasted_image_1789978382674.png +0 -0
  180. package/upload/pasted_image_1789978392749.png +0 -0
  181. package/upload/pasted_image_1789978474879.png +0 -0
  182. package/upload/pasted_image_1789978523652.png +0 -0
  183. package/upload/pasted_image_1789984219089.png +0 -0
  184. package/upload/pasted_image_1789984491896.png +0 -0
  185. package/upload/pasted_image_1789985017950.png +0 -0
  186. package/upload/pasted_image_1789985036765.png +0 -0
  187. package/upload/pasted_image_1789985049848.png +0 -0
  188. package/upload/pasted_image_1790002427833.png +0 -0
  189. package/upload/pasted_image_1790002659944.png +0 -0
  190. package/upload/pasted_image_1790037038476.png +0 -0
  191. package/upload/screenshot_analysis.json +0 -28
  192. package/upload/vision_output.json +0 -28
package/src/lib/track.ts DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * Plausible Analytics custom event tracking.
3
- *
4
- * Usage:
5
- * track("shared_scenario", { tab: "calculator" })
6
- * track("switched_tab", { tab: "build-vs-buy" })
7
- * track("toggled_feature", { feature: "continuous_batching", enabled: true })
8
- *
9
- * The window.plausible function is set up by the init script in layout.tsx.
10
- * If Plausible isn't loaded yet (e.g., during SSR or ad-blocker), calls are
11
- * silently no-ops — no errors thrown.
12
- *
13
- * Custom events show up in your Plausible dashboard under "Custom Events"
14
- * (may need to be enabled in Plausible site settings → "Custom events").
15
- */
16
-
17
- type EventProps = Record<string, string | number | boolean | undefined>;
18
-
19
- export function track(eventName: string, props?: EventProps): void {
20
- if (typeof window === "undefined") return;
21
-
22
- // Cast window to access the plausible function we set up via init script
23
- const w = window as Window & {
24
- plausible?: (eventName: string, options?: { props?: EventProps }) => void;
25
- };
26
-
27
- if (typeof w.plausible === "function") {
28
- w.plausible(eventName, props ? { props } : undefined);
29
- }
30
- // Silent no-op if Plausible isn't loaded (SSR, ad-blocker, dev mode)
31
- }
@@ -1,256 +0,0 @@
1
- /**
2
- * URL-hash state serialization for tokcalc.
3
- *
4
- * Format: `#t=<tab>&<key>=<value>&...`
5
- * - Compact keys to keep URLs short
6
- * - Empty/optional values omitted entirely (not encoded as `&=`
7
- * - Booleans encoded as `1`/`0` (omitted when false)
8
- * - All numbers as-is (NaN → omitted)
9
- *
10
- * Two state namespaces:
11
- * - Calculator tab: m/g/q/n/b/p/o/c/s/k/cb/cbm/r/cp/ch/ct/cpr
12
- * - Build vs Buy tab: sm/sg/sq/sn/sp/u/b/i/o/r/ap/am
13
- *
14
- * The `t` key (tab) determines which namespace is active.
15
- */
16
-
17
- export type Tab = "calculator" | "build-vs-buy" | "reference";
18
-
19
- /** Calculator tab state — shape mirrors the useState vars in page.tsx */
20
- export interface CalcTabState {
21
- modelId: string;
22
- gpuId: string;
23
- quantization: string;
24
- numGpus: number;
25
- batchSize: number;
26
- promptTokens: number;
27
- outputTokens: number;
28
- gpuHourlyCost: number | "";
29
- useSpeculative: boolean;
30
- speculativeBoost: number;
31
- useContinuousBatching: boolean;
32
- continuousBatchingMultiplier: number;
33
- reasoningTokens: number;
34
- cachePrefixTokens: number;
35
- cacheHitRate: number;
36
- cacheTTL: string;
37
- cacheProvider: string;
38
- engineId?: string;
39
- }
40
-
41
- /** Build-vs-Buy tab state — shape mirrors BuildVsBuyTab useState vars */
42
- export interface BvbTabState {
43
- shModel: string;
44
- shGpu: string;
45
- shQuant: string;
46
- shNumGpus: number;
47
- shGpuPrice: number | "";
48
- utilization: number;
49
- batchSize: number;
50
- inputTokens: number;
51
- outputTokens: number;
52
- reqsPerDay: number;
53
- apiProvider: string;
54
- apiModel: string;
55
- }
56
-
57
- /** Parse the URL hash into a structured state object. */
58
- export function parseUrlHash(hash: string): {
59
- tab: Tab;
60
- calc?: Partial<CalcTabState>;
61
- bvb?: Partial<BvbTabState>;
62
- } {
63
- // Strip leading `#`
64
- const stripped = hash.startsWith("#") ? hash.slice(1) : hash;
65
- if (!stripped) return { tab: "calculator" };
66
-
67
- const params = new URLSearchParams(stripped);
68
- const tabParam = params.get("t");
69
- const tab: Tab =
70
- tabParam === "build-vs-buy" ? "build-vs-buy" :
71
- tabParam === "reference" ? "reference" :
72
- "calculator";
73
-
74
- if (tab === "calculator") {
75
- return {
76
- tab,
77
- calc: {
78
- modelId: params.get("m") ?? undefined,
79
- gpuId: params.get("g") ?? undefined,
80
- quantization: params.get("q") ?? undefined,
81
- numGpus: numOrUndef(params.get("n")),
82
- batchSize: numOrUndef(params.get("b")),
83
- promptTokens: numOrUndef(params.get("p")),
84
- outputTokens: numOrUndef(params.get("o")),
85
- gpuHourlyCost: numOrUndefOrEmpty(params.get("c")),
86
- useSpeculative: boolOrUndef(params.get("s")),
87
- speculativeBoost: numOrUndef(params.get("k")),
88
- useContinuousBatching: boolOrUndef(params.get("cb")),
89
- continuousBatchingMultiplier: numOrUndef(params.get("cbm")),
90
- reasoningTokens: numOrUndef(params.get("r")),
91
- cachePrefixTokens: numOrUndef(params.get("cp")),
92
- cacheHitRate: numOrUndef(params.get("ch")),
93
- cacheTTL: params.get("ct") ?? undefined,
94
- cacheProvider: params.get("cpr") ?? undefined,
95
- engineId: params.get("e") ?? undefined,
96
- } as Partial<CalcTabState>,
97
- };
98
- }
99
-
100
- if (tab === "build-vs-buy") {
101
- return {
102
- tab,
103
- bvb: {
104
- shModel: params.get("sm") ?? undefined,
105
- shGpu: params.get("sg") ?? undefined,
106
- shQuant: params.get("sq") ?? undefined,
107
- shNumGpus: numOrUndef(params.get("sn")),
108
- shGpuPrice: numOrUndefOrEmpty(params.get("sp")),
109
- utilization: numOrUndef(params.get("u")),
110
- batchSize: numOrUndef(params.get("b")),
111
- inputTokens: numOrUndef(params.get("i")),
112
- outputTokens: numOrUndef(params.get("o")),
113
- reqsPerDay: numOrUndef(params.get("r")),
114
- apiProvider: params.get("ap") ?? undefined,
115
- apiModel: params.get("am") ?? undefined,
116
- } as Partial<BvbTabState>,
117
- };
118
- }
119
-
120
- return { tab };
121
- }
122
-
123
- /** Serialize Calculator tab state to a URL hash (without leading `#`). */
124
- export function serializeCalcState(s: CalcTabState): string {
125
- const p = new URLSearchParams();
126
- p.set("t", "calculator");
127
- if (s.modelId) p.set("m", s.modelId);
128
- if (s.gpuId) p.set("g", s.gpuId);
129
- if (s.quantization) p.set("q", s.quantization);
130
- if (s.numGpus !== 1) p.set("n", String(s.numGpus));
131
- if (s.batchSize !== 1) p.set("b", String(s.batchSize));
132
- if (s.promptTokens !== 500) p.set("p", String(s.promptTokens));
133
- if (s.outputTokens !== 200) p.set("o", String(s.outputTokens));
134
- if (s.gpuHourlyCost !== "") p.set("c", String(s.gpuHourlyCost));
135
- if (s.useSpeculative) { p.set("s", "1"); p.set("k", String(s.speculativeBoost)); }
136
- if (s.useContinuousBatching) { p.set("cb", "1"); p.set("cbm", String(s.continuousBatchingMultiplier)); }
137
- if (s.reasoningTokens > 0) p.set("r", String(s.reasoningTokens));
138
- if (s.cachePrefixTokens > 0) {
139
- p.set("cp", String(s.cachePrefixTokens));
140
- p.set("ch", String(s.cacheHitRate));
141
- if (s.cacheTTL !== "5m") p.set("ct", s.cacheTTL);
142
- if (s.cacheProvider !== "self-hosted") p.set("cpr", s.cacheProvider);
143
- }
144
- if (s.engineId && s.engineId !== "generic") p.set("e", s.engineId);
145
- return p.toString();
146
- }
147
-
148
- /** Serialize Build-vs-Buy tab state to a URL hash (without leading `#`). */
149
- export function serializeBvbState(s: BvbTabState): string {
150
- const p = new URLSearchParams();
151
- p.set("t", "build-vs-buy");
152
- if (s.shModel) p.set("sm", s.shModel);
153
- if (s.shGpu) p.set("sg", s.shGpu);
154
- if (s.shQuant) p.set("sq", s.shQuant);
155
- if (s.shNumGpus !== 1) p.set("sn", String(s.shNumGpus));
156
- if (s.shGpuPrice !== "") p.set("sp", String(s.shGpuPrice));
157
- if (s.utilization !== 50) p.set("u", String(s.utilization));
158
- if (s.batchSize !== 8) p.set("b", String(s.batchSize));
159
- if (s.inputTokens !== 500) p.set("i", String(s.inputTokens));
160
- if (s.outputTokens !== 200) p.set("o", String(s.outputTokens));
161
- if (s.reqsPerDay !== 1000) p.set("r", String(s.reqsPerDay));
162
- if (s.apiProvider !== "openai") p.set("ap", s.apiProvider);
163
- if (s.apiModel !== "gpt-4o-mini") p.set("am", s.apiModel);
164
- return p.toString();
165
- }
166
-
167
- /** Write a hash to the URL without adding a history entry. */
168
- export function writeUrlHash(hash: string): void {
169
- if (typeof window === "undefined") return;
170
- const newUrl = `${window.location.pathname}${window.location.search}#${hash}`;
171
- window.history.replaceState(null, "", newUrl);
172
- }
173
-
174
- /** Copy current URL to clipboard. Returns true on success. */
175
- export async function copyCurrentUrlToClipboard(): Promise<boolean> {
176
- if (typeof navigator === "undefined" || !navigator.clipboard) return false;
177
- try {
178
- await navigator.clipboard.writeText(window.location.href);
179
- return true;
180
- } catch {
181
- return false;
182
- }
183
- }
184
-
185
- /* ============================================================
186
- LOCALSTORAGE PERSISTENCE (Phase A bonus)
187
- ============================================================
188
- On unmount (page unload), write the current state to localStorage.
189
- On mount, if no URL hash exists, restore from localStorage.
190
- URL hash always wins — explicit shares override persistence.
191
- */
192
-
193
- const STORAGE_KEY_CALC = "tokcalc:calc-state:v1";
194
- const STORAGE_KEY_BVB = "tokcalc:bvb-state:v1";
195
-
196
- /** Save Calculator tab state to localStorage. Silently fails on error. */
197
- export function saveCalcToStorage(s: CalcTabState): void {
198
- if (typeof window === "undefined") return;
199
- try {
200
- window.localStorage.setItem(STORAGE_KEY_CALC, JSON.stringify(s));
201
- } catch {
202
- // Quota exceeded or disabled — non-fatal
203
- }
204
- }
205
-
206
- /** Save Build-vs-Buy tab state to localStorage. Silently fails on error. */
207
- export function saveBvbToStorage(s: BvbTabState): void {
208
- if (typeof window === "undefined") return;
209
- try {
210
- window.localStorage.setItem(STORAGE_KEY_BVB, JSON.stringify(s));
211
- } catch {
212
- // Quota exceeded or disabled — non-fatal
213
- }
214
- }
215
-
216
- /** Read saved Calculator state from localStorage (or null if none). */
217
- export function loadCalcFromStorage(): Partial<CalcTabState> | null {
218
- if (typeof window === "undefined") return null;
219
- try {
220
- const raw = window.localStorage.getItem(STORAGE_KEY_CALC);
221
- return raw ? JSON.parse(raw) : null;
222
- } catch {
223
- return null;
224
- }
225
- }
226
-
227
- /** Read saved Build-vs-Buy state from localStorage (or null if none). */
228
- export function loadBvbFromStorage(): Partial<BvbTabState> | null {
229
- if (typeof window === "undefined") return null;
230
- try {
231
- const raw = window.localStorage.getItem(STORAGE_KEY_BVB);
232
- return raw ? JSON.parse(raw) : null;
233
- } catch {
234
- return null;
235
- }
236
- }
237
-
238
- /* ---------- internal helpers ---------- */
239
-
240
- function numOrUndef(v: string | null): number | undefined {
241
- if (v === null || v === "") return undefined;
242
- const n = Number(v);
243
- return Number.isFinite(n) ? n : undefined;
244
- }
245
-
246
- function numOrUndefOrEmpty(v: string | null): number | "" | undefined {
247
- if (v === null) return undefined;
248
- if (v === "") return "";
249
- const n = Number(v);
250
- return Number.isFinite(n) ? n : undefined;
251
- }
252
-
253
- function boolOrUndef(v: string | null): boolean | undefined {
254
- if (v === null) return undefined;
255
- return v === "1" || v === "true";
256
- }
package/src/lib/utils.ts DELETED
@@ -1,6 +0,0 @@
1
- import { clsx, type ClassValue } from "clsx"
2
- import { twMerge } from "tailwind-merge"
3
-
4
- export function cn(...inputs: ClassValue[]) {
5
- return twMerge(clsx(inputs))
6
- }
@@ -1,64 +0,0 @@
1
- import type { Config } from "tailwindcss";
2
- import tailwindcssAnimate from "tailwindcss-animate";
3
-
4
- const config: Config = {
5
- darkMode: "class",
6
- content: [
7
- "./pages/**/*.{js,ts,jsx,tsx,mdx}",
8
- "./components/**/*.{js,ts,jsx,tsx,mdx}",
9
- "./app/**/*.{js,ts,jsx,tsx,mdx}",
10
- ],
11
- theme: {
12
- extend: {
13
- colors: {
14
- background: 'hsl(var(--background))',
15
- foreground: 'hsl(var(--foreground))',
16
- card: {
17
- DEFAULT: 'hsl(var(--card))',
18
- foreground: 'hsl(var(--card-foreground))'
19
- },
20
- popover: {
21
- DEFAULT: 'hsl(var(--popover))',
22
- foreground: 'hsl(var(--popover-foreground))'
23
- },
24
- primary: {
25
- DEFAULT: 'hsl(var(--primary))',
26
- foreground: 'hsl(var(--primary-foreground))'
27
- },
28
- secondary: {
29
- DEFAULT: 'hsl(var(--secondary))',
30
- foreground: 'hsl(var(--secondary-foreground))'
31
- },
32
- muted: {
33
- DEFAULT: 'hsl(var(--muted))',
34
- foreground: 'hsl(var(--muted-foreground))'
35
- },
36
- accent: {
37
- DEFAULT: 'hsl(var(--accent))',
38
- foreground: 'hsl(var(--accent-foreground))'
39
- },
40
- destructive: {
41
- DEFAULT: 'hsl(var(--destructive))',
42
- foreground: 'hsl(var(--destructive-foreground))'
43
- },
44
- border: 'hsl(var(--border))',
45
- input: 'hsl(var(--input))',
46
- ring: 'hsl(var(--ring))',
47
- chart: {
48
- '1': 'hsl(var(--chart-1))',
49
- '2': 'hsl(var(--chart-2))',
50
- '3': 'hsl(var(--chart-3))',
51
- '4': 'hsl(var(--chart-4))',
52
- '5': 'hsl(var(--chart-5))'
53
- }
54
- },
55
- borderRadius: {
56
- lg: 'var(--radius)',
57
- md: 'calc(var(--radius) - 2px)',
58
- sm: 'calc(var(--radius) - 4px)'
59
- }
60
- }
61
- },
62
- plugins: [tailwindcssAnimate],
63
- };
64
- export default config;
@@ -1,75 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -euo pipefail
4
-
5
- SCRIPT_DIR="$(cd "$(dirname "$0")/../.zscripts" && pwd)"
6
- TEST_ROOT="$(mktemp -d)"
7
- trap 'rm -rf "$TEST_ROOT"' EXIT
8
-
9
- FAKE_BIN="$TEST_ROOT/bin"
10
- mkdir -p "$FAKE_BIN"
11
- cat >"$FAKE_BIN/bun" <<'EOF'
12
- #!/bin/bash
13
- set -euo pipefail
14
-
15
- if [ "$#" -ne 2 ] || [ "$1" != "run" ] || [ "$2" != "db:push" ]; then
16
- echo "unexpected bun invocation: $*" >&2
17
- exit 1
18
- fi
19
-
20
- case "${DATABASE_URL:-}" in
21
- file:*) db_path="${DATABASE_URL#file:}" ;;
22
- *)
23
- echo "DATABASE_URL must be an absolute SQLite file URL" >&2
24
- exit 1
25
- ;;
26
- esac
27
-
28
- case "$db_path" in
29
- /*) ;;
30
- *)
31
- echo "database path must be absolute: $db_path" >&2
32
- exit 1
33
- ;;
34
- esac
35
-
36
- mkdir -p "$(dirname "$db_path")"
37
- if [ ! -f "$db_path" ]; then
38
- printf 'initialized\n' >"$db_path"
39
- fi
40
- printf '%s\n' "$DATABASE_URL" >>"${DB_PUSH_CALLS:?}"
41
- EOF
42
- chmod +x "$FAKE_BIN/bun"
43
-
44
- export PATH="$FAKE_BIN:$PATH"
45
- export DB_PUSH_CALLS="$TEST_ROOT/db-push-calls"
46
-
47
- # 没有 Preview 数据库时,应只在部署产物中初始化空库,不修改项目目录。
48
- EMPTY_PROJECT="$TEST_ROOT/empty-project"
49
- EMPTY_BUILD="$TEST_ROOT/empty-build"
50
- mkdir -p "$EMPTY_PROJECT"
51
-
52
- PROJECT_DIR="$EMPTY_PROJECT" BUILD_DIR="$EMPTY_BUILD" \
53
- bash "$SCRIPT_DIR/database-runtime-build.sh"
54
-
55
- test -f "$EMPTY_BUILD/db/custom.db"
56
- test "$(cat "$EMPTY_BUILD/db/custom.db")" = "initialized"
57
- test ! -e "$EMPTY_PROJECT/db/custom.db"
58
-
59
- # 有 Preview 数据库时,应保留数据和同目录文件,再对产物执行 schema 同步。
60
- EXISTING_PROJECT="$TEST_ROOT/existing-project"
61
- EXISTING_BUILD="$TEST_ROOT/existing-build"
62
- mkdir -p "$EXISTING_PROJECT/db"
63
- printf 'preview-data\n' >"$EXISTING_PROJECT/db/custom.db"
64
- printf 'sidecar\n' >"$EXISTING_PROJECT/db/README.txt"
65
-
66
- PROJECT_DIR="$EXISTING_PROJECT" BUILD_DIR="$EXISTING_BUILD" \
67
- bash "$SCRIPT_DIR/database-runtime-build.sh"
68
-
69
- test "$(cat "$EXISTING_BUILD/db/custom.db")" = "preview-data"
70
- test "$(cat "$EXISTING_BUILD/db/README.txt")" = "sidecar"
71
- test "$(wc -l <"$DB_PUSH_CALLS" | tr -d ' ')" = "2"
72
- grep -Fx "file:$EMPTY_BUILD/db/custom.db" "$DB_PUSH_CALLS"
73
- grep -Fx "file:$EXISTING_BUILD/db/custom.db" "$DB_PUSH_CALLS"
74
-
75
- echo "database runtime build tests passed"
@@ -1,64 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -euo pipefail
4
-
5
- SCRIPT_DIR="$(cd "$(dirname "$0")/../.zscripts" && pwd)"
6
- TEST_ROOT="$(mktemp -d)"
7
- trap 'rm -rf "$TEST_ROOT"' EXIT
8
-
9
- PROJECT_DIR="$TEST_ROOT/project"
10
- BUILD_DIR="$TEST_ROOT/build"
11
- mkdir -p \
12
- "$PROJECT_DIR/scripts" \
13
- "$PROJECT_DIR/.venv" \
14
- "$BUILD_DIR/next-service-dist"
15
-
16
- cat >"$PROJECT_DIR/requirements.txt" <<'EOF'
17
- EOF
18
- cat >"$PROJECT_DIR/scripts/report.py" <<'EOF'
19
- print("report")
20
- EOF
21
- cat >"$PROJECT_DIR/.venv/should-not-copy.py" <<'EOF'
22
- ignored
23
- EOF
24
-
25
- PROJECT_DIR="$PROJECT_DIR" BUILD_DIR="$BUILD_DIR" \
26
- bash "$SCRIPT_DIR/python-runtime-build.sh"
27
-
28
- test -f "$BUILD_DIR/next-service-dist/scripts/report.py"
29
- test ! -e "$BUILD_DIR/next-service-dist/.venv/should-not-copy.py"
30
-
31
- PYPROJECT_DIR="$TEST_ROOT/pyproject-app"
32
- PYPROJECT_BUILD="$TEST_ROOT/pyproject-build"
33
- mkdir -p "$PYPROJECT_DIR" "$PYPROJECT_BUILD/next-service-dist"
34
- cat >"$PYPROJECT_DIR/pyproject.toml" <<'EOF'
35
- [project]
36
- name = "deploy-test"
37
- version = "0.1.0"
38
- requires-python = ">=3.12"
39
- dependencies = []
40
- EOF
41
- cat >"$PYPROJECT_DIR/app.py" <<'EOF'
42
- print("pyproject app")
43
- EOF
44
-
45
- PROJECT_DIR="$PYPROJECT_DIR" BUILD_DIR="$PYPROJECT_BUILD" \
46
- bash "$SCRIPT_DIR/python-runtime-build.sh"
47
- test -f "$PYPROJECT_BUILD/next-service-dist/app.py"
48
- test -f "$PYPROJECT_BUILD/python-runtime/requirements.txt"
49
-
50
- NODE_ONLY_PROJECT="$TEST_ROOT/node-only"
51
- NODE_ONLY_BUILD="$TEST_ROOT/node-only-build"
52
- mkdir -p "$NODE_ONLY_PROJECT/mini-services/python-worker" "$NODE_ONLY_BUILD"
53
- cat >"$NODE_ONLY_PROJECT/package.json" <<'EOF'
54
- {"name": "node-only"}
55
- EOF
56
- cat >"$NODE_ONLY_PROJECT/mini-services/python-worker/main.py" <<'EOF'
57
- print("unsupported preview-only service")
58
- EOF
59
-
60
- PROJECT_DIR="$NODE_ONLY_PROJECT" BUILD_DIR="$NODE_ONLY_BUILD" \
61
- bash "$SCRIPT_DIR/python-runtime-build.sh"
62
- test ! -e "$NODE_ONLY_BUILD/python-runtime"
63
-
64
- echo "python runtime build tests passed"
@@ -1,31 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -euo pipefail
4
-
5
- RUNNER_IMAGE="${RUNNER_IMAGE:-z-ai-python-deploy-runner:test}"
6
- SCRIPT_DIR="$(cd "$(dirname "$0")/../.zscripts" && pwd)"
7
- TEST_ROOT="$(mktemp -d)"
8
- trap 'rm -rf "$TEST_ROOT"' EXIT
9
-
10
- PROJECT_DIR="$TEST_ROOT/project"
11
- BUILD_DIR="$TEST_ROOT/build"
12
- mkdir -p "$PROJECT_DIR" "$BUILD_DIR/next-service-dist"
13
-
14
- cat >"$PROJECT_DIR/requirements.txt" <<'EOF'
15
- idna==3.10
16
- EOF
17
- cat >"$PROJECT_DIR/check_runtime.py" <<'EOF'
18
- import idna
19
-
20
- assert idna.__version__ == "3.10"
21
- print("python artifact import passed")
22
- EOF
23
-
24
- PROJECT_DIR="$PROJECT_DIR" BUILD_DIR="$BUILD_DIR" \
25
- bash "$SCRIPT_DIR/python-runtime-build.sh"
26
-
27
- docker run --rm \
28
- --entrypoint sh \
29
- -v "$BUILD_DIR:/app" \
30
- "$RUNNER_IMAGE" \
31
- -c 'PYTHONPATH=/app/python-runtime/site-packages:/app/next-service-dist python /app/next-service-dist/check_runtime.py'