@krak-stack/registry 0.1.38 → 0.1.40
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.
- package/README.md +106 -29
- package/dist/components/ui/app-brand.js +17 -17
- package/dist/components/ui/code-block.js +4 -4
- package/dist/components/ui/copy-button.js +2 -2
- package/dist/components/ui/data-table.js +55 -55
- package/dist/components/ui/editing-locale-switcher.js +8 -8
- package/dist/components/ui/effect-form.js +12 -12
- package/dist/components/ui/error-component.js +6 -6
- package/dist/components/ui/file-picker.js +2 -2
- package/dist/components/ui/form.js +24 -24
- package/dist/components/ui/icon-input.js +5 -5
- package/dist/components/ui/locale-switcher.js +2 -2
- package/dist/components/ui/search-menu.js +2 -2
- package/dist/components/ui/sidebar-layout.js +1 -1
- package/dist/components/ui/theme-switcher.js +3 -3
- package/dist/lib/docs.js +52 -111
- package/dist/lib/docs.server.js +0 -28
- package/dist/lib/documentation-toolkit.js +0 -28
- package/dist/lib/httpapi-adapter.d.ts +73 -0
- package/dist/lib/httpapi-adapter.js +189 -0
- package/dist/lib/httpapi-cli.d.ts +4 -22
- package/dist/lib/httpapi-cli.js +199 -313
- package/dist/lib/httpapi-toolkit.d.ts +7 -16
- package/dist/lib/httpapi-toolkit.js +158 -214
- package/dist/lib/query.d.ts +30 -3
- package/dist/lib/query.js +13 -3
- package/dist/lib/webfetch-toolkit.d.ts +1 -1
- package/dist/lib/webfetch-toolkit.js +48 -50
- package/dist/oxlint/anti-slop/index.js +2 -2
- package/dist/services/agent/client/index.js +6 -6
- package/dist/services/agent/index.js +2 -2
- package/package.json +4 -12
- package/dist/lib/httpapi-client.d.ts +0 -34
- package/dist/lib/httpapi-client.js +0 -122
- package/dist/lib/httpapi-helpers.d.ts +0 -79
- package/dist/lib/httpapi-helpers.js +0 -130
- package/dist/lib/httpapi-mcp.d.ts +0 -25
- package/dist/lib/httpapi-mcp.js +0 -321
|
@@ -227,7 +227,7 @@ function CopyButton({
|
|
|
227
227
|
valueDescription,
|
|
228
228
|
copyVariant = "default",
|
|
229
229
|
locale: localeOverride,
|
|
230
|
-
messages
|
|
230
|
+
messages,
|
|
231
231
|
onCopied,
|
|
232
232
|
onCopyError,
|
|
233
233
|
resetDelay = 1500,
|
|
@@ -239,7 +239,7 @@ function CopyButton({
|
|
|
239
239
|
const locale = useKrakstackLocale(localeOverride);
|
|
240
240
|
const [copyState, setCopyState] = useState("idle");
|
|
241
241
|
const copyTimeout = useRef(undefined);
|
|
242
|
-
const labels = copyButtonMessages(locale,
|
|
242
|
+
const labels = copyButtonMessages(locale, messages);
|
|
243
243
|
const accessibleLabel = ariaLabel ?? (valueDescription ? `${labels.copy} ${valueDescription}` : labels.copy);
|
|
244
244
|
const isLarge = copyVariant === "large";
|
|
245
245
|
const defaultSize = copyVariant === "sm" ? "icon-xs" : isLarge ? "sm" : "icon-sm";
|
|
@@ -341,12 +341,12 @@ function CodeBlock({
|
|
|
341
341
|
code,
|
|
342
342
|
language = "text",
|
|
343
343
|
locale: localeOverride,
|
|
344
|
-
messages
|
|
344
|
+
messages
|
|
345
345
|
}) {
|
|
346
346
|
const locale = useKrakstackLocale2(localeOverride);
|
|
347
347
|
const normalizedLanguage = language.toLowerCase() || "text";
|
|
348
348
|
const highlighted = highlight(code, { lang: normalizedLanguage });
|
|
349
|
-
const labels = codeBlockMessages(locale,
|
|
349
|
+
const labels = codeBlockMessages(locale, messages);
|
|
350
350
|
return /* @__PURE__ */ jsxs2("div", {
|
|
351
351
|
className: "not-prose bg-muted overflow-hidden rounded-md border text-[var(--th-token)]",
|
|
352
352
|
"data-code-theme": true,
|
|
@@ -385,7 +385,7 @@ var MarkdownContent = ({
|
|
|
385
385
|
codeBlocks,
|
|
386
386
|
html,
|
|
387
387
|
locale,
|
|
388
|
-
messages
|
|
388
|
+
messages
|
|
389
389
|
}) => {
|
|
390
390
|
const content = [];
|
|
391
391
|
let remainingHtml = html;
|
|
@@ -404,7 +404,7 @@ var MarkdownContent = ({
|
|
|
404
404
|
code: block.code,
|
|
405
405
|
language: block.language,
|
|
406
406
|
locale,
|
|
407
|
-
messages
|
|
407
|
+
messages
|
|
408
408
|
})
|
|
409
409
|
}, `code-${index}`));
|
|
410
410
|
remainingHtml = remainingHtml.slice(markerIndex + marker.length);
|
|
@@ -282,8 +282,8 @@ class AgentService extends Context.Service()("AgentService", {
|
|
|
282
282
|
}));
|
|
283
283
|
});
|
|
284
284
|
const complete = Stream.fromEffect(Effect.gen(function* () {
|
|
285
|
-
const
|
|
286
|
-
return { type: "history", value:
|
|
285
|
+
const history = yield* conversation.exportJson;
|
|
286
|
+
return { type: "history", value: history };
|
|
287
287
|
})).pipe(Stream.concat(Stream.succeed({ type: "finish" })));
|
|
288
288
|
const response = Stream.concat(renderedRounds, complete).pipe(Stream.provideService(LanguageModel.LanguageModel, model), Stream.catch((error) => Stream.fromEffect(Effect.logError("Agent stream failed", streamErrorDetails(error))).pipe(Stream.drain, Stream.concat(Stream.make({
|
|
289
289
|
type: "error",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/registry",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "Tree-shakable KrakStack components and Effect services.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -37,17 +37,9 @@
|
|
|
37
37
|
"types": "./dist/lib/httpapi-cli.d.ts",
|
|
38
38
|
"import": "./dist/lib/httpapi-cli.js"
|
|
39
39
|
},
|
|
40
|
-
"./httpapi/
|
|
41
|
-
"types": "./dist/lib/httpapi-
|
|
42
|
-
"import": "./dist/lib/httpapi-
|
|
43
|
-
},
|
|
44
|
-
"./httpapi/helpers": {
|
|
45
|
-
"types": "./dist/lib/httpapi-helpers.d.ts",
|
|
46
|
-
"import": "./dist/lib/httpapi-helpers.js"
|
|
47
|
-
},
|
|
48
|
-
"./httpapi/mcp": {
|
|
49
|
-
"types": "./dist/lib/httpapi-mcp.d.ts",
|
|
50
|
-
"import": "./dist/lib/httpapi-mcp.js"
|
|
40
|
+
"./httpapi/adapter": {
|
|
41
|
+
"types": "./dist/lib/httpapi-adapter.d.ts",
|
|
42
|
+
"import": "./dist/lib/httpapi-adapter.js"
|
|
51
43
|
},
|
|
52
44
|
"./opentelemetry/api": {
|
|
53
45
|
"types": "./dist/services/opentelemetry/api.d.ts",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer, Schema } from "effect";
|
|
2
|
-
import { HttpClient } from "effect/http";
|
|
3
|
-
import { HttpApi, HttpApiGroup } from "effect/http-api";
|
|
4
|
-
import type { HttpApiOperationEntry, HttpApiOperationInput } from "./httpapi-helpers.js";
|
|
5
|
-
import type { Json } from "effect/Schema";
|
|
6
|
-
export type ApiClientConfig<Id extends string, Groups extends HttpApiGroup.Constraint> = {
|
|
7
|
-
readonly api: HttpApi.HttpApi<Id, Groups>;
|
|
8
|
-
readonly baseUrl: string;
|
|
9
|
-
readonly encodeResult?: (result: ErrorOptions["cause"], operation: HttpApiOperationEntry) => Effect.Effect<Json, Error>;
|
|
10
|
-
};
|
|
11
|
-
export type ApiClientExecuteOptions = {
|
|
12
|
-
readonly operation: HttpApiOperationEntry;
|
|
13
|
-
readonly input: HttpApiOperationInput;
|
|
14
|
-
};
|
|
15
|
-
export declare const executeHttpApiOperation: (options: {
|
|
16
|
-
readonly operation: HttpApiOperationEntry;
|
|
17
|
-
readonly input: Partial<HttpApiOperationInput>;
|
|
18
|
-
}, client: ApiClientService) => Effect.Effect<unknown, Error, never>;
|
|
19
|
-
export type HttpApiOperationResultValue = null | undefined | string | number | boolean | Date | Uint8Array | ReadonlyArray<HttpApiOperationResultValue> | {
|
|
20
|
-
readonly [key: string]: HttpApiOperationResultValue;
|
|
21
|
-
};
|
|
22
|
-
export declare const HttpApiOperationResult: Schema.Union<readonly [Schema.Codec<HttpApiOperationResultValue, Json, never, never>, Schema.Undefined]>;
|
|
23
|
-
export type HttpApiOperationResult = typeof HttpApiOperationResult.Type;
|
|
24
|
-
export declare const encodeHttpApiOperationResult: (result: unknown) => Effect.Effect<string | number | boolean | Schema.JsonArray | Schema.JsonObject | null, Error, never>;
|
|
25
|
-
export declare const makeHttpApiOperationResultEncoder: <Id extends string, Groups extends HttpApiGroup.Constraint>(api: HttpApi.HttpApi<Id, Groups>) => (result: unknown, operation: HttpApiOperationEntry) => Effect.Effect<string | number | boolean | Schema.JsonArray | Schema.JsonObject | null, Error, never>;
|
|
26
|
-
export type ApiClientService = {
|
|
27
|
-
readonly encodeResult: (result: ErrorOptions["cause"], operation: HttpApiOperationEntry) => Effect.Effect<Json, Error>;
|
|
28
|
-
readonly execute: (options: ApiClientExecuteOptions) => Effect.Effect<ErrorOptions["cause"], Error>;
|
|
29
|
-
};
|
|
30
|
-
declare const ApiClient_base: Context.ServiceClass<ApiClient, "ApiClient", ApiClientService>;
|
|
31
|
-
export declare class ApiClient extends ApiClient_base {
|
|
32
|
-
static readonly layer: <Id extends string, Groups extends HttpApiGroup.Constraint>(config: ApiClientConfig<Id, Groups>) => Layer.Layer<ApiClient, never, HttpClient.HttpClient | Exclude<import("effect/http-api/HttpApiMiddleware").MiddlewareClient<import("effect/http-api/HttpApiEndpoint").Middleware<HttpApiGroup.Endpoints<Groups>>>, import("effect/Scope").Scope>>;
|
|
33
|
-
}
|
|
34
|
-
export {};
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
// ../../src/lib/httpapi-client.ts
|
|
2
|
-
import { Context, Effect, Layer, Schema, SchemaTransformation } from "effect";
|
|
3
|
-
import { HttpClient } from "effect/http";
|
|
4
|
-
import {
|
|
5
|
-
HttpApi,
|
|
6
|
-
HttpApiClient as EffectHttpApiClient,
|
|
7
|
-
OpenApi
|
|
8
|
-
} from "effect/http-api";
|
|
9
|
-
var executeHttpApiOperation = Effect.fn("HttpApiClient.executeOperation")((options, client) => client.execute({
|
|
10
|
-
operation: options.operation,
|
|
11
|
-
input: {
|
|
12
|
-
body: options.input.body,
|
|
13
|
-
headers: options.input.headers ?? {},
|
|
14
|
-
params: options.input.params ?? {},
|
|
15
|
-
query: options.input.query ?? {}
|
|
16
|
-
}
|
|
17
|
-
}));
|
|
18
|
-
var UndefinedFromNull = Schema.Null.pipe(Schema.decodeTo(Schema.Undefined, SchemaTransformation.transform({
|
|
19
|
-
decode: () => {
|
|
20
|
-
return;
|
|
21
|
-
},
|
|
22
|
-
encode: () => null
|
|
23
|
-
})));
|
|
24
|
-
var HttpApiOperationResultValue = Schema.suspend(() => Schema.Union([
|
|
25
|
-
Schema.Null,
|
|
26
|
-
UndefinedFromNull,
|
|
27
|
-
Schema.String,
|
|
28
|
-
Schema.Number,
|
|
29
|
-
Schema.Boolean,
|
|
30
|
-
Schema.DateFromString,
|
|
31
|
-
Schema.Uint8ArrayFromBase64,
|
|
32
|
-
Schema.Array(HttpApiOperationResultValue),
|
|
33
|
-
Schema.Record(Schema.String, HttpApiOperationResultValue)
|
|
34
|
-
]));
|
|
35
|
-
var HttpApiOperationResult = Schema.Union([
|
|
36
|
-
HttpApiOperationResultValue,
|
|
37
|
-
Schema.Undefined
|
|
38
|
-
]).annotate({ identifier: "HttpApiOperationResult" });
|
|
39
|
-
var encodeHttpApiOperationResult = Effect.fn("HttpApiClient.encodeOperationResult")((result) => Schema.encodeUnknownEffect(HttpApiOperationResult)(result).pipe(Effect.map((encoded) => encoded ?? null), Effect.mapError((cause) => new Error("HTTP API result is not serializable", { cause }))));
|
|
40
|
-
var reflectedSchema = (schema) => Schema.make(schema.ast);
|
|
41
|
-
var operationResultSchemas = (api) => {
|
|
42
|
-
const schemas = new Map;
|
|
43
|
-
HttpApi.reflect(api, {
|
|
44
|
-
onGroup: () => {
|
|
45
|
-
return;
|
|
46
|
-
},
|
|
47
|
-
onEndpoint: ({ endpoint, group, successes }) => {
|
|
48
|
-
const operationId = Context.getOrElse(endpoint.annotations, OpenApi.Identifier, () => group.topLevel ? endpoint.identifier : `${group.identifier}.${endpoint.identifier}`);
|
|
49
|
-
const operationSchemas = Array.from(successes.values()).flat().map(reflectedSchema);
|
|
50
|
-
if (operationSchemas.length === 1 && operationSchemas[0]) {
|
|
51
|
-
schemas.set(operationId, operationSchemas[0]);
|
|
52
|
-
} else if (operationSchemas.length > 1) {
|
|
53
|
-
schemas.set(operationId, Schema.Union(operationSchemas));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return schemas;
|
|
58
|
-
};
|
|
59
|
-
var makeHttpApiOperationResultEncoder = (api) => {
|
|
60
|
-
const schemas = operationResultSchemas(api);
|
|
61
|
-
return Effect.fn("HttpApiClient.encodeOperationResultWithSchema")((result, operation) => {
|
|
62
|
-
const operationId = operation.operation.operationId;
|
|
63
|
-
const schema = operationId ? schemas.get(operationId) : undefined;
|
|
64
|
-
if (!schema)
|
|
65
|
-
return encodeHttpApiOperationResult(result);
|
|
66
|
-
return Schema.encodeUnknownEffect(schema)(result).pipe(Effect.flatMap(encodeHttpApiOperationResult), Effect.mapError((cause) => new Error("HTTP API result does not match its success schema", {
|
|
67
|
-
cause
|
|
68
|
-
})));
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
var GeneratedOperation = Schema.declare((value) => value instanceof Function).annotate({ identifier: "GeneratedOperation" });
|
|
72
|
-
var GeneratedOperationEffect = Schema.declare((value) => Effect.isEffect(value)).annotate({ identifier: "GeneratedOperationEffect" });
|
|
73
|
-
var makeGeneratedClient = (api, http, baseUrl) => EffectHttpApiClient.makeWith(api, {
|
|
74
|
-
baseUrl,
|
|
75
|
-
httpClient: http
|
|
76
|
-
});
|
|
77
|
-
var executeGeneratedOperation = Effect.fn("HttpApiClient.executeGeneratedOperation")(function* (client, { input, operation: entry }) {
|
|
78
|
-
const operationId = entry.operation.operationId;
|
|
79
|
-
if (!operationId) {
|
|
80
|
-
return yield* Effect.fail(new Error(`No generated API client operation for ${entry.method} ${entry.path}`));
|
|
81
|
-
}
|
|
82
|
-
const target = Object(client);
|
|
83
|
-
const groupName = Object.keys(target).filter((name) => operationId.startsWith(`${name}.`)).sort((a, b) => b.length - a.length)[0];
|
|
84
|
-
const group = groupName ? Object.entries(target).find(([name]) => name === groupName)?.[1] : target;
|
|
85
|
-
const endpointName = groupName ? operationId.slice(groupName.length + 1) : operationId;
|
|
86
|
-
const endpointCandidate = group instanceof Function ? undefined : Object.entries(Object(group)).find(([name]) => name === endpointName)?.[1];
|
|
87
|
-
const endpoint = Schema.decodeUnknownOption(GeneratedOperation)(endpointCandidate);
|
|
88
|
-
if (endpoint._tag === "None") {
|
|
89
|
-
return yield* Effect.fail(new Error(`No generated API client operation for ${operationId}`));
|
|
90
|
-
}
|
|
91
|
-
const result = Schema.decodeUnknownOption(GeneratedOperationEffect)(endpoint.value({
|
|
92
|
-
headers: input.headers,
|
|
93
|
-
params: input.params,
|
|
94
|
-
query: input.query,
|
|
95
|
-
payload: input.body
|
|
96
|
-
}));
|
|
97
|
-
if (result._tag === "None") {
|
|
98
|
-
return yield* Effect.fail(new Error(`Generated API client operation ${operationId} is invalid`));
|
|
99
|
-
}
|
|
100
|
-
return yield* result.value;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
class ApiClient extends Context.Service()("ApiClient") {
|
|
104
|
-
static layer = (config) => Layer.effect(this, Effect.gen(function* () {
|
|
105
|
-
const http = yield* HttpClient.HttpClient;
|
|
106
|
-
const encodeResult = makeHttpApiOperationResultEncoder(config.api);
|
|
107
|
-
const client = yield* makeGeneratedClient(config.api, http, config.baseUrl);
|
|
108
|
-
return {
|
|
109
|
-
encodeResult: config.encodeResult ?? ((result, operation) => encodeResult(result, operation)),
|
|
110
|
-
execute: Effect.fn("ApiClient.execute")(function* (options) {
|
|
111
|
-
return yield* executeGeneratedOperation(client, options);
|
|
112
|
-
})
|
|
113
|
-
};
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
export {
|
|
117
|
-
ApiClient,
|
|
118
|
-
HttpApiOperationResult,
|
|
119
|
-
encodeHttpApiOperationResult,
|
|
120
|
-
executeHttpApiOperation,
|
|
121
|
-
makeHttpApiOperationResultEncoder
|
|
122
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, JsonSchema, Layer, Schema } from "effect";
|
|
2
|
-
import type { Json } from "effect/Schema";
|
|
3
|
-
import { HttpApi, OpenApi } from "effect/http-api";
|
|
4
|
-
export declare const JsonObjectSchema: Schema.$Record<Schema.String, Schema.Codec<Json, Json, never, never>>;
|
|
5
|
-
export type JsonObject = typeof JsonObjectSchema.Type;
|
|
6
|
-
export type HttpApiDocument = ReturnType<typeof OpenApi.fromApi>;
|
|
7
|
-
export type HttpApiMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
8
|
-
export declare const HttpApiMethods: ReadonlyArray<HttpApiMethod>;
|
|
9
|
-
export type HttpApiParameter = {
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly in: "path" | "query" | "header" | "cookie";
|
|
12
|
-
readonly required?: boolean;
|
|
13
|
-
readonly description?: string;
|
|
14
|
-
readonly schema?: JsonSchema.JsonSchema;
|
|
15
|
-
};
|
|
16
|
-
export type HttpApiOperation = {
|
|
17
|
-
readonly operationId?: string;
|
|
18
|
-
readonly summary?: string;
|
|
19
|
-
readonly description?: string;
|
|
20
|
-
readonly parameters?: ReadonlyArray<HttpApiParameter>;
|
|
21
|
-
readonly requestBody?: {
|
|
22
|
-
readonly required?: boolean;
|
|
23
|
-
readonly content?: Record<string, {
|
|
24
|
-
readonly schema?: JsonSchema.JsonSchema;
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
readonly tags?: ReadonlyArray<string>;
|
|
28
|
-
};
|
|
29
|
-
export type HttpApiOperationEntry = {
|
|
30
|
-
readonly method: HttpApiMethod;
|
|
31
|
-
readonly path: string;
|
|
32
|
-
readonly operation: HttpApiOperation;
|
|
33
|
-
};
|
|
34
|
-
export type HttpApiOperationInputValue = ErrorOptions["cause"];
|
|
35
|
-
export type HttpApiOperationInputValues = Readonly<Record<string, HttpApiOperationInputValue>>;
|
|
36
|
-
export type HttpApiOperationInput = {
|
|
37
|
-
readonly body?: HttpApiOperationInputValue;
|
|
38
|
-
readonly headers: HttpApiOperationInputValues;
|
|
39
|
-
readonly params: HttpApiOperationInputValues;
|
|
40
|
-
readonly query: HttpApiOperationInputValues;
|
|
41
|
-
};
|
|
42
|
-
export type HttpApiOperationDefinition = HttpApiOperationEntry & {
|
|
43
|
-
readonly name: string;
|
|
44
|
-
readonly inputSchema: Schema.Codec<Partial<HttpApiOperationInput>, Json>;
|
|
45
|
-
readonly inputJsonSchema: JsonSchema.JsonSchema;
|
|
46
|
-
readonly readOnly: boolean;
|
|
47
|
-
readonly destructive: boolean;
|
|
48
|
-
readonly idempotent: boolean;
|
|
49
|
-
};
|
|
50
|
-
export type HttpApiSpecConfig = {
|
|
51
|
-
readonly api: HttpApi.Constraint;
|
|
52
|
-
readonly methods?: ReadonlyArray<HttpApiMethod>;
|
|
53
|
-
readonly include?: (operation: HttpApiOperationEntry) => boolean;
|
|
54
|
-
};
|
|
55
|
-
export declare const toHttpError: (message: string, error: ErrorOptions["cause"]) => Error;
|
|
56
|
-
export declare const sanitizeHttpName: (name: string) => string;
|
|
57
|
-
export declare const httpApiToolName: (method: string, path: string, operation: HttpApiOperation) => string;
|
|
58
|
-
export declare const httpApiOperations: ({ spec, methods, }: {
|
|
59
|
-
readonly spec: HttpApiDocument;
|
|
60
|
-
readonly methods?: ReadonlyArray<HttpApiMethod>;
|
|
61
|
-
}) => ReadonlyArray<HttpApiOperationEntry>;
|
|
62
|
-
export declare const parseJsonObject: (value: string | undefined, label: string) => Effect.Effect<{
|
|
63
|
-
readonly [x: string]: Json;
|
|
64
|
-
}, Error, never>;
|
|
65
|
-
export declare const parseJsonValue: (value: string | undefined, label: string) => Effect.Effect<Json | undefined, Error, never>;
|
|
66
|
-
declare const HttpApiSpec_base: Context.ServiceClass<HttpApiSpec, "HttpApiSpec", {
|
|
67
|
-
info: OpenApi.OpenAPISpecInfo;
|
|
68
|
-
operations: readonly HttpApiOperationDefinition[];
|
|
69
|
-
}> & {
|
|
70
|
-
readonly make: (config: HttpApiSpecConfig) => Effect.Effect<{
|
|
71
|
-
info: OpenApi.OpenAPISpecInfo;
|
|
72
|
-
operations: readonly HttpApiOperationDefinition[];
|
|
73
|
-
}, Error, never>;
|
|
74
|
-
};
|
|
75
|
-
export declare class HttpApiSpec extends HttpApiSpec_base {
|
|
76
|
-
static readonly layer: (config: HttpApiSpecConfig) => Layer.Layer<HttpApiSpec, Error, never>;
|
|
77
|
-
}
|
|
78
|
-
export type HttpApiSpecService = typeof HttpApiSpec.Service;
|
|
79
|
-
export {};
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// ../../src/lib/httpapi-helpers.tsx
|
|
2
|
-
import { Context, Effect, Layer, Option, Schema } from "effect";
|
|
3
|
-
import { HttpApi, OpenApi } from "effect/http-api";
|
|
4
|
-
var JsonObjectSchema = Schema.Record(Schema.String, Schema.Json).annotate({
|
|
5
|
-
identifier: "HttpJsonObject",
|
|
6
|
-
title: "HTTP JSON object",
|
|
7
|
-
description: "A JSON object passed to an HTTP API operation.",
|
|
8
|
-
examples: [{ id: "example-id" }]
|
|
9
|
-
});
|
|
10
|
-
var JsonObjectFromString = Schema.fromJsonString(JsonObjectSchema);
|
|
11
|
-
var JsonValueFromString = Schema.fromJsonString(Schema.Json);
|
|
12
|
-
var HttpApiMethods = [
|
|
13
|
-
"get",
|
|
14
|
-
"post",
|
|
15
|
-
"put",
|
|
16
|
-
"patch",
|
|
17
|
-
"delete"
|
|
18
|
-
];
|
|
19
|
-
var HttpApiOperationSchema = Schema.declare((value) => Schema.is(JsonObjectSchema)(value)).annotate({ identifier: "HttpApiOperation" });
|
|
20
|
-
var decodeHttpApiOperation = Schema.decodeUnknownOption(HttpApiOperationSchema);
|
|
21
|
-
var toHttpError = (message, error) => new Error(message, { cause: error });
|
|
22
|
-
var sanitizeHttpName = (name) => name.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
23
|
-
var httpApiToolName = (method, path, operation) => {
|
|
24
|
-
const fallback = `${method}_${path.replace(/^\/api\//, "").replace(/[/:{}]/g, "_")}`;
|
|
25
|
-
return (operation.operationId || fallback).replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").slice(0, 64);
|
|
26
|
-
};
|
|
27
|
-
var httpApiOperations = ({
|
|
28
|
-
spec,
|
|
29
|
-
methods = HttpApiMethods
|
|
30
|
-
}) => {
|
|
31
|
-
const operations = [];
|
|
32
|
-
for (const [path, pathItem] of Object.entries(spec.paths)) {
|
|
33
|
-
for (const method of methods) {
|
|
34
|
-
const operation = decodeHttpApiOperation(pathItem[method]);
|
|
35
|
-
if (Option.isSome(operation))
|
|
36
|
-
operations.push({ method, path, operation: operation.value });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return operations;
|
|
40
|
-
};
|
|
41
|
-
var reflectedSchema = (schema) => Schema.make(schema.ast);
|
|
42
|
-
var reflectedOperationInputSchemas = (api) => {
|
|
43
|
-
const schemas = new Map;
|
|
44
|
-
HttpApi.reflect(api, {
|
|
45
|
-
onGroup: () => {
|
|
46
|
-
return;
|
|
47
|
-
},
|
|
48
|
-
onEndpoint: ({ endpoint, group }) => {
|
|
49
|
-
const operationId = Context.getOrElse(endpoint.annotations, OpenApi.Identifier, () => group.topLevel ? endpoint.identifier : `${group.identifier}.${endpoint.identifier}`);
|
|
50
|
-
const fields = {};
|
|
51
|
-
if (endpoint.params)
|
|
52
|
-
fields.params = Schema.toType(reflectedSchema(endpoint.params));
|
|
53
|
-
if (endpoint.query)
|
|
54
|
-
fields.query = Schema.optionalKey(Schema.toType(reflectedSchema(endpoint.query)));
|
|
55
|
-
if (endpoint.headers)
|
|
56
|
-
fields.headers = Schema.optionalKey(Schema.toType(reflectedSchema(endpoint.headers)));
|
|
57
|
-
const payloads = Array.from(endpoint.payload.values()).flatMap(({ schemas: schemas2 }) => schemas2.map(reflectedSchema));
|
|
58
|
-
if (payloads.length === 1 && payloads[0])
|
|
59
|
-
fields.body = payloads[0];
|
|
60
|
-
else if (payloads.length > 1)
|
|
61
|
-
fields.body = Schema.Union(payloads);
|
|
62
|
-
const input = Object.keys(fields).length === 0 ? Schema.Record(Schema.String, Schema.Never) : Schema.Struct(fields);
|
|
63
|
-
schemas.set(operationId, Schema.make(Schema.toCodecJson(input).ast).annotate({ identifier: `${sanitizeHttpName(operationId)}ToolInput` }));
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return schemas;
|
|
67
|
-
};
|
|
68
|
-
var parseJsonObject = Effect.fn("Http.parseJsonObject")(function* (value, label) {
|
|
69
|
-
if (!value)
|
|
70
|
-
return {};
|
|
71
|
-
return yield* Schema.decodeUnknownEffect(JsonObjectFromString)(value).pipe(Effect.mapError(() => new Error(`${label} must be a JSON object`)));
|
|
72
|
-
});
|
|
73
|
-
var parseJsonValue = Effect.fn("Http.parseJsonValue")(function* (value, label) {
|
|
74
|
-
if (!value)
|
|
75
|
-
return;
|
|
76
|
-
return yield* Schema.decodeUnknownEffect(JsonValueFromString)(value).pipe(Effect.mapError(() => new Error(`${label} must be valid JSON`)));
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
class HttpApiSpec extends Context.Service()("HttpApiSpec", {
|
|
80
|
-
make: (config) => Effect.try({
|
|
81
|
-
try: () => {
|
|
82
|
-
const api = config.api;
|
|
83
|
-
if (!HttpApi.isHttpApi(api))
|
|
84
|
-
throw new Error("HttpApiSpec requires a valid HttpApi");
|
|
85
|
-
const spec = OpenApi.fromApi(api);
|
|
86
|
-
const schemas = reflectedOperationInputSchemas(api);
|
|
87
|
-
const names = new Set;
|
|
88
|
-
const operations = httpApiOperations({
|
|
89
|
-
spec,
|
|
90
|
-
methods: config.methods
|
|
91
|
-
}).filter((entry) => config.include?.(entry) ?? true).map((entry) => {
|
|
92
|
-
const name = httpApiToolName(entry.method, entry.path, entry.operation);
|
|
93
|
-
if (!name || names.has(name))
|
|
94
|
-
throw new Error(`Duplicate or empty HTTP API tool name: ${name}`);
|
|
95
|
-
names.add(name);
|
|
96
|
-
const inputSchema = entry.operation.operationId ? schemas.get(entry.operation.operationId) : undefined;
|
|
97
|
-
if (!inputSchema)
|
|
98
|
-
throw new Error(`Missing endpoint schema for ${entry.operation.operationId}`);
|
|
99
|
-
const document = Schema.toJsonSchemaDocument(inputSchema.annotate({ identifier: undefined }));
|
|
100
|
-
return {
|
|
101
|
-
...entry,
|
|
102
|
-
name,
|
|
103
|
-
inputSchema,
|
|
104
|
-
inputJsonSchema: {
|
|
105
|
-
...document.schema,
|
|
106
|
-
$defs: document.definitions
|
|
107
|
-
},
|
|
108
|
-
readOnly: entry.method === "get",
|
|
109
|
-
destructive: entry.method === "delete",
|
|
110
|
-
idempotent: entry.method === "get" || entry.method === "put" || entry.method === "delete"
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
return { info: spec.info, operations };
|
|
114
|
-
},
|
|
115
|
-
catch: (error) => toHttpError("Failed to build HTTP API spec", error)
|
|
116
|
-
})
|
|
117
|
-
}) {
|
|
118
|
-
static layer = (config) => Layer.effect(this, this.make(config));
|
|
119
|
-
}
|
|
120
|
-
export {
|
|
121
|
-
HttpApiMethods,
|
|
122
|
-
HttpApiSpec,
|
|
123
|
-
JsonObjectSchema,
|
|
124
|
-
httpApiOperations,
|
|
125
|
-
httpApiToolName,
|
|
126
|
-
parseJsonObject,
|
|
127
|
-
parseJsonValue,
|
|
128
|
-
sanitizeHttpName,
|
|
129
|
-
toHttpError
|
|
130
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Context, Effect, Layer } from "effect";
|
|
2
|
-
import { McpServer } from "effect/ai";
|
|
3
|
-
import type { HttpApiGroup } from "effect/http-api";
|
|
4
|
-
import { ApiClient, type ApiClientConfig } from "./httpapi-client.js";
|
|
5
|
-
import { HttpApiSpec, type HttpApiSpecConfig } from "./httpapi-helpers.js";
|
|
6
|
-
export type HttpApiMcpConfig = {
|
|
7
|
-
readonly toolMetaKey?: string;
|
|
8
|
-
};
|
|
9
|
-
export type HttpApiMcpHttpConfig<Id extends string, Groups extends HttpApiGroup.Constraint> = ApiClientConfig<Id, Groups> & Pick<HttpApiSpecConfig, "methods" | "include"> & HttpApiMcpConfig & {
|
|
10
|
-
readonly path?: Parameters<typeof McpServer.layerHttp>[0]["path"];
|
|
11
|
-
};
|
|
12
|
-
declare const HttpApiMcp_base: Context.ServiceClass<HttpApiMcp, "HttpApiMcp", {
|
|
13
|
-
registerTools: Effect.Effect<void, never, ApiClient | McpServer.McpServer>;
|
|
14
|
-
}> & {
|
|
15
|
-
readonly make: (config: HttpApiMcpConfig) => Effect.Effect<{
|
|
16
|
-
registerTools: Effect.Effect<void, never, ApiClient | McpServer.McpServer>;
|
|
17
|
-
}, never, HttpApiSpec>;
|
|
18
|
-
};
|
|
19
|
-
export declare class HttpApiMcp extends HttpApiMcp_base {
|
|
20
|
-
static readonly layer: (config: HttpApiMcpConfig) => Layer.Layer<HttpApiMcp, never, HttpApiSpec>;
|
|
21
|
-
static readonly layerHttp: <Id extends string, Groups extends HttpApiGroup.Constraint>(config: HttpApiMcpHttpConfig<Id, Groups>) => Layer.Layer<McpServer.McpServer | import("effect/ai/McpSchema").McpServerClient, Error | import("effect/Cause").IllegalArgumentError, import("effect/http/HttpClient").HttpClient | import("effect/http/HttpRouter").HttpRouter | Exclude<import("effect/http-api/HttpApiMiddleware").MiddlewareClient<import("effect/http-api/HttpApiEndpoint").Middleware<HttpApiGroup.Endpoints<Groups>>>, import("effect/Scope").Scope>>;
|
|
22
|
-
}
|
|
23
|
-
export declare const httpApiMcpToolsLayer: Layer.Layer<never, never, ApiClient | HttpApiMcp | McpServer.McpServer>;
|
|
24
|
-
export declare const httpApiMcpServerLayer: (path: Parameters<typeof McpServer.layerHttp>[0]["path"]) => Layer.Layer<McpServer.McpServer | import("effect/ai/McpSchema").McpServerClient, import("effect/Cause").IllegalArgumentError, HttpApiSpec | import("effect/http/HttpRouter").HttpRouter>;
|
|
25
|
-
export {};
|