clawfire 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +182 -0
  2. package/dist/admin.cjs +309 -0
  3. package/dist/admin.cjs.map +1 -0
  4. package/dist/admin.d.cts +93 -0
  5. package/dist/admin.d.ts +93 -0
  6. package/dist/admin.js +274 -0
  7. package/dist/admin.js.map +1 -0
  8. package/dist/auth-DQ3cifhb.d.cts +55 -0
  9. package/dist/auth-DtnUPbXT.d.ts +55 -0
  10. package/dist/chunk-37Y2XI7X.js +75 -0
  11. package/dist/chunk-YGIPORYL.js +339 -0
  12. package/dist/cli.js +241 -0
  13. package/dist/client.cjs +97 -0
  14. package/dist/client.cjs.map +1 -0
  15. package/dist/client.d.cts +4 -0
  16. package/dist/client.d.ts +4 -0
  17. package/dist/client.js +68 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/codegen.cjs +648 -0
  20. package/dist/codegen.cjs.map +1 -0
  21. package/dist/codegen.d.cts +25 -0
  22. package/dist/codegen.d.ts +25 -0
  23. package/dist/codegen.js +617 -0
  24. package/dist/codegen.js.map +1 -0
  25. package/dist/config-QMBJRn9G.d.cts +46 -0
  26. package/dist/config-QMBJRn9G.d.ts +46 -0
  27. package/dist/dev-server-QAVWINAT.js +973 -0
  28. package/dist/dev.cjs +1388 -0
  29. package/dist/dev.cjs.map +1 -0
  30. package/dist/dev.d.cts +111 -0
  31. package/dist/dev.d.ts +111 -0
  32. package/dist/dev.js +1349 -0
  33. package/dist/dev.js.map +1 -0
  34. package/dist/discover-BPMAZFBD.js +9 -0
  35. package/dist/discover-DYNqz_ym.d.cts +28 -0
  36. package/dist/discover-DYNqz_ym.d.ts +28 -0
  37. package/dist/errors-s_mP7rs9.d.cts +33 -0
  38. package/dist/errors-s_mP7rs9.d.ts +33 -0
  39. package/dist/functions.cjs +1156 -0
  40. package/dist/functions.cjs.map +1 -0
  41. package/dist/functions.d.cts +115 -0
  42. package/dist/functions.d.ts +115 -0
  43. package/dist/functions.js +1108 -0
  44. package/dist/functions.js.map +1 -0
  45. package/dist/hosting-7WVFHAYJ.js +85 -0
  46. package/dist/html-PCUCJGBH.js +7 -0
  47. package/dist/index.cjs +349 -0
  48. package/dist/index.cjs.map +1 -0
  49. package/dist/index.d.cts +22 -0
  50. package/dist/index.d.ts +22 -0
  51. package/dist/index.js +312 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/playground.cjs +364 -0
  54. package/dist/playground.cjs.map +1 -0
  55. package/dist/playground.d.cts +12 -0
  56. package/dist/playground.d.ts +12 -0
  57. package/dist/playground.js +337 -0
  58. package/dist/playground.js.map +1 -0
  59. package/dist/router-BVB_I-tu.d.ts +65 -0
  60. package/dist/router-Cikk8Heq.d.cts +65 -0
  61. package/dist/schema-BJsictSV.d.cts +172 -0
  62. package/dist/schema-BJsictSV.d.ts +172 -0
  63. package/package.json +150 -0
  64. package/templates/CLAUDE.md +71 -0
  65. package/templates/app/routes/auth/login.ts +35 -0
  66. package/templates/app/routes/health.ts +20 -0
  67. package/templates/app/schemas/user.ts +26 -0
  68. package/templates/clawfire.config.ts +25 -0
  69. package/templates/functions/index.ts +43 -0
  70. package/templates/starter/.claude/skills/clawfire-api/SKILL.md +131 -0
  71. package/templates/starter/.claude/skills/clawfire-auth/SKILL.md +111 -0
  72. package/templates/starter/.claude/skills/clawfire-deploy/SKILL.md +95 -0
  73. package/templates/starter/.claude/skills/clawfire-diagnose/SKILL.md +99 -0
  74. package/templates/starter/.claude/skills/clawfire-model/SKILL.md +128 -0
  75. package/templates/starter/CLAUDE.md +227 -0
  76. package/templates/starter/app/routes/health.ts +20 -0
  77. package/templates/starter/app/routes/todos/create.ts +25 -0
  78. package/templates/starter/app/routes/todos/delete.ts +20 -0
  79. package/templates/starter/app/routes/todos/list.ts +26 -0
  80. package/templates/starter/app/routes/todos/update.ts +32 -0
  81. package/templates/starter/app/schemas/todo.ts +16 -0
  82. package/templates/starter/app/store.ts +56 -0
  83. package/templates/starter/clawfire.config.ts +25 -0
  84. package/templates/starter/dev.ts +12 -0
  85. package/templates/starter/package.json +19 -0
  86. package/templates/starter/public/index.html +365 -0
  87. package/templates/starter/tsconfig.json +17 -0
