@r_masseater/masseater-utils 0.0.0 → 0.1.2

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 (130) hide show
  1. package/LICENSE +87 -0
  2. package/README.md +97 -1
  3. package/dist/context-B_4aJtEC.mjs +6 -0
  4. package/dist/context-B_4aJtEC.mjs.map +1 -0
  5. package/dist/failure-CjeINRVu.mjs +19 -0
  6. package/dist/failure-CjeINRVu.mjs.map +1 -0
  7. package/dist/github-workflow.d.mts +77 -0
  8. package/dist/github-workflow.mjs +110 -0
  9. package/dist/github-workflow.mjs.map +1 -0
  10. package/dist/index-CUo4CRam.d.mts +1 -0
  11. package/dist/index-Cb8YSEwo.d.mts +31 -0
  12. package/dist/index-DudHILTn.d.mts +6 -0
  13. package/dist/index-KNezbJnC.d.mts +121 -0
  14. package/dist/kestrion-node.d.mts +6 -0
  15. package/dist/kestrion-node.mjs +9 -0
  16. package/dist/kestrion-node.mjs.map +1 -0
  17. package/dist/kestrion-npm.d.mts +25 -0
  18. package/dist/kestrion-npm.mjs +54 -0
  19. package/dist/kestrion-npm.mjs.map +1 -0
  20. package/dist/kestrion-pnpm.d.mts +29 -0
  21. package/dist/kestrion-pnpm.mjs +68 -0
  22. package/dist/kestrion-pnpm.mjs.map +1 -0
  23. package/dist/kestrion.d.mts +2 -0
  24. package/dist/kestrion.mjs +46 -0
  25. package/dist/kestrion.mjs.map +1 -0
  26. package/dist/mapped-import-mapper.d.mts +24 -0
  27. package/dist/mapped-import-mapper.mjs +34 -0
  28. package/dist/mapped-import-mapper.mjs.map +1 -0
  29. package/dist/mapped-import-vite.d.mts +21 -0
  30. package/dist/mapped-import-vite.mjs +49 -0
  31. package/dist/mapped-import-vite.mjs.map +1 -0
  32. package/dist/mapped-import.d.mts +2 -0
  33. package/dist/mapped-import.mjs +36 -0
  34. package/dist/mapped-import.mjs.map +1 -0
  35. package/dist/node-main.d.mts +19 -0
  36. package/dist/node-main.mjs +59 -0
  37. package/dist/node-main.mjs.map +1 -0
  38. package/dist/normalize-CogX79EO.mjs +76 -0
  39. package/dist/normalize-CogX79EO.mjs.map +1 -0
  40. package/dist/otlp-ohapzeFh.mjs +18 -0
  41. package/dist/otlp-ohapzeFh.mjs.map +1 -0
  42. package/dist/otlp-schema-CDBPGJ5s.mjs +125 -0
  43. package/dist/otlp-schema-CDBPGJ5s.mjs.map +1 -0
  44. package/dist/otlp-spans-D88555DO.mjs +52 -0
  45. package/dist/otlp-spans-D88555DO.mjs.map +1 -0
  46. package/dist/package-json-CYRyaF9U.mjs +58 -0
  47. package/dist/package-json-CYRyaF9U.mjs.map +1 -0
  48. package/dist/plugin-kit.d.mts +5663 -0
  49. package/dist/plugin-kit.mjs +11501 -0
  50. package/dist/plugin-kit.mjs.map +1 -0
  51. package/dist/receive-S2txZwcV.mjs +61 -0
  52. package/dist/receive-S2txZwcV.mjs.map +1 -0
  53. package/dist/route-handlers-Cn3O2hmf.mjs +14 -0
  54. package/dist/route-handlers-Cn3O2hmf.mjs.map +1 -0
  55. package/dist/route-handlers-E2lwhaAf.d.mts +14 -0
  56. package/dist/run-Cc5W9mi8.mjs +13 -0
  57. package/dist/run-Cc5W9mi8.mjs.map +1 -0
  58. package/dist/run-D59Owiv1.d.mts +5 -0
  59. package/dist/skerm.d.mts +6 -0
  60. package/dist/skerm.mjs +128 -0
  61. package/dist/skerm.mjs.map +1 -0
  62. package/dist/span-BKjRu617.mjs +60 -0
  63. package/dist/span-BKjRu617.mjs.map +1 -0
  64. package/dist/telemetry-BEWIE8tU.d.mts +51 -0
  65. package/dist/vitest-otlp-collector-files.d.mts +8 -0
  66. package/dist/vitest-otlp-collector-files.mjs +13 -0
  67. package/dist/vitest-otlp-collector-files.mjs.map +1 -0
  68. package/dist/vitest-otlp-current-receiver-8c7rIP1N.mjs +13 -0
  69. package/dist/vitest-otlp-current-receiver-8c7rIP1N.mjs.map +1 -0
  70. package/dist/vitest-otlp-current-receiver-DphmM9Ha.d.mts +10 -0
  71. package/dist/vitest-otlp-semconv.d.mts +3 -0
  72. package/dist/vitest-otlp-semconv.mjs +92 -0
  73. package/dist/vitest-otlp-semconv.mjs.map +1 -0
  74. package/dist/vitest-otlp-setup.d.mts +1 -0
  75. package/dist/vitest-otlp-setup.mjs +295 -0
  76. package/dist/vitest-otlp-setup.mjs.map +1 -0
  77. package/dist/vitest-otlp-tail-to-otlp.mjs +271 -0
  78. package/dist/vitest-otlp-tail-to-otlp.mjs.map +1 -0
  79. package/dist/vitest-otlp-workers.d.mts +26 -0
  80. package/dist/vitest-otlp-workers.mjs +54 -0
  81. package/dist/vitest-otlp-workers.mjs.map +1 -0
  82. package/dist/vitest-otlp.d.mts +51 -0
  83. package/dist/vitest-otlp.mjs +66 -0
  84. package/dist/vitest-otlp.mjs.map +1 -0
  85. package/dist/workers-tracing-alchemy.d.mts +22 -0
  86. package/dist/workers-tracing-alchemy.mjs +124 -0
  87. package/dist/workers-tracing-alchemy.mjs.map +1 -0
  88. package/dist/workers-tracing-browser-logs.d.mts +4 -0
  89. package/dist/workers-tracing-browser-logs.mjs +67 -0
  90. package/dist/workers-tracing-browser-logs.mjs.map +1 -0
  91. package/dist/workers-tracing-browser-spans.d.mts +4 -0
  92. package/dist/workers-tracing-browser-spans.mjs +13 -0
  93. package/dist/workers-tracing-browser-spans.mjs.map +1 -0
  94. package/dist/workers-tracing-effect-tracing.d.mts +8 -0
  95. package/dist/workers-tracing-effect-tracing.mjs +68 -0
  96. package/dist/workers-tracing-effect-tracing.mjs.map +1 -0
  97. package/dist/workers-tracing-effect-tracing.plain.d.mts +7 -0
  98. package/dist/workers-tracing-effect-tracing.plain.mjs +9 -0
  99. package/dist/workers-tracing-effect-tracing.plain.mjs.map +1 -0
  100. package/dist/workers-tracing-elysia.d.mts +5 -0
  101. package/dist/workers-tracing-elysia.mjs +53 -0
  102. package/dist/workers-tracing-elysia.mjs.map +1 -0
  103. package/dist/workers-tracing-elysia.plain.d.mts +3 -0
  104. package/dist/workers-tracing-elysia.plain.mjs +3 -0
  105. package/dist/workers-tracing-oxlint.d.mts +6 -0
  106. package/dist/workers-tracing-oxlint.mjs +8 -0
  107. package/dist/workers-tracing-oxlint.mjs.map +1 -0
  108. package/dist/workers-tracing-tanstack-start.d.mts +22 -0
  109. package/dist/workers-tracing-tanstack-start.mjs +28 -0
  110. package/dist/workers-tracing-tanstack-start.mjs.map +1 -0
  111. package/dist/workers-tracing-tanstack-start.plain.d.mts +9 -0
  112. package/dist/workers-tracing-tanstack-start.plain.mjs +10 -0
  113. package/dist/workers-tracing-tanstack-start.plain.mjs.map +1 -0
  114. package/dist/workers-tracing-trace-sink.d.mts +7 -0
  115. package/dist/workers-tracing-trace-sink.mjs +29 -0
  116. package/dist/workers-tracing-trace-sink.mjs.map +1 -0
  117. package/dist/workers-tracing-workers-ai.d.mts +33 -0
  118. package/dist/workers-tracing-workers-ai.mjs +108 -0
  119. package/dist/workers-tracing-workers-ai.mjs.map +1 -0
  120. package/package.json +252 -5
  121. package/skills/add-scroll-chip-row/SKILL.md +59 -0
  122. package/skills/assert-exported-telemetry/SKILL.md +131 -0
  123. package/skills/find-cache-folder/SKILL.md +36 -0
  124. package/skills/import-custom-format/SKILL.md +76 -0
  125. package/skills/read-hook-input/SKILL.md +39 -0
  126. package/skills/read-node-ecosystem/SKILL.md +131 -0
  127. package/skills/run-effect-main/SKILL.md +82 -0
  128. package/skills/trace-workers/SKILL.md +152 -0
  129. package/skills/write-actions-steps/SKILL.md +76 -0
  130. package/src/app/skerm.css +139 -0
