@krak-stack/registry 0.1.37 → 0.1.39

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 (38) hide show
  1. package/README.md +131 -7
  2. package/dist/components/ui/app-brand.js +17 -17
  3. package/dist/components/ui/code-block.js +4 -4
  4. package/dist/components/ui/copy-button.js +2 -2
  5. package/dist/components/ui/data-table.js +56 -56
  6. package/dist/components/ui/editing-locale-switcher.js +8 -8
  7. package/dist/components/ui/effect-form.js +12 -12
  8. package/dist/components/ui/error-component.js +6 -6
  9. package/dist/components/ui/file-picker.js +2 -2
  10. package/dist/components/ui/form.js +24 -24
  11. package/dist/components/ui/icon-input.js +5 -5
  12. package/dist/components/ui/locale-switcher.js +2 -2
  13. package/dist/components/ui/search-menu.js +2 -2
  14. package/dist/components/ui/sidebar-layout.js +1 -1
  15. package/dist/components/ui/theme-switcher.js +3 -3
  16. package/dist/lib/docs.js +52 -111
  17. package/dist/lib/docs.server.js +1 -29
  18. package/dist/lib/documentation-toolkit.js +0 -28
  19. package/dist/lib/httpapi-adapter.d.ts +73 -0
  20. package/dist/lib/httpapi-adapter.js +189 -0
  21. package/dist/lib/httpapi-cli.d.ts +4 -22
  22. package/dist/lib/httpapi-cli.js +227 -533
  23. package/dist/lib/httpapi-toolkit.d.ts +15 -12
  24. package/dist/lib/httpapi-toolkit.js +175 -381
  25. package/dist/lib/query.d.ts +2 -2
  26. package/dist/lib/query.js +18 -5
  27. package/dist/lib/webfetch-toolkit.d.ts +1 -1
  28. package/dist/lib/webfetch-toolkit.js +48 -50
  29. package/dist/oxlint/anti-slop/index.js +2 -2
  30. package/dist/services/agent/client/index.js +6 -6
  31. package/dist/services/agent/index.js +3 -3
  32. package/package.json +5 -13
  33. package/dist/lib/httpapi-client.d.ts +0 -30
  34. package/dist/lib/httpapi-client.js +0 -112
  35. package/dist/lib/httpapi-helpers.d.ts +0 -101
  36. package/dist/lib/httpapi-helpers.js +0 -286
  37. package/dist/lib/httpapi-mcp.d.ts +0 -20
  38. package/dist/lib/httpapi-mcp.js +0 -477