@@ -0,0 +1,648 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/codegen.ts
21
+ var codegen_exports = {};
22
+ __export(codegen_exports, {
23
+ discoverRoutes: () => discoverRoutes,
24
+ generateClientCode: () => generateClientCode,
25
+ generateManifestJson: () => generateManifestJson,
26
+ generatePlaygroundHtml: () => generatePlaygroundHtml,
27
+ generateRouteImports: () => generateRouteImports
28
+ });
29
+ module.exports = __toCommonJS(codegen_exports);
30
+
31
+ // src/codegen/client-gen.ts
32
+ function generateClientCode(manifest, options) {
33
+ const baseUrl = options?.baseUrl || "";
34
+ const lines = [];
35
+ lines.push("// AUTO-GENERATED by Clawfire \u2014 DO NOT EDIT");
36
+ lines.push("// Regenerate: clawfire codegen");
37
+ lines.push("");
38
+ lines.push("/* eslint-disable */");
39
+ lines.push("");
40
+ lines.push("// \u2500\u2500\u2500 Types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
41
+ lines.push("");
42
+ for (const api of manifest.apis) {
43
+ const typeName = pathToTypeName(api.path);
44
+ lines.push(`/** ${api.meta.description} */`);
45
+ lines.push(`export interface ${typeName}Input ${jsonSchemaToTsType(api.inputSchema)}`);
46
+ lines.push("");
47
+ lines.push(`export interface ${typeName}Output ${jsonSchemaToTsType(api.outputSchema)}`);
48
+ lines.push("");
49
+ }
50
+ lines.push("// \u2500\u2500\u2500 Response Wrapper \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
51
+ lines.push("");
52
+ lines.push("interface ClawfireResponse<T> {");
53
+ lines.push(" data: T;");
54
+ lines.push("}");
55
+ lines.push("");
56
+ lines.push("interface ClawfireError {");
57
+ lines.push(" error: {");
58
+ lines.push(" code: string;");
59
+ lines.push(" message: string;");
60
+ lines.push(" details?: unknown;");
61
+ lines.push(" };");
62
+ lines.push("}");
63
+ lines.push("");
64
+ lines.push("// \u2500\u2500\u2500 HTTP Client \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
65
+ lines.push("");
66
+ lines.push("type GetTokenFn = () => Promise<string | null>;");
67
+ lines.push("");
68
+ lines.push("let _baseUrl = " + JSON.stringify(baseUrl) + ";");
69
+ lines.push("let _getToken: GetTokenFn = async () => null;");
70
+ lines.push("");
71
+ lines.push("/**");
72
+ lines.push(" * API \uD074\uB77C\uC774\uC5B8\uD2B8 \uC124\uC815");
73
+ lines.push(" * @param baseUrl - API \uAE30\uBCF8 URL (\uC608: https://us-central1-myproject.cloudfunctions.net/api)");
74
+ lines.push(" * @param getToken - \uC778\uC99D \uD1A0\uD070 \uBC18\uD658 \uD568\uC218");
75
+ lines.push(" */");
76
+ lines.push("export function configureClient(baseUrl: string, getToken?: GetTokenFn) {");
77
+ lines.push(" _baseUrl = baseUrl;");
78
+ lines.push(" if (getToken) _getToken = getToken;");
79
+ lines.push("}");
80
+ lines.push("");
81
+ lines.push("async function call<TInput, TOutput>(path: string, input: TInput): Promise<TOutput> {");
82
+ lines.push(" const token = await _getToken();");
83
+ lines.push(" const headers: Record<string, string> = {");
84
+ lines.push(' "Content-Type": "application/json",');
85
+ lines.push(" };");
86
+ lines.push(' if (token) headers["Authorization"] = `Bearer ${token}`;');
87
+ lines.push("");
88
+ lines.push(" const res = await fetch(`${_baseUrl}/api${path}`, {");
89
+ lines.push(' method: "POST",');
90
+ lines.push(" headers,");
91
+ lines.push(" body: JSON.stringify(input),");
92
+ lines.push(" });");
93
+ lines.push("");
94
+ lines.push(" const json = await res.json();");
95
+ lines.push("");
96
+ lines.push(" if (!res.ok) {");
97
+ lines.push(" const err = json as ClawfireError;");
98
+ lines.push(" throw new Error(err.error?.message || `API error: ${res.status}`);");
99
+ lines.push(" }");
100
+ lines.push("");
101
+ lines.push(" return (json as ClawfireResponse<TOutput>).data;");
102
+ lines.push("}");
103
+ lines.push("");
104
+ lines.push("// \u2500\u2500\u2500 API Client \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
105
+ lines.push("");
106
+ const tree = buildApiTree(manifest.apis);
107
+ lines.push(generateApiObject(tree));
108
+ return lines.join("\n");
109
+ }
110
+ function pathToTypeName(path) {
111
+ return path.split("/").filter(Boolean).filter((p) => !p.startsWith(":")).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join("");
112
+ }
113
+ function buildApiTree(apis) {
114
+ const root = { apis: [], children: {} };
115
+ for (const api of apis) {
116
+ const parts = api.path.split("/").filter(Boolean).filter((p) => !p.startsWith(":"));
117
+ let node = root;
118
+ for (let i = 0; i < parts.length - 1; i++) {
119
+ if (!node.children[parts[i]]) {
120
+ node.children[parts[i]] = { apis: [], children: {} };
121
+ }
122
+ node = node.children[parts[i]];
123
+ }
124
+ const name = parts[parts.length - 1] || "index";
125
+ const typeName = pathToTypeName(api.path);
126
+ node.apis.push({ name, path: api.path, typeName, meta: api.meta });
127
+ }
128
+ return root;
129
+ }
130
+ function generateApiObject(tree, indent = "") {
131
+ const lines = [];
132
+ lines.push(`${indent}export const api = {`);
133
+ for (const [name, child] of Object.entries(tree.children)) {
134
+ lines.push(`${indent} ${name}: {`);
135
+ for (const api of child.apis) {
136
+ lines.push(`${indent} /** ${api.meta.description}${api.meta.auth ? ` [${api.meta.auth}]` : ""} */`);
137
+ lines.push(
138
+ `${indent} ${api.name}: (input: ${api.typeName}Input): Promise<${api.typeName}Output> => call("${api.path}", input),`
139
+ );
140
+ }
141
+ for (const [subName, subChild] of Object.entries(child.children)) {
142
+ lines.push(`${indent} ${subName}: {`);
143
+ for (const subApi of subChild.apis) {
144
+ lines.push(`${indent} /** ${subApi.meta.description}${subApi.meta.auth ? ` [${subApi.meta.auth}]` : ""} */`);
145
+ lines.push(
146
+ `${indent} ${subApi.name}: (input: ${subApi.typeName}Input): Promise<${subApi.typeName}Output> => call("${subApi.path}", input),`
147
+ );
148
+ }
149
+ for (const [deepName, deepChild] of Object.entries(subChild.children)) {
150
+ lines.push(`${indent} ${deepName}: {`);
151
+ for (const deepApi of deepChild.apis) {
152
+ lines.push(`${indent} /** ${deepApi.meta.description} */`);
153
+ lines.push(
154
+ `${indent} ${deepApi.name}: (input: ${deepApi.typeName}Input): Promise<${deepApi.typeName}Output> => call("${deepApi.path}", input),`
155
+ );
156
+ }
157
+ lines.push(`${indent} },`);
158
+ }
159
+ lines.push(`${indent} },`);
160
+ }
161
+ lines.push(`${indent} },`);
162
+ }
163
+ for (const api of tree.apis) {
164
+ lines.push(`${indent} /** ${api.meta.description} */`);
165
+ lines.push(
166
+ `${indent} ${api.name}: (input: ${api.typeName}Input): Promise<${api.typeName}Output> => call("${api.path}", input),`
167
+ );
168
+ }
169
+ lines.push(`${indent}};`);
170
+ return lines.join("\n");
171
+ }
172
+ function jsonSchemaToTsType(schema) {
173
+ if (!schema) return "{}";
174
+ const type = schema.type;
175
+ switch (type) {
176
+ case "object": {
177
+ const props = schema.properties;
178
+ if (!props) return "Record<string, unknown>";
179
+ const required = schema.required || [];
180
+ const fields = [];
181
+ for (const [key, propSchema] of Object.entries(props)) {
182
+ const isRequired = required.includes(key);
183
+ const tsType = jsonSchemaToInlineType(propSchema);
184
+ fields.push(` ${key}${isRequired ? "" : "?"}: ${tsType};`);
185
+ }
186
+ return `{
187
+ ${fields.join("\n")}
188
+ }`;
189
+ }
190
+ default:
191
+ return "{}";
192
+ }
193
+ }
194
+ function jsonSchemaToInlineType(schema) {
195
+ if (!schema) return "unknown";
196
+ if ("const" in schema) return JSON.stringify(schema.const);
197
+ if (schema.enum) return schema.enum.map((v) => JSON.stringify(v)).join(" | ");
198
+ const nullable = schema.nullable ? " | null" : "";
199
+ const optional = schema.optional ? "" : "";
200
+ const type = schema.type;
201
+ switch (type) {
202
+ case "string":
203
+ return `string${nullable}`;
204
+ case "number":
205
+ return `number${nullable}`;
206
+ case "boolean":
207
+ return `boolean${nullable}`;
208
+ case "array": {
209
+ const items = schema.items;
210
+ const itemType = items ? jsonSchemaToInlineType(items) : "unknown";
211
+ return `${itemType}[]${nullable}`;
212
+ }
213
+ case "object": {
214
+ const props = schema.properties;
215
+ if (!props) {
216
+ const additionalProps = schema.additionalProperties;
217
+ if (additionalProps) return `Record<string, ${jsonSchemaToInlineType(additionalProps)}>${nullable}`;
218
+ return `Record<string, unknown>${nullable}`;
219
+ }
220
+ const required = schema.required || [];
221
+ const fields = Object.entries(props).map(([k, v]) => `${k}${required.includes(k) ? "" : "?"}: ${jsonSchemaToInlineType(v)}`).join("; ");
222
+ return `{ ${fields} }${nullable}`;
223
+ }
224
+ default:
225
+ if (schema.oneOf) {
226
+ return schema.oneOf.map(jsonSchemaToInlineType).join(" | ");
227
+ }
228
+ return "unknown";
229
+ }
230
+ }
231
+ function generateManifestJson(manifest) {
232
+ return JSON.stringify(manifest, null, 2);
233
+ }
234
+
235
+ // src/playground/html.ts
236
+ function generatePlaygroundHtml(options) {
237
+ const title = options?.title || "Clawfire Playground";
238
+ const apiBaseUrl = options?.apiBaseUrl || "";
239
+ return `<!DOCTYPE html>
240
+ <html lang="en">
241
+ <head>
242
+ <meta charset="UTF-8">
243
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
244
+ <title>${title}</title>
245
+ <style>
246
+ :root {
247
+ --bg: #0a0a0a;
248
+ --surface: #141414;
249
+ --surface2: #1e1e1e;
250
+ --border: #2a2a2a;
251
+ --text: #e5e5e5;
252
+ --text2: #a3a3a3;
253
+ --accent: #f97316;
254
+ --accent2: #fb923c;
255
+ --green: #22c55e;
256
+ --red: #ef4444;
257
+ --blue: #3b82f6;
258
+ --yellow: #eab308;
259
+ --radius: 8px;
260
+ --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
261
+ --mono: 'JetBrains Mono', 'Fira Code', monospace;
262
+ }
263
+ * { margin: 0; padding: 0; box-sizing: border-box; }
264
+ body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
265
+
266
+ .layout { display: grid; grid-template-columns: 320px 1fr; min-height: 100vh; }
267
+ .sidebar { background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
268
+ .main { padding: 24px; overflow-y: auto; }
269
+
270
+ .logo { padding: 20px; border-bottom: 1px solid var(--border); }
271
+ .logo h1 { font-size: 20px; font-weight: 700; color: var(--accent); }
272
+ .logo p { font-size: 12px; color: var(--text2); margin-top: 4px; }
273
+
274
+ .auth-section { padding: 16px; border-bottom: 1px solid var(--border); }
275
+ .auth-section label { font-size: 12px; color: var(--text2); display: block; margin-bottom: 6px; }
276
+ .auth-input { width: 100%; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border);
277
+ border-radius: var(--radius); color: var(--text); font-family: var(--mono); font-size: 12px; }
278
+ .auth-status { font-size: 11px; margin-top: 6px; }
279
+ .auth-status.ok { color: var(--green); }
280
+ .auth-status.no { color: var(--text2); }
281
+
282
+ .search { padding: 12px 16px; border-bottom: 1px solid var(--border); }
283
+ .search input { width: 100%; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border);
284
+ border-radius: var(--radius); color: var(--text); font-size: 13px; }
285
+
286
+ .api-list { padding: 8px 0; }
287
+ .api-group { padding: 4px 0; }
288
+ .api-group-title { padding: 8px 16px; font-size: 11px; color: var(--text2); text-transform: uppercase;
289
+ letter-spacing: 0.5px; font-weight: 600; }
290
+ .api-item { padding: 8px 16px; cursor: pointer; transition: background 0.15s; display: flex; align-items: center;
291
+ gap: 8px; font-size: 13px; }
292
+ .api-item:hover { background: var(--surface2); }
293
+ .api-item.active { background: var(--surface2); border-left: 2px solid var(--accent); }
294
+ .api-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; }
295
+ .badge-public { background: #22c55e20; color: var(--green); }
296
+ .badge-auth { background: #3b82f620; color: var(--blue); }
297
+ .badge-role { background: #eab30820; color: var(--yellow); }
298
+ .badge-reauth { background: #ef444420; color: var(--red); }
299
+
300
+ .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
301
+ .panel-header { padding: 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
302
+ justify-content: space-between; }
303
+ .panel-header h2 { font-size: 16px; font-weight: 600; }
304
+ .panel-body { padding: 16px; }
305
+
306
+ .field { margin-bottom: 12px; }
307
+ .field label { font-size: 12px; color: var(--text2); display: block; margin-bottom: 4px; }
308
+ .field-type { font-size: 11px; color: var(--text2); font-family: var(--mono); }
309
+ .field-required { color: var(--red); font-size: 11px; }
310
+
311
+ textarea, input[type="text"] { width: 100%; padding: 10px 14px; background: var(--surface2);
312
+ border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
313
+ font-family: var(--mono); font-size: 13px; resize: vertical; }
314
+ textarea { min-height: 200px; }
315
+
316
+ .btn { padding: 10px 20px; border: none; border-radius: var(--radius); font-size: 14px;
317
+ font-weight: 600; cursor: pointer; transition: all 0.15s; }
318
+ .btn-primary { background: var(--accent); color: white; }
319
+ .btn-primary:hover { background: var(--accent2); }
320
+ .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
321
+
322
+ .response-section { margin-top: 16px; }
323
+ .status-badge { font-size: 12px; padding: 4px 8px; border-radius: 4px; font-weight: 600; }
324
+ .status-ok { background: #22c55e20; color: var(--green); }
325
+ .status-err { background: #ef444420; color: var(--red); }
326
+ pre { background: var(--surface2); padding: 16px; border-radius: var(--radius); overflow-x: auto;
327
+ font-family: var(--mono); font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
328
+
329
+ .schema-info { font-size: 12px; color: var(--text2); line-height: 1.6; }
330
+ .schema-info code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-family: var(--mono);
331
+ font-size: 11px; }
332
+
333
+ .empty-state { text-align: center; padding: 80px 40px; color: var(--text2); }
334
+ .empty-state h2 { font-size: 24px; margin-bottom: 8px; color: var(--text); }
335
+
336
+ .timer { font-size: 12px; color: var(--text2); font-family: var(--mono); }
337
+
338
+ @media (max-width: 768px) {
339
+ .layout { grid-template-columns: 1fr; }
340
+ .sidebar { max-height: 40vh; }
341
+ }
342
+ </style>
343
+ </head>
344
+ <body>
345
+ <div class="layout">
346
+ <div class="sidebar">
347
+ <div class="logo">
348
+ <h1>Clawfire</h1>
349
+ <p>API Playground</p>
350
+ </div>
351
+ <div class="auth-section">
352
+ <label>Bearer Token</label>
353
+ <input type="text" class="auth-input" id="token-input" placeholder="Paste your ID token...">
354
+ <div class="auth-status no" id="auth-status">Not authenticated</div>
355
+ </div>
356
+ <div class="search">
357
+ <input type="text" id="search-input" placeholder="Search APIs...">
358
+ </div>
359
+ <div class="api-list" id="api-list"></div>
360
+ </div>
361
+ <div class="main" id="main-content">
362
+ <div class="empty-state">
363
+ <h2>Select an API</h2>
364
+ <p>Choose an API from the sidebar to test it.</p>
365
+ </div>
366
+ </div>
367
+ </div>
368
+
369
+ <script>
370
+ const BASE_URL = ${JSON.stringify(apiBaseUrl)} || window.location.origin;
371
+ let manifest = null;
372
+ let selectedApi = null;
373
+
374
+ async function loadManifest() {
375
+ try {
376
+ const res = await fetch(BASE_URL + '/api/__manifest', { method: 'POST' });
377
+ manifest = await res.json();
378
+ renderApiList(manifest.apis);
379
+ } catch (e) {
380
+ document.getElementById('api-list').innerHTML =
381
+ '<div style="padding:16px;color:var(--red);font-size:13px;">Failed to load API manifest. Make sure your server is running.</div>';
382
+ }
383
+ }
384
+
385
+ function renderApiList(apis) {
386
+ const groups = {};
387
+ apis.forEach(api => {
388
+ const parts = api.path.split('/').filter(Boolean);
389
+ const group = parts.length > 1 ? parts[0] : 'root';
390
+ if (!groups[group]) groups[group] = [];
391
+ groups[group].push(api);
392
+ });
393
+
394
+ const el = document.getElementById('api-list');
395
+ el.innerHTML = Object.entries(groups).map(([group, items]) =>
396
+ '<div class="api-group">' +
397
+ '<div class="api-group-title">' + group + '</div>' +
398
+ items.map(api => {
399
+ const auth = api.meta.auth || 'public';
400
+ const badgeClass = 'badge-' + auth;
401
+ return '<div class="api-item" onclick="selectApi(\\'' + api.path + '\\')">' +
402
+ '<span class="api-badge ' + badgeClass + '">' + auth.toUpperCase() + '</span>' +
403
+ '<span>' + api.path + '</span>' +
404
+ '</div>';
405
+ }).join('') +
406
+ '</div>'
407
+ ).join('');
408
+ }
409
+
410
+ function selectApi(path) {
411
+ selectedApi = manifest.apis.find(a => a.path === path);
412
+ if (!selectedApi) return;
413
+
414
+ document.querySelectorAll('.api-item').forEach(el => el.classList.remove('active'));
415
+ event.currentTarget?.classList.add('active');
416
+
417
+ const main = document.getElementById('main-content');
418
+ const exampleInput = selectedApi.meta.exampleInput
419
+ ? JSON.stringify(selectedApi.meta.exampleInput, null, 2)
420
+ : generateExampleFromSchema(selectedApi.inputSchema);
421
+
422
+ main.innerHTML =
423
+ '<div class="panel">' +
424
+ '<div class="panel-header">' +
425
+ '<h2>POST ' + selectedApi.path + '</h2>' +
426
+ '<span class="api-badge badge-' + (selectedApi.meta.auth || 'public') + '">' +
427
+ (selectedApi.meta.auth || 'public').toUpperCase() + '</span>' +
428
+ '</div>' +
429
+ '<div class="panel-body">' +
430
+ '<p style="color:var(--text2);margin-bottom:16px;">' + (selectedApi.meta.description || '') + '</p>' +
431
+ (selectedApi.meta.tags ? '<div style="margin-bottom:12px;">' + selectedApi.meta.tags.map(t =>
432
+ '<span style="background:var(--surface2);padding:2px 8px;border-radius:4px;font-size:11px;margin-right:4px;">' + t + '</span>'
433
+ ).join('') + '</div>' : '') +
434
+ '<div class="schema-info" style="margin-bottom:16px;">' +
435
+ '<strong>Input Schema:</strong><br>' + renderSchemaInfo(selectedApi.inputSchema) +
436
+ '</div>' +
437
+ '<div class="schema-info" style="margin-bottom:16px;">' +
438
+ '<strong>Output Schema:</strong><br>' + renderSchemaInfo(selectedApi.outputSchema) +
439
+ '</div>' +
440
+ '</div>' +
441
+ '</div>' +
442
+ '<div class="panel">' +
443
+ '<div class="panel-header"><h2>Request</h2></div>' +
444
+ '<div class="panel-body">' +
445
+ '<textarea id="req-body" placeholder="Request JSON body">' + exampleInput + '</textarea>' +
446
+ '<div style="margin-top:12px;display:flex;align-items:center;gap:12px;">' +
447
+ '<button class="btn btn-primary" onclick="sendRequest()">Send Request</button>' +
448
+ '<span class="timer" id="timer"></span>' +
449
+ '</div>' +
450
+ '</div>' +
451
+ '</div>' +
452
+ '<div class="response-section" id="response-section"></div>';
453
+ }
454
+
455
+ function renderSchemaInfo(schema) {
456
+ if (!schema || !schema.properties) return '<code>void</code>';
457
+ return Object.entries(schema.properties).map(([key, prop]) => {
458
+ const required = schema.required?.includes(key);
459
+ const type = prop.type || 'unknown';
460
+ const enumVals = prop.enum ? ' (' + prop.enum.join(', ') + ')' : '';
461
+ return '<code>' + key + '</code>: <span class="field-type">' + type + enumVals + '</span>' +
462
+ (required ? ' <span class="field-required">required</span>' : ' <span style="color:var(--text2);font-size:11px;">optional</span>');
463
+ }).join('<br>');
464
+ }
465
+
466
+ function generateExampleFromSchema(schema) {
467
+ if (!schema || !schema.properties) return '{}';
468
+ const obj = {};
469
+ for (const [key, prop] of Object.entries(schema.properties)) {
470
+ if (prop.enum) { obj[key] = prop.enum[0]; continue; }
471
+ switch (prop.type) {
472
+ case 'string': obj[key] = prop.format === 'email' ? 'user@example.com' : 'string'; break;
473
+ case 'number': obj[key] = 0; break;
474
+ case 'boolean': obj[key] = false; break;
475
+ case 'array': obj[key] = []; break;
476
+ case 'object': obj[key] = {}; break;
477
+ default: obj[key] = null;
478
+ }
479
+ }
480
+ return JSON.stringify(obj, null, 2);
481
+ }
482
+
483
+ async function sendRequest() {
484
+ if (!selectedApi) return;
485
+ const body = document.getElementById('req-body').value;
486
+ const token = document.getElementById('token-input').value;
487
+ const timer = document.getElementById('timer');
488
+ const section = document.getElementById('response-section');
489
+
490
+ let parsed;
491
+ try { parsed = JSON.parse(body); } catch {
492
+ section.innerHTML = '<div class="panel"><div class="panel-body"><pre style="color:var(--red)">Invalid JSON</pre></div></div>';
493
+ return;
494
+ }
495
+
496
+ const start = performance.now();
497
+ timer.textContent = 'Sending...';
498
+
499
+ try {
500
+ const headers = { 'Content-Type': 'application/json' };
501
+ if (token) headers['Authorization'] = 'Bearer ' + token;
502
+
503
+ const res = await fetch(BASE_URL + '/api' + selectedApi.path, {
504
+ method: 'POST', headers, body: JSON.stringify(parsed)
505
+ });
506
+ const elapsed = Math.round(performance.now() - start);
507
+ timer.textContent = elapsed + 'ms';
508
+
509
+ const json = await res.json();
510
+ const isOk = res.ok;
511
+
512
+ section.innerHTML =
513
+ '<div class="panel">' +
514
+ '<div class="panel-header">' +
515
+ '<h2>Response</h2>' +
516
+ '<span class="status-badge ' + (isOk ? 'status-ok' : 'status-err') + '">' +
517
+ res.status + ' ' + res.statusText + '</span>' +
518
+ '</div>' +
519
+ '<div class="panel-body"><pre>' + syntaxHighlight(JSON.stringify(json, null, 2)) + '</pre></div>' +
520
+ '</div>';
521
+ } catch (e) {
522
+ const elapsed = Math.round(performance.now() - start);
523
+ timer.textContent = elapsed + 'ms';
524
+ section.innerHTML =
525
+ '<div class="panel"><div class="panel-body"><pre style="color:var(--red)">Network error: ' + e.message + '</pre></div></div>';
526
+ }
527
+ }
528
+
529
+ function syntaxHighlight(json) {
530
+ return json.replace(/("(\\\\u[a-fA-F0-9]{4}|\\\\[^u]|[^\\\\"])*"(\\s*:)?)|\\b(true|false|null)\\b|-?\\d+(\\.\\d+)?([eE][+-]?\\d+)?/g,
531
+ function(match) {
532
+ let cls = 'color:#eab308';
533
+ if (/^"/.test(match)) {
534
+ if (/:$/.test(match)) cls = 'color:#3b82f6';
535
+ else cls = 'color:#22c55e';
536
+ } else if (/true|false/.test(match)) cls = 'color:#f97316';
537
+ else if (/null/.test(match)) cls = 'color:#ef4444';
538
+ return '<span style="' + cls + '">' + match + '</span>';
539
+ }
540
+ );
541
+ }
542
+
543
+ // Search
544
+ document.getElementById('search-input')?.addEventListener('input', (e) => {
545
+ if (!manifest) return;
546
+ const q = e.target.value.toLowerCase();
547
+ const filtered = manifest.apis.filter(a => a.path.toLowerCase().includes(q) || a.meta.description?.toLowerCase().includes(q));
548
+ renderApiList(filtered);
549
+ });
550
+
551
+ // Token status
552
+ document.getElementById('token-input')?.addEventListener('input', (e) => {
553
+ const el = document.getElementById('auth-status');
554
+ if (e.target.value) {
555
+ el.textContent = 'Token set';
556
+ el.className = 'auth-status ok';
557
+ } else {
558
+ el.textContent = 'Not authenticated';
559
+ el.className = 'auth-status no';
560
+ }
561
+ });
562
+
563
+ loadManifest();
564
+ </script>
565
+ </body>
566
+ </html>`;
567
+ }
568
+
569
+ // src/core/schema.ts
570
+ var import_zod = require("zod");
571
+
572
+ // src/routing/discover.ts
573
+ var import_path = require("path");
574
+ var import_fs = require("fs");
575
+ function discoverRoutes(routesDir) {
576
+ if (!(0, import_fs.existsSync)(routesDir)) {
577
+ return [];
578
+ }
579
+ const routes = [];
580
+ scanDirectory(routesDir, routesDir, routes);
581
+ return routes.sort((a, b) => a.apiPath.localeCompare(b.apiPath));
582
+ }
583
+ function scanDirectory(baseDir, currentDir, routes) {
584
+ const entries = (0, import_fs.readdirSync)(currentDir);
585
+ for (const entry of entries) {
586
+ const fullPath = (0, import_path.join)(currentDir, entry);
587
+ const stat = (0, import_fs.statSync)(fullPath);
588
+ if (stat.isDirectory()) {
589
+ if (entry.startsWith(".") || entry === "node_modules") continue;
590
+ scanDirectory(baseDir, fullPath, routes);
591
+ } else if (stat.isFile()) {
592
+ if (!entry.endsWith(".ts") && !entry.endsWith(".js")) continue;
593
+ if (entry.startsWith("_")) continue;
594
+ if (entry.endsWith(".d.ts")) continue;
595
+ const relativePath = (0, import_path.relative)(baseDir, fullPath);
596
+ const route = filePathToRoute(relativePath);
597
+ routes.push(route);
598
+ }
599
+ }
600
+ }
601
+ function filePathToRoute(filePath) {
602
+ const params = [];
603
+ let routePath = filePath.replace(/\.(ts|js)$/, "");
604
+ routePath = routePath.replace(/\\/g, "/");
605
+ if (routePath.endsWith("/index") || routePath === "index") {
606
+ routePath = routePath.replace(/\/?index$/, "");
607
+ }
608
+ routePath = routePath.replace(/\[([^\]]+)\]/g, (_, param) => {
609
+ params.push(param);
610
+ return `:${param}`;
611
+ });
612
+ const apiPath = `/${routePath}`;
613
+ return {
614
+ filePath,
615
+ apiPath,
616
+ params
617
+ };
618
+ }
619
+ function generateRouteImports(routes, routesDir) {
620
+ const lines = [
621
+ "// AUTO-GENERATED by Clawfire \u2014 DO NOT EDIT",
622
+ "// This file is regenerated whenever routes change.",
623
+ "",
624
+ 'import { createRouter } from "clawfire/functions";',
625
+ ""
626
+ ];
627
+ routes.forEach((route, i) => {
628
+ const importPath = `./${route.filePath.replace(/\.(ts|js)$/, ".js")}`;
629
+ lines.push(`import route_${i} from "${importPath}";`);
630
+ });
631
+ lines.push("");
632
+ lines.push("export function registerAllRoutes(router: ReturnType<typeof createRouter>) {");
633
+ routes.forEach((route, i) => {
634
+ lines.push(` router.register("${route.apiPath}", route_${i});`);
635
+ });
636
+ lines.push(" return router;");
637
+ lines.push("}");
638
+ return lines.join("\n");
639
+ }
640
+ // Annotate the CommonJS export names for ESM import in node:
641
+ 0 && (module.exports = {
642
+ discoverRoutes,
643
+ generateClientCode,
644
+ generateManifestJson,
645
+ generatePlaygroundHtml,
646
+ generateRouteImports
647
+ });
648
+ //# sourceMappingURL=codegen.cjs.map