@effect-uai/core 0.1.0

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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -0
  3. package/dist/AiError-CqmYjXyx.d.mts +110 -0
  4. package/dist/AiError-CqmYjXyx.d.mts.map +1 -0
  5. package/dist/Items-D1C2686t.d.mts +372 -0
  6. package/dist/Items-D1C2686t.d.mts.map +1 -0
  7. package/dist/Loop-CzSJo1h8.d.mts +87 -0
  8. package/dist/Loop-CzSJo1h8.d.mts.map +1 -0
  9. package/dist/Outcome-C2JYknCu.d.mts +40 -0
  10. package/dist/Outcome-C2JYknCu.d.mts.map +1 -0
  11. package/dist/StructuredFormat-B5ueioNr.d.mts +88 -0
  12. package/dist/StructuredFormat-B5ueioNr.d.mts.map +1 -0
  13. package/dist/Tool-5wxOCuOh.d.mts +86 -0
  14. package/dist/Tool-5wxOCuOh.d.mts.map +1 -0
  15. package/dist/ToolEvent-B2N10hr3.d.mts +29 -0
  16. package/dist/ToolEvent-B2N10hr3.d.mts.map +1 -0
  17. package/dist/Turn-rlTfuHaQ.d.mts +211 -0
  18. package/dist/Turn-rlTfuHaQ.d.mts.map +1 -0
  19. package/dist/chunk-CfYAbeIz.mjs +13 -0
  20. package/dist/domain/AiError.d.mts +2 -0
  21. package/dist/domain/AiError.mjs +40 -0
  22. package/dist/domain/AiError.mjs.map +1 -0
  23. package/dist/domain/Items.d.mts +2 -0
  24. package/dist/domain/Items.mjs +238 -0
  25. package/dist/domain/Items.mjs.map +1 -0
  26. package/dist/domain/Turn.d.mts +2 -0
  27. package/dist/domain/Turn.mjs +82 -0
  28. package/dist/domain/Turn.mjs.map +1 -0
  29. package/dist/index.d.mts +14 -0
  30. package/dist/index.mjs +14 -0
  31. package/dist/language-model/LanguageModel.d.mts +60 -0
  32. package/dist/language-model/LanguageModel.d.mts.map +1 -0
  33. package/dist/language-model/LanguageModel.mjs +33 -0
  34. package/dist/language-model/LanguageModel.mjs.map +1 -0
  35. package/dist/loop/Loop.d.mts +2 -0
  36. package/dist/loop/Loop.mjs +172 -0
  37. package/dist/loop/Loop.mjs.map +1 -0
  38. package/dist/match/Match.d.mts +16 -0
  39. package/dist/match/Match.d.mts.map +1 -0
  40. package/dist/match/Match.mjs +15 -0
  41. package/dist/match/Match.mjs.map +1 -0
  42. package/dist/observability/Metrics.d.mts +45 -0
  43. package/dist/observability/Metrics.d.mts.map +1 -0
  44. package/dist/observability/Metrics.mjs +52 -0
  45. package/dist/observability/Metrics.mjs.map +1 -0
  46. package/dist/streaming/JSONL.d.mts +34 -0
  47. package/dist/streaming/JSONL.d.mts.map +1 -0
  48. package/dist/streaming/JSONL.mjs +51 -0
  49. package/dist/streaming/JSONL.mjs.map +1 -0
  50. package/dist/streaming/Lines.d.mts +27 -0
  51. package/dist/streaming/Lines.d.mts.map +1 -0
  52. package/dist/streaming/Lines.mjs +32 -0
  53. package/dist/streaming/Lines.mjs.map +1 -0
  54. package/dist/streaming/SSE.d.mts +31 -0
  55. package/dist/streaming/SSE.d.mts.map +1 -0
  56. package/dist/streaming/SSE.mjs +58 -0
  57. package/dist/streaming/SSE.mjs.map +1 -0
  58. package/dist/structured-format/StructuredFormat.d.mts +2 -0
  59. package/dist/structured-format/StructuredFormat.mjs +68 -0
  60. package/dist/structured-format/StructuredFormat.mjs.map +1 -0
  61. package/dist/testing/MockProvider.d.mts +48 -0
  62. package/dist/testing/MockProvider.d.mts.map +1 -0
  63. package/dist/testing/MockProvider.mjs +95 -0
  64. package/dist/testing/MockProvider.mjs.map +1 -0
  65. package/dist/tool/HistoryCheck.d.mts +24 -0
  66. package/dist/tool/HistoryCheck.d.mts.map +1 -0
  67. package/dist/tool/HistoryCheck.mjs +39 -0
  68. package/dist/tool/HistoryCheck.mjs.map +1 -0
  69. package/dist/tool/Outcome.d.mts +2 -0
  70. package/dist/tool/Outcome.mjs +45 -0
  71. package/dist/tool/Outcome.mjs.map +1 -0
  72. package/dist/tool/Resolvers.d.mts +44 -0
  73. package/dist/tool/Resolvers.d.mts.map +1 -0
  74. package/dist/tool/Resolvers.mjs +67 -0
  75. package/dist/tool/Resolvers.mjs.map +1 -0
  76. package/dist/tool/Tool.d.mts +2 -0
  77. package/dist/tool/Tool.mjs +79 -0
  78. package/dist/tool/Tool.mjs.map +1 -0
  79. package/dist/tool/ToolEvent.d.mts +2 -0
  80. package/dist/tool/ToolEvent.mjs +8 -0
  81. package/dist/tool/ToolEvent.mjs.map +1 -0
  82. package/dist/tool/Toolkit.d.mts +34 -0
  83. package/dist/tool/Toolkit.d.mts.map +1 -0
  84. package/dist/tool/Toolkit.mjs +105 -0
  85. package/dist/tool/Toolkit.mjs.map +1 -0
  86. package/package.json +127 -0
  87. package/src/domain/AiError.ts +93 -0
  88. package/src/domain/Items.ts +260 -0
  89. package/src/domain/Turn.ts +174 -0
  90. package/src/index.ts +13 -0
  91. package/src/language-model/LanguageModel.ts +73 -0
  92. package/src/loop/Loop.test.ts +412 -0
  93. package/src/loop/Loop.ts +295 -0
  94. package/src/match/Match.ts +9 -0
  95. package/src/observability/Metrics.ts +87 -0
  96. package/src/streaming/JSONL.test.ts +85 -0
  97. package/src/streaming/JSONL.ts +96 -0
  98. package/src/streaming/Lines.ts +34 -0
  99. package/src/streaming/SSE.test.ts +72 -0
  100. package/src/streaming/SSE.ts +114 -0
  101. package/src/structured-format/StructuredFormat.ts +160 -0
  102. package/src/testing/MockProvider.ts +161 -0
  103. package/src/tool/HistoryCheck.ts +49 -0
  104. package/src/tool/Outcome.ts +101 -0
  105. package/src/tool/Resolvers.test.ts +426 -0
  106. package/src/tool/Resolvers.ts +166 -0
  107. package/src/tool/Tool.ts +150 -0
  108. package/src/tool/ToolEvent.ts +37 -0
  109. package/src/tool/Toolkit.test.ts +45 -0
  110. package/src/tool/Toolkit.ts +228 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Betalyra Sociedade Unipessoal Lda.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @effect-uai/core
