@r_masseater/masseater-utils 0.12.0 → 0.13.1
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/dist/{client-DX2jXirb.mjs → client-BSzBrLkG.mjs} +4 -4
- package/dist/{client-DX2jXirb.mjs.map → client-BSzBrLkG.mjs.map} +1 -1
- package/dist/desktop-shell/media-notes.mjs +9 -3
- package/dist/desktop-shell/media-notes.mjs.map +1 -1
- package/dist/desktop-shell/release-cli.mjs +3 -4
- package/dist/desktop-shell/release-cli.mjs.map +1 -1
- package/dist/{headers-Bpv9DhNS.mjs → headers-B6rDlN_n.mjs} +4 -4
- package/dist/headers-B6rDlN_n.mjs.map +1 -0
- package/dist/model-server/process.mjs +12 -9
- package/dist/model-server/process.mjs.map +1 -1
- package/dist/model-server.mjs +1 -1
- package/dist/{node-main-BrhzkUvP.mjs → node-main-Cx8sevy0.mjs} +5 -2
- package/dist/{node-main-BrhzkUvP.mjs.map → node-main-Cx8sevy0.mjs.map} +1 -1
- package/dist/node-main.mjs +2 -2
- package/dist/plugin-kit.mjs +4 -4
- package/dist/plugin-kit.mjs.map +1 -1
- package/dist/{run-main-Chtieg-p.mjs → run-main-CfugYs_u.mjs} +9 -6
- package/dist/{run-main-Chtieg-p.mjs.map → run-main-CfugYs_u.mjs.map} +1 -1
- package/dist/security-headers/http.mjs +1 -1
- package/dist/security-headers/response.mjs +1 -1
- package/dist/security-headers/static.mjs +1 -1
- package/dist/security-headers/vite.mjs +1 -1
- package/dist/security-headers.mjs +1 -1
- package/dist/{static-page-headers-muClDOhu.mjs → static-page-headers-gBsEgnqj.mjs} +2 -2
- package/dist/{static-page-headers-muClDOhu.mjs.map → static-page-headers-gBsEgnqj.mjs.map} +1 -1
- package/dist/{usage-meter-B196tKiM.mjs → usage-meter-ifuOWUth.mjs} +3 -3
- package/dist/usage-meter-ifuOWUth.mjs.map +1 -0
- package/dist/usage-meter.mjs +1 -1
- package/dist/vitest-otlp/setup.mjs +1 -2
- package/dist/vitest-otlp/setup.mjs.map +1 -1
- package/dist/workers-tracing/alchemy.d.mts +2 -0
- package/dist/workers-tracing/alchemy.mjs +6 -0
- package/dist/workers-tracing/alchemy.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/add-scroll-chip-row/SKILL.md +1 -1
- package/skills/assert-exported-telemetry/SKILL.md +1 -1
- package/skills/build-tauri-app/SKILL.md +1 -1
- package/skills/find-cache-folder/SKILL.md +1 -1
- package/skills/import-custom-format/SKILL.md +1 -1
- package/skills/name-stack-resources/SKILL.md +1 -1
- package/skills/read-hook-input/SKILL.md +1 -1
- package/skills/read-node-ecosystem/SKILL.md +1 -1
- package/skills/run-effect-main/SKILL.md +1 -1
- package/skills/share-types-with-rust/SKILL.md +1 -1
- package/skills/trace-workers/SKILL.md +4 -1
- package/skills/use-model-server/SKILL.md +1 -1
- package/skills/write-actions-steps/SKILL.md +1 -1
- package/dist/headers-Bpv9DhNS.mjs.map +0 -1
- package/dist/usage-meter-B196tKiM.mjs.map +0 -1
|
@@ -13,6 +13,8 @@ export declare const DEFAULT_DESTINATION = "workers-tracing";
|
|
|
13
13
|
export declare const traceSink: (args_0?: TraceSinkProps | undefined) => Effect.Effect<Workers.ObservabilityDestination, never, import("alchemy").Provider<import("alchemy").Random> | import("@alchemy.run/cloudflare").Providers>;
|
|
14
14
|
export interface TracingOptions {
|
|
15
15
|
readonly destinations?: readonly string[];
|
|
16
|
+
readonly traceSampleRate?: number;
|
|
17
|
+
readonly logSampleRate?: number;
|
|
16
18
|
}
|
|
17
19
|
export declare const traced: (options?: TracingOptions) => (props: WorkerProps) => WorkerProps;
|
|
18
20
|
export type WorkerService = ProviderService<Worker>;
|
|
@@ -39,6 +39,10 @@ const traceSink = Effect.fn("traceSink")(function* traceSink({ destination = DEF
|
|
|
39
39
|
});
|
|
40
40
|
// src/app/workers-tracing-alchemy.ts
|
|
41
41
|
const laterDate = Order.max(Order.String);
|
|
42
|
+
const sampledAt = (rate) => pipe(Option.fromUndefinedOr(rate), Option.match({
|
|
43
|
+
onNone: () => ({}),
|
|
44
|
+
onSome: (headSamplingRate) => ({ headSamplingRate })
|
|
45
|
+
}));
|
|
42
46
|
const withDestinations = (added) => (own) => pipe(Option.fromNullishOr(own), Option.getOrElse(() => []), Array.appendAll(added), Array.dedupe);
|
|
43
47
|
const isVersionOfAnotherWorker = ({ version }) => pipe(Option.fromUndefinedOr(version), Option.exists(({ parent }) => Predicate.isNotUndefined(parent)));
|
|
44
48
|
const optsOutOfTraces = ({ observability }) => pipe(Option.fromUndefinedOr(observability), Option.flatMapNullishOr(({ traces }) => traces), Option.exists(({ enabled }) => enabled === false));
|
|
@@ -72,11 +76,13 @@ const withTraces = (options) => (props) => {
|
|
|
72
76
|
enabled: true,
|
|
73
77
|
invocationLogs: true,
|
|
74
78
|
persist: true,
|
|
79
|
+
...sampledAt(options.logSampleRate),
|
|
75
80
|
...logs
|
|
76
81
|
},
|
|
77
82
|
traces: {
|
|
78
83
|
enabled: true,
|
|
79
84
|
persist: true,
|
|
85
|
+
...sampledAt(options.traceSampleRate),
|
|
80
86
|
...traces,
|
|
81
87
|
destinations: withDestinations(options.destinations ?? [])(destinations)
|
|
82
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alchemy.mjs","names":["Arr","Rec","providerLayer"],"sources":["../../src/shared/config/compatibility.ts","../../src/features/sink-traces/model/trace-sink.ts","../../src/app/workers-tracing-alchemy.ts"],"sourcesContent":["export const COMPATIBILITY_DATE = \"2026-08-25\";\n","import { Workers } from \"@alchemy.run/cloudflare\";\nimport { makeRandom } from \"alchemy\";\nimport { map } from \"alchemy/Output\";\nimport { Effect, Redacted } from \"effect\";\n\nimport { COMPATIBILITY_DATE } from \"#/shared/config/index.ts\";\n\nexport interface TraceSinkProps {\n readonly destination?: string;\n readonly workerName?: string;\n readonly logpush?: boolean;\n readonly cpuMs?: number;\n}\n\nexport const DEFAULT_DESTINATION = \"workers-tracing\";\n\nconst DEFAULT_CPU_MS = 1000;\n\nconst sinkMain = (): string =>\n decodeURIComponent(\n new URL(import.meta.resolve(\"@r_masseater/masseater-utils/workers-tracing/trace-sink-worker\"))\n .pathname,\n );\n\nexport const traceSink = Effect.fn(\"traceSink\")(function* traceSink({\n destination = DEFAULT_DESTINATION,\n workerName = `${destination}-sink`,\n logpush = true,\n cpuMs = DEFAULT_CPU_MS,\n}: TraceSinkProps = {}) {\n const token = yield* makeRandom(\"TraceSinkToken\");\n const sink = yield* Workers.Worker(\"TraceSink\", {\n name: workerName,\n main: sinkMain(),\n compatibility: { date: COMPATIBILITY_DATE },\n logpush,\n limits: { cpuMs },\n env: { TRACE_SINK_TOKEN: token },\n observability: {\n enabled: true,\n logs: { enabled: true, invocationLogs: false, persist: true },\n traces: { enabled: false },\n issues: { enabled: true },\n },\n });\n return yield* Workers.ObservabilityDestination(\"Traces\", {\n name: destination,\n url: map(sink.url, (url) => new URL(\"/v1/traces\", url).href),\n headers: {\n authorization: map(token, (value) => Redacted.make(`Bearer ${Redacted.value(value)}`)),\n },\n logpushDataset: \"opentelemetry-traces\",\n });\n});\n","import { Worker } from \"@alchemy.run/cloudflare/Workers/Worker\";\nimport type { WorkerProps } from \"@alchemy.run/cloudflare/Workers/Worker\";\nimport { effect as providerLayer, tryFindProviderRegistrationByType } from \"alchemy/Provider\";\nimport type { ProviderService } from \"alchemy/Provider\";\nimport { Array as Arr, Effect, Layer, Option, Order, Predicate, Record as Rec, pipe } from \"effect\";\n\nimport { COMPATIBILITY_DATE } from \"#/shared/config/index.ts\";\n\nconst laterDate = Order.max(Order.String);\n\nexport interface TracingOptions {\n readonly destinations?: readonly string[];\n}\n\nconst withDestinations =\n (added: readonly string[]) =>\n (own: readonly string[] | null | undefined): string[] =>\n pipe(\n Option.fromNullishOr(own),\n Option.getOrElse((): readonly string[] => []),\n Arr.appendAll(added),\n Arr.dedupe,\n );\n\nconst isVersionOfAnotherWorker = ({ version }: WorkerProps): boolean =>\n pipe(\n Option.fromUndefinedOr(version),\n Option.exists(({ parent }) => Predicate.isNotUndefined(parent)),\n );\n\nconst optsOutOfTraces = ({ observability }: WorkerProps): boolean =>\n pipe(\n Option.fromUndefinedOr(observability),\n Option.flatMapNullishOr(({ traces }) => traces),\n Option.exists(({ enabled }) => enabled === false),\n );\n\nconst withIssues = (props: WorkerProps): WorkerProps => {\n const { observability = {} } = props;\n return {\n ...props,\n observability: { ...observability, issues: { enabled: true, ...observability.issues } },\n };\n};\n\nconst withTraces =\n (options: TracingOptions) =>\n (props: WorkerProps): WorkerProps => {\n const { observability = {}, compatibility = {} } = props;\n const { logs, traces } = observability;\n const destinations = pipe(\n Option.fromNullishOr(traces),\n Option.flatMapNullishOr((own) => own.destinations),\n Option.getOrUndefined,\n );\n return {\n ...props,\n compatibility: {\n ...compatibility,\n date: laterDate(compatibility.date ?? COMPATIBILITY_DATE, COMPATIBILITY_DATE),\n },\n observability: {\n ...observability,\n enabled: true,\n logs: { enabled: true, invocationLogs: true, persist: true, ...logs },\n traces: {\n enabled: true,\n persist: true,\n ...traces,\n destinations: withDestinations(options.destinations ?? [])(destinations),\n },\n },\n };\n };\n\nexport const traced =\n (options: TracingOptions = {}) =>\n (props: WorkerProps): WorkerProps => {\n if (isVersionOfAnotherWorker(props)) {\n return props;\n }\n const issued = withIssues(props);\n if (optsOutOfTraces(props)) {\n return issued;\n }\n return withTraces(options)(issued);\n };\n\nexport type WorkerService = ProviderService<Worker>;\n\ntype Tunable = Readonly<{ news: WorkerProps; olds?: WorkerProps | undefined }>;\n\nconst tracedInput =\n (options: TracingOptions) =>\n <Input extends Tunable>(input: Input): Input => ({\n ...input,\n news: traced(options)(input.news),\n ...pipe(\n Option.fromUndefinedOr(input.olds),\n Option.match({ onNone: () => ({}), onSome: (olds) => ({ olds: traced(options)(olds) }) }),\n ),\n });\n\nconst tunedReconcile =\n (options: TracingOptions) =>\n <Input extends Tunable, Output>(\n service: Readonly<{ reconcile: (input: Input) => Output }>,\n ): Readonly<{ reconcile: (input: Input) => Output }> => ({\n reconcile: (input) => service.reconcile(tracedInput(options)(input)),\n });\n\nconst tunedPrecreate =\n (options: TracingOptions) =>\n <Input extends Tunable, Output>(\n service: Readonly<{ precreate?: ((input: Input) => Output) | undefined }>,\n ): Readonly<{ precreate?: (input: Input) => Output }> =>\n pipe(\n Option.fromUndefinedOr(service.precreate),\n Option.match({\n onNone: () => ({}),\n onSome: (precreate) => ({\n precreate: (input: Input): Output => precreate(tracedInput(options)(input)),\n }),\n }),\n );\n\nexport const tuneService =\n (options: TracingOptions) =>\n <Service extends WorkerService>(service: Service): Service => ({\n ...service,\n ...tunedReconcile(options)(service),\n ...tunedPrecreate(options)(service),\n ...pipe(\n Option.fromUndefinedOr(service.modes),\n Option.match({\n onNone: () => ({}),\n onSome: (modes) => {\n const tune = tuneService(options);\n return { modes: pipe(modes, Rec.map(Effect.map(tune))) };\n },\n }),\n ),\n });\n\nconst tracingProvider = (options: TracingOptions): Layer.Layer<never> => {\n const tune = tuneService(options);\n return providerLayer(\n Worker,\n tryFindProviderRegistrationByType<Worker>(Worker.Type).pipe(\n Effect.flatMap(Effect.fromOption),\n Effect.map(tune),\n Effect.orDie,\n ),\n );\n};\n\nexport const withWorkersTracing =\n (options: TracingOptions = {}) =>\n <Out, Error, In>(providers: Layer.Layer<Out, Error, In>): Layer.Layer<Out, Error, In> =>\n Layer.provideMerge(tracingProvider(options), providers);\n\nexport { COMPATIBILITY_DATE } from \"#/shared/config/index.ts\";\nexport { DEFAULT_DESTINATION, traceSink } from \"#/features/sink-traces/index.ts\";\nexport type { TraceSinkProps } from \"#/features/sink-traces/index.ts\";\n"],"mappings":";;;;;;;AAAA,MAAa,qBAAqB;;ACclC,MAAa,sBAAsB;AAEnC,MAAM,iBAAiB;AAEvB,MAAM,iBACJ,mBACE,IAAI,IAAI,YAAY,QAAQ,gEAAgE,CAAC,CAAC,CAC3F,QACL;AAEF,MAAa,YAAY,OAAO,GAAG,WAAW,CAAC,CAAC,UAAU,UAAU,EACl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ACE,OAAO,gBAAgB,QAAQ,SAAS,GACxC,OAAO,MAAM;CACX,eAAe,CAAC;CAChB,SAAS,eAAe,EACtB,YAAY,UAAyB,UAAU,YAAY,OAAO,CAAC,CAAC,KAAK,CAAC,EAC5E;AACF,CAAC,CACH;AAEJ,MAAa,eACV,aAC+B,aAA+B;CAC7D,GAAG;CACH,GAAG,eAAe,OAAO,CAAC,CAAC,OAAO;CAClC,GAAG,eAAe,OAAO,CAAC,CAAC,OAAO;CAClC,GAAG,KACD,OAAO,gBAAgB,QAAQ,KAAK,GACpC,OAAO,MAAM;EACX,eAAe,CAAC;EAChB,SAAS,UAAU;GACjB,MAAM,OAAO,YAAY,OAAO;GAChC,OAAO,EAAE,OAAO,KAAK,OAAOC,OAAI,IAAI,OAAO,IAAI,IAAI,CAAC,CAAC,EAAE;EACzD;CACF,CAAC,CACH;AACF;AAEF,MAAM,mBAAmB,YAAgD;CACvE,MAAM,OAAO,YAAY,OAAO;CAChC,OAAOC,OACL,QACA,kCAA0C,OAAO,IAAI,CAAC,CAAC,KACrD,OAAO,QAAQ,OAAO,UAAU,GAChC,OAAO,IAAI,IAAI,GACf,OAAO,KACT,CACF;AACF;AAEA,MAAa,sBACV,UAA0B,CAAC,OACX,cACf,MAAM,aAAa,gBAAgB,OAAO,GAAG,SAAS"}
|
|
1
|
+
{"version":3,"file":"alchemy.mjs","names":["Arr","Rec","providerLayer"],"sources":["../../src/shared/config/compatibility.ts","../../src/features/sink-traces/model/trace-sink.ts","../../src/app/workers-tracing-alchemy.ts"],"sourcesContent":["export const COMPATIBILITY_DATE = \"2026-08-25\";\n","import { Workers } from \"@alchemy.run/cloudflare\";\nimport { makeRandom } from \"alchemy\";\nimport { map } from \"alchemy/Output\";\nimport { Effect, Redacted } from \"effect\";\n\nimport { COMPATIBILITY_DATE } from \"#/shared/config/index.ts\";\n\nexport interface TraceSinkProps {\n readonly destination?: string;\n readonly workerName?: string;\n readonly logpush?: boolean;\n readonly cpuMs?: number;\n}\n\nexport const DEFAULT_DESTINATION = \"workers-tracing\";\n\nconst DEFAULT_CPU_MS = 1000;\n\nconst sinkMain = (): string =>\n decodeURIComponent(\n new URL(import.meta.resolve(\"@r_masseater/masseater-utils/workers-tracing/trace-sink-worker\"))\n .pathname,\n );\n\nexport const traceSink = Effect.fn(\"traceSink\")(function* traceSink({\n destination = DEFAULT_DESTINATION,\n workerName = `${destination}-sink`,\n logpush = true,\n cpuMs = DEFAULT_CPU_MS,\n}: TraceSinkProps = {}) {\n const token = yield* makeRandom(\"TraceSinkToken\");\n const sink = yield* Workers.Worker(\"TraceSink\", {\n name: workerName,\n main: sinkMain(),\n compatibility: { date: COMPATIBILITY_DATE },\n logpush,\n limits: { cpuMs },\n env: { TRACE_SINK_TOKEN: token },\n observability: {\n enabled: true,\n logs: { enabled: true, invocationLogs: false, persist: true },\n traces: { enabled: false },\n issues: { enabled: true },\n },\n });\n return yield* Workers.ObservabilityDestination(\"Traces\", {\n name: destination,\n url: map(sink.url, (url) => new URL(\"/v1/traces\", url).href),\n headers: {\n authorization: map(token, (value) => Redacted.make(`Bearer ${Redacted.value(value)}`)),\n },\n logpushDataset: \"opentelemetry-traces\",\n });\n});\n","import { Worker } from \"@alchemy.run/cloudflare/Workers/Worker\";\nimport type { WorkerProps } from \"@alchemy.run/cloudflare/Workers/Worker\";\nimport { effect as providerLayer, tryFindProviderRegistrationByType } from \"alchemy/Provider\";\nimport type { ProviderService } from \"alchemy/Provider\";\nimport { Array as Arr, Effect, Layer, Option, Order, Predicate, Record as Rec, pipe } from \"effect\";\n\nimport { COMPATIBILITY_DATE } from \"#/shared/config/index.ts\";\n\nconst laterDate = Order.max(Order.String);\n\nexport interface TracingOptions {\n readonly destinations?: readonly string[];\n readonly traceSampleRate?: number;\n readonly logSampleRate?: number;\n}\n\nconst sampledAt = (rate: number | undefined): Readonly<{ headSamplingRate?: number }> =>\n pipe(\n Option.fromUndefinedOr(rate),\n Option.match({ onNone: () => ({}), onSome: (headSamplingRate) => ({ headSamplingRate }) }),\n );\n\nconst withDestinations =\n (added: readonly string[]) =>\n (own: readonly string[] | null | undefined): string[] =>\n pipe(\n Option.fromNullishOr(own),\n Option.getOrElse((): readonly string[] => []),\n Arr.appendAll(added),\n Arr.dedupe,\n );\n\nconst isVersionOfAnotherWorker = ({ version }: WorkerProps): boolean =>\n pipe(\n Option.fromUndefinedOr(version),\n Option.exists(({ parent }) => Predicate.isNotUndefined(parent)),\n );\n\nconst optsOutOfTraces = ({ observability }: WorkerProps): boolean =>\n pipe(\n Option.fromUndefinedOr(observability),\n Option.flatMapNullishOr(({ traces }) => traces),\n Option.exists(({ enabled }) => enabled === false),\n );\n\nconst withIssues = (props: WorkerProps): WorkerProps => {\n const { observability = {} } = props;\n return {\n ...props,\n observability: { ...observability, issues: { enabled: true, ...observability.issues } },\n };\n};\n\nconst withTraces =\n (options: TracingOptions) =>\n (props: WorkerProps): WorkerProps => {\n const { observability = {}, compatibility = {} } = props;\n const { logs, traces } = observability;\n const destinations = pipe(\n Option.fromNullishOr(traces),\n Option.flatMapNullishOr((own) => own.destinations),\n Option.getOrUndefined,\n );\n return {\n ...props,\n compatibility: {\n ...compatibility,\n date: laterDate(compatibility.date ?? COMPATIBILITY_DATE, COMPATIBILITY_DATE),\n },\n observability: {\n ...observability,\n enabled: true,\n logs: {\n enabled: true,\n invocationLogs: true,\n persist: true,\n ...sampledAt(options.logSampleRate),\n ...logs,\n },\n traces: {\n enabled: true,\n persist: true,\n ...sampledAt(options.traceSampleRate),\n ...traces,\n destinations: withDestinations(options.destinations ?? [])(destinations),\n },\n },\n };\n };\n\nexport const traced =\n (options: TracingOptions = {}) =>\n (props: WorkerProps): WorkerProps => {\n if (isVersionOfAnotherWorker(props)) {\n return props;\n }\n const issued = withIssues(props);\n if (optsOutOfTraces(props)) {\n return issued;\n }\n return withTraces(options)(issued);\n };\n\nexport type WorkerService = ProviderService<Worker>;\n\ntype Tunable = Readonly<{ news: WorkerProps; olds?: WorkerProps | undefined }>;\n\nconst tracedInput =\n (options: TracingOptions) =>\n <Input extends Tunable>(input: Input): Input => ({\n ...input,\n news: traced(options)(input.news),\n ...pipe(\n Option.fromUndefinedOr(input.olds),\n Option.match({ onNone: () => ({}), onSome: (olds) => ({ olds: traced(options)(olds) }) }),\n ),\n });\n\nconst tunedReconcile =\n (options: TracingOptions) =>\n <Input extends Tunable, Output>(\n service: Readonly<{ reconcile: (input: Input) => Output }>,\n ): Readonly<{ reconcile: (input: Input) => Output }> => ({\n reconcile: (input) => service.reconcile(tracedInput(options)(input)),\n });\n\nconst tunedPrecreate =\n (options: TracingOptions) =>\n <Input extends Tunable, Output>(\n service: Readonly<{ precreate?: ((input: Input) => Output) | undefined }>,\n ): Readonly<{ precreate?: (input: Input) => Output }> =>\n pipe(\n Option.fromUndefinedOr(service.precreate),\n Option.match({\n onNone: () => ({}),\n onSome: (precreate) => ({\n precreate: (input: Input): Output => precreate(tracedInput(options)(input)),\n }),\n }),\n );\n\nexport const tuneService =\n (options: TracingOptions) =>\n <Service extends WorkerService>(service: Service): Service => ({\n ...service,\n ...tunedReconcile(options)(service),\n ...tunedPrecreate(options)(service),\n ...pipe(\n Option.fromUndefinedOr(service.modes),\n Option.match({\n onNone: () => ({}),\n onSome: (modes) => {\n const tune = tuneService(options);\n return { modes: pipe(modes, Rec.map(Effect.map(tune))) };\n },\n }),\n ),\n });\n\nconst tracingProvider = (options: TracingOptions): Layer.Layer<never> => {\n const tune = tuneService(options);\n return providerLayer(\n Worker,\n tryFindProviderRegistrationByType<Worker>(Worker.Type).pipe(\n Effect.flatMap(Effect.fromOption),\n Effect.map(tune),\n Effect.orDie,\n ),\n );\n};\n\nexport const withWorkersTracing =\n (options: TracingOptions = {}) =>\n <Out, Error, In>(providers: Layer.Layer<Out, Error, In>): Layer.Layer<Out, Error, In> =>\n Layer.provideMerge(tracingProvider(options), providers);\n\nexport { COMPATIBILITY_DATE } from \"#/shared/config/index.ts\";\nexport { DEFAULT_DESTINATION, traceSink } from \"#/features/sink-traces/index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CAAC,OACX,cACf,MAAM,aAAa,gBAAgB,OAAO,GAAG,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r_masseater/masseater-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
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, and what the Tauri desktop apps share: OpenTelemetry for the screens, Vite settings, the media-notes screens and the release commands.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"actions",
|
|
@@ -9,7 +9,7 @@ description: >
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: core
|
|
11
11
|
library: "@r_masseater/masseater-utils"
|
|
12
|
-
library_version: 0.
|
|
12
|
+
library_version: 0.13.1
|
|
13
13
|
sources:
|
|
14
14
|
- src/app
|
|
15
15
|
- src/features/sink-traces
|
|
@@ -127,6 +127,9 @@ It fails with `WorkersAiError` and logs a cut-off answer. The msch preset report
|
|
|
127
127
|
Deploy `traceSink()` once per account as its own stack.
|
|
128
128
|
Then name its destination in `withWorkersTracing({ destinations: ["workers-tracing"] })`.
|
|
129
129
|
The sink logs every received span, and `workers-traces` reads them back through the Workers Observability API.
|
|
130
|
+
Every span becomes one Workers Logs event, so a busy Worker can exceed the monthly allowance of log events.
|
|
131
|
+
Pass `traceSampleRate` and `logSampleRate`, from 0 to 1, to `withWorkersTracing` to keep that share of the traces and invocation logs of every Worker in the stack that sets no `headSamplingRate` of its own.
|
|
132
|
+
A request that `workers-traces --expect` checks is kept only at the sampled share, so a Worker that CI checks this way keeps its own `headSamplingRate: 1`.
|
|
130
133
|
|
|
131
134
|
```sh
|
|
132
135
|
workers-traces --request https://app.example.com/ --expect "GET /" --expect invite.load --wait 60
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"headers-Bpv9DhNS.mjs","names":["Arr","Rec"],"sources":["../src/entities/policy/model/headers.ts"],"sourcesContent":["import { Array as Arr, Option, Record as Rec, pipe } from \"effect\";\n\nimport { WEB_ANALYTICS_REPORT_ORIGIN, WEB_ANALYTICS_SCRIPT_ORIGIN } from \"#/shared/config/index.ts\";\n\nconst SECURITY_HEADERS_BASE = {\n \"Strict-Transport-Security\": \"max-age=31536000; includeSubDomains\",\n \"X-Content-Type-Options\": \"nosniff\",\n \"X-Frame-Options\": \"DENY\",\n \"Referrer-Policy\": \"strict-origin-when-cross-origin\",\n \"Permissions-Policy\": \"camera=(), geolocation=(), microphone=(), payment=(), usb=()\",\n} as const;\n\nexport const SECURITY_HEADERS = {\n ...SECURITY_HEADERS_BASE,\n \"Cross-Origin-Opener-Policy\": \"same-origin\",\n \"Cross-Origin-Embedder-Policy\": \"require-corp\",\n \"Cross-Origin-Resource-Policy\": \"same-origin\",\n} as const;\n\nexport const SECURITY_HEADERS_CREDENTIALLESS = {\n ...SECURITY_HEADERS,\n \"Cross-Origin-Embedder-Policy\": \"credentialless\",\n} as const;\n\nexport const SECURITY_HEADERS_EMBEDDING = {\n ...SECURITY_HEADERS_BASE,\n \"Cross-Origin-Opener-Policy\": \"same-origin\",\n \"Cross-Origin-Resource-Policy\": \"same-origin\",\n} as const;\n\nexport const ASSET_CACHE_CONTROL = \"public, max-age=31536000, immutable\";\n\nconst OBJECT_SOURCE_NONE = \"object-src 'none'\";\n\nconst BASE_URI_NONE = \"base-uri 'none'\";\n\nconst FRAME_ANCESTORS_NONE = \"frame-ancestors 'none'\";\n\nconst REPORT_ENDPOINT = \"default\";\n\nconst REPORT_TO = `report-to ${REPORT_ENDPOINT}`;\n\nexport const SERVER_RESPONSE_HEADERS = {\n ...SECURITY_HEADERS_BASE,\n \"Content-Security-Policy\": pipe(\n [FRAME_ANCESTORS_NONE, BASE_URI_NONE, OBJECT_SOURCE_NONE],\n Arr.join(\"; \"),\n ),\n} as const;\n\nconst workerDirective = (worker: readonly string[] | undefined): readonly string[] =>\n Arr.fromOption(\n Option.map(Option.fromNullishOr(worker), (sources) =>\n pipe([\"worker-src 'self'\", ...sources], Arr.join(\" \")),\n ),\n );\n\nconst frameDirective = (frame: readonly string[] | undefined): readonly string[] =>\n Arr.fromOption(\n Option.map(Option.fromNullishOr(frame), (sources) =>\n pipe([\"frame-src\", ...sources], Arr.join(\" \")),\n ),\n );\n\nconst fontDirective = (font: readonly string[] | undefined): readonly string[] =>\n Arr.fromOption(\n Option.map(Option.fromNullishOr(font), (sources) =>\n pipe([\"font-src 'self'\", ...sources], Arr.join(\" \")),\n ),\n );\n\nexport const contentSecurityPolicy = ({\n script,\n style,\n worker,\n font,\n frame,\n image = [],\n styleAttr = false,\n report = false,\n}: Readonly<{\n script: readonly string[];\n style: readonly string[];\n worker?: readonly string[];\n font?: readonly string[];\n frame?: readonly string[];\n image?: readonly string[];\n styleAttr?: boolean;\n report?: boolean;\n}>): string =>\n pipe(\n [\n \"default-src 'self'\",\n pipe([\"script-src 'self'\", WEB_ANALYTICS_SCRIPT_ORIGIN, ...script], Arr.join(\" \")),\n pipe([\"style-src 'self'\", ...style], Arr.join(\" \")),\n ...Arr.fromOption(Option.liftPredicate(\"style-src-attr 'unsafe-inline'\", () => styleAttr)),\n ...workerDirective(worker),\n ...fontDirective(font),\n ...frameDirective(frame),\n pipe([\"img-src 'self' data:\", ...image], Arr.join(\" \")),\n `connect-src 'self' ${WEB_ANALYTICS_REPORT_ORIGIN}`,\n OBJECT_SOURCE_NONE,\n BASE_URI_NONE,\n \"form-action 'self'\",\n FRAME_ANCESTORS_NONE,\n ...Arr.fromOption(Option.liftPredicate(REPORT_TO, () => report)),\n ],\n Arr.join(\"; \"),\n );\n\nexport const STATIC_PAGE_HEADERS = {\n ...SECURITY_HEADERS,\n \"Content-Security-Policy\": contentSecurityPolicy({\n script: [\"'wasm-unsafe-eval'\"],\n style: [],\n worker: [\"blob:\"],\n }),\n} as const;\n\nexport interface PageSources {\n readonly image?: readonly string[];\n readonly frame?: readonly string[];\n readonly script?: readonly string[];\n readonly font?: readonly string[];\n readonly report?: string;\n readonly speculationRules?: string;\n}\n\nconst isolationOf = (frame: readonly string[] | undefined): Readonly<Record<string, string>> =>\n Option.match(Option.fromNullishOr(frame), {\n onNone: () => SECURITY_HEADERS_CREDENTIALLESS,\n onSome: () => SECURITY_HEADERS_EMBEDDING,\n });\n\nconst reportingOf = (report: string | undefined): Readonly<Record<string, string>> =>\n Option.match(Option.fromNullishOr(report), {\n onNone: () => ({}),\n onSome: (url) => ({ \"Reporting-Endpoints\": `${REPORT_ENDPOINT}=\"${url}\"` }),\n });\n\nconst speculationOf = (url: string | undefined): Readonly<Record<string, string>> =>\n Option.match(Option.fromNullishOr(url), {\n onNone: () => ({}),\n onSome: (rules) => ({ \"Speculation-Rules\": `\"${rules}\"` }),\n });\n\nexport const serverPageHeaders = ({\n image = [],\n script = [],\n frame,\n font,\n report,\n speculationRules,\n}: PageSources): Readonly<Record<string, string>> => ({\n ...isolationOf(frame),\n ...reportingOf(report),\n ...speculationOf(speculationRules),\n \"Content-Security-Policy\": contentSecurityPolicy({\n script,\n style: [],\n image: [\"blob:\", ...image],\n styleAttr: true,\n report: Option.isSome(Option.fromNullishOr(report)),\n ...Rec.getSomes({ frame: Option.fromNullishOr(frame), font: Option.fromNullishOr(font) }),\n }),\n});\n\nexport const SERVER_PAGE_HEADERS = serverPageHeaders({});\n\nexport const EMBEDDED_VIDEO_SOURCES = {\n image: [\"https://i.ytimg.com\", \"https://nicovideo.cdn.nimg.jp\"],\n frame: [\"https://embed.nicovideo.jp\", \"https://www.youtube-nocookie.com\"],\n font: [\"data:\"],\n} as const satisfies PageSources;\n\nexport const SPECULATION_RULES_FILE = \"_speculation-rules\";\n\nexport const assetHeaders = ({\n page,\n base = \"\",\n}: Readonly<{ page: Readonly<Record<string, string>>; base?: string }>): string =>\n pipe(\n [\n `${base}/*`,\n ...pipe(\n Rec.toEntries(page),\n Arr.map(([name, value]) => ` ${name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AC,SAAS,GAAG,KAAK;EACzB,WAAW;EACX,QAAQ,OAAO,OAAO,OAAO,cAAc,MAAM,CAAC;EAClD,GAAGC,OAAI,SAAS;GAAE,OAAO,OAAO,cAAc,KAAK;GAAG,MAAM,OAAO,cAAc,IAAI;EAAE,CAAC;CAC1F,CAAC;AACH;AAEA,MAAa,sBAAsB,kBAAkB,CAAC,CAAC;AAEvD,MAAa,yBAAyB;CACpC,OAAO,CAAC,uBAAuB,+BAA+B;CAC9D,OAAO,CAAC,8BAA8B,kCAAkC;CACxE,MAAM,CAAC,OAAO;AAChB;AAEA,MAAa,yBAAyB;AAEtC,MAAa,gBAAgB,EAC3B,MACA,OAAO,SAEP,KACE;CACE,GAAG,KAAK;CACR,GAAG,KACDA,OAAI,UAAU,IAAI,GAClBD,MAAI,KAAK,CAAC,MAAM,WAAW,KAAK,KAAK,IAAI,OAAO,CAClD;CACA,GAAG,KAAK;CACR,oBAAoB;CACpB;AACF,GACAA,MAAI,KAAK,IAAI,CACf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usage-meter-B196tKiM.mjs","names":["Arr","Arr","Rec","Str"],"sources":["../src/shared/lib/usage-spool.ts","../src/shared/lib/usage-meter.ts"],"sourcesContent":["import {\n Array as Arr,\n Effect,\n FileSystem,\n Layer,\n Option,\n Path,\n Random,\n Schema,\n pipe,\n} from \"effect\";\nimport type { Context } from \"effect\";\n\nimport { TallyList } from \"./usage-tally.ts\";\nimport type { Tally } from \"./usage-tally.ts\";\n\nexport interface Seen {\n readonly moduleUrl: string;\n readonly kind: string;\n readonly name: string;\n readonly calls: number;\n}\n\nconst ManifestFields = Schema.Struct({ name: Schema.String, version: Schema.String });\n\ntype Manifest = typeof ManifestFields.Type;\n\ntype Services = FileSystem.FileSystem | Path.Path;\n\nconst MANIFEST = \"package.json\";\n\nconst decodeManifest = Schema.decodeUnknownOption(Schema.fromJsonString(ManifestFields));\n\nconst encodeTallies = Schema.encodeEffect(Schema.fromJsonString(TallyList));\n\nconst manifestAbove = (\n directory: string,\n): Effect.Effect<Option.Option<Manifest>, never, Services> =>\n Effect.gen(function* manifestAboveDirectory() {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const text = yield* fs.readFileString(path.join(directory, MANIFEST)).pipe(Effect.option);\n const found = pipe(text, Option.flatMap(decodeManifest));\n const parent = path.dirname(directory);\n if (Option.isSome(found) || parent === directory) {\n return found;\n }\n return yield* manifestAbove(parent);\n });\n\nconst tallyOf = ({\n moduleUrl,\n kind,\n name,\n calls,\n}: Seen): Effect.Effect<Option.Option<Tally>, never, Services> =>\n Effect.gen(function* tallyOfSeen() {\n const path = yield* Path.Path;\n const file = yield* path.fromFileUrl(new URL(moduleUrl)).pipe(Effect.option);\n if (Option.isNone(file)) {\n return Option.none<Tally>();\n }\n const manifest = yield* manifestAbove(path.dirname(file.value));\n return pipe(\n manifest,\n Option.map(({ name: library, version }): Tally => ({ library, version, kind, name, calls })),\n );\n });\n\nconst written = (spool: string, seen: readonly Seen[]): Effect.Effect<void, never, Services> =>\n Effect.gen(function* writeSpool() {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const tallies = yield* Effect.forEach(seen, tallyOf, { concurrency: \"unbounded\" }).pipe(\n Effect.map(Arr.getSomes),\n );\n const text = yield* encodeTallies(tallies);\n const suffix = yield* Random.nextInt;\n yield* fs.makeDirectory(spool, { recursive: true });\n yield* fs.writeFileString(\n path.join(spool, `${String(process.pid)}-${String(suffix)}.json`),\n text,\n );\n }).pipe(Effect.ignore);\n\nconst taggedError = Schema.TaggedError;\n\nclass NodeServicesMissing extends taggedError<\n NodeServicesMissing,\n { readonly brand: unique symbol }\n>()(\"NodeServicesMissing\", { message: Schema.String }) {}\n\nconst nodeServices = Effect.tryPromise({\n try: () => import(\"@effect/platform-node/NodeServices\"),\n catch: () => NodeServicesMissing.make({ message: \"@effect/platform-node could not be loaded\" }),\n}).pipe(Effect.flatMap(({ layer }) => Layer.build(layer)));\n\nexport const spoolWritten =\n (spool: string) =>\n (seen: readonly Seen[]): Effect.Effect<void> =>\n nodeServices.pipe(\n Effect.flatMap((services: Context.Context<Services>) =>\n Effect.provideContext(written(spool, seen), services),\n ),\n Effect.scoped,\n Effect.ignore,\n );\n","import {\n Array as Arr,\n Config,\n Effect,\n Exit,\n Option,\n Predicate,\n Record as Rec,\n String as Str,\n pipe,\n} from \"effect\";\n\nimport { spoolWritten } from \"./usage-spool.ts\";\nimport type { Seen } from \"./usage-spool.ts\";\nimport { NO_CALLS, SPOOL_ENV } from \"./usage-tally.ts\";\n\nexport interface UsageMeter {\n readonly rules: <Name extends string, Rule>(\n rules: Readonly<Record<Name, Rule>>,\n ) => Readonly<Record<Name, Rule>>;\n readonly functions: <Name extends string, Value>(\n functions: Readonly<Record<Name, Value>>,\n ) => Readonly<Record<Name, Value>>;\n readonly plugins: <Plugin extends RulePlugin>(\n plugins: Readonly<Record<string, Plugin>>,\n ) => Readonly<Record<string, Plugin>>;\n readonly within: (prefix: string) => UsageMeter;\n}\n\nexport interface RulePlugin {\n readonly rules?: Readonly<Record<string, unknown>> | undefined;\n}\n\ninterface Declared {\n readonly moduleUrl: string;\n readonly kind: string;\n readonly name: string;\n}\n\ntype Callable = (...args: readonly unknown[]) => unknown;\n\nconst RULE_ENTRIES = [\"create\", \"createOnce\", \"check\", \"linter\", \"fixer\"] as const;\n\nconst RULE = \"rule\";\n\nconst FUNCTION = \"function\";\n\nconst ONE_CALL = 1;\n\nconst PREFIX_SEPARATOR = \"/\";\n\nconst KEY_SEPARATOR = \"\\u0000\";\n\nconst idle: UsageMeter = {\n rules: (rules) => rules,\n functions: (functions) => functions,\n plugins: (plugins) => plugins,\n within: () => idle,\n};\n\nconst declared = new Map<string, Declared>();\n\nconst calls = new Map<string, number>();\n\nconst state = { flushed: false, scheduled: false };\n\nconst spoolSetting = Exit.match(\n Effect.runSyncExit(Config.NonEmptyString(SPOOL_ENV).pipe(Config.option)),\n {\n onSuccess: (value) => value,\n onFailure: () => Option.none<string>(),\n },\n);\n\nconst isCallable = (value: unknown): value is Callable => Predicate.isFunction(value);\n\nconst keyOf = ({ moduleUrl, kind, name }: Declared): string =>\n Arr.join([moduleUrl, kind, name], KEY_SEPARATOR);\n\nconst countCall = (key: string): void => {\n const next = (calls.get(key) ?? NO_CALLS) + ONE_CALL;\n calls.set(key, next);\n};\n\nconst counted = <Value extends Callable>(key: string, callable: Value): Value =>\n Object.assign(function countedCall(this: unknown, ...args: readonly unknown[]): unknown {\n countCall(key);\n return callable.call(this, ...args);\n }, callable);\n\nconst ruleCounted = <Rule>(key: string, rule: Rule): Rule => {\n if (isCallable(rule)) {\n return counted(key, rule);\n }\n if (!Predicate.isObject(rule)) {\n return rule;\n }\n const entries = pipe(\n RULE_ENTRIES,\n Arr.flatMap((entry) =>\n pipe(\n Option.liftPredicate(Rec.get({ ...rule }, entry), Option.isSome),\n Option.flatMap((found) => Option.liftPredicate(found.value, isCallable)),\n Option.map((callable) => [entry, counted(key, callable)] as const),\n Option.toArray,\n ),\n ),\n );\n if (Arr.isReadonlyArrayEmpty(entries)) {\n return rule;\n }\n return { ...rule, ...Rec.fromEntries(entries) };\n};\n\nconst functionCounted = <Value>(key: string, value: Value): Value => {\n if (isCallable(value)) {\n return counted(key, value);\n }\n return value;\n};\n\nexport const flushUsage: Effect.Effect<void> = Effect.suspend(() => {\n if (state.flushed || Option.isNone(spoolSetting)) {\n return Effect.void;\n }\n state.flushed = true;\n const seen = pipe(\n [...declared],\n Arr.map(([key, exported]): Seen => ({ ...exported, calls: calls.get(key) ?? NO_CALLS })),\n );\n return spoolWritten(spoolSetting.value)(seen);\n});\n\nconst flushOnExit = (): void => {\n if (state.scheduled) {\n return;\n }\n state.scheduled = true;\n process.once(\"beforeExit\", () => {\n Effect.runFork(flushUsage);\n });\n};\n\nconst qualified = (prefix: string, name: string): string =>\n pipe([prefix, name], Arr.filter(Str.isNonEmpty), Arr.join(PREFIX_SEPARATOR));\n\nconst wrapped =\n (moduleUrl: string, prefix: string, kind: string) =>\n <Name extends string, Value>(\n wrap: (key: string, value: Value) => Value,\n ): ((names: Readonly<Record<Name, Value>>) => Readonly<Record<Name, Value>>) =>\n (names) => {\n flushOnExit();\n return pipe(\n names,\n Rec.map((value: Value, name: Name) => {\n const exported: Declared = { moduleUrl, kind, name: qualified(prefix, name) };\n declared.set(keyOf(exported), exported);\n return wrap(keyOf(exported), value);\n }),\n );\n };\n\nconst meterOf = (moduleUrl: string, prefix: string): UsageMeter => {\n const rules: UsageMeter[\"rules\"] = (named) =>\n wrapped(moduleUrl, prefix, RULE)(ruleCounted)(named);\n const plugins: UsageMeter[\"plugins\"] = (named) =>\n pipe(\n named,\n Rec.map((plugin, name) =>\n pipe(\n Option.fromUndefinedOr(plugin.rules),\n Option.match({\n onNone: () => plugin,\n onSome: (pluginRules) => ({\n ...plugin,\n rules: meterOf(moduleUrl, qualified(prefix, name)).rules(pluginRules),\n }),\n }),\n ),\n ),\n );\n return {\n rules,\n functions: (named) => wrapped(moduleUrl, prefix, FUNCTION)(functionCounted)(named),\n plugins,\n within: (inner) => meterOf(moduleUrl, qualified(prefix, inner)),\n };\n};\n\nexport const usageMeter = (moduleUrl: string): UsageMeter =>\n pipe(\n spoolSetting,\n Option.match({\n onNone: () => idle,\n onSome: () => meterOf(moduleUrl, \"\"),\n }),\n );\n"],"mappings":";;;AAuBA,MAAM,iBAAiB,OAAO,OAAO;CAAE,MAAM,OAAO;CAAQ,SAAS,OAAO;AAAO,CAAC;AAMpF,MAAM,WAAW;AAEjB,MAAM,iBAAiB,OAAO,oBAAoB,OAAO,eAAe,cAAc,CAAC;AAEvF,MAAM,gBAAgB,OAAO,aAAa,OAAO,eAAe,SAAS,CAAC;AAE1E,MAAM,iBACJ,cAEA,OAAO,IAAI,UAAU,yBAAyB;CAC5C,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,OAAO,GAAG,eAAe,KAAK,KAAK,WAAW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