@@ -0,0 +1,6 @@
1
+ export interface RestrictedSyntax {
2
+ readonly selector: string;
3
+ readonly message: string;
4
+ }
5
+ export declare const restrictedSyntax: readonly RestrictedSyntax[];
6
+ //# sourceMappingURL=workers-tracing-oxlint.d.mts.map
@@ -0,0 +1,8 @@
1
+ // src/app/workers-tracing-oxlint.ts
2
+ const restrictedSyntax = [{
3
+ selector: "CallExpression[callee.property.name=\"run\"][callee.object.property.name=\"AI\"]:not(CallExpression[callee.name=\"runWorkersAi\"] *)",
4
+ message: "Call Workers AI inside runWorkersAi from @r_masseater/masseater-utils/workers-tracing/workers-ai, so an out-of-capacity error is retried and a cut-off answer is logged."
5
+ }];
6
+ export { restrictedSyntax };
7
+
8
+ //# sourceMappingURL=workers-tracing-oxlint.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workers-tracing-oxlint.mjs","names":[],"sources":["../src/app/workers-tracing-oxlint.ts"],"sourcesContent":["export interface RestrictedSyntax {\n readonly selector: string;\n readonly message: string;\n}\n\nexport const restrictedSyntax: readonly RestrictedSyntax[] = [\n {\n selector:\n 'CallExpression[callee.property.name=\"run\"][callee.object.property.name=\"AI\"]:not(CallExpression[callee.name=\"runWorkersAi\"] *)',\n message:\n \"Call Workers AI inside runWorkersAi from @r_masseater/masseater-utils/workers-tracing/workers-ai, so an out-of-capacity error is retried and a cut-off answer is logged.\",\n },\n];\n"],"mappings":";AAKA,MAAa,mBAAgD,CAC3D;CACE,UACE;CACF,SACE;AACJ,CACF"}
@@ -0,0 +1,22 @@
1
+ export interface StartRequest<Result> {
2
+ readonly request: Request;
3
+ readonly pathname: string;
4
+ readonly handlerType: string;
5
+ readonly next: () => PromiseLike<Result> | Result;
6
+ }
7
+ export interface ServerFnCall<Result> {
8
+ readonly method: string;
9
+ readonly serverFnMeta: {
10
+ readonly id: string;
11
+ readonly name: string;
12
+ readonly filename: string;
13
+ };
14
+ readonly next: () => PromiseLike<Result> | Result;
15
+ }
16
+ export declare const traceRequest: <Result extends {
17
+ readonly response: Response;
18
+ }>({ request, pathname, handlerType, next }: StartRequest<Result>) => Promise<Result>;
19
+ export declare const traceServerFn: <Result>({ method, serverFnMeta, next }: ServerFnCall<Result>) => Promise<Result>;
20
+ export declare const requestSpan: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, unknown>;
21
+ export declare const serverFnSpan: import("@tanstack/react-start").FunctionMiddlewareAfterServer<{}, unknown, undefined, unknown, undefined, undefined, unknown>;
22
+ //# sourceMappingURL=workers-tracing-tanstack-start.d.mts.map
@@ -0,0 +1,28 @@
1
+ import { a as traced, i as requestSpans, r as recordStatus } from "./span-BKjRu617.mjs";
2
+ import { Function } from "effect";
3
+ import { tracing } from "cloudflare:workers";
4
+ import { createMiddleware } from "@tanstack/react-start";
5
+ // src/app/workers-tracing-tanstack-start.ts
6
+ const traceRequest = ({ request, pathname, handlerType, next }) => tracing.enterSpan(`${request.method} ${pathname}`, (span) => {
7
+ span.setAttributes({
8
+ "http.request.method": request.method,
9
+ "url.path": pathname,
10
+ "tanstack_start.handler": handlerType
11
+ });
12
+ requestSpans.set(request, span);
13
+ return traced(({ response }) => recordStatus(response.status))(next)(span);
14
+ });
15
+ const traceServerFn = ({ method, serverFnMeta, next }) => tracing.enterSpan(`serverFn ${serverFnMeta.name}`, (span) => {
16
+ span.setAttributes({
17
+ "tanstack_start.server_fn.id": serverFnMeta.id,
18
+ "tanstack_start.server_fn.name": serverFnMeta.name,
19
+ "code.file.path": serverFnMeta.filename,
20
+ "http.request.method": method
21
+ });
22
+ return traced(() => Function.constVoid)(next)(span);
23
+ });
24
+ const requestSpan = createMiddleware().server(traceRequest);
25
+ const serverFnSpan = createMiddleware({ type: "function" }).server(traceServerFn);
26
+ export { requestSpan, serverFnSpan, traceRequest, traceServerFn };
27
+
28
+ //# sourceMappingURL=workers-tracing-tanstack-start.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workers-tracing-tanstack-start.mjs","names":[],"sources":["../src/app/workers-tracing-tanstack-start.ts"],"sourcesContent":["import { createMiddleware } from \"@tanstack/react-start\";\nimport { tracing } from \"cloudflare:workers\";\nimport { Function } from \"effect\";\n\nimport { recordStatus, requestSpans, traced } from \"#/entities/span/index.ts\";\n\nexport interface StartRequest<Result> {\n readonly request: Request;\n readonly pathname: string;\n readonly handlerType: string;\n readonly next: () => PromiseLike<Result> | Result;\n}\n\nexport interface ServerFnCall<Result> {\n readonly method: string;\n readonly serverFnMeta: { readonly id: string; readonly name: string; readonly filename: string };\n readonly next: () => PromiseLike<Result> | Result;\n}\n\nexport const traceRequest = <Result extends { readonly response: Response }>({\n request,\n pathname,\n handlerType,\n next,\n}: StartRequest<Result>): Promise<Result> =>\n tracing.enterSpan(`${request.method} ${pathname}`, (span) => {\n span.setAttributes({\n \"http.request.method\": request.method,\n \"url.path\": pathname,\n \"tanstack_start.handler\": handlerType,\n });\n requestSpans.set(request, span);\n return traced(({ response }: Result) => recordStatus(response.status))(next)(span);\n });\n\nexport const traceServerFn = <Result>({\n method,\n serverFnMeta,\n next,\n}: ServerFnCall<Result>): Promise<Result> =>\n tracing.enterSpan(`serverFn ${serverFnMeta.name}`, (span) => {\n span.setAttributes({\n \"tanstack_start.server_fn.id\": serverFnMeta.id,\n \"tanstack_start.server_fn.name\": serverFnMeta.name,\n \"code.file.path\": serverFnMeta.filename,\n \"http.request.method\": method,\n });\n return traced<Result>(() => Function.constVoid)(next)(span);\n });\n\nexport const requestSpan = createMiddleware().server(traceRequest);\n\nexport const serverFnSpan = createMiddleware({ type: \"function\" }).server(traceServerFn);\n"],"mappings":";;;;;AAmBA,MAAa,gBAAgE,EAC3E,SACA,UACA,aACA,WAEA,QAAQ,UAAU,GAAG,QAAQ,OAAO,GAAG,aAAa,SAAS;CAC3D,KAAK,cAAc;EACjB,uBAAuB,QAAQ;EAC/B,YAAY;EACZ,0BAA0B;CAC5B,CAAC;CACD,aAAa,IAAI,SAAS,IAAI;CAC9B,OAAO,QAAQ,EAAE,eAAuB,aAAa,SAAS,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI;AACnF,CAAC;AAEH,MAAa,iBAAyB,EACpC,QACA,cACA,WAEA,QAAQ,UAAU,YAAY,aAAa,SAAS,SAAS;CAC3D,KAAK,cAAc;EACjB,+BAA+B,aAAa;EAC5C,iCAAiC,aAAa;EAC9C,kBAAkB,aAAa;EAC/B,uBAAuB;CACzB,CAAC;CACD,OAAO,aAAqB,SAAS,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI;AAC5D,CAAC;AAEH,MAAa,cAAc,iBAAiB,CAAC,CAAC,OAAO,YAAY;AAEjE,MAAa,eAAe,iBAAiB,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,OAAO,aAAa"}
@@ -0,0 +1,9 @@
1
+ declare const passThrough: <Result>({ next }: Readonly<{
2
+ next: () => PromiseLike<Result> | Result;
3
+ }>) => Promise<Result>;
4
+ export declare const requestSpan: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, unknown>;
5
+ export declare const serverFnSpan: import("@tanstack/react-start").FunctionMiddlewareAfterServer<{}, unknown, undefined, unknown, undefined, undefined, unknown>;
6
+ export declare const traceRequest: typeof passThrough;
7
+ export declare const traceServerFn: typeof passThrough;
8
+ export {};
9
+ //# sourceMappingURL=workers-tracing-tanstack-start.plain.d.mts.map
@@ -0,0 +1,10 @@
1
+ import { createMiddleware } from "@tanstack/react-start";
2
+ // src/app/workers-tracing-tanstack-start.plain.ts
3
+ const passThrough = ({ next }) => Promise.resolve(next());
4
+ const requestSpan = createMiddleware().server(passThrough);
5
+ const serverFnSpan = createMiddleware({ type: "function" }).server(passThrough);
6
+ const traceRequest = passThrough;
7
+ const traceServerFn = passThrough;
8
+ export { requestSpan, serverFnSpan, traceRequest, traceServerFn };
9
+
10
+ //# sourceMappingURL=workers-tracing-tanstack-start.plain.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workers-tracing-tanstack-start.plain.mjs","names":[],"sources":["../src/app/workers-tracing-tanstack-start.plain.ts"],"sourcesContent":["import { createMiddleware } from \"@tanstack/react-start\";\n\nconst passThrough = <Result>({\n next,\n}: Readonly<{ next: () => PromiseLike<Result> | Result }>): Promise<Result> =>\n Promise.resolve(next());\n\nexport const requestSpan = createMiddleware().server(passThrough);\nexport const serverFnSpan = createMiddleware({ type: \"function\" }).server(passThrough);\n\nexport const traceRequest = passThrough;\nexport const traceServerFn = passThrough;\n"],"mappings":";;AAEA,MAAM,eAAuB,EAC3B,WAEA,QAAQ,QAAQ,KAAK,CAAC;AAExB,MAAa,cAAc,iBAAiB,CAAC,CAAC,OAAO,WAAW;AAChE,MAAa,eAAe,iBAAiB,EAAE,MAAM,WAAW,CAAC,CAAC,CAAC,OAAO,WAAW;AAErF,MAAa,eAAe;AAC5B,MAAa,gBAAgB"}
@@ -0,0 +1,7 @@
1
+ declare const worker: {
2
+ fetch: (request: Request, env: Readonly<{
3
+ TRACE_SINK_TOKEN: string;
4
+ }>) => Promise<Response>;
5
+ };
6
+ export { worker as default };
7
+ //# sourceMappingURL=workers-tracing-trace-sink.d.mts.map
@@ -0,0 +1,29 @@
1
+ import { i as logTraceRequest, n as UnreadableBody, r as bodyOf, t as TraceRequest } from "./otlp-spans-D88555DO.mjs";
2
+ import { Effect, Logger, ManagedRuntime, Schema } from "effect";
3
+ import { Mac } from "effect/crypto";
4
+ // src/app/workers-tracing-trace-sink.ts
5
+ const runtime = ManagedRuntime.make(Logger.layer([Logger.withLeveledConsole(Logger.formatStructured)]));
6
+ const encoder = new TextEncoder();
7
+ const digestOf = (text) => Effect.promise(() => crypto.subtle.digest("SHA-256", encoder.encode(text))).pipe(Effect.map((digest) => new Uint8Array(digest)));
8
+ const isAuthorized = Effect.fn("otlp.authorized")(function* isAuthorized(request, env) {
9
+ const given = yield* digestOf(request.headers.get("authorization") ?? "");
10
+ const expected = yield* digestOf(`Bearer ${env.TRACE_SINK_TOKEN}`);
11
+ return Mac.timingSafeEqual(given, expected);
12
+ });
13
+ const receive = (request, env) => Effect.gen(function* receiveTraces() {
14
+ if (!(yield* isAuthorized(request, env))) {
15
+ yield* Effect.logWarning("otlp.unauthorized");
16
+ return Response.json({});
17
+ }
18
+ const body = yield* Effect.tryPromise({
19
+ try: () => bodyOf(request),
20
+ catch: (cause) => UnreadableBody.make({ message: String(cause) })
21
+ });
22
+ const traces = yield* Schema.decodeUnknownEffect(TraceRequest)(body);
23
+ yield* logTraceRequest(traces);
24
+ return Response.json({});
25
+ }).pipe(Effect.catchCause((cause) => Effect.logError("otlp.rejected", cause).pipe(Effect.annotateLogs({ contentEncoding: request.headers.get("content-encoding") }), Effect.as(new Response("", { status: 400 })))));
26
+ const worker = { fetch: (request, env) => runtime.runPromise(receive(request, env)) };
27
+ export { worker as default };
28
+
29
+ //# sourceMappingURL=workers-tracing-trace-sink.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workers-tracing-trace-sink.mjs","names":[],"sources":["../src/app/workers-tracing-trace-sink.ts"],"sourcesContent":["import { Effect, Logger, ManagedRuntime, Schema } from \"effect\";\nimport { Mac } from \"effect/crypto\";\n\nimport { TraceRequest, UnreadableBody, bodyOf, logTraceRequest } from \"#/entities/span/index.ts\";\n\ntype TraceSinkEnv = Readonly<{ TRACE_SINK_TOKEN: string }>;\n\nconst runtime = ManagedRuntime.make(\n Logger.layer([Logger.withLeveledConsole(Logger.formatStructured)]),\n);\n\nconst encoder = new TextEncoder();\n\nconst digestOf = (text: string): Effect.Effect<Uint8Array> =>\n Effect.promise(() => crypto.subtle.digest(\"SHA-256\", encoder.encode(text))).pipe(\n Effect.map((digest) => new Uint8Array(digest)),\n );\n\nconst isAuthorized = Effect.fn(\"otlp.authorized\")(function* isAuthorized(\n request: Request,\n env: TraceSinkEnv,\n) {\n const given = yield* digestOf(request.headers.get(\"authorization\") ?? \"\");\n const expected = yield* digestOf(`Bearer ${env.TRACE_SINK_TOKEN}`);\n return Mac.timingSafeEqual(given, expected);\n});\n\nconst receive = (request: Request, env: TraceSinkEnv): Effect.Effect<Response> =>\n Effect.gen(function* receiveTraces() {\n const authorized = yield* isAuthorized(request, env);\n if (!authorized) {\n yield* Effect.logWarning(\"otlp.unauthorized\");\n return Response.json({});\n }\n const body = yield* Effect.tryPromise({\n try: () => bodyOf(request),\n catch: (cause) => UnreadableBody.make({ message: String(cause) }),\n });\n const traces = yield* Schema.decodeUnknownEffect(TraceRequest)(body);\n yield* logTraceRequest(traces);\n return Response.json({});\n }).pipe(\n Effect.catchCause((cause) =>\n Effect.logError(\"otlp.rejected\", cause).pipe(\n Effect.annotateLogs({ contentEncoding: request.headers.get(\"content-encoding\") }),\n Effect.as(new Response(\"\", { status: 400 })),\n ),\n ),\n );\n\nconst worker = {\n fetch: (request: Request, env: Readonly<{ TRACE_SINK_TOKEN: string }>): Promise<Response> =>\n runtime.runPromise(receive(request, env)),\n};\n\nexport default worker;\n"],"mappings":";;;;AAOA,MAAM,UAAU,eAAe,KAC7B,OAAO,MAAM,CAAC,OAAO,mBAAmB,OAAO,gBAAgB,CAAC,CAAC,CACnE;AAEA,MAAM,UAAU,IAAI,YAAY;AAEhC,MAAM,YAAY,SAChB,OAAO,cAAc,OAAO,OAAO,OAAO,WAAW,QAAQ,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,KAC1E,OAAO,KAAK,WAAW,IAAI,WAAW,MAAM,CAAC,CAC/C;AAEF,MAAM,eAAe,OAAO,GAAG,iBAAiB,CAAC,CAAC,UAAU,aAC1D,SACA,KACA;CACA,MAAM,QAAQ,OAAO,SAAS,QAAQ,QAAQ,IAAI,eAAe,KAAK,EAAE;CACxE,MAAM,WAAW,OAAO,SAAS,UAAU,IAAI,kBAAkB;CACjE,OAAO,IAAI,gBAAgB,OAAO,QAAQ;AAC5C,CAAC;AAED,MAAM,WAAW,SAAkB,QACjC,OAAO,IAAI,UAAU,gBAAgB;CAEnC,IAAI,EAAC,OADqB,aAAa,SAAS,GAAG,IAClC;EACf,OAAO,OAAO,WAAW,mBAAmB;EAC5C,OAAO,SAAS,KAAK,CAAC,CAAC;CACzB;CACA,MAAM,OAAO,OAAO,OAAO,WAAW;EACpC,WAAW,OAAO,OAAO;EACzB,QAAQ,UAAU,eAAe,KAAK,EAAE,SAAS,OAAO,KAAK,EAAE,CAAC;CAClE,CAAC;CACD,MAAM,SAAS,OAAO,OAAO,oBAAoB,YAAY,CAAC,CAAC,IAAI;CACnE,OAAO,gBAAgB,MAAM;CAC7B,OAAO,SAAS,KAAK,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC,KACD,OAAO,YAAY,UACjB,OAAO,SAAS,iBAAiB,KAAK,CAAC,CAAC,KACtC,OAAO,aAAa,EAAE,iBAAiB,QAAQ,QAAQ,IAAI,kBAAkB,EAAE,CAAC,GAChF,OAAO,GAAG,IAAI,SAAS,IAAI,EAAE,QAAQ,IAAI,CAAC,CAAC,CAC7C,CACF,CACF;AAEF,MAAM,SAAS,EACb,QAAQ,SAAkB,QACxB,QAAQ,WAAW,QAAQ,SAAS,GAAG,CAAC,EAC5C"}
@@ -0,0 +1,33 @@
1
+ import { Effect, Schema } from "effect";
2
+ declare const EXCEPTION_EVENTS: {
3
+ readonly chat: "gen_ai.client.inference.exception";
4
+ readonly embeddings: "gen_ai.client.embeddings.exception";
5
+ readonly decision: "gen_ai.client.decision.exception";
6
+ };
7
+ export type Operation = keyof typeof EXCEPTION_EVENTS;
8
+ declare const WorkersAiError_base: Schema.Class<WorkersAiError, Schema.TaggedStruct<"WorkersAiError", {
9
+ readonly errorType: Schema.String;
10
+ readonly outOfCapacity: Schema.Boolean;
11
+ readonly cause: Schema.Unknown;
12
+ }>, import("effect/Cause").YieldableError & {
13
+ readonly brand: unique symbol;
14
+ }>;
15
+ export declare class WorkersAiError extends WorkersAiError_base {}
16
+ export type GatewayMetadata = Readonly<Record<string, string>>;
17
+ export interface GatewayOptions {
18
+ readonly gateway: Readonly<{
19
+ id: string;
20
+ metadata: GatewayMetadata;
21
+ }>;
22
+ }
23
+ export interface WorkersAiCall<Output> {
24
+ readonly operation: Operation;
25
+ readonly model: string;
26
+ readonly caller: string;
27
+ readonly gateway?: string;
28
+ readonly prompt?: string;
29
+ readonly call: (options: GatewayOptions) => PromiseLike<Output>;
30
+ }
31
+ export declare const runWorkersAi: <Output>({ call, caller, gateway, ...request }: WorkersAiCall<Output>) => Effect.Effect<Output, WorkersAiError>;
32
+ export {};
33
+ //# sourceMappingURL=workers-tracing-workers-ai.d.mts.map
@@ -0,0 +1,108 @@
1
+ import { Array, Effect, Option, Predicate, Schedule, Schema, pipe } from "effect";
2
+ // src/app/workers-tracing-workers-ai.ts
3
+ const PROVIDER = "cloudflare.workers_ai";
4
+ const DEFAULT_GATEWAY = "default";
5
+ const OUT_OF_CAPACITY = "3040";
6
+ const ERROR_CODE = /(?<!\d)(?<code>\d{4}): /u;
7
+ const RETRY_TIMES = 4;
8
+ const RETRY_BASE = "2 seconds";
9
+ const COMPLETE_REASONS = /* @__PURE__ */ new Set(["stop", "tool_calls"]);
10
+ const EXCEPTION_EVENTS = {
11
+ chat: "gen_ai.client.inference.exception",
12
+ embeddings: "gen_ai.client.embeddings.exception",
13
+ decision: "gen_ai.client.decision.exception"
14
+ };
15
+ const taggedError = Schema.TaggedError;
16
+ var WorkersAiError = class extends taggedError()("WorkersAiError", {
17
+ errorType: Schema.String,
18
+ outOfCapacity: Schema.Boolean,
19
+ cause: Schema.Unknown
20
+ }) {};
21
+ const ApiErrors = Schema.Struct({ errors: Schema.NonEmptyArray(Schema.Struct({ code: Schema.Finite })) });
22
+ const Choice = Schema.Struct({ finish_reason: Schema.String });
23
+ const Tokens = Schema.optional(Schema.Finite);
24
+ const Usage = Schema.Struct({
25
+ prompt_tokens: Tokens,
26
+ completion_tokens: Tokens
27
+ });
28
+ const Answer = Schema.Struct({
29
+ choices: Choice.pipe(Schema.Array, Schema.optional),
30
+ usage: Schema.optional(Usage)
31
+ });
32
+ const decodeApiErrors = Schema.decodeUnknownOption(ApiErrors);
33
+ const decodeAnswer = Schema.decodeUnknownOption(Answer);
34
+ const messageCode = ({ message }) => pipe(Option.fromNullishOr(ERROR_CODE.exec(message)), Option.flatMap(({ groups }) => Option.fromNullishOr(groups)), Option.flatMap(({ code }) => Option.fromNullishOr(code)));
35
+ const errorTypeOf = (cause) => pipe(decodeApiErrors(cause), Option.map(({ errors: [{ code }] }) => `${code}`), Option.orElse(() => pipe(Option.liftPredicate(cause, Predicate.isError), Option.flatMap(messageCode))), Option.orElse(() => pipe(Option.liftPredicate(cause, Predicate.isError), Option.map(({ name }) => name))), Option.getOrElse(() => "_OTHER"));
36
+ const exceptionOf = (cause) => pipe(Option.liftPredicate(cause, Predicate.isError), Option.match({
37
+ onNone: () => ({}),
38
+ onSome: ({ name, message }) => ({
39
+ "exception.type": name,
40
+ "exception.message": message
41
+ })
42
+ }));
43
+ const attribute = (key, value) => pipe(value, Option.match({
44
+ onNone: () => ({}),
45
+ onSome: (present) => ({ [key]: present })
46
+ }));
47
+ const finishReasons = ({ choices }) => pipe(Option.fromUndefinedOr(choices), Option.map(Array.map(({ finish_reason }) => finish_reason)));
48
+ const usageOf = ({ usage }) => Option.fromUndefinedOr(usage);
49
+ const answerAttributes = (answer) => ({
50
+ ...attribute("gen_ai.response.finish_reasons", finishReasons(answer)),
51
+ ...attribute("gen_ai.usage.input_tokens", pipe(usageOf(answer), Option.flatMap(({ prompt_tokens }) => Option.fromUndefinedOr(prompt_tokens)))),
52
+ ...attribute("gen_ai.usage.output_tokens", pipe(usageOf(answer), Option.flatMap(({ completion_tokens }) => Option.fromUndefinedOr(completion_tokens))))
53
+ });
54
+ const isCutOff = (answer) => pipe(finishReasons(answer), Option.exists(Array.some((reason) => !COMPLETE_REASONS.has(reason))));
55
+ const requestAttributes = ({ operation, model, prompt }) => ({
56
+ "gen_ai.operation.name": operation,
57
+ "gen_ai.provider.name": PROVIDER,
58
+ "gen_ai.request.model": model,
59
+ ...attribute("gen_ai.prompt.name", Option.fromUndefinedOr(prompt))
60
+ });
61
+ const traceIdOf = Effect.currentSpan.pipe(Effect.map(({ traceId }) => ({ trace_id: traceId })), Effect.orElseSucceed(() => ({})));
62
+ const gatewayOptions = (caller, gateway) => traceIdOf.pipe(Effect.map((trace) => ({ gateway: {
63
+ id: gateway,
64
+ metadata: {
65
+ caller,
66
+ ...trace
67
+ }
68
+ } })));
69
+ const recordAnswer = (attributes) => (output) => pipe(decodeAnswer(output), Option.match({
70
+ onNone: () => Effect.void,
71
+ onSome: (answer) => {
72
+ const answered = answerAttributes(answer);
73
+ const recorded = Effect.annotateCurrentSpan(answered);
74
+ if (!isCutOff(answer)) return recorded;
75
+ return recorded.pipe(Effect.andThen(Effect.logWarning("Workers AI cut the answer off")), Effect.annotateLogs({
76
+ ...attributes,
77
+ ...answered
78
+ }));
79
+ }
80
+ }));
81
+ const runWorkersAi = ({ call, caller, gateway = DEFAULT_GATEWAY, ...request }) => {
82
+ const attributes = requestAttributes(request);
83
+ return gatewayOptions(caller, gateway).pipe(Effect.flatMap((options) => Effect.tryPromise({
84
+ try: () => Promise.resolve(call(options)),
85
+ catch: (cause) => {
86
+ const errorType = errorTypeOf(cause);
87
+ return WorkersAiError.make({
88
+ errorType,
89
+ outOfCapacity: errorType === OUT_OF_CAPACITY,
90
+ cause
91
+ });
92
+ }
93
+ })), Effect.tapError(({ errorType, cause }) => Effect.logWarning(EXCEPTION_EVENTS[request.operation]).pipe(Effect.annotateLogs({
94
+ ...attributes,
95
+ ...exceptionOf(cause),
96
+ "error.type": errorType
97
+ }))), Effect.retry({
98
+ schedule: Schedule.exponential(RETRY_BASE),
99
+ times: RETRY_TIMES,
100
+ while: ({ outOfCapacity }) => outOfCapacity
101
+ }), Effect.tapError(({ errorType }) => Effect.annotateCurrentSpan("error.type", errorType)), Effect.tap(recordAnswer(attributes)), Effect.withSpan(`${request.operation} ${request.model}`, {
102
+ kind: "client",
103
+ attributes
104
+ }));
105
+ };
106
+ export { WorkersAiError, runWorkersAi };
107
+
108
+ //# sourceMappingURL=workers-tracing-workers-ai.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workers-tracing-workers-ai.mjs","names":[],"sources":["../src/app/workers-tracing-workers-ai.ts"],"sourcesContent":["import { Array, Effect, Option, Predicate, Schedule, Schema, pipe } from \"effect\";\n\nconst PROVIDER = \"cloudflare.workers_ai\";\nconst DEFAULT_GATEWAY = \"default\";\nconst OUT_OF_CAPACITY = \"3040\";\nconst ERROR_CODE = /(?<!\\d)(?<code>\\d{4}): /u;\nconst RETRY_TIMES = 4;\nconst RETRY_BASE = \"2 seconds\";\nconst COMPLETE_REASONS: ReadonlySet<string> = new Set([\"stop\", \"tool_calls\"]);\nconst EXCEPTION_EVENTS = {\n chat: \"gen_ai.client.inference.exception\",\n embeddings: \"gen_ai.client.embeddings.exception\",\n decision: \"gen_ai.client.decision.exception\",\n} as const;\n\nexport type Operation = keyof typeof EXCEPTION_EVENTS;\n\nconst taggedError = Schema.TaggedError;\n\nexport class WorkersAiError extends taggedError<\n WorkersAiError,\n { readonly brand: unique symbol }\n>()(\"WorkersAiError\", {\n errorType: Schema.String,\n outOfCapacity: Schema.Boolean,\n cause: Schema.Unknown,\n}) {}\n\nconst ApiErrors = Schema.Struct({\n errors: Schema.NonEmptyArray(Schema.Struct({ code: Schema.Finite })),\n});\n\nconst Choice = Schema.Struct({ finish_reason: Schema.String });\nconst Tokens = Schema.optional(Schema.Finite);\nconst Usage = Schema.Struct({ prompt_tokens: Tokens, completion_tokens: Tokens });\nconst Answer = Schema.Struct({\n choices: Choice.pipe(Schema.Array, Schema.optional),\n usage: Schema.optional(Usage),\n});\n\nconst decodeApiErrors = Schema.decodeUnknownOption(ApiErrors);\nconst decodeAnswer = Schema.decodeUnknownOption(Answer);\n\nconst messageCode = ({ message }: Readonly<Pick<Error, \"message\">>): Option.Option<string> =>\n pipe(\n Option.fromNullishOr(ERROR_CODE.exec(message)),\n Option.flatMap(({ groups }) => Option.fromNullishOr(groups)),\n Option.flatMap(({ code }) => Option.fromNullishOr(code)),\n );\n\nconst errorTypeOf = (cause: unknown): string =>\n pipe(\n decodeApiErrors(cause),\n Option.map(({ errors: [{ code }] }) => `${code}`),\n Option.orElse(() =>\n pipe(Option.liftPredicate(cause, Predicate.isError), Option.flatMap(messageCode)),\n ),\n Option.orElse(() =>\n pipe(\n Option.liftPredicate(cause, Predicate.isError),\n Option.map(({ name }) => name),\n ),\n ),\n Option.getOrElse(() => \"_OTHER\"),\n );\n\nconst exceptionOf = (cause: unknown): Readonly<Record<string, string>> =>\n pipe(\n Option.liftPredicate(cause, Predicate.isError),\n Option.match({\n onNone: () => ({}),\n onSome: ({ name, message }) => ({ \"exception.type\": name, \"exception.message\": message }),\n }),\n );\n\ntype Attributes = Readonly<Record<string, unknown>>;\n\nconst attribute = <Value>(key: string, value: Option.Option<Value>): Attributes =>\n pipe(value, Option.match({ onNone: () => ({}), onSome: (present) => ({ [key]: present }) }));\n\nconst finishReasons = ({ choices }: typeof Answer.Type): Option.Option<readonly string[]> =>\n pipe(\n Option.fromUndefinedOr(choices),\n Option.map(Array.map(({ finish_reason }) => finish_reason)),\n );\n\nconst usageOf = ({ usage }: typeof Answer.Type): Option.Option<typeof Usage.Type> =>\n Option.fromUndefinedOr(usage);\n\nconst answerAttributes = (answer: typeof Answer.Type): Attributes => ({\n ...attribute(\"gen_ai.response.finish_reasons\", finishReasons(answer)),\n ...attribute(\n \"gen_ai.usage.input_tokens\",\n pipe(\n usageOf(answer),\n Option.flatMap(({ prompt_tokens }) => Option.fromUndefinedOr(prompt_tokens)),\n ),\n ),\n ...attribute(\n \"gen_ai.usage.output_tokens\",\n pipe(\n usageOf(answer),\n Option.flatMap(({ completion_tokens }) => Option.fromUndefinedOr(completion_tokens)),\n ),\n ),\n});\n\nconst isCutOff = (answer: typeof Answer.Type): boolean =>\n pipe(finishReasons(answer), Option.exists(Array.some((reason) => !COMPLETE_REASONS.has(reason))));\n\nexport type GatewayMetadata = Readonly<Record<string, string>>;\n\nexport interface GatewayOptions {\n readonly gateway: Readonly<{ id: string; metadata: GatewayMetadata }>;\n}\n\nexport interface WorkersAiCall<Output> {\n readonly operation: Operation;\n readonly model: string;\n readonly caller: string;\n readonly gateway?: string;\n readonly prompt?: string;\n readonly call: (options: GatewayOptions) => PromiseLike<Output>;\n}\n\nconst requestAttributes = ({\n operation,\n model,\n prompt,\n}: Readonly<Pick<WorkersAiCall<unknown>, \"model\" | \"operation\" | \"prompt\">>): Attributes => ({\n \"gen_ai.operation.name\": operation,\n \"gen_ai.provider.name\": PROVIDER,\n \"gen_ai.request.model\": model,\n ...attribute(\"gen_ai.prompt.name\", Option.fromUndefinedOr(prompt)),\n});\n\nconst traceIdOf: Effect.Effect<GatewayMetadata> = Effect.currentSpan.pipe(\n Effect.map(({ traceId }) => ({ trace_id: traceId })),\n Effect.orElseSucceed(() => ({})),\n);\n\nconst gatewayOptions = (caller: string, gateway: string): Effect.Effect<GatewayOptions> =>\n traceIdOf.pipe(\n Effect.map((trace) => ({ gateway: { id: gateway, metadata: { caller, ...trace } } })),\n );\n\nconst recordAnswer =\n (attributes: Attributes) =>\n (output: unknown): Effect.Effect<void> =>\n pipe(\n decodeAnswer(output),\n Option.match({\n onNone: () => Effect.void,\n onSome: (answer) => {\n const answered = answerAttributes(answer);\n const recorded = Effect.annotateCurrentSpan(answered);\n if (!isCutOff(answer)) {\n return recorded;\n }\n return recorded.pipe(\n Effect.andThen(Effect.logWarning(\"Workers AI cut the answer off\")),\n Effect.annotateLogs({ ...attributes, ...answered }),\n );\n },\n }),\n );\n\nexport const runWorkersAi = <Output>({\n call,\n caller,\n gateway = DEFAULT_GATEWAY,\n ...request\n}: WorkersAiCall<Output>): Effect.Effect<Output, WorkersAiError> => {\n const attributes = requestAttributes(request);\n return gatewayOptions(caller, gateway).pipe(\n Effect.flatMap((options) =>\n Effect.tryPromise({\n try: () => Promise.resolve(call(options)),\n catch: (cause) => {\n const errorType = errorTypeOf(cause);\n return WorkersAiError.make({\n errorType,\n outOfCapacity: errorType === OUT_OF_CAPACITY,\n cause,\n });\n },\n }),\n ),\n Effect.tapError(({ errorType, cause }) =>\n Effect.logWarning(EXCEPTION_EVENTS[request.operation]).pipe(\n Effect.annotateLogs({ ...attributes, ...exceptionOf(cause), \"error.type\": errorType }),\n ),\n ),\n Effect.retry({\n schedule: Schedule.exponential(RETRY_BASE),\n times: RETRY_TIMES,\n while: ({ outOfCapacity }) => outOfCapacity,\n }),\n Effect.tapError(({ errorType }) => Effect.annotateCurrentSpan(\"error.type\", errorType)),\n Eff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F,CACF,GACA,OAAO,MAAM;EACX,UAAU,SAAS,YAAY,UAAU;EACzC,OAAO;EACP,QAAQ,EAAE,oBAAoB;CAChC,CAAC,GACD,OAAO,UAAU,EAAE,gBAAgB,OAAO,oBAAoB,cAAc,SAAS,CAAC,GACtF,OAAO,IAAI,aAAa,UAAU,CAAC,GACnC,OAAO,SAAS,GAAG,QAAQ,UAAU,GAAG,QAAQ,SAAS;EAAE,MAAM;EAAU;CAAW,CAAC,CACzF;AACF"}
package/package.json CHANGED
@@ -1,15 +1,262 @@
1
1
  {
2
2
  "name": "@r_masseater/masseater-utils",
3
- "version": "0.0.0",
4
- "description": "Reserves the name until the first release from CI.",
3
+ "version": "0.1.2",
4
+ "description": "The small shared libraries of masseater's repositories as subpaths of one package: a chip row for React, Claude Code plugin helpers, Effect entry points for Node.js and GitHub Actions, file import mapping, Node package readers, OTLP assertions for Vitest and Cloudflare Workers tracing.",
5
+ "keywords": [
6
+ "actions",
7
+ "claude-code",
8
+ "cloudflare-workers",
9
+ "effect",
10
+ "elysia",
11
+ "github-actions",
12
+ "opentelemetry",
13
+ "otlp",
14
+ "package-json",
15
+ "pnpm",
16
+ "react",
17
+ "tanstack-intent",
18
+ "tanstack-start",
19
+ "tracing",
20
+ "vite-plugin",
21
+ "vitest-plugin"
22
+ ],
23
+ "homepage": "https://github.com/masseater/ecosystems/tree/main/libs/masseater-utils#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/masseater/ecosystems/issues"
26
+ },
5
27
  "license": "MIT",
