@krak-stack/registry 0.1.58 → 0.1.60

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 (41) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +3 -0
  3. package/dist/components/ui/data-table.d.ts +2 -0
  4. package/dist/components/ui/data-table.js +6 -2
  5. package/dist/components/ui/item.d.ts +22 -0
  6. package/dist/components/ui/trace.d.ts +18 -0
  7. package/dist/services/agent/client/index.js +584 -434
  8. package/dist/services/agent/client/widget.d.ts +1 -0
  9. package/dist/services/events/browser.js +29 -3
  10. package/dist/services/events/client/audit-log-table.js +6 -2
  11. package/dist/services/events/client/tracking-notice.js +2 -1
  12. package/dist/services/events/index.d.ts +26 -56
  13. package/dist/services/events/index.js +118 -7
  14. package/dist/services/events/schema.d.ts +66 -24
  15. package/dist/services/events/schema.js +34 -3
  16. package/dist/services/opentelemetry/api.js +2 -1
  17. package/dist/services/opentelemetry/browser.d.ts +1 -1
  18. package/dist/services/opentelemetry/browser.js +2 -1
  19. package/dist/services/opentelemetry/events.d.ts +1 -1
  20. package/dist/services/opentelemetry/index.d.ts +1 -1
  21. package/dist/services/opentelemetry/index.js +2 -1
  22. package/dist/services/opentelemetry/schema.d.ts +3 -1
  23. package/dist/services/opentelemetry/web-vitals.js +2 -1
  24. package/dist/services/speech/api.d.ts +13 -0
  25. package/dist/services/speech/api.js +60 -0
  26. package/dist/services/speech/index.d.ts +39 -0
  27. package/dist/services/speech/index.js +105 -0
  28. package/dist/services/speech/schema.d.ts +43 -0
  29. package/dist/services/speech/schema.js +54 -0
  30. package/dist/services/webhooks/http-client.d.ts +7 -0
  31. package/dist/services/webhooks/http-client.js +57 -0
  32. package/dist/services/webhooks/index.d.ts +341 -0
  33. package/dist/services/webhooks/index.js +737 -0
  34. package/dist/services/webhooks/migrations.d.ts +5 -0
  35. package/dist/services/webhooks/migrations.js +44 -0
  36. package/dist/services/webhooks/schema.d.ts +243 -0
  37. package/dist/services/webhooks/schema.js +333 -0
  38. package/dist/services/webhooks/url.d.ts +3 -0
  39. package/dist/services/webhooks/url.js +32 -0
  40. package/package.json +37 -1
  41. package/dist/components/ui/marker.d.ts +0 -10
@@ -37,6 +37,7 @@ var EventAttributeValue = Schema.Union([
37
37
  Schema.Array(Schema.Boolean)
38
38
  ]);
39
39
  var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