2
+
3
+ Low-level primitives for building AI agents with [Effect](https://effect.website).
4
+
5
+ The core thesis: **the user owns the loop**. State is a plain record;
6
+ `Loop` events control iteration; the body is a `Stream`. There is no
7
+ agent runtime, no orchestrator, no provider lock-in.
8
+
9
+ This package exposes:
10
+
11
+ - **Domain types** - `Items`, `Turn`, `AiError`
12
+ - **Provider contract** - `LanguageModel`
13
+ - **Loop primitive** - `Loop` (`loop`, `value`, `next`, `stop`, `nextAfter`, `nextAfterFold`, `streamUntilComplete`)
14
+ - **Tools** - `Tool`, `Toolkit`, `Outcome`, `ToolEvent`, `Resolvers`, `HistoryCheck`
15
+ - **Streaming codecs** - `SSE`, `JSONL`, `Lines`
16
+ - **Structured output** - `StructuredFormat`
17
+ - **Observability** - `Metrics`
18
+ - **Testing** - `testing/MockProvider`
19
+
20
+ No provider deps. Pair with one of:
21
+
22
+ - [`@effect-uai/responses`](https://www.npmjs.com/package/@effect-uai/responses) - OpenAI Responses API
23
+ - [`@effect-uai/anthropic`](https://www.npmjs.com/package/@effect-uai/anthropic) - Anthropic Messages
24
+ - [`@effect-uai/google`](https://www.npmjs.com/package/@effect-uai/google) - Google Gemini
25
+
26
+ ## Install
27
+
28
+ ```sh
29
+ pnpm add @effect-uai/core effect
30
+ ```
31
+
32
+ ESM-only. Requires `effect@4.x` as a peer.
33
+
34
+ ## Docs
35
+
36
+ Full docs: <https://effect-uai.betalyra.com>
37
+
38
+ Start with the [Quickstart](https://effect-uai.betalyra.com/start/getting-started/)
39
+ and then [Basic usage](https://effect-uai.betalyra.com/recipes/basic-usage/).
40
+
41
+ ## License
42
+
43
+ MIT
@@ -0,0 +1,110 @@
1
+ import { Duration } from "effect";
2
+ import * as _$effect_Types0 from "effect/Types";
3
+ import * as _$effect_Cause0 from "effect/Cause";
4
+
5
+ //#region src/domain/AiError.d.ts
6
+ declare namespace AiError_d_exports {
7
+ export { AiError, AuthFailed, AuthSubtype, Cancelled, ContentFiltered, ContextLengthExceeded, GenerationFailed, IncompleteTurn, InvalidRequest, RateLimited, Scope$1 as Scope, Timeout, Unavailable };
8
+ }
9
+ type Scope$1 = "rpm" | "tpm" | "rpd" | "tpd";
10
+ declare const RateLimited_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
11
+ readonly _tag: "RateLimited";
12
+ } & Readonly<A>;
13
+ declare class RateLimited extends RateLimited_base<{
14
+ provider: string;
15
+ retryAfter?: Duration.Duration;
16
+ scope?: Scope$1;
17
+ requestId?: string;
18
+ raw: unknown;
19
+ }> {}
20
+ declare const Unavailable_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
21
+ readonly _tag: "Unavailable";
22
+ } & Readonly<A>;
23
+ declare class Unavailable extends Unavailable_base<{
24
+ provider: string;
25
+ retryAfter?: Duration.Duration;
26
+ status?: number;
27
+ requestId?: string;
28
+ raw: unknown;
29
+ }> {}
30
+ declare const Timeout_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
31
+ readonly _tag: "Timeout";
32
+ } & Readonly<A>;
33
+ declare class Timeout extends Timeout_base<{
34
+ provider: string;
35
+ requestId?: string;
36
+ raw: unknown;
37
+ }> {}
38
+ declare const ContentFiltered_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
39
+ readonly _tag: "ContentFiltered";
40
+ } & Readonly<A>;
41
+ declare class ContentFiltered extends ContentFiltered_base<{
42
+ provider: string;
43
+ reason?: string;
44
+ requestId?: string;
45
+ raw: unknown;
46
+ }> {}
47
+ declare const ContextLengthExceeded_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
48
+ readonly _tag: "ContextLengthExceeded";
49
+ } & Readonly<A>;
50
+ declare class ContextLengthExceeded extends ContextLengthExceeded_base<{
51
+ provider: string;
52
+ modelLimit?: number;
53
+ requested?: number;
54
+ raw: unknown;
55
+ }> {}
56
+ declare const InvalidRequest_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
57
+ readonly _tag: "InvalidRequest";
58
+ } & Readonly<A>;
59
+ declare class InvalidRequest extends InvalidRequest_base<{
60
+ provider: string;
61
+ param?: string;
62
+ requestId?: string;
63
+ raw: unknown;
64
+ }> {}
65
+ type AuthSubtype = "auth" | "permission" | "billing" | "quota";
66
+ declare const AuthFailed_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
67
+ readonly _tag: "AuthFailed";
68
+ } & Readonly<A>;
69
+ declare class AuthFailed extends AuthFailed_base<{
70
+ provider: string;
71
+ subtype: AuthSubtype;
72
+ raw: unknown;
73
+ }> {}
74
+ declare const Cancelled_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
75
+ readonly _tag: "Cancelled";
76
+ } & Readonly<A>;
77
+ declare class Cancelled extends Cancelled_base<{
78
+ provider: string;
79
+ }> {}
80
+ declare const GenerationFailed_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
81
+ readonly _tag: "GenerationFailed";
82
+ } & Readonly<A>;
83
+ /**
84
+ * The model errored mid-generation. Distinct from `Unavailable` (transport
85
+ * problem before generation started) and from `IncompleteTurn` (provider
86
+ * stream ended without a terminal event). The provider's own error message,
87
+ * if any, is on `message`.
88
+ */
89
+ declare class GenerationFailed extends GenerationFailed_base<{
90
+ provider: string;
91
+ code?: string;
92
+ message?: string;
93
+ requestId?: string;
94
+ raw: unknown;
95
+ }> {}
96
+ declare const IncompleteTurn_base: new <A extends Record<string, any> = {}>(args: _$effect_Types0.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }>) => _$effect_Cause0.YieldableError & {
97
+ readonly _tag: "IncompleteTurn";
98
+ } & Readonly<A>;
99
+ /**
100
+ * The provider's delta stream ended without a terminal `turn_complete`.
101
+ * Indicates a misbehaving provider or a connection that dropped mid-flight.
102
+ * Non-terminal deltas seen so far have already been emitted downstream.
103
+ */
104
+ declare class IncompleteTurn extends IncompleteTurn_base<{
105
+ raw?: unknown;
106
+ }> {}
107
+ type AiError = RateLimited | Unavailable | Timeout | ContentFiltered | ContextLengthExceeded | InvalidRequest | AuthFailed | Cancelled | IncompleteTurn | GenerationFailed;
108
+ //#endregion
109
+ export { Cancelled as a, GenerationFailed as c, RateLimited as d, Scope$1 as f, AuthSubtype as i, IncompleteTurn as l, Unavailable as m, AiError_d_exports as n, ContentFiltered as o, Timeout as p, AuthFailed as r, ContextLengthExceeded as s, AiError as t, InvalidRequest as u };
110
+ //# sourceMappingURL=AiError-CqmYjXyx.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiError-CqmYjXyx.d.mts","names":[],"sources":["../src/domain/AiError.ts"],"mappings":";;;;;;;;KAEY,OAAA;AAAA,cAAqC,gBAAA;;;cAEpC,WAAA,SAAoB,gBAAA;EAC/B,QAAA;EACA,UAAA,GAAa,QAAA,CAAS,QAAA;EACtB,KAAA,GAAQ,OAAA;EACR,SAAA;EACA,GAAA;AAAA;AAAA,cACG,gBAAA;;;cAEQ,WAAA,SAAoB,gBAAA;EAC/B,QAAA;EACA,UAAA,GAAa,QAAA,CAAS,QAAA;EACtB,MAAA;EACA,SAAA;EACA,GAAA;AAAA;AAAA,cACG,YAAA;;;cAEQ,OAAA,SAAgB,YAAA;EAC3B,QAAA;EACA,SAAA;EACA,GAAA;AAAA;AAAA,cACG,oBAAA;;;cAEQ,eAAA,SAAwB,oBAAA;EACnC,QAAA;EACA,MAAA;EACA,SAAA;EACA,GAAA;AAAA;AAAA,cACG,0BAAA;;;cAEQ,qBAAA,SAA8B,0BAAA;EACzC,QAAA;EACA,UAAA;EACA,SAAA;EACA,GAAA;AAAA;AAAA,cACG,mBAAA;;;cAEQ,cAAA,SAAuB,mBAAA;EAClC,QAAA;EACA,KAAA;EACA,SAAA;EACA,GAAA;AAAA;AAAA,KAGU,WAAA;AAAA,cAAyD,eAAA;;;cAExD,UAAA,SAAmB,eAAA;EAC9B,QAAA;EACA,OAAA,EAAS,WAAA;EACT,GAAA;AAAA;AAAA,cACG,cAAA;;;cAEQ,SAAA,SAAkB,cAAA;EAC7B,QAAA;AAAA;AAAA,cACG,qBAAA;;;;;;;;;cAQQ,gBAAA,SAAyB,qBAAA;EACpC,QAAA;EACA,IAAA;EACA,OAAA;EACA,SAAA;EACA,GAAA;AAAA;AAAA,cACG,mBAAA;;;;;;;;cAOQ,cAAA,SAAuB,mBAAA;EAClC,GAAA;AAAA;AAAA,KAGU,OAAA,GACR,WAAA,GACA,WAAA,GACA,OAAA,GACA,eAAA,GACA,qBAAA,GACA,cAAA,GACA,UAAA,GACA,SAAA,GACA,cAAA,GACA,gBAAA"}
@@ -0,0 +1,372 @@
1
+ import { Schema } from "effect";
2
+
3
+ //#region src/domain/Items.d.ts
4
+ declare namespace Items_d_exports {
5
+ export { Annotation, ContainerFileCitation, ContentBlock, FileCitation, FilePath, FunctionCall, FunctionCallOutput, ImageBase64Source, ImageSource, ImageUrlSource, InputImage, InputText, InputTokensDetails, Item, Message, OutputText, OutputTokensDetails, Reasoning, Refusal, Role, StopReason, UrlCitation, Usage, assistantText, functionCallOutput, isContainerFileCitation, isFileCitation, isFilePath, isFunctionCall, isFunctionCallOutput, isImageBase64Source, isImageUrlSource, isInputImage, isInputText, isMessage, isOutputText, isReasoning, isRefusal, isUrlCitation, systemText, userText };
6
+ }
7
+ declare const InputText: Schema.Struct<{
8
+ readonly type: Schema.Literal<"input_text">;
9
+ readonly text: Schema.String;
10
+ }>;
11
+ type InputText = typeof InputText.Type;
12
+ /**
13
+ * Where an image lives. `url` covers HTTP(S) URLs (the model fetches
14
+ * them); `base64` covers inline bytes embedded in the request. Provider
15
+ * encoders dispatch on `_tag`. File-id / uploaded-asset references are
16
+ * provider-specific and stay out of this union for now.
17
+ */
18
+ declare const ImageUrlSource: Schema.Struct<{
19
+ readonly _tag: Schema.Literal<"url">;
20
+ readonly url: Schema.String;
21
+ }>;
22
+ type ImageUrlSource = typeof ImageUrlSource.Type;
23
+ /**
24
+ * Inline image bytes. `data` is **already base64-encoded** (matches what
25
+ * the wire formats expect; no double-encoding needed downstream).
26
+ * `media_type` is the MIME type, e.g. `"image/png"`.
27
+ */
28
+ declare const ImageBase64Source: Schema.Struct<{
29
+ readonly _tag: Schema.Literal<"base64">;
30
+ readonly media_type: Schema.String;
31
+ readonly data: Schema.String;
32
+ }>;
33
+ type ImageBase64Source = typeof ImageBase64Source.Type;
34
+ declare const ImageSource: Schema.Union<readonly [Schema.Struct<{
35
+ readonly _tag: Schema.Literal<"url">;
36
+ readonly url: Schema.String;
37
+ }>, Schema.Struct<{
38
+ readonly _tag: Schema.Literal<"base64">;
39
+ readonly media_type: Schema.String;
40
+ readonly data: Schema.String;
41
+ }>]>;
42
+ type ImageSource = typeof ImageSource.Type;
43
+ declare const isImageUrlSource: (s: ImageSource) => s is ImageUrlSource;
44
+ declare const isImageBase64Source: (s: ImageSource) => s is ImageBase64Source;
45
+ /**
46
+ * User-provided image content block. Pair with `InputText` inside a
47
+ * `Message.content` array to ask "what's in this image?" style questions.
48
+ */
49
+ declare const InputImage: Schema.Struct<{
50
+ readonly type: Schema.Literal<"input_image">;
51
+ readonly source: Schema.Union<readonly [Schema.Struct<{
52
+ readonly _tag: Schema.Literal<"url">;
53
+ readonly url: Schema.String;
54
+ }>, Schema.Struct<{
55
+ readonly _tag: Schema.Literal<"base64">;
56
+ readonly media_type: Schema.String;
57
+ readonly data: Schema.String;
58
+ }>]>;
59
+ }>;
60
+ type InputImage = typeof InputImage.Type;
61
+ declare const UrlCitation: Schema.Struct<{
62
+ readonly type: Schema.Literal<"url_citation">;
63
+ readonly url: Schema.String;
64
+ readonly start_index: Schema.Number;
65
+ readonly end_index: Schema.Number;
66
+ readonly title: Schema.String;
67
+ }>;
68
+ type UrlCitation = typeof UrlCitation.Type;
69
+ declare const FileCitation: Schema.Struct<{
70
+ readonly type: Schema.Literal<"file_citation">;
71
+ readonly file_id: Schema.String;
72
+ readonly index: Schema.Number;
73
+ }>;
74
+ type FileCitation = typeof FileCitation.Type;
75
+ declare const ContainerFileCitation: Schema.Struct<{
76
+ readonly type: Schema.Literal<"container_file_citation">;
77
+ readonly container_id: Schema.String;
78
+ readonly file_id: Schema.String;
79
+ readonly start_index: Schema.Number;
80
+ readonly end_index: Schema.Number;
81
+ }>;
82
+ type ContainerFileCitation = typeof ContainerFileCitation.Type;
83
+ declare const FilePath: Schema.Struct<{
84
+ readonly type: Schema.Literal<"file_path">;
85
+ readonly file_id: Schema.String;
86
+ readonly index: Schema.Number;
87
+ }>;
88
+ type FilePath = typeof FilePath.Type;
89
+ declare const Annotation: Schema.Union<readonly [Schema.Struct<{
90
+ readonly type: Schema.Literal<"url_citation">;
91
+ readonly url: Schema.String;
92
+ readonly start_index: Schema.Number;
93
+ readonly end_index: Schema.Number;
94
+ readonly title: Schema.String;
95
+ }>, Schema.Struct<{
96
+ readonly type: Schema.Literal<"file_citation">;
97
+ readonly file_id: Schema.String;
98
+ readonly index: Schema.Number;
99
+ }>, Schema.Struct<{
100
+ readonly type: Schema.Literal<"container_file_citation">;
101
+ readonly container_id: Schema.String;
102
+ readonly file_id: Schema.String;
103
+ readonly start_index: Schema.Number;
104
+ readonly end_index: Schema.Number;
105
+ }>, Schema.Struct<{
106
+ readonly type: Schema.Literal<"file_path">;
107
+ readonly file_id: Schema.String;
108
+ readonly index: Schema.Number;
109
+ }>]>;
110
+ type Annotation = typeof Annotation.Type;
111
+ declare const isUrlCitation: (a: Annotation) => a is UrlCitation;
112
+ declare const isFileCitation: (a: Annotation) => a is FileCitation;
113
+ declare const isContainerFileCitation: (a: Annotation) => a is ContainerFileCitation;
114
+ declare const isFilePath: (a: Annotation) => a is FilePath;
115
+ declare const OutputText: Schema.Struct<{
116
+ readonly type: Schema.Literal<"output_text">;
117
+ readonly text: Schema.String;
118
+ readonly annotations: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
119
+ readonly type: Schema.Literal<"url_citation">;
120
+ readonly url: Schema.String;
121
+ readonly start_index: Schema.Number;
122
+ readonly end_index: Schema.Number;
123
+ readonly title: Schema.String;
124
+ }>, Schema.Struct<{
125
+ readonly type: Schema.Literal<"file_citation">;
126
+ readonly file_id: Schema.String;
127
+ readonly index: Schema.Number;
128
+ }>, Schema.Struct<{
129
+ readonly type: Schema.Literal<"container_file_citation">;
130
+ readonly container_id: Schema.String;
131
+ readonly file_id: Schema.String;
132
+ readonly start_index: Schema.Number;
133
+ readonly end_index: Schema.Number;
134
+ }>, Schema.Struct<{
135
+ readonly type: Schema.Literal<"file_path">;
136
+ readonly file_id: Schema.String;
137
+ readonly index: Schema.Number;
138
+ }>]>>>;
139
+ }>;
140
+ type OutputText = typeof OutputText.Type;
141
+ /**
142
+ * Model-emitted refusal. Distinct from `output_text`: the model declined
143
+ * to answer rather than producing normal output. Pair with
144
+ * `stop_reason: "refusal"` on the surrounding `Turn`. Streamed via the
145
+ * `refusal_delta` `TurnEvent`.
146
+ */
147
+ declare const Refusal: Schema.Struct<{
148
+ readonly type: Schema.Literal<"refusal">;
149
+ readonly text: Schema.String;
150
+ }>;
151
+ type Refusal = typeof Refusal.Type;
152
+ declare const ContentBlock: Schema.Union<readonly [Schema.Struct<{
153
+ readonly type: Schema.Literal<"input_text">;
154
+ readonly text: Schema.String;
155
+ }>, Schema.Struct<{
156
+ readonly type: Schema.Literal<"input_image">;
157
+ readonly source: Schema.Union<readonly [Schema.Struct<{
158
+ readonly _tag: Schema.Literal<"url">;
159
+ readonly url: Schema.String;
160
+ }>, Schema.Struct<{
161
+ readonly _tag: Schema.Literal<"base64">;
162
+ readonly media_type: Schema.String;
163
+ readonly data: Schema.String;
164
+ }>]>;
165
+ }>, Schema.Struct<{
166
+ readonly type: Schema.Literal<"output_text">;
167
+ readonly text: Schema.String;
168
+ readonly annotations: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
169
+ readonly type: Schema.Literal<"url_citation">;
170
+ readonly url: Schema.String;
171
+ readonly start_index: Schema.Number;
172
+ readonly end_index: Schema.Number;
173
+ readonly title: Schema.String;
174
+ }>, Schema.Struct<{
175
+ readonly type: Schema.Literal<"file_citation">;
176
+ readonly file_id: Schema.String;
177
+ readonly index: Schema.Number;
178
+ }>, Schema.Struct<{
179
+ readonly type: Schema.Literal<"container_file_citation">;
180
+ readonly container_id: Schema.String;
181
+ readonly file_id: Schema.String;
182
+ readonly start_index: Schema.Number;
183
+ readonly end_index: Schema.Number;
184
+ }>, Schema.Struct<{
185
+ readonly type: Schema.Literal<"file_path">;
186
+ readonly file_id: Schema.String;
187
+ readonly index: Schema.Number;
188
+ }>]>>>;
189
+ }>, Schema.Struct<{
190
+ readonly type: Schema.Literal<"refusal">;
191
+ readonly text: Schema.String;
192
+ }>]>;
193
+ type ContentBlock = typeof ContentBlock.Type;
194
+ declare const Role: Schema.Literals<readonly ["user", "assistant", "system"]>;
195
+ type Role = typeof Role.Type;
196
+ declare const Message: Schema.Struct<{
197
+ readonly type: Schema.Literal<"message">;
198
+ readonly role: Schema.Literals<readonly ["user", "assistant", "system"]>;
199
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
200
+ readonly type: Schema.Literal<"input_text">;
201
+ readonly text: Schema.String;
202
+ }>, Schema.Struct<{
203
+ readonly type: Schema.Literal<"input_image">;
204
+ readonly source: Schema.Union<readonly [Schema.Struct<{
205
+ readonly _tag: Schema.Literal<"url">;
206
+ readonly url: Schema.String;
207
+ }>, Schema.Struct<{
208
+ readonly _tag: Schema.Literal<"base64">;
209
+ readonly media_type: Schema.String;
210
+ readonly data: Schema.String;
211
+ }>]>;
212
+ }>, Schema.Struct<{
213
+ readonly type: Schema.Literal<"output_text">;
214
+ readonly text: Schema.String;
215
+ readonly annotations: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
216
+ readonly type: Schema.Literal<"url_citation">;
217
+ readonly url: Schema.String;
218
+ readonly start_index: Schema.Number;
219
+ readonly end_index: Schema.Number;
220
+ readonly title: Schema.String;
221
+ }>, Schema.Struct<{
222
+ readonly type: Schema.Literal<"file_citation">;
223
+ readonly file_id: Schema.String;
224
+ readonly index: Schema.Number;
225
+ }>, Schema.Struct<{
226
+ readonly type: Schema.Literal<"container_file_citation">;
227
+ readonly container_id: Schema.String;
228
+ readonly file_id: Schema.String;
229
+ readonly start_index: Schema.Number;
230
+ readonly end_index: Schema.Number;
231
+ }>, Schema.Struct<{
232
+ readonly type: Schema.Literal<"file_path">;
233
+ readonly file_id: Schema.String;
234
+ readonly index: Schema.Number;
235
+ }>]>>>;
236
+ }>, Schema.Struct<{
237
+ readonly type: Schema.Literal<"refusal">;
238
+ readonly text: Schema.String;
239
+ }>]>>;
240
+ readonly providerData: Schema.optional<Schema.Unknown>;
241
+ }>;
242
+ type Message = typeof Message.Type;
243
+ declare const FunctionCall: Schema.Struct<{
244
+ readonly type: Schema.Literal<"function_call">;
245
+ readonly call_id: Schema.String;
246
+ readonly name: Schema.String;
247
+ readonly arguments: Schema.String;
248
+ readonly providerData: Schema.optional<Schema.Unknown>;
249
+ }>;
250
+ type FunctionCall = typeof FunctionCall.Type;
251
+ declare const FunctionCallOutput: Schema.Struct<{
252
+ readonly type: Schema.Literal<"function_call_output">;
253
+ readonly call_id: Schema.String;
254
+ readonly output: Schema.String;
255
+ readonly providerData: Schema.optional<Schema.Unknown>;
256
+ }>;
257
+ type FunctionCallOutput = typeof FunctionCallOutput.Type;
258
+ /**
259
+ * Reasoning item - top-level, mirrors OpenAI Responses API. Common shape
260
+ * across providers covers `summary` (human-readable text) and `signature`
261
+ * (opaque round-trip blob - Anthropic's signed thinking, OpenAI's
262
+ * encrypted_content, etc.). Provider-specific fields go in `providerData`.
263
+ */
264
+ declare const Reasoning: Schema.Struct<{
265
+ readonly type: Schema.Literal<"reasoning">;
266
+ readonly id: Schema.optional<Schema.String>;
267
+ readonly summary: Schema.optional<Schema.String>;
268
+ readonly signature: Schema.optional<Schema.String>;
269
+ readonly providerData: Schema.optional<Schema.Unknown>;
270
+ }>;
271
+ type Reasoning = typeof Reasoning.Type;
272
+ declare const Item: Schema.Union<readonly [Schema.Struct<{
273
+ readonly type: Schema.Literal<"message">;
274
+ readonly role: Schema.Literals<readonly ["user", "assistant", "system"]>;
275
+ readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
276
+ readonly type: Schema.Literal<"input_text">;
277
+ readonly text: Schema.String;
278
+ }>, Schema.Struct<{
279
+ readonly type: Schema.Literal<"input_image">;
280
+ readonly source: Schema.Union<readonly [Schema.Struct<{
281
+ readonly _tag: Schema.Literal<"url">;
282
+ readonly url: Schema.String;
283
+ }>, Schema.Struct<{
284
+ readonly _tag: Schema.Literal<"base64">;
285
+ readonly media_type: Schema.String;
286
+ readonly data: Schema.String;
287
+ }>]>;
288
+ }>, Schema.Struct<{
289
+ readonly type: Schema.Literal<"output_text">;
290
+ readonly text: Schema.String;
291
+ readonly annotations: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
292
+ readonly type: Schema.Literal<"url_citation">;
293
+ readonly url: Schema.String;
294
+ readonly start_index: Schema.Number;
295
+ readonly end_index: Schema.Number;
296
+ readonly title: Schema.String;
297
+ }>, Schema.Struct<{
298
+ readonly type: Schema.Literal<"file_citation">;
299
+ readonly file_id: Schema.String;
300
+ readonly index: Schema.Number;
301
+ }>, Schema.Struct<{
302
+ readonly type: Schema.Literal<"container_file_citation">;
303
+ readonly container_id: Schema.String;
304
+ readonly file_id: Schema.String;
305
+ readonly start_index: Schema.Number;
306
+ readonly end_index: Schema.Number;
307
+ }>, Schema.Struct<{
308
+ readonly type: Schema.Literal<"file_path">;
309
+ readonly file_id: Schema.String;
310
+ readonly index: Schema.Number;
311
+ }>]>>>;
312
+ }>, Schema.Struct<{
313
+ readonly type: Schema.Literal<"refusal">;
314
+ readonly text: Schema.String;
315
+ }>]>>;
316
+ readonly providerData: Schema.optional<Schema.Unknown>;
317
+ }>, Schema.Struct<{
318
+ readonly type: Schema.Literal<"function_call">;
319
+ readonly call_id: Schema.String;
320
+ readonly name: Schema.String;
321
+ readonly arguments: Schema.String;
322
+ readonly providerData: Schema.optional<Schema.Unknown>;
323
+ }>, Schema.Struct<{
324
+ readonly type: Schema.Literal<"function_call_output">;
325
+ readonly call_id: Schema.String;
326
+ readonly output: Schema.String;
327
+ readonly providerData: Schema.optional<Schema.Unknown>;
328
+ }>, Schema.Struct<{
329
+ readonly type: Schema.Literal<"reasoning">;
330
+ readonly id: Schema.optional<Schema.String>;
331
+ readonly summary: Schema.optional<Schema.String>;
332
+ readonly signature: Schema.optional<Schema.String>;
333
+ readonly providerData: Schema.optional<Schema.Unknown>;
334
+ }>]>;
335
+ type Item = typeof Item.Type;
336
+ declare const isInputText: (block: ContentBlock) => block is InputText;
337
+ declare const isInputImage: (block: ContentBlock) => block is InputImage;
338
+ declare const isOutputText: (block: ContentBlock) => block is OutputText;
339
+ declare const isRefusal: (block: ContentBlock) => block is Refusal;
340
+ declare const isMessage: (item: Item) => item is Message;
341
+ declare const isFunctionCall: (item: Item) => item is FunctionCall;
342
+ declare const isFunctionCallOutput: (item: Item) => item is FunctionCallOutput;
343
+ declare const isReasoning: (item: Item) => item is Reasoning;
344
+ declare const InputTokensDetails: Schema.Struct<{
345
+ readonly cached_tokens: Schema.optional<Schema.Number>;
346
+ }>;
347
+ type InputTokensDetails = typeof InputTokensDetails.Type;
348
+ declare const OutputTokensDetails: Schema.Struct<{
349
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
350
+ }>;
351
+ type OutputTokensDetails = typeof OutputTokensDetails.Type;
352
+ declare const Usage: Schema.Struct<{
353
+ readonly input_tokens: Schema.optional<Schema.Number>;
354
+ readonly output_tokens: Schema.optional<Schema.Number>;
355
+ readonly total_tokens: Schema.optional<Schema.Number>;
356
+ readonly input_tokens_details: Schema.optional<Schema.Struct<{
357
+ readonly cached_tokens: Schema.optional<Schema.Number>;
358
+ }>>;
359
+ readonly output_tokens_details: Schema.optional<Schema.Struct<{
360
+ readonly reasoning_tokens: Schema.optional<Schema.Number>;
361
+ }>>;
362
+ }>;
363
+ type Usage = typeof Usage.Type;
364
+ declare const StopReason: Schema.Literals<readonly ["stop", "tool_calls", "max_tokens", "refusal", "content_filter", "max_tool_calls"]>;
365
+ type StopReason = typeof StopReason.Type;
366
+ declare const userText: (text: string) => Message;
367
+ declare const systemText: (text: string) => Message;
368
+ declare const assistantText: (text: string) => Message;
369
+ declare const functionCallOutput: (call_id: string, output: string) => FunctionCallOutput;
370
+ //#endregion
371
+ export { isFunctionCall as A, isUrlCitation as B, UrlCitation as C, isContainerFileCitation as D, functionCallOutput as E, isInputText as F, userText as H, isMessage as I, isOutputText as L, isImageBase64Source as M, isImageUrlSource as N, isFileCitation as O, isInputImage as P, isReasoning as R, StopReason as S, assistantText as T, systemText as V, OutputText as _, FilePath as a, Refusal as b, ImageBase64Source as c, InputImage as d, InputText as f, Message as g, Items_d_exports as h, FileCitation as i, isFunctionCallOutput as j, isFilePath as k, ImageSource as l, Item as m, ContainerFileCitation as n, FunctionCall as o, InputTokensDetails as p, ContentBlock as r, FunctionCallOutput as s, Annotation as t, ImageUrlSource as u, OutputTokensDetails as v, Usage as w, Role as x, Reasoning as y, isRefusal as z };
372
+ //# sourceMappingURL=Items-D1C2686t.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Items-D1C2686t.d.mts","names":[],"sources":["../src/domain/Items.ts"],"mappings":";;;;;;cAMa,SAAA,EAAS,MAAA,CAAA,MAAA;EAAA;;;KAIV,SAAA,UAAmB,SAAA,CAAU,IAAA;;;;;;;cAQ5B,cAAA,EAAc,MAAA,CAAA,MAAA;EAAA;;;KAIf,cAAA,UAAwB,cAAA,CAAe,IAAA;;;;;;cAOtC,iBAAA,EAAiB,MAAA,CAAA,MAAA;EAAA;;;;KAKlB,iBAAA,UAA2B,iBAAA,CAAkB,IAAA;AAAA,cAE5C,WAAA,EAAW,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MA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AAA,cAClC,cAAA,GAAkB,IAAA,EAAM,IAAA,KAAO,IAAA,IAAQ,YAAA;AAAA,cACvC,oBAAA,GAAwB,IAAA,EAAM,IAAA,KAAO,IAAA,IAAQ,kBAAA;AAAA,cAE7C,WAAA,GAAe,IAAA,EAAM,IAAA,KAAO,IAAA,IAAQ,SAAA;AAAA,cAMpC,kBAAA,EAAkB,MAAA,CAAA,MAAA;EAAA;;KAGnB,kBAAA,UAA4B,kBAAA,CAAmB,IAAA;AAAA,cAE9C,mBAAA,EAAmB,MAAA,CAAA,MAAA;EAAA;;KAGpB,mBAAA,UAA6B,mBAAA,CAAoB,IAAA;AAAA,cAEhD,KAAA,EAAK,MAAA,CAAA,MAAA;EAAA;;;;;;;;;;KAON,KAAA,UAAe,KAAA,CAAM,IAAA;AAAA,cAEpB,UAAA,EAAU,MAAA,CAAA,QAAA;AAAA,KAUX,UAAA,UAAoB,UAAA,CAAW,IAAA;AAAA,cAM9B,QAAA,GAAY,IAAA,aAAe,OAAA;AAAA,cAM3B,UAAA,GAAc,IAAA,aAAe,OAAA;AAAA,cAM7B,aAAA,GAAiB,IAAA,aAAe,OAAA;AAAA,cAMhC,kBAAA,GAAsB,OAAA,UAAiB,MAAA,aAAiB,kBAAA"}
@@ -0,0 +1,87 @@
1
+ import { l as IncompleteTurn } from "./AiError-CqmYjXyx.mjs";
2
+ import { a as TurnEvent, i as Turn } from "./Turn-rlTfuHaQ.mjs";
3
+ import { Data, Effect, Stream } from "effect";
4
+
5
+ //#region src/loop/Loop.d.ts
6
+ declare namespace Loop_d_exports {
7
+ export { Event, loop, next, nextAfter, nextAfterFold, stop, stopAfter, stopEvent, streamUntilComplete, value };
8
+ }
9
+ /**
10
+ * The tagged union a body emits per pull. `Value` carries a payload that
11
+ * flows downstream. `Next` ends the current iteration and continues with a
12
+ * new state. `Stop` ends the loop entirely.
13
+ */
14
+ type Event<A, S> = Data.TaggedEnum<{
15
+ Value: {
16
+ readonly value: A;
17
+ };
18
+ Next: {
19
+ readonly state: S;
20
+ };
21
+ Stop: {};
22
+ }>;
23
+ /** Wrap a value so it flows through the loop to downstream consumers. */
24
+ declare const value: <A>(a: A) => Event<A, never>;
25
+ /** End the current iteration and continue with a new state. */
26
+ declare const next: <S>(state: S) => Event<never, S>;
27
+ /** The terminal `Stop` event. Use `stop` (the Stream) to end a loop body. */
28
+ declare const stopEvent: Event<never, never>;
29
+ /**
30
+ * A single-element stream that ends the loop. Return this from a body when
31
+ * there's nothing else to emit; equivalent to `stopAfter(Stream.empty)` but
32
+ * named for the common case.
33
+ */
34
+ declare const stop: Stream.Stream<Event<never, never>>;
35
+ /**
36
+ * Pipe a raw `Stream<A>` into the loop's emit shape, then terminate the
37
+ * iteration with `next(state)`. Common shape for "stream this turn's
38
+ * deltas, then continue with updated history."
39
+ */
40
+ declare const nextAfter: <S, A, E, R>(stream: Stream.Stream<A, E, R>, state: S) => Stream.Stream<Event<A, S>, E, R>;
41
+ /**
42
+ * Pipe a raw `Stream<A>` into the loop's emit shape, then terminate the
43
+ * loop. Common shape for "stream this turn's deltas, then we're done."
44
+ */
45
+ declare const stopAfter: <A, E, R>(stream: Stream.Stream<A, E, R>) => Stream.Stream<Event<A, never>, E, R>;
46
+ /**
47
+ * General `nextAfter` variant: drain `stream` to the consumer, fold elements
48
+ * into an accumulator, and at end-of-stream emit one `next(build(finalAcc))`.
49
+ *
50
+ * Subsumes `nextAfter` when state is constant (`reduce: (s, _) => s`,
51
+ * `build: (s) => s`). Used by `Toolkit.nextStateFrom` to collect tool
52
+ * results and build next state without exposing a Ref to recipes.
53
+ */
54
+ declare const nextAfterFold: <A, B, S, E, R>(stream: Stream.Stream<A, E, R>, initial: B, reduce: (acc: B, a: A) => B, build: (b: B) => S) => Stream.Stream<Event<A, S>, E, R>;
55
+ /**
56
+ * Lift a provider's `Stream<TurnEvent>` into a loop body's `Stream<Event<TurnEvent | A, S>>`.
57
+ * Each delta passes through as `value(delta)` (including the terminal
58
+ * `turn_complete`, so the consumer sees turn boundaries naturally). Once
59
+ * the terminal arrives, `then(turn)` runs and its returned stream of loop
60
+ * events (typically tool outputs followed by `next(state)` or `stop`) is
61
+ * concatenated.
62
+ *
63
+ * Pre-pipe transforms (`Stream.tap` / `Stream.map` / `Stream.filter`) on
64
+ * the raw delta stream cover anything an `emit`-style callback would do.
65
+ *
66
+ * If the upstream ends without a `turn_complete`, the resulting stream
67
+ * fails with `AiError.IncompleteTurn`. Catch it via `Stream.catchTag` if
68
+ * you want to recover.
69
+ */
70
+ declare const streamUntilComplete: <S, A, E2 = never, R2 = never>(then: (turn: Turn) => Effect.Effect<Stream.Stream<Event<A, S>, E2, R2>, E2, R2>) => <E, R>(deltas: Stream.Stream<TurnEvent, E, R>) => Stream.Stream<Event<TurnEvent | A, S>, E | E2 | IncompleteTurn, R | R2>;
71
+ type LoopBody<S, A, E, R> = (state: S) => Stream.Stream<Event<A, S>, E, R> | Effect.Effect<Stream.Stream<Event<A, S>, E, R>, E, R>;
72
+ /**
73
+ * Drive a state-threaded loop body. Each iteration runs `body(state)` to get
74
+ * a `Stream<Event<A, S>>`; values flow downstream, `next(s)` continues with
75
+ * a new state, `stop` ends the loop. See the file header for the full
76
+ * pull-based execution model.
77
+ *
78
+ * Dual: data-first `loop(initial, body)` and data-last `loop(body)(initial)`
79
+ * (or `pipe(initial, loop(body))`) both work.
80
+ */
81
+ declare const loop: {
82
+ <S, A, E, R>(body: LoopBody<S, A, E, R>): (initial: S) => Stream.Stream<A, E, R>;
83
+ <S, A, E, R>(initial: S, body: LoopBody<S, A, E, R>): Stream.Stream<A, E, R>;
84
+ };
85
+ //#endregion
86
+ export { nextAfter as a, stopAfter as c, value as d, next as i, stopEvent as l, Loop_d_exports as n, nextAfterFold as o, loop as r, stop as s, Event as t, streamUntilComplete as u };
87
+ //# sourceMappingURL=Loop-CzSJo1h8.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Loop-CzSJo1h8.d.mts","names":[],"sources":["../src/loop/Loop.ts"],"mappings":";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