@@ -1,286 +0,0 @@
1
- // ../../src/lib/httpapi-helpers.tsx
2
- import {
3
- Context,
4
- Effect,
5
- JsonSchema,
6
- Layer,
7
- Option,
8
- Schema,
9
- SchemaRepresentation
10
- } from "effect";
11
- import { HttpApi, OpenApi } from "effect/http-api";
12
- var JsonObjectSchema = Schema.Record(Schema.String, Schema.Json).annotate({
13
- identifier: "HttpJsonObject",
14
- title: "HTTP JSON object",
15
- description: "A JSON object passed to an HTTP API operation.",
16
- examples: [{ id: "example-id" }]
17
- });
18
- var JsonObjectFromString = Schema.fromJsonString(JsonObjectSchema);
19
- var JsonValueFromString = Schema.fromJsonString(Schema.Json);
20
- var JsonSchemaAnnotations = Schema.Struct({
21
- title: Schema.optional(Schema.String),
22
- description: Schema.optional(Schema.String),
23
- examples: Schema.optional(Schema.Array(Schema.Json))
24
- }).annotate({
25
- identifier: "HttpJsonSchemaAnnotations",
26
- title: "HTTP JSON Schema annotations",
27
- description: "JSON Schema annotations surfaced on generated tool inputs."
28
- });
29
- var HttpApiToolInputSchema = Schema.Struct({
30
- body: Schema.optional(Schema.Json)
31
- }).annotate({
32
- identifier: "HttpApiToolInput",
33
- title: "HTTP API tool input",
34
- description: "Input accepted by an HTTP API-backed tool.",
35
- examples: [{ body: { id: "example-id" } }]
36
- });
37
- var HttpApiMethods = [
38
- "get",
39
- "post",
40
- "put",
41
- "patch",
42
- "delete"
43
- ];
44
- var HttpApiOperationSchema = Schema.declare((value) => Schema.is(JsonObjectSchema)(value)).annotate({ identifier: "HttpApiOperation" });
45
- var decodeHttpApiOperation = Schema.decodeUnknownOption(HttpApiOperationSchema);
46
- var toHttpError = (message, error) => new Error(message, { cause: error });
47
- var sanitizeHttpName = (name) => name.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
48
- var httpApiToolName = (method, path, operation) => {
49
- const fallback = `${method}_${path.replace(/^\/api\//, "").replace(/[/:{}]/g, "_")}`;
50
- return (operation.operationId || fallback).replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").slice(0, 64);
51
- };
52
- var httpApiOperations = ({
53
- spec,
54
- methods = HttpApiMethods
55
- }) => {
56
- const operations = [];
57
- for (const [path, pathItem] of Object.entries(spec.paths)) {
58
- for (const method of methods) {
59
- const operation = decodeHttpApiOperation(pathItem[method]);
60
- if (Option.isSome(operation)) {
61
- operations.push({ method, path, operation: operation.value });
62
- }
63
- }
64
- }
65
- return operations;
66
- };
67
- var httpApiToolEntries = Effect.fn("Http.toolEntries")(function* (operations) {
68
- return yield* Effect.try({
69
- try: () => {
70
- const names = new Set;
71
- return operations.map((entry) => {
72
- const name = httpApiToolName(entry.method, entry.path, entry.operation);
73
- if (!name || names.has(name)) {
74
- throw new Error(`Duplicate or empty HTTP API tool name: ${name}`);
75
- }
76
- names.add(name);
77
- return { ...entry, name };
78
- });
79
- },
80
- catch: (error) => error instanceof Error ? error : new Error(String(error))
81
- });
82
- });
83
- var decodeAnnotations = Schema.decodeUnknownOption(JsonSchemaAnnotations);
84
- var schemaWithVisibleAnnotations = (schema) => {
85
- const directAnnotations = decodeAnnotations(schema).pipe(Option.getOrElse(() => ({})));
86
- const allOf = Array.isArray(schema.allOf) ? schema.allOf : [];
87
- const annotations = allOf.reduce((acc, item) => ({
88
- ...acc,
89
- ...decodeAnnotations(item).pipe(Option.getOrElse(() => ({})))
90
- }), directAnnotations);
91
- const visible = { ...schema };
92
- if ("title" in annotations && !("title" in schema)) {
93
- visible.title = annotations.title;
94
- }
95
- if ("description" in annotations && !("description" in schema)) {
96
- visible.description = annotations.description;
97
- }
98
- if ("examples" in annotations && !("examples" in schema)) {
99
- visible.examples = annotations.examples;
100
- }
101
- return visible;
102
- };
103
- var referencedDefinitions = (schema, definitions) => {
104
- const names = new Set;
105
- const pending = [Schema.decodeUnknownSync(Schema.Json)(schema)];
106
- while (pending.length > 0) {
107
- const current = pending.pop();
108
- if (Array.isArray(current)) {
109
- pending.push(...current);
110
- continue;
111
- }
112
- const record = Schema.decodeUnknownOption(Schema.Record(Schema.String, Schema.Json))(current);
113
- if (Option.isNone(record))
114
- continue;
115
- for (const [key, value] of Object.entries(record.value)) {
116
- if (key === "$ref" && Schema.is(Schema.String)(value)) {
117
- const name = value.match(/^#\/(?:\$defs|components\/schemas)\/(.+)$/)?.[1];
118
- if (name && !names.has(name) && definitions[name]) {
119
- names.add(name);
120
- pending.push(Schema.decodeUnknownSync(Schema.Json)(definitions[name]));
121
- }
122
- } else if (key !== "$defs") {
123
- pending.push(value);
124
- }
125
- }
126
- }
127
- return Object.fromEntries([...names].map((name) => [name, definitions[name]]));
128
- };
129
- var operationParameters = (parameters, location) => parameters.filter((parameter) => parameter.in === location);
130
- var httpApiOperationInputSchema = (operation) => {
131
- const parameters = operation.parameters ?? [];
132
- const pathParameters = operationParameters(parameters, "path");
133
- const queryParameters = operationParameters(parameters, "query");
134
- const headerParameters = operationParameters(parameters, "header");
135
- const properties = {};
136
- const required = [];
137
- const body = operation.requestBody?.content?.["application/json"]?.schema;
138
- for (const parameter of [
139
- ...pathParameters,
140
- ...queryParameters,
141
- ...headerParameters
142
- ]) {
143
- const property = {
144
- ...parameter.schema ? schemaWithVisibleAnnotations(parameter.schema) : { type: "string" }
145
- };
146
- if (parameter.description)
147
- property.description = parameter.description;
148
- properties[parameter.name] = property;
149
- if (parameter.required)
150
- required.push(parameter.name);
151
- }
152
- if (body) {
153
- properties.body = body;
154
- if (operation.requestBody?.required)
155
- required.push("body");
156
- }
157
- return {
158
- type: "object",
159
- properties,
160
- required,
161
- additionalProperties: false
162
- };
163
- };
164
- var decodeJsonObject = Schema.decodeUnknownOption(JsonObjectSchema);
165
- var decodeHttpApiOperationInput = Effect.fn("Http.decodeApiOperationInput")(function* (input, operation) {
166
- const payload = yield* Schema.decodeUnknownEffect(JsonObjectSchema)(input ?? {}).pipe(Effect.mapError(() => new Error("Tool input must be a JSON object")));
167
- const decoded = yield* Schema.decodeUnknownEffect(HttpApiToolInputSchema)(payload).pipe(Effect.mapError(() => new Error("Tool input must be a JSON object")));
168
- const parameters = operation.parameters ?? [];
169
- const pickParameters = (location) => {
170
- const nestedKey = location === "path" ? "params" : location;
171
- const nested = decodeJsonObject(payload[nestedKey]).pipe(Option.getOrElse(() => ({})));
172
- return Object.fromEntries(operationParameters(parameters, location).map((parameter) => [
173
- parameter.name,
174
- nested[parameter.name] ?? payload[parameter.name]
175
- ]).filter(([, value]) => value !== undefined));
176
- };
177
- return {
178
- ...decoded,
179
- headers: pickParameters("header"),
180
- params: pickParameters("path"),
181
- query: pickParameters("query")
182
- };
183
- });
184
- var reflectedSchema = (schema) => Schema.make(schema.ast);
185
- var reflectedOperationInputSchemas = (api) => {
186
- const schemas = new Map;
187
- HttpApi.reflect(api, {
188
- onGroup: () => {
189
- return;
190
- },
191
- onEndpoint: ({ endpoint, group }) => {
192
- const operationId = Context.getOrElse(endpoint.annotations, OpenApi.Identifier, () => group.topLevel ? endpoint.identifier : `${group.identifier}.${endpoint.identifier}`);
193
- const fields = {};
194
- if (endpoint.params)
195
- fields.params = reflectedSchema(endpoint.params);
196
- if (endpoint.query) {
197
- fields.query = Schema.optionalKey(reflectedSchema(endpoint.query));
198
- }
199
- if (endpoint.headers) {
200
- fields.headers = Schema.optionalKey(reflectedSchema(endpoint.headers));
201
- }
202
- const payloadSchemas = Array.from(endpoint.payload.values()).flatMap(({ schemas: schemas2 }) => schemas2.map(reflectedSchema));
203
- if (payloadSchemas.length === 1 && payloadSchemas[0]) {
204
- fields.body = payloadSchemas[0];
205
- } else if (payloadSchemas.length > 1) {
206
- fields.body = Schema.Union(payloadSchemas);
207
- }
208
- const inputSchema = Object.keys(fields).length === 0 ? Schema.Record(Schema.String, Schema.Never) : Schema.Struct(fields);
209
- schemas.set(operationId, inputSchema.annotate({
210
- identifier: `${sanitizeHttpName(operationId)}ToolInput`
211
- }));
212
- }
213
- });
214
- return schemas;
215
- };
216
- var parseJsonObject = Effect.fn("Http.parseJsonObject")(function* (value, label) {
217
- if (!value)
218
- return {};
219
- return yield* Schema.decodeUnknownEffect(JsonObjectFromString)(value).pipe(Effect.mapError(() => new Error(`${label} must be a JSON object`)));
220
- });
221
- var parseJsonValue = Effect.fn("Http.parseJsonValue")(function* (value, label) {
222
- if (!value)
223
- return;
224
- return yield* Schema.decodeUnknownEffect(JsonValueFromString)(value).pipe(Effect.mapError(() => new Error(`${label} must be valid JSON`)));
225
- });
226
-
227
- class HttpApiSpec extends Context.Service()("HttpApiSpec", {
228
- make: (config) => Effect.try({
229
- try: () => {
230
- const api = config.api;
231
- if (!HttpApi.isHttpApi(api)) {
232
- throw new Error("HttpApiSpec requires a valid HttpApi");
233
- }
234
- const spec = OpenApi.fromApi(api);
235
- const reflectedSchemas = reflectedOperationInputSchemas(api);
236
- const operations = httpApiOperations({
237
- spec,
238
- methods: config.methods
239
- }).filter((operation) => config.include?.(operation) ?? true);
240
- const operationJsonSchema = (operation) => {
241
- const schema = httpApiOperationInputSchema(operation);
242
- const document = JsonSchema.fromSchemaOpenApi3_1({
243
- ...schema,
244
- $defs: spec.components?.schemas
245
- });
246
- const definitions = document.definitions ?? {};
247
- const usedDefinitions = referencedDefinitions(document.schema, definitions);
248
- const result = { ...document.schema };
249
- if (Object.keys(usedDefinitions).length > 0) {
250
- result.$defs = usedDefinitions;
251
- }
252
- return result;
253
- };
254
- return {
255
- info: spec.info,
256
- operations,
257
- decodeOperationInput: decodeHttpApiOperationInput,
258
- operationJsonSchema,
259
- operationSchema: (operation) => {
260
- const reflected = operation.operationId ? reflectedSchemas.get(operation.operationId) : undefined;
261
- if (reflected)
262
- return reflected;
263
- const document = JsonSchema.fromSchemaOpenApi3_1(operationJsonSchema(operation));
264
- return reflectedSchema(SchemaRepresentation.fromJsonSchemaDocument(document));
265
- }
266
- };
267
- },
268
- catch: (error) => toHttpError("Failed to build HTTP API spec", error)
269
- })
270
- }) {
271
- static layer = (config) => Layer.effect(this, this.make(config));
272
- }
273
- export {
274
- HttpApiMethods,
275
- HttpApiSpec,
276
- JsonObjectSchema,
277
- decodeHttpApiOperationInput,
278
- httpApiOperationInputSchema,
279
- httpApiOperations,
280
- httpApiToolEntries,
281
- httpApiToolName,
282
- parseJsonObject,
283
- parseJsonValue,
284
- sanitizeHttpName,
285
- toHttpError
286
- };
@@ -1,20 +0,0 @@
1
- import { Context, Effect, Layer } from "effect";
2
- import { McpSchema, McpServer } from "effect/ai";
3
- import { ApiClient } from "./httpapi-client.js";
4
- import { HttpApiSpec } from "./httpapi-helpers.js";
5
- export type HttpApiMcpConfig = {
6
- readonly toolMetaKey?: string;
7
- };
8
- declare const HttpApiMcp_base: Context.ServiceClass<HttpApiMcp, "HttpApiMcp", {
9
- registerTools: Effect.Effect<void, Error, McpServer.McpServer>;
10
- }> & {
11
- readonly make: (config: HttpApiMcpConfig) => Effect.Effect<{
12
- registerTools: Effect.Effect<void, Error, McpServer.McpServer>;
13
- }, never, ApiClient | HttpApiSpec>;
14
- };
15
- export declare class HttpApiMcp extends HttpApiMcp_base {
16
- static readonly layer: (config: HttpApiMcpConfig) => Layer.Layer<HttpApiMcp, never, ApiClient | HttpApiSpec>;
17
- }
18
- export declare const httpApiMcpToolsLayer: Layer.Layer<never, Error, HttpApiMcp | McpServer.McpServer>;
19
- export declare const httpApiMcpServerLayer: (path: Parameters<typeof McpServer.layerHttp>[0]["path"]) => Layer.Layer<McpServer.McpServer | McpSchema.McpServerClient, import("effect/Cause").IllegalArgumentError, HttpApiSpec | import("effect/http/HttpRouter").HttpRouter>;
20
- export {};