6
28
  "repository": {
7
29
  "type": "git",
8
30
  "url": "git+https://github.com/masseater/ecosystems.git",
9
31
  "directory": "libs/masseater-utils"
10
32
  },
11
- "homepage": "https://github.com/masseater/ecosystems/tree/main/libs/masseater-utils#readme",
12
- "bugs": {
13
- "url": "https://github.com/masseater/ecosystems/issues"
33
+ "files": [
34
+ "LICENSE",
35
+ "dist",
36
+ "skills",
37
+ "src/app/skerm.css"
38
+ ],
39
+ "type": "module",
40
+ "sideEffects": [
41
+ "*.css",
42
+ "./dist/vitest-otlp-setup.mjs"
43
+ ],
44
+ "imports": {
45
+ "#/*": "./src/*"
46
+ },
47
+ "exports": {
48
+ "./skerm": {
49
+ "types": "./dist/skerm.d.mts",
50
+ "default": "./dist/skerm.mjs"
51
+ },
52
+ "./skerm.css": "./src/app/skerm.css",
53
+ "./plugin-kit": {
54
+ "types": "./dist/plugin-kit.d.mts",
55
+ "default": "./dist/plugin-kit.mjs"
56
+ },
57
+ "./node-main": {
58
+ "types": "./dist/node-main.d.mts",
59
+ "default": "./dist/node-main.mjs"
60
+ },
61
+ "./github-workflow": {
62
+ "types": "./dist/github-workflow.d.mts",
63
+ "default": "./dist/github-workflow.mjs"
64
+ },
65
+ "./mapped-import": {
66
+ "types": "./dist/mapped-import.d.mts",
67
+ "default": "./dist/mapped-import.mjs"
68
+ },
69
+ "./mapped-import/mapper": {
70
+ "types": "./dist/mapped-import-mapper.d.mts",
71
+ "default": "./dist/mapped-import-mapper.mjs"
72
+ },
73
+ "./mapped-import/vite": {
74
+ "types": "./dist/mapped-import-vite.d.mts",
75
+ "default": "./dist/mapped-import-vite.mjs"
76
+ },
77
+ "./kestrion": {
78
+ "types": "./dist/kestrion.d.mts",
79
+ "default": "./dist/kestrion.mjs"
80
+ },
81
+ "./kestrion/npm": {
82
+ "types": "./dist/kestrion-npm.d.mts",
83
+ "default": "./dist/kestrion-npm.mjs"
84
+ },
85
+ "./kestrion/pnpm": {
86
+ "types": "./dist/kestrion-pnpm.d.mts",
87
+ "default": "./dist/kestrion-pnpm.mjs"
88
+ },
89
+ "./kestrion/node": {
90
+ "types": "./dist/kestrion-node.d.mts",
91
+ "default": "./dist/kestrion-node.mjs"
92
+ },
93
+ "./vitest-otlp": {
94
+ "types": "./dist/vitest-otlp.d.mts",
95
+ "default": "./dist/vitest-otlp.mjs"
96
+ },
97
+ "./vitest-otlp/setup": {
98
+ "types": "./dist/vitest-otlp-setup.d.mts",
99
+ "default": "./dist/vitest-otlp-setup.mjs"
100
+ },
101
+ "./vitest-otlp/semconv": {
102
+ "types": "./dist/vitest-otlp-semconv.d.mts",
103
+ "default": "./dist/vitest-otlp-semconv.mjs"
104
+ },
105
+ "./vitest-otlp/workers": {
106
+ "types": "./dist/vitest-otlp-workers.d.mts",
107
+ "default": "./dist/vitest-otlp-workers.mjs"
108
+ },
109
+ "./vitest-otlp/collector-files": {
110
+ "types": "./dist/vitest-otlp-collector-files.d.mts",
111
+ "default": "./dist/vitest-otlp-collector-files.mjs"
112
+ },
113
+ "./vitest-otlp/tail-worker": "./dist/vitest-otlp-tail-to-otlp.mjs",
114
+ "./workers-tracing/alchemy": {
115
+ "types": "./dist/workers-tracing-alchemy.d.mts",
116
+ "default": "./dist/workers-tracing-alchemy.mjs"
117
+ },
118
+ "./workers-tracing/browser-logs": {
119
+ "types": "./dist/workers-tracing-browser-logs.d.mts",
120
+ "default": "./dist/workers-tracing-browser-logs.mjs"
121
+ },
122
+ "./workers-tracing/browser-spans": {
123
+ "types": "./dist/workers-tracing-browser-spans.d.mts",
124
+ "default": "./dist/workers-tracing-browser-spans.mjs"
125
+ },
126
+ "./workers-tracing/oxlint": {
127
+ "types": "./dist/workers-tracing-oxlint.d.mts",
128
+ "default": "./dist/workers-tracing-oxlint.mjs"
129
+ },
130
+ "./workers-tracing/workers-ai": {
131
+ "types": "./dist/workers-tracing-workers-ai.d.mts",
132
+ "default": "./dist/workers-tracing-workers-ai.mjs"
133
+ },
134
+ "./workers-tracing/elysia": {
135
+ "types": "./dist/workers-tracing-elysia.d.mts",
136
+ "workerd": "./dist/workers-tracing-elysia.mjs",
137
+ "node": "./dist/workers-tracing-elysia.plain.mjs",
138
+ "default": "./dist/workers-tracing-elysia.mjs"
139
+ },
140
+ "./workers-tracing/tanstack-start": {
141
+ "types": "./dist/workers-tracing-tanstack-start.d.mts",
142
+ "workerd": "./dist/workers-tracing-tanstack-start.mjs",
143
+ "browser": "./dist/workers-tracing-tanstack-start.plain.mjs",
144
+ "node": "./dist/workers-tracing-tanstack-start.plain.mjs",
145
+ "default": "./dist/workers-tracing-tanstack-start.mjs"
146
+ },
147
+ "./workers-tracing/effect": {
148
+ "types": "./dist/workers-tracing-effect-tracing.d.mts",
149
+ "workerd": "./dist/workers-tracing-effect-tracing.mjs",
150
+ "browser": "./dist/workers-tracing-effect-tracing.plain.mjs",
151
+ "node": "./dist/workers-tracing-effect-tracing.plain.mjs",
152
+ "default": "./dist/workers-tracing-effect-tracing.mjs"
153
+ },
154
+ "./workers-tracing/trace-sink-worker": "./dist/workers-tracing-trace-sink.mjs",
155
+ "./package.json": "./package.json"
156
+ },
157
+ "publishConfig": {
158
+ "access": "public",
159
+ "provenance": true
160
+ },
161
+ "devDependencies": {
162
+ "@alchemy.run/cloudflare": "2.0.0-beta.87",
163
+ "@bufbuild/buf": "1.75.0",
164
+ "@bufbuild/protobuf": "2.17.0",
165
+ "@cloudflare/workers-types": "5.20261125.1",
166
+ "@effect/platform-node": "4.1.7",
167
+ "@effect/vitest": "4.1.7",
168
+ "@npmcli/package-json": "8.0.1",
169
+ "@opentelemetry/api": "1.10.0",
170
+ "@opentelemetry/sdk-node": "0.301.2",
171
+ "@pnpm/deps.path": "1101.0.11",
172
+ "@pnpm/lockfile.fs": "1100.2.20",
173
+ "@pnpm/workspace.projects-reader": "1101.1.9",
174
+ "@pnpm/workspace.workspace-manifest-reader": "1100.3.4",
175
+ "@pnpm/workspace.workspace-manifest-writer": "1100.2.13",
176
+ "@tanstack/react-start": "1.169.7",
177
+ "@tanstack/router-core": "1.171.39",
178
+ "@types/node": "26.6.11",
179
+ "@types/npmcli__package-json": "4.0.4",
180
+ "@types/react": "19.3.3",
181
+ "alchemy": "2.0.0-beta.87",
182
+ "effect": "4.1.7",
183
+ "elysia": "1.4.32",
184
+ "miniflare": "4.20260730.0",
185
+ "publint": "0.3.25",
186
+ "react": "19.3.1",
187
+ "ts-content-mapper": "0.1.1",
188
+ "typescript": "7.1.0-dev.20261126.1",
189
+ "vite-plus": "1.8.0"
190
+ },
191
+ "peerDependencies": {
192
+ "@alchemy.run/cloudflare": "^2.0.0-beta.85",
193
+ "@bufbuild/protobuf": ">=2.17.0",
194
+ "@effect/platform-node": ">=4.1.5",
195
+ "@npmcli/package-json": ">=8.0.1",
196
+ "@pnpm/deps.path": ">=1101.0.11",
197
+ "@pnpm/lockfile.fs": ">=1100.2.20",
198
+ "@pnpm/workspace.projects-reader": ">=1101.1.9",
199
+ "@pnpm/workspace.workspace-manifest-reader": ">=1100.3.4",
200
+ "@pnpm/workspace.workspace-manifest-writer": ">=1100.2.13",
201
+ "@tanstack/react-start": "^1.169.4",
202
+ "alchemy": "^2.0.0-beta.85",
203
+ "effect": "^4.1.0",
204
+ "elysia": "^1.4.30",
205
+ "react": "^19.3.1",
206
+ "ts-content-mapper": ">=0.1.1",
207
+ "vite-plus": "^1.8.0"
208
+ },
209
+ "peerDependenciesMeta": {
210
+ "@alchemy.run/cloudflare": {
211
+ "optional": true
212
+ },
213
+ "@bufbuild/protobuf": {
214
+ "optional": true
215
+ },
216
+ "@effect/platform-node": {
217
+ "optional": true
218
+ },
219
+ "@npmcli/package-json": {
220
+ "optional": true
221
+ },
222
+ "@pnpm/deps.path": {
223
+ "optional": true
224
+ },
225
+ "@pnpm/lockfile.fs": {
226
+ "optional": true
227
+ },
228
+ "@pnpm/workspace.projects-reader": {
229
+ "optional": true
230
+ },
231
+ "@pnpm/workspace.workspace-manifest-reader": {
232
+ "optional": true
233
+ },
234
+ "@pnpm/workspace.workspace-manifest-writer": {
235
+ "optional": true
236
+ },
237
+ "@tanstack/react-start": {
238
+ "optional": true
239
+ },
240
+ "alchemy": {
241
+ "optional": true
242
+ },
243
+ "effect": {
244
+ "optional": true
245
+ },
246
+ "elysia": {
247
+ "optional": true
248
+ },
249
+ "react": {
250
+ "optional": true
251
+ },
252
+ "ts-content-mapper": {
253
+ "optional": true
254
+ },
255
+ "vite-plus": {
256
+ "optional": true
257
+ }
258
+ },
259
+ "engines": {
260
+ "node": ">=26.13.1"
14
261
  }
15
262
  }
@@ -0,0 +1,59 @@
1
+ ---
2
+ name: add-scroll-chip-row
3
+ description: >
4
+ Use when a React page shows a row of filter chips or tags that must scroll sideways instead of
5
+ wrapping: ScrollChipRow of @r_masseater/masseater-utils/skerm, the stylesheet it needs, the aria attributes that
6
+ mark the current chip, and the colors of its arrow buttons.
7
+ metadata:
8
+ type: core
9
+ library: "@r_masseater/masseater-utils"
10
+ sources:
11
+ - src/app/skerm.*
12
+ - src/features/scroll-chip-row/**
13
+ - README.md
14
+ ---
15
+
16
+ # add-scroll-chip-row
17
+
18
+ `@r_masseater/masseater-utils/skerm` keeps a row of chips on one line. The current chip scrolls into view, the edges fade where chips are hidden, and arrow buttons page the row on a device with a hovering pointer. Use it instead of writing the scrolling, the fade or the arrows again.
19
+
20
+ ## Setup
21
+
22
+ ```sh
23
+ vp add @r_masseater/masseater-utils react effect
24
+ ```
25
+
26
+ Import the stylesheet once, in the entry of the site: `import "@r_masseater/masseater-utils/skerm.css";`.
27
+
28
+ ## Put chips in the row
29
+
30
+ ```tsx
31
+ import { ScrollChipRow } from "@r_masseater/masseater-utils/skerm";
32
+
33
+ export const Kinds = ({
34
+ kinds,
35
+ current,
36
+ }: Readonly<{ kinds: readonly string[]; current: string }>) => (
37
+ <ScrollChipRow label="Kinds">
38
+ {kinds.map((kind) => (
39
+ <li key={kind}>
40
+ <button aria-pressed={kind === current} type="button">
41
+ {kind}
42
+ </button>
43
+ </li>
44
+ ))}
45
+ </ScrollChipRow>
46
+ );
47
+ ```
48
+
49
+ - The children are list items. `label` names the row for screen readers.
50
+ - Mark the current chip with `aria-current` (not `"false"`) or `aria-pressed="true"`. The row scrolls to that chip when it changes.
51
+
52
+ ## Match the theme
53
+
54
+ Set `--skerm-surface`, `--skerm-on-surface`, `--skerm-border` and `--skerm-hover` on any ancestor of the row, such as `:root`. Each one falls back to a system color, so a site with its own theme maps its tokens to them once.
55
+
56
+ ## Common mistakes
57
+
58
+ - Do not wrap the chips in your own `overflow-x` container. The row already scrolls, and a second scroller breaks the fade and the arrows.
59
+ - Do not give a chip `aria-current="false"` to mean "not current" unless you want it ignored. The row skips `"false"`.