40
+ var EventPropertiesSchema = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "EventProperties" });
40
41
  var EventOptionsSchema = Schema.Struct({
41
42
  userId: Schema.optional(Schema.NonEmptyString),
42
43
  anonymousId: Schema.optional(Schema.NonEmptyString),
@@ -47,7 +48,7 @@ var EventOptionsSchema = Schema.Struct({
47
48
  }).annotate({ identifier: "EventOptions" });
48
49
  var TelemetryEvent = Schema.Struct({
49
50
  name: Schema.NonEmptyString,
50
- properties: Schema.optional(EventAttributesSchema),
51
+ properties: Schema.optional(EventPropertiesSchema),
51
52
  options: Schema.optional(EventOptionsSchema)
52
53
  }).annotate({ identifier: "TelemetryEvent" });
53
54
 
@@ -259,7 +260,7 @@ var AuditTarget = Schema3.Struct({
259
260
  var trackEventFields = {
260
261
  eventId: Schema3.optional(EventId),
261
262
  name: Schema3.NonEmptyString.check(Schema3.isMaxLength(128)),
262
- properties: Schema3.optional(EventAttributesSchema),
263
+ properties: Schema3.optional(EventPropertiesSchema),
263
264
  identity: Schema3.optional(EventIdentity),
264
265
  timestamp: Schema3.optional(Schema3.DateTimeUtc)
265
266
  };
@@ -274,6 +275,24 @@ var TrackEvent = Schema3.Union([
274
275
  target: AuditTarget
275
276
  })
276
277
  ]).annotate({ identifier: "TrackEvent" });
278
+ var EventInputProperties = Schema3.Record(Schema3.String, Schema3.Unknown).annotate({ identifier: "EventInputProperties" });
279
+ var TrackEventInput = Schema3.Union([
280
+ Schema3.Struct({
281
+ ...TrackEvent.members[0].fields,
282
+ properties: Schema3.optional(EventInputProperties)
283
+ }),
284
+ Schema3.Struct({
285
+ ...TrackEvent.members[1].fields,
286
+ properties: Schema3.optional(EventInputProperties)
287
+ })
288
+ ]).annotate({ identifier: "TrackEventInput" });
289
+ var EventSubscription = Schema3.Struct({
290
+ name: Schema3.NonEmptyString.check(Schema3.isMaxLength(128)),
291
+ events: Schema3.NonEmptyArray(trackEventFields.name)
292
+ }).annotate({ identifier: "EventSubscription" });
293
+
294
+ class EventSubscriberError extends Schema3.TaggedError()("EventSubscriberError", { subscription: Schema3.String }) {
295
+ }
277
296
  var EventActionFilter = Schema3.Struct({
278
297
  id: Schema3.Literal("eventName"),
279
298
  kind: Schema3.Literal("values"),
@@ -364,7 +383,7 @@ var AttributeValue = Schema3.Union([
364
383
  ]);
365
384
  var EventAttribute = Schema3.Struct({
366
385
  key: Schema3.NonEmptyString.check(Schema3.isMaxLength(128)),
367
- value: AttributeValue
386
+ value: Schema3.StructWithRest(Schema3.Struct({ stringValue: Schema3.optional(Schema3.String) }), [Schema3.Record(Schema3.String, Schema3.Json)])
368
387
  }).annotate({ identifier: "EventAttribute" });
369
388
  var EventLogRecord = Schema3.Struct({
370
389
  eventName: Schema3.NonEmptyString.check(Schema3.isMaxLength(128), Schema3.isPattern(/^[^\r\n]+$/)),
@@ -375,6 +394,13 @@ var EventLogRecord = Schema3.Struct({
375
394
  spanId: Schema3.optional(Schema3.String.check(Schema3.isPattern(/^[a-f0-9]{16}$/))),
376
395
  attributes: Schema3.Array(EventAttribute).check(Schema3.isMaxLength(64), Schema3.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
377
396
  }).annotate({ identifier: "EventLogRecord" });
397
+ var BrowserEventLogRecord = Schema3.Struct({
398
+ ...EventLogRecord.fields,
399
+ attributes: Schema3.Array(Schema3.Struct({
400
+ key: EventAttribute.fields.key,
401
+ value: AttributeValue
402
+ })).check(Schema3.isMaxLength(64), Schema3.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
403
+ }).annotate({ identifier: "BrowserEventLogRecord" });
378
404
  var extensions = Schema3.Record(Schema3.String, Schema3.Unknown);
379
405
  var OtlpLogs = Schema3.StructWithRest(Schema3.Struct({
380
406
  resourceLogs: Schema3.Array(Schema3.StructWithRest(Schema3.Struct({
@@ -400,6 +426,7 @@ export {
400
426
  AuditCount,
401
427
  AuditSortId,
402
428
  AuditTarget,
429
+ BrowserEventLogRecord,
403
430
  BrowserEventOptions,
404
431
  BrowserEventPath,
405
432
  BrowserPage,
@@ -413,12 +440,15 @@ export {
413
440
  EventGeolocationError,
414
441
  EventId,
415
442
  EventIdentity,
443
+ EventInputProperties,
416
444
  EventIpAddress,
417
445
  EventLogRecord,
418
446
  EventQuery,
419
447
  EventQueryStandard,
420
448
  EventRegion,
421
449
  EventSource,
450
+ EventSubscriberError,
451
+ EventSubscription,
422
452
  EventUuid,
423
453
  EventsPersistenceError,
424
454
  ExistingEventRequest,
@@ -429,6 +459,7 @@ export {
429
459
  StoredEventPayload,
430
460
  StoredEventRequest,
431
461
  TrackEvent,
462
+ TrackEventInput,
432
463
  VisitorEventSession,
433
464
  VisitorEventsRequest
434
465
  };
@@ -74,6 +74,7 @@ var EventAttributeValue = Schema.Union([
74
74
  Schema.Array(Schema.Boolean)
75
75
  ]);
76
76
  var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
77
+ var EventPropertiesSchema = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "EventProperties" });
77
78
  var EventOptionsSchema = Schema.Struct({
78
79
  userId: Schema.optional(Schema.NonEmptyString),
79
80
  anonymousId: Schema.optional(Schema.NonEmptyString),
@@ -84,7 +85,7 @@ var EventOptionsSchema = Schema.Struct({
84
85
  }).annotate({ identifier: "EventOptions" });
85
86
  var TelemetryEvent = Schema.Struct({
86
87
  name: Schema.NonEmptyString,
87
- properties: Schema.optional(EventAttributesSchema),
88
+ properties: Schema.optional(EventPropertiesSchema),
88
89
  options: Schema.optional(EventOptionsSchema)
89
90
  }).annotate({ identifier: "TelemetryEvent" });
90
91
 
@@ -26,7 +26,7 @@ export interface BrowserOtlpOptions {
26
26
  }
27
27
  export declare class BrowserOtlp {
28
28
  static readonly event: (name: string, properties?: {
29
- readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
29
+ readonly [x: string]: Schema.Json;
30
30
  } | undefined, options?: {
31
31
  readonly userId?: string | undefined;
32
32
  readonly anonymousId?: string | undefined;
@@ -62,6 +62,7 @@ var EventAttributeValue = Schema.Union([
62
62
  Schema.Array(Schema.Boolean)
63
63
  ]);
64
64
  var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
65
+ var EventPropertiesSchema = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "EventProperties" });
65
66
  var EventOptionsSchema = Schema.Struct({
66
67
  userId: Schema.optional(Schema.NonEmptyString),
67
68
  anonymousId: Schema.optional(Schema.NonEmptyString),
@@ -72,7 +73,7 @@ var EventOptionsSchema = Schema.Struct({
72
73
  }).annotate({ identifier: "EventOptions" });
73
74
  var TelemetryEvent = Schema.Struct({
74
75
  name: Schema.NonEmptyString,
75
- properties: Schema.optional(EventAttributesSchema),
76
+ properties: Schema.optional(EventPropertiesSchema),
76
77
  options: Schema.optional(EventOptionsSchema)
77
78
  }).annotate({ identifier: "TelemetryEvent" });
78
79
 
@@ -27,7 +27,7 @@ interface EventRecord {
27
27
  }
28
28
  /** Emits an INFO event without creating a tracing span or persisting identity. */
29
29
  export declare const event: (name: string, properties?: {
30
- readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
30
+ readonly [x: string]: Schema.Json;
31
31
  } | undefined, options?: {
32
32
  readonly userId?: string | undefined;
33
33
  readonly anonymousId?: string | undefined;
@@ -8,7 +8,7 @@ declare const Otlp_base: Context.ServiceClass<Otlp, "krakstack/opentelemetry/Otl
8
8
  /** Runtime-neutral server telemetry for HTTP applications, workers, and CLIs. */
9
9
  export declare class Otlp extends Otlp_base {
10
10
  static readonly event: (name: string, properties?: {
11
- readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
11
+ readonly [x: string]: Schema.Json;
12
12
  } | undefined, options?: {
13
13
  readonly userId?: string | undefined;
14
14
  readonly anonymousId?: string | undefined;
@@ -61,6 +61,7 @@ var EventAttributeValue = Schema.Union([
61
61
  Schema.Array(Schema.Boolean)
62
62
  ]);
63
63
  var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
64
+ var EventPropertiesSchema = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "EventProperties" });
64
65
  var EventOptionsSchema = Schema.Struct({
65
66
  userId: Schema.optional(Schema.NonEmptyString),
66
67
  anonymousId: Schema.optional(Schema.NonEmptyString),
@@ -71,7 +72,7 @@ var EventOptionsSchema = Schema.Struct({
71
72
  }).annotate({ identifier: "EventOptions" });
72
73
  var TelemetryEvent = Schema.Struct({
73
74
  name: Schema.NonEmptyString,
74
- properties: Schema.optional(EventAttributesSchema),
75
+ properties: Schema.optional(EventPropertiesSchema),
75
76
  options: Schema.optional(EventOptionsSchema)
76
77
  }).annotate({ identifier: "TelemetryEvent" });
77
78
 
@@ -19,6 +19,7 @@ export declare const BrowserWebVital: Schema.Struct<{
19
19
  readonly navigationType: Schema.Literals<readonly ["navigate", "reload", "back-forward", "back-forward-cache", "prerender", "restore"]>;
20
20
  }>;
21
21
  export declare const EventAttributesSchema: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Finite>, Schema.$Array<Schema.Boolean>]>>;
22
+ export declare const EventPropertiesSchema: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
22
23
  export declare const EventOptionsSchema: Schema.Struct<{
23
24
  readonly userId: Schema.optional<Schema.NonEmptyString>;
24
25
  readonly anonymousId: Schema.optional<Schema.NonEmptyString>;
@@ -29,7 +30,7 @@ export declare const EventOptionsSchema: Schema.Struct<{
29
30
  }>;
30
31
  export declare const TelemetryEvent: Schema.Struct<{
31
32
  readonly name: Schema.NonEmptyString;
32
- readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite, Schema.Boolean, Schema.$Array<Schema.String>, Schema.$Array<Schema.Finite>, Schema.$Array<Schema.Boolean>]>>>;
33
+ readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
33
34
  readonly options: Schema.optional<Schema.Struct<{
34
35
  readonly userId: Schema.optional<Schema.NonEmptyString>;
35
36
  readonly anonymousId: Schema.optional<Schema.NonEmptyString>;
@@ -40,4 +41,5 @@ export declare const TelemetryEvent: Schema.Struct<{
40
41
  }>>;
41
42
  }>;
42
43
  export type EventAttributes = typeof EventAttributesSchema.Type;
44
+ export type EventProperties = typeof EventPropertiesSchema.Type;
43
45
  export type EventOptions = typeof EventOptionsSchema.Type;
@@ -55,6 +55,7 @@ var EventAttributeValue = Schema.Union([
55
55
  Schema.Array(Schema.Boolean)
56
56
  ]);
57
57
  var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
58
+ var EventPropertiesSchema = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "EventProperties" });
58
59
  var EventOptionsSchema = Schema.Struct({
59
60
  userId: Schema.optional(Schema.NonEmptyString),
60
61
  anonymousId: Schema.optional(Schema.NonEmptyString),
@@ -65,7 +66,7 @@ var EventOptionsSchema = Schema.Struct({
65
66
  }).annotate({ identifier: "EventOptions" });
66
67
  var TelemetryEvent = Schema.Struct({
67
68
  name: Schema.NonEmptyString,
68
- properties: Schema.optional(EventAttributesSchema),
69
+ properties: Schema.optional(EventPropertiesSchema),
69
70
  options: Schema.optional(EventOptionsSchema)
70
71
  }).annotate({ identifier: "TelemetryEvent" });
71
72
 
@@ -0,0 +1,13 @@
1
+ import { HttpApiEndpoint, HttpApiGroup } from "effect/http-api";
2
+ import { Schema } from "effect";
3
+ import { SpeechUnavailable } from "./schema.js";
4
+ export declare const SpeechApiGroup: HttpApiGroup.HttpApiGroup<"speech", HttpApiEndpoint.HttpApiEndpoint<"synthesize", "POST", "/speech/synthesis", never, never, Schema.toCodecJson<Schema.Struct<{
5
+ readonly text: Schema.String;
6
+ readonly language: Schema.Literals<readonly ["en", "fr", "es", "zh", "ja", "ko"]>;
7
+ }>>, never, Schema.toCodecJson<Schema.Uint8Array>, Schema.toCodecJson<typeof SpeechUnavailable>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"transcribe", "POST", "/speech/transcriptions", never, never, Schema.toCodecJson<Schema.Struct<{
8
+ readonly audio: Schema.Uint8ArrayFromBase64;
9
+ readonly mimeType: Schema.Literals<readonly ["audio/webm", "audio/ogg", "audio/mp4", "audio/wav"]>;
10
+ readonly language: Schema.optionalKey<Schema.String>;
11
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
12
+ readonly text: Schema.String;
13
+ }>>, Schema.toCodecJson<typeof SpeechUnavailable>, never, never>, false>;
@@ -0,0 +1,60 @@
1
+ // ../../src/services/speech/api.ts
2
+ import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/http-api";
3
+ import { Schema as Schema2 } from "effect";
4
+
5
+ // ../../src/services/speech/schema.ts
6
+ import { Schema } from "effect";
7
+ var MAX_AUDIO_BYTES = 2 * 1024 * 1024;
8
+ var AudioMimeType = Schema.Literals([
9
+ "audio/webm",
10
+ "audio/ogg",
11
+ "audio/mp4",
12
+ "audio/wav"
13
+ ]).annotate({ identifier: "SpeechAudioMimeType" });
14
+ var TranscribeAudio = Schema.Struct({
15
+ audio: Schema.Uint8ArrayFromBase64.check(Schema.isMinLength(1), Schema.isMaxLength(MAX_AUDIO_BYTES)),
16
+ mimeType: AudioMimeType,
17
+ language: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[a-z]{2,3}$/)))
18
+ }).annotate({ identifier: "TranscribeAudio" });
19
+ var Transcription = Schema.Struct({
20
+ text: Schema.String.check(Schema.isMaxLength(12000))
21
+ }).annotate({ identifier: "SpeechTranscription" });
22
+ var WhisperRequest = Schema.Struct({
23
+ audio: TranscribeAudio.fields.audio,
24
+ language: TranscribeAudio.fields.language,
25
+ task: Schema.Literal("transcribe"),
26
+ vad_filter: Schema.Boolean
27
+ }).annotate({ identifier: "GatewayWhisperRequest" });
28
+ var WhisperResponse = Schema.Struct({
29
+ success: Schema.Literal(true),
30
+ result: Transcription
31
+ }).annotate({ identifier: "GatewayWhisperResponse" });
32
+
33
+ class SpeechUnavailable extends Schema.TaggedError()("SpeechUnavailable", {}, { httpApiStatus: 503 }) {
34
+ }
35
+ var SynthesizeSpeech = Schema.Struct({
36
+ text: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(4000), Schema.isPattern(/\S/)),
37
+ language: Schema.Literals(["en", "fr", "es", "zh", "ja", "ko"])
38
+ }).annotate({ identifier: "SynthesizeSpeech" });
39
+ var MeloRequest = Schema.Struct({
40
+ prompt: SynthesizeSpeech.fields.text,
41
+ lang: SynthesizeSpeech.fields.language
42
+ }).annotate({ identifier: "GatewayMeloRequest" });
43
+ var MeloResponse = Schema.Struct({
44
+ success: Schema.Literal(true),
45
+ result: Schema.Struct({ audio: Schema.Uint8ArrayFromBase64.check(Schema.isMinLength(1)) })
46
+ }).annotate({ identifier: "GatewayMeloResponse" });
47
+
48
+ // ../../src/services/speech/api.ts
49
+ var SpeechApiGroup = HttpApiGroup.make("speech").add(HttpApiEndpoint.post("transcribe", "/speech/transcriptions", {
50
+ payload: TranscribeAudio,
51
+ success: Transcription,
52
+ error: [SpeechUnavailable]
53
+ }), HttpApiEndpoint.post("synthesize", "/speech/synthesis", {
54
+ payload: SynthesizeSpeech,
55
+ success: Schema2.Uint8Array.pipe(HttpApiSchema.asUint8Array({ contentType: "audio/mpeg" })),
56
+ error: [SpeechUnavailable]
57
+ }));
58
+ export {
59
+ SpeechApiGroup
60
+ };
@@ -0,0 +1,39 @@
1
+ import { Context, Effect, Layer, Redacted } from "effect";
2
+ import { HttpClient } from "effect/http";
3
+ import { SpeechUnavailable } from "./schema.js";
4
+ export interface SpeechOptions {
5
+ readonly baseUrl: string;
6
+ readonly apiKey: Redacted.Redacted<string>;
7
+ readonly gatewayId: string;
8
+ }
9
+ declare const Speech_base: Context.ServiceClass<Speech, "@krak-stack/registry/speech/Speech", {
10
+ transcribe: (input: {
11
+ readonly audio: Uint8Array<ArrayBufferLike>;
12
+ readonly mimeType: "audio/mp4" | "audio/ogg" | "audio/wav" | "audio/webm";
13
+ readonly language?: string | undefined;
14
+ }) => Effect.Effect<{
15
+ text: string;
16
+ }, SpeechUnavailable, never>;
17
+ synthesize: (input: {
18
+ readonly text: string;
19
+ readonly language: "en" | "es" | "fr" | "ja" | "ko" | "zh";
20
+ }) => Effect.Effect<Uint8Array<ArrayBufferLike>, SpeechUnavailable, never>;
21
+ }> & {
22
+ readonly make: (options: SpeechOptions) => Effect.Effect<{
23
+ transcribe: (input: {
24
+ readonly audio: Uint8Array<ArrayBufferLike>;
25
+ readonly mimeType: "audio/mp4" | "audio/ogg" | "audio/wav" | "audio/webm";
26
+ readonly language?: string | undefined;
27
+ }) => Effect.Effect<{
28
+ text: string;
29
+ }, SpeechUnavailable, never>;
30
+ synthesize: (input: {
31
+ readonly text: string;
32
+ readonly language: "en" | "es" | "fr" | "ja" | "ko" | "zh";
33
+ }) => Effect.Effect<Uint8Array<ArrayBufferLike>, SpeechUnavailable, never>;
34
+ }, never, HttpClient.HttpClient>;
35
+ };
36
+ export declare class Speech extends Speech_base {
37
+ static readonly layer: (options: SpeechOptions) => Layer.Layer<Speech, never, never>;
38
+ }
39
+ export {};
@@ -0,0 +1,105 @@
1
+ // ../../src/services/speech/index.ts
2
+ import { Context, Effect, Layer, Schema as Schema2 } from "effect";
3
+ import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
4
+
5
+ // ../../src/services/speech/schema.ts
6
+ import { Schema } from "effect";
7
+ var MAX_AUDIO_BYTES = 2 * 1024 * 1024;
8
+ var AudioMimeType = Schema.Literals([
9
+ "audio/webm",
10
+ "audio/ogg",
11
+ "audio/mp4",
12
+ "audio/wav"
13
+ ]).annotate({ identifier: "SpeechAudioMimeType" });
14
+ var TranscribeAudio = Schema.Struct({
15
+ audio: Schema.Uint8ArrayFromBase64.check(Schema.isMinLength(1), Schema.isMaxLength(MAX_AUDIO_BYTES)),
16
+ mimeType: AudioMimeType,
17
+ language: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[a-z]{2,3}$/)))
18
+ }).annotate({ identifier: "TranscribeAudio" });
19
+ var Transcription = Schema.Struct({
20
+ text: Schema.String.check(Schema.isMaxLength(12000))
21
+ }).annotate({ identifier: "SpeechTranscription" });
22
+ var WhisperRequest = Schema.Struct({
23
+ audio: TranscribeAudio.fields.audio,
24
+ language: TranscribeAudio.fields.language,
25
+ task: Schema.Literal("transcribe"),
26
+ vad_filter: Schema.Boolean
27
+ }).annotate({ identifier: "GatewayWhisperRequest" });
28
+ var WhisperResponse = Schema.Struct({
29
+ success: Schema.Literal(true),
30
+ result: Transcription
31
+ }).annotate({ identifier: "GatewayWhisperResponse" });
32
+
33
+ class SpeechUnavailable extends Schema.TaggedError()("SpeechUnavailable", {}, { httpApiStatus: 503 }) {
34
+ }
35
+ var SynthesizeSpeech = Schema.Struct({
36
+ text: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(4000), Schema.isPattern(/\S/)),
37
+ language: Schema.Literals(["en", "fr", "es", "zh", "ja", "ko"])
38
+ }).annotate({ identifier: "SynthesizeSpeech" });
39
+ var MeloRequest = Schema.Struct({
40
+ prompt: SynthesizeSpeech.fields.text,
41
+ lang: SynthesizeSpeech.fields.language
42
+ }).annotate({ identifier: "GatewayMeloRequest" });
43
+ var MeloResponse = Schema.Struct({
44
+ success: Schema.Literal(true),
45
+ result: Schema.Struct({ audio: Schema.Uint8ArrayFromBase64.check(Schema.isMinLength(1)) })
46
+ }).annotate({ identifier: "GatewayMeloResponse" });
47
+
48
+ // ../../src/services/speech/index.ts
49
+ class Speech extends Context.Service()("@krak-stack/registry/speech/Speech", {
50
+ make: (options) => Effect.gen(function* () {
51
+ const http = (yield* HttpClient.HttpClient).pipe(HttpClient.filterStatusOk);
52
+ const transcribe = Effect.fn("Speech.transcribe")(function* (input) {
53
+ const url = yield* Schema2.decodeUnknownEffect(Schema2.URLFromString)(options.baseUrl);
54
+ const path = yield* Schema2.decodeUnknownEffect(Schema2.String.check(Schema2.isPattern(/^\/.*accounts\/[^/]+\/ai\/(v1|run)\/?$/)))(url.pathname);
55
+ url.pathname = path.replace(/\/(v1|run)\/?$/, "/run/@cf/openai/whisper-large-v3-turbo");
56
+ url.search = "";
57
+ url.hash = "";
58
+ let payload = {
59
+ audio: input.audio,
60
+ task: "transcribe",
61
+ vad_filter: true
62
+ };
63
+ if (input.language)
64
+ payload = { ...payload, language: input.language };
65
+ const request = yield* HttpClientRequest.post(url.toString()).pipe(HttpClientRequest.bearerToken(options.apiKey), HttpClientRequest.setHeaders({
66
+ "cf-aig-gateway-id": options.gatewayId,
67
+ "cf-aig-skip-cache": "true",
68
+ "cf-aig-collect-log": "false"
69
+ }), HttpClientRequest.schemaBodyJson(WhisperRequest)(payload));
70
+ const response = yield* http.execute(request);
71
+ const body = yield* HttpClientResponse.schemaBodyJson(WhisperResponse)(response);
72
+ return { text: body.result.text.trim() };
73
+ }, Effect.timeout("60 seconds"), Effect.mapError(() => new SpeechUnavailable({})));
74
+ const synthesize = Effect.fn("Speech.synthesize")(function* (input) {
75
+ const payload = yield* Schema2.decodeUnknownEffect(SynthesizeSpeech)(input);
76
+ const url = yield* Schema2.decodeUnknownEffect(Schema2.URLFromString)(options.baseUrl);
77
+ const path = yield* Schema2.decodeUnknownEffect(Schema2.String.check(Schema2.isPattern(/^\/.*accounts\/[^/]+\/ai\/(v1|run)\/?$/)))(url.pathname);
78
+ url.pathname = path.replace(/\/(v1|run)\/?$/, "/run/@cf/myshell-ai/melotts");
79
+ url.search = "";
80
+ url.hash = "";
81
+ const request = yield* HttpClientRequest.post(url.toString()).pipe(HttpClientRequest.bearerToken(options.apiKey), HttpClientRequest.setHeaders({
82
+ "cf-aig-gateway-id": options.gatewayId,
83
+ "cf-aig-skip-cache": "true",
84
+ "cf-aig-collect-log": "false",
85
+ accept: "audio/mpeg"
86
+ }), HttpClientRequest.schemaBodyJson(MeloRequest)({
87
+ prompt: payload.text,
88
+ lang: payload.language
89
+ }));
90
+ const response = yield* http.execute(request);
91
+ if (response.headers["content-type"]?.split(";")[0]?.trim() === "audio/mpeg") {
92
+ const bytes = new Uint8Array(yield* response.arrayBuffer);
93
+ return yield* Schema2.decodeUnknownEffect(Schema2.Uint8Array.check(Schema2.isMinLength(1)))(bytes);
94
+ }
95
+ const body = yield* HttpClientResponse.schemaBodyJson(MeloResponse)(response);
96
+ return body.result.audio;
97
+ }, Effect.timeout("60 seconds"), Effect.mapError(() => new SpeechUnavailable({})));
98
+ return { transcribe, synthesize };
99
+ })
100
+ }) {
101
+ static layer = (options) => Layer.effect(this, this.make(options)).pipe(Layer.provide(FetchHttpClient.layer));
102
+ }
103
+ export {
104
+ Speech
105
+ };
@@ -0,0 +1,43 @@
1
+ import { Schema } from "effect";
2
+ export declare const MAX_AUDIO_BYTES: number;
3
+ export declare const AudioMimeType: Schema.Literals<readonly ["audio/webm", "audio/ogg", "audio/mp4", "audio/wav"]>;
4
+ export declare const TranscribeAudio: Schema.Struct<{
5
+ readonly audio: Schema.Uint8ArrayFromBase64;
6
+ readonly mimeType: Schema.Literals<readonly ["audio/webm", "audio/ogg", "audio/mp4", "audio/wav"]>;
7
+ readonly language: Schema.optionalKey<Schema.String>;
8
+ }>;
9
+ export declare const Transcription: Schema.Struct<{
10
+ readonly text: Schema.String;
11
+ }>;
12
+ export declare const WhisperRequest: Schema.Struct<{
13
+ readonly audio: Schema.Uint8ArrayFromBase64;
14
+ readonly language: Schema.optionalKey<Schema.String>;
15
+ readonly task: Schema.Literal<"transcribe">;
16
+ readonly vad_filter: Schema.Boolean;
17
+ }>;
18
+ export declare const WhisperResponse: Schema.Struct<{
19
+ readonly success: Schema.Literal<true>;
20
+ readonly result: Schema.Struct<{
21
+ readonly text: Schema.String;
22
+ }>;
23
+ }>;
24
+ declare const SpeechUnavailable_base: Schema.Class<SpeechUnavailable, Schema.TaggedStruct<"SpeechUnavailable", {}>, import("effect/Cause").YieldableError>;
25
+ export declare class SpeechUnavailable extends SpeechUnavailable_base {
26
+ }
27
+ export type TranscribeAudio = typeof TranscribeAudio.Type;
28
+ export declare const SynthesizeSpeech: Schema.Struct<{
29
+ readonly text: Schema.String;
30
+ readonly language: Schema.Literals<readonly ["en", "fr", "es", "zh", "ja", "ko"]>;
31
+ }>;
32
+ export type SynthesizeSpeech = typeof SynthesizeSpeech.Type;
33
+ export declare const MeloRequest: Schema.Struct<{
34
+ readonly prompt: Schema.String;
35
+ readonly lang: Schema.Literals<readonly ["en", "fr", "es", "zh", "ja", "ko"]>;
36
+ }>;
37
+ export declare const MeloResponse: Schema.Struct<{
38
+ readonly success: Schema.Literal<true>;
39
+ readonly result: Schema.Struct<{
40
+ readonly audio: Schema.Uint8ArrayFromBase64;
41
+ }>;
42
+ }>;
43
+ export {};
@@ -0,0 +1,54 @@
1
+ // ../../src/services/speech/schema.ts
2
+ import { Schema } from "effect";
3
+ var MAX_AUDIO_BYTES = 2 * 1024 * 1024;
4
+ var AudioMimeType = Schema.Literals([
5
+ "audio/webm",
6
+ "audio/ogg",
7
+ "audio/mp4",
8
+ "audio/wav"
9
+ ]).annotate({ identifier: "SpeechAudioMimeType" });
10
+ var TranscribeAudio = Schema.Struct({
11
+ audio: Schema.Uint8ArrayFromBase64.check(Schema.isMinLength(1), Schema.isMaxLength(MAX_AUDIO_BYTES)),
12
+ mimeType: AudioMimeType,
13
+ language: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^[a-z]{2,3}$/)))
14
+ }).annotate({ identifier: "TranscribeAudio" });
15
+ var Transcription = Schema.Struct({
16
+ text: Schema.String.check(Schema.isMaxLength(12000))
17
+ }).annotate({ identifier: "SpeechTranscription" });
18
+ var WhisperRequest = Schema.Struct({
19
+ audio: TranscribeAudio.fields.audio,
20
+ language: TranscribeAudio.fields.language,
21
+ task: Schema.Literal("transcribe"),
22
+ vad_filter: Schema.Boolean
23
+ }).annotate({ identifier: "GatewayWhisperRequest" });
24
+ var WhisperResponse = Schema.Struct({
25
+ success: Schema.Literal(true),
26
+ result: Transcription
27
+ }).annotate({ identifier: "GatewayWhisperResponse" });
28
+
29
+ class SpeechUnavailable extends Schema.TaggedError()("SpeechUnavailable", {}, { httpApiStatus: 503 }) {
30
+ }
31
+ var SynthesizeSpeech = Schema.Struct({
32
+ text: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(4000), Schema.isPattern(/\S/)),
33
+ language: Schema.Literals(["en", "fr", "es", "zh", "ja", "ko"])
34
+ }).annotate({ identifier: "SynthesizeSpeech" });
35
+ var MeloRequest = Schema.Struct({
36
+ prompt: SynthesizeSpeech.fields.text,
37
+ lang: SynthesizeSpeech.fields.language
38
+ }).annotate({ identifier: "GatewayMeloRequest" });
39
+ var MeloResponse = Schema.Struct({
40
+ success: Schema.Literal(true),
41
+ result: Schema.Struct({ audio: Schema.Uint8ArrayFromBase64.check(Schema.isMinLength(1)) })
42
+ }).annotate({ identifier: "GatewayMeloResponse" });
43
+ export {
44
+ AudioMimeType,
45
+ MAX_AUDIO_BYTES,
46
+ MeloRequest,
47
+ MeloResponse,
48
+ SpeechUnavailable,
49
+ SynthesizeSpeech,
50
+ TranscribeAudio,
51
+ Transcription,
52
+ WhisperRequest,
53
+ WhisperResponse
54
+ };
@@ -0,0 +1,7 @@
1
+ import { Effect, Layer } from "effect";
2
+ import { Dns } from "effect/net";
3
+ import { HttpClient } from "effect/http";
4
+ /** DNS preflight. Network egress rules must also prevent DNS rebinding. */
5
+ export declare const isPublicWebhookDestination: (url: URL) => Effect.Effect<boolean, never, Dns.Dns>;
6
+ /** Built-in fetch client with public-destination checks and no redirects. */
7
+ export declare const layer: Layer.Layer<HttpClient.HttpClient, never, Dns.Dns>;
@@ -0,0 +1,57 @@
1
+ // ../../src/services/webhooks/http-client.ts
2
+ import { Effect, Layer, Result } from "effect";
3
+ import { Dns, NetAddress } from "effect/net";
4
+ import { FetchHttpClient, HttpClient, HttpClientError } from "effect/http";
5
+
6
+ // ../../src/services/webhooks/url.ts
7
+ var hostname = (value) => value.toLowerCase().replace(/^\[|\]$/g, "").replace(/\.$/, "");
8
+ var isPublicIpAddress = (value) => {
9
+ const address = hostname(value);
10
+ const octets = address.split(".");
11
+ if (octets.length === 4 && octets.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255)) {
12
+ const [a = 0, b = 0, c = 0] = octets.map(Number);
13
+ return !(a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && (b === 0 || b === 168 || b === 88 && c === 99) || a === 198 && (b === 18 || b === 19 || b === 51) || a === 203 && b === 0 || a >= 224);
14
+ }
15
+ const first = Number.parseInt(address.split(":")[0] ?? "", 16);
16
+ return address.includes(":") && first >= 8192 && first <= 16383 && !address.startsWith("2001:") && !address.startsWith("2002:") && !address.startsWith("3fff:");
17
+ };
18
+ var isPublicWebhookUrl = (url) => {
19
+ if (!["https:", "http:"].includes(url.protocol) || url.username || url.password)
20
+ return false;
21
+ const host = hostname(url.hostname);
22
+ if (!host || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local"))
23
+ return false;
24
+ return !(host.includes(":") || /^\d+(?:\.\d+){3}$/.test(host)) || isPublicIpAddress(host);
25
+ };
26
+
27
+ // ../../src/services/webhooks/http-client.ts
28
+ var isPublicWebhookDestination = Effect.fn("Webhooks.isPublicDestination")(function* (url) {
29
+ if (!isPublicWebhookUrl(url))
30
+ return false;
31
+ const hostname = url.hostname.replace(/^\[|\]$/g, "");
32
+ if (Result.isSuccess(NetAddress.ipFromString(hostname)))
33
+ return true;
34
+ const dns = yield* Dns.Dns;
35
+ return yield* dns.lookup(hostname).pipe(Effect.map((addresses) => addresses.every((address) => isPublicIpAddress(NetAddress.formatIp(address)))), Effect.catch(() => Effect.succeed(false)));
36
+ });
37
+ var layer = Layer.effect(HttpClient.HttpClient, Effect.gen(function* () {
38
+ const client = yield* HttpClient.HttpClient;
39
+ const dns = yield* Dns.Dns;
40
+ return client.pipe(HttpClient.transform((response, request) => Effect.gen(function* () {
41
+ if (!(yield* isPublicWebhookDestination(new URL(request.url)).pipe(Effect.provideService(Dns.Dns, dns)))) {
42
+ return yield* new HttpClientError.HttpClientError({
43
+ reason: new HttpClientError.TransportError({
44
+ request,
45
+ description: "Webhook destination is not public"
46
+ })
47
+ });
48
+ }
49
+ return yield* response.pipe(Effect.provideService(FetchHttpClient.RequestInit, {
50
+ redirect: "error"
51
+ }));
52
+ })));
53
+ })).pipe(Layer.provide(FetchHttpClient.layer));
54
+ export {
55
+ isPublicWebhookDestination,
56
+ layer
57
+ };