@alchemy.run/pkg 0.0.0-placeholder → 2.0.0-beta.78

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 (70) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +117 -0
  4. package/dist/Manifest.d.ts +107 -0
  5. package/dist/Manifest.d.ts.map +1 -0
  6. package/dist/Manifest.js +58 -0
  7. package/dist/Manifest.js.map +1 -0
  8. package/dist/Protocol.d.ts +186 -0
  9. package/dist/Protocol.d.ts.map +1 -0
  10. package/dist/Protocol.js +115 -0
  11. package/dist/Protocol.js.map +1 -0
  12. package/dist/Registry/Bindings.d.ts +134 -0
  13. package/dist/Registry/Bindings.d.ts.map +1 -0
  14. package/dist/Registry/Bindings.js +92 -0
  15. package/dist/Registry/Bindings.js.map +1 -0
  16. package/dist/Registry/GitHub.d.ts +96 -0
  17. package/dist/Registry/GitHub.d.ts.map +1 -0
  18. package/dist/Registry/GitHub.js +226 -0
  19. package/dist/Registry/GitHub.js.map +1 -0
  20. package/dist/Registry/Handler.d.ts +53 -0
  21. package/dist/Registry/Handler.d.ts.map +1 -0
  22. package/dist/Registry/Handler.js +375 -0
  23. package/dist/Registry/Handler.js.map +1 -0
  24. package/dist/Registry/KVCache.d.ts +24 -0
  25. package/dist/Registry/KVCache.d.ts.map +1 -0
  26. package/dist/Registry/KVCache.js +42 -0
  27. package/dist/Registry/KVCache.js.map +1 -0
  28. package/dist/Registry/Sweep.d.ts +12 -0
  29. package/dist/Registry/Sweep.d.ts.map +1 -0
  30. package/dist/Registry/Sweep.js +69 -0
  31. package/dist/Registry/Sweep.js.map +1 -0
  32. package/dist/Registry/Tags.d.ts +49 -0
  33. package/dist/Registry/Tags.d.ts.map +1 -0
  34. package/dist/Registry/Tags.js +80 -0
  35. package/dist/Registry/Tags.js.map +1 -0
  36. package/dist/Registry.d.ts +378 -0
  37. package/dist/Registry.d.ts.map +1 -0
  38. package/dist/Registry.js +119 -0
  39. package/dist/Registry.js.map +1 -0
  40. package/dist/cli/bin.d.ts +18 -0
  41. package/dist/cli/bin.d.ts.map +1 -0
  42. package/dist/cli/bin.js +33 -0
  43. package/dist/cli/bin.js.map +1 -0
  44. package/dist/cli/pack.d.ts +169 -0
  45. package/dist/cli/pack.d.ts.map +1 -0
  46. package/dist/cli/pack.js +447 -0
  47. package/dist/cli/pack.js.map +1 -0
  48. package/dist/cli/publish.d.ts +33 -0
  49. package/dist/cli/publish.d.ts.map +1 -0
  50. package/dist/cli/publish.js +76 -0
  51. package/dist/cli/publish.js.map +1 -0
  52. package/dist/index.d.ts +3 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +6 -0
  55. package/dist/index.js.map +1 -0
  56. package/migrations/0001_init.sql +19 -0
  57. package/package.json +89 -1
  58. package/src/Manifest.ts +76 -0
  59. package/src/Protocol.ts +163 -0
  60. package/src/Registry/Bindings.ts +134 -0
  61. package/src/Registry/GitHub.ts +365 -0
  62. package/src/Registry/Handler.ts +549 -0
  63. package/src/Registry/KVCache.ts +68 -0
  64. package/src/Registry/Sweep.ts +117 -0
  65. package/src/Registry/Tags.ts +117 -0
  66. package/src/Registry.ts +197 -0
  67. package/src/cli/bin.ts +101 -0
  68. package/src/cli/pack.ts +603 -0
  69. package/src/cli/publish.ts +129 -0
  70. package/src/index.ts +5 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitHub.d.ts","sourceRoot":"","sources":["../../src/Registry/GitHub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAC;AAC3D,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,KAAK,MAAM,+BAA+B,CAAC;AACvD,OAAO,KAAK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C,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,WASvD,CAAC;AAEf,wEAAwE;AACxE,eAAO,MAAM,QAAQ,UAAW;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC,WAAqE,CAAC;;mBA0FpD,MAAM,SAAS,MAAM;IAMpC;;;OAGG;6BACsB,MAAM,SAAS,MAAM,QAAQ,MAAM;IAW5D;;;OAGG;kCAC2B,MAAM,YAAY,MAAM,OAAO,MAAM;2BAmB5C,MAAM,UAAU,MAAM;IAG7C;;;OAGG;2BAEK,MAAM,SACL;QACL,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B;IAkBH;;;OAGG;0BAEK,MAAM,SACL,MAAM,UACL,MAAM,QACR,MAAM;;AAmDlB,qBAAa,SAAU,SAAQ,cAGE;CAAG;AAEpC,eAAO,MAAM,aAAa,uEAAgC,CAAC"}
@@ -0,0 +1,226 @@
1
+ import * as Github from "@distilled.cloud/github";
2
+ import * as Actions from "@distilled.cloud/github/actions";
3
+ import * as Apps from "@distilled.cloud/github/apps";
4
+ import * as Checks from "@distilled.cloud/github/checks";
5
+ import * as Issues from "@distilled.cloud/github/issues";
6
+ import * as Pulls from "@distilled.cloud/github/pulls";
7
+ import * as Repos from "@distilled.cloud/github/repos";
8
+ import * as Arr from "effect/Array";
9
+ import * as Clock from "effect/Clock";
10
+ import * as Context from "effect/Context";
11
+ import * as Data from "effect/Data";
12
+ import * as DateTime from "effect/DateTime";
13
+ import * as Duration from "effect/Duration";
14
+ import * as Effect from "effect/Effect";
15
+ import * as Encoding from "effect/Encoding";
16
+ import * as Layer from "effect/Layer";
17
+ import * as Option from "effect/Option";
18
+ import * as Redacted from "effect/Redacted";
19
+ import * as Schema from "effect/Schema";
20
+ import * as Stream from "effect/Stream";
21
+ import * as HttpClient from "effect/unstable/http/HttpClient";
22
+ import * as crypto from "node:crypto";
23
+ import { COMMENT_MARKER, RegistryConfig } from "./Bindings.js";
24
+ import * as KVCache from "./KVCache.js";
25
+ export class CryptoError extends Data.TaggedError("CryptoError") {
26
+ }
27
+ export class AppNotInstalled extends Data.TaggedError("AppNotInstalled") {
28
+ get message() {
29
+ return `The GitHub App is not installed on ${this.repo}`;
30
+ }
31
+ }
32
+ /** Import an RSA private key PEM (PKCS#1 or PKCS#8) for RS256 signing. */
33
+ export const importPrivateKey = (pem) => Effect.try({
34
+ try: () => crypto.createPrivateKey({ key: pem }),
35
+ catch: (cause) => new CryptoError({ message: `invalid private key: ${cause}` }),
36
+ });
37
+ /** Sign a compact RS256 JWT, used to authenticate as the GitHub App. */
38
+ export const signJwt = (claims, key) => Effect.try({
39
+ try: () => {
40
+ const header = Encoding.encodeBase64Url(JSON.stringify({ alg: "RS256", typ: "JWT" }));
41
+ const payload = Encoding.encodeBase64Url(JSON.stringify(claims));
42
+ const input = `${header}.${payload}`;
43
+ const signature = crypto.sign("sha256", Buffer.from(input), key);
44
+ return `${input}.${Encoding.encodeBase64Url(new Uint8Array(signature))}`;
45
+ },
46
+ catch: (cause) => new CryptoError({ message: `signing failed: ${cause}` }),
47
+ });
48
+ /**
49
+ * Install commands per package, grouped. A group marked `collapsed`
50
+ * renders as a closed `<details>` block so a long list of secondary
51
+ * packages stays out of the way.
52
+ */
53
+ export const renderInstalls = (packages, groups) => {
54
+ const collapsed = new Set(groups.filter((g) => g.collapsed).map((g) => g.name));
55
+ // One code block per package so each command has its own copy button, in
56
+ // the order the manifest lists them, which is the order they were given
57
+ // to `pkg pack`. Blank lines around the markdown inside `<details>` are
58
+ // what make GitHub render it.
59
+ return Object.entries(Arr.groupBy(packages, (pkg) => pkg.group))
60
+ .flatMap(([group, members]) => {
61
+ const installs = members.flatMap(({ url }) => [
62
+ "```sh",
63
+ `pnpm install ${url}`,
64
+ "```",
65
+ "",
66
+ ]);
67
+ return collapsed.has(group)
68
+ ? [
69
+ "<details>",
70
+ `<summary><b>${group}</b> (${members.length})</summary>`,
71
+ "",
72
+ ...installs,
73
+ "</details>",
74
+ "",
75
+ ]
76
+ : [`### ${group}`, "", ...installs];
77
+ })
78
+ .join("\n");
79
+ };
80
+ /**
81
+ * GitHub's `<relative-time>` element, rendered as a live relative time in
82
+ * comments, with a plain UTC fallback like `Sep 7, 2026 at 2:42 PM UTC`.
83
+ */
84
+ const relativeTime = (millis) => {
85
+ const date = DateTime.makeUnsafe(millis);
86
+ const label = DateTime.formatUtc(date, {
87
+ locale: "en-US",
88
+ dateStyle: "medium",
89
+ timeStyle: "short",
90
+ });
91
+ return `<relative-time datetime="${DateTime.formatIso(date)}">${label} UTC</relative-time>`;
92
+ };
93
+ export const renderComment = (packages, groups, times) => [
94
+ COMMENT_MARKER,
95
+ "",
96
+ "Install the packages built from this commit:",
97
+ "",
98
+ renderInstalls(packages, groups),
99
+ `Published ${relativeTime(times.publishedAt)}. Expires ${relativeTime(times.expiresAt)}, extended while this pull request is open.`,
100
+ ].join("\n");
101
+ /** Render any GitHub operation failure for logs and error responses. */
102
+ export const describe = (error) => (error.message ? `${error._tag}: ${error.message}` : error._tag);
103
+ const USER_AGENT = "alchemy-pkg";
104
+ const split = (repo) => {
105
+ const [owner, name] = repo.split("/");
106
+ return { owner: owner ?? "", repo: name ?? "" };
107
+ };
108
+ /**
109
+ * Installation tokens are refreshed two minutes before GitHub expires them:
110
+ * one for clock skew, one for the minute KV's edge cache may keep serving an
111
+ * expired entry.
112
+ */
113
+ const TOKEN_MARGIN = Duration.minutes(2);
114
+ /**
115
+ * The registry's GitHub App: every operation runs as the App's installation
116
+ * on the repository in question. Installation tokens live in the KV cache,
117
+ * so one mint per repository serves every isolate for about an hour.
118
+ */
119
+ const make = Effect.gen(function* () {
120
+ const config = yield* RegistryConfig;
121
+ const http = yield* HttpClient.HttpClient;
122
+ /** Run a distilled GitHub operation as the given bearer token. */
123
+ const as = (token, operation) => operation.pipe(Effect.provideService(Github.Credentials, Effect.succeed({
124
+ token: Redacted.make(token),
125
+ apiBaseUrl: config.github.apiUrl,
126
+ userAgent: USER_AGENT,
127
+ })), Effect.provideService(HttpClient.HttpClient, http));
128
+ // The credentials are read here, when a token is minted, never during the
129
+ // Worker's Init: `Registry.ts` binds them explicitly, so plan time never
130
+ // resolves them. Importing the key is a sub-millisecond step next to the
131
+ // two GitHub calls a mint makes, so nothing is kept between mints.
132
+ const appJwt = Effect.gen(function* () {
133
+ const pem = yield* config.github.privateKey;
134
+ const key = yield* importPrivateKey(Redacted.value(pem));
135
+ const now = Math.floor((yield* Clock.currentTimeMillis) / 1000);
136
+ return yield* signJwt({ iat: now - 60, exp: now + 540, iss: yield* config.github.appId }, key);
137
+ });
138
+ // Failures are not kept: the next call retries the mint.
139
+ const tokens = KVCache.make((repo) => `token:${repo}`, Schema.String, (repo) => Effect.gen(function* () {
140
+ const jwt = yield* appJwt;
141
+ const installation = yield* as(jwt, Apps.getRepoInstallation(split(repo))).pipe(Effect.catchTag("NotFound", () => new AppNotInstalled({ repo })));
142
+ const access = yield* as(jwt, Apps.createInstallationAccessToken({
143
+ installation_id: installation.id,
144
+ }));
145
+ const now = yield* Clock.currentTimeMillis;
146
+ return {
147
+ value: access.token,
148
+ ttl: Duration.subtract(Duration.millis(Math.max(0, Date.parse(access.expires_at) - now)), TOKEN_MARGIN),
149
+ };
150
+ }));
151
+ /** A GitHub operation run as the App's installation on `repo`. */
152
+ const asInstallation = (repo, operation) => Effect.flatMap(tokens(repo), (token) => as(token, operation));
153
+ return {
154
+ getRun: (repo, runId) => asInstallation(repo, Actions.getWorkflowRun({ ...split(repo), run_id: runId })),
155
+ /**
156
+ * Artifacts named `name` uploaded to a run so far, including by jobs
157
+ * still in progress.
158
+ */
159
+ listRunArtifacts: (repo, runId, name) => asInstallation(repo, Actions.listWorkflowRunArtifacts({
160
+ ...split(repo),
161
+ run_id: runId,
162
+ name,
163
+ per_page: 100,
164
+ })).pipe(Effect.map((page) => page.artifacts)),
165
+ /**
166
+ * Pull requests against `repo` whose head is `sha` in `headRepo`, the
167
+ * repository the commit was pushed to.
168
+ */
169
+ pullRequestsForCommit: (repo, headRepo, sha) => asInstallation(repo, Repos.listPullRequestsAssociatedWithCommit({
170
+ ...split(repo),
171
+ commit_sha: sha,
172
+ per_page: 100,
173
+ })).pipe(Effect.map((pulls) => pulls.filter((pr) => pr.head.sha === sha &&
174
+ pr.head.repo?.full_name === headRepo &&
175
+ pr.base.repo.full_name === repo))),
176
+ getPullRequest: (repo, number) => asInstallation(repo, Pulls.get({ ...split(repo), pull_number: number })),
177
+ /**
178
+ * Publish a completed check run on `headSha`. GitHub shows the newest run
179
+ * per name and App, so re-publishing the same commit simply supersedes it.
180
+ */
181
+ createCheckRun: (repo, input) => Effect.flatMap(DateTime.now, (now) => asInstallation(repo, Checks.create({
182
+ ...split(repo),
183
+ name: input.name,
184
+ head_sha: input.headSha,
185
+ status: "completed",
186
+ conclusion: "success",
187
+ completed_at: DateTime.formatIso(now),
188
+ details_url: input.detailsUrl,
189
+ output: { title: input.title, summary: input.summary },
190
+ }))),
191
+ /**
192
+ * Create or update the comment on `issue` whose body starts with
193
+ * `marker`, looking through the first five pages of comments.
194
+ */
195
+ upsertComment: (repo, issue, marker, body) => Effect.gen(function* () {
196
+ const comments = Stream.paginate(1, (page) => asInstallation(repo, Issues.listComments({
197
+ ...split(repo),
198
+ issue_number: issue,
199
+ per_page: 100,
200
+ page,
201
+ })).pipe(Effect.map((comments) => [
202
+ comments,
203
+ comments.length < 100 || page >= 5
204
+ ? Option.none()
205
+ : Option.some(page + 1),
206
+ ])));
207
+ const existing = yield* comments.pipe(Stream.filter((comment) => comment.body?.startsWith(marker) === true), Stream.take(1), Stream.runCollect, Effect.map(Arr.head));
208
+ yield* Option.match(existing, {
209
+ onNone: () => asInstallation(repo, Issues.createComment({
210
+ ...split(repo),
211
+ issue_number: issue,
212
+ body,
213
+ })),
214
+ onSome: (comment) => asInstallation(repo, Issues.updateComment({
215
+ ...split(repo),
216
+ comment_id: comment.id,
217
+ body,
218
+ })),
219
+ });
220
+ }),
221
+ };
222
+ });
223
+ export class GitHubApp extends Context.Service()("@alchemy.run/pkg/GitHubApp") {
224
+ }
225
+ export const GitHubAppLive = Layer.effect(GitHubApp, make);
226
+ //# sourceMappingURL=GitHub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitHub.js","sourceRoot":"","sources":["../../src/Registry/GitHub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,yBAAyB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAC;AAC3D,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AACrD,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAC;AACzD,OAAO,KAAK,KAAK,MAAM,+BAA+B,CAAC;AACvD,OAAO,KAAK,KAAK,MAAM,+BAA+B,CAAC;AACvD,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,K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ACH;aACJ,CAAC,CAAC;QACL,CAAC,CAAC;KACL,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,OAAO,SAAU,SAAQ,OAAO,CAAC,OAAO,EAG3C,CAAC,4BAA4B,CAAC;CAAG;AAEpC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ import * as Cloudflare from "alchemy/Cloudflare";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Schema from "effect/Schema";
4
+ import { HttpServerRequest } from "effect/unstable/http/HttpServerRequest";
5
+ import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
6
+ import { RegistryConfig } from "./Bindings.ts";
7
+ import * as GitHub from "./GitHub.ts";
8
+ /** What GitHub says about a run. */
9
+ declare const Run: Schema.Struct<{
10
+ readonly repo: Schema.String;
11
+ readonly runId: Schema.Number;
12
+ readonly attempt: Schema.Number;
13
+ readonly headSha: Schema.String;
14
+ readonly headBranch: Schema.NullOr<Schema.String>;
15
+ readonly headRepo: Schema.String;
16
+ readonly pr: Schema.NullOr<Schema.Number>;
17
+ }>;
18
+ type Run = typeof Run.Type;
19
+ /**
20
+ * Tags every package in a publication receives, all derived from the run.
21
+ * Runs on the repository's own commits get the head commit, the short
22
+ * commit, `branch:<name>`, and `pr:N` for pull requests. A fork's run gets
23
+ * only `pr:N`: commit tags are shared by every publisher, and a fork can
24
+ * run any commit it likes, including one already published from the
25
+ * repository, so letting it write them would let it repoint them.
26
+ */
27
+ export declare const tagsFor: (run: Run) => string[];
28
+ /** The tag install commands are written against. */
29
+ export declare const installTag: (run: Run) => string;
30
+ /**
31
+ * Parse `/<name>/<tag>` and `/<name>/-/<sha256>.tgz`. Scoped names take
32
+ * two segments; the tag is everything after the name and may itself contain
33
+ * `/` and `:`.
34
+ */
35
+ export declare const parseInstallPath: (pathname: string, scope: string | undefined) => {
36
+ kind: "tag";
37
+ name: string;
38
+ tag: string;
39
+ } | {
40
+ kind: "tarball";
41
+ name: string;
42
+ sha256: string;
43
+ } | undefined;
44
+ /**
45
+ * The registry Worker's Init phase. Runs at plan time to register bindings
46
+ * and the cron trigger, and once per isolate at runtime to build the
47
+ * router. Everything it needs comes from {@link RegistryConfig}.
48
+ */
49
+ export declare const handler: Effect.Effect<{
50
+ fetch: Effect.Effect<Effect.Effect<HttpServerResponse.HttpServerResponse, import("effect/unstable/http/HttpBody").HttpBodyError | import("effect/unstable/http/HttpServerError").HttpServerError, GitHub.GitHubApp | HttpServerRequest | Cloudflare.Providers | Cloudflare.R2.ReadWriteBucket | Cloudflare.KV.ReadWriteNamespace | RegistryConfig | import("alchemy").RuntimeContext | import("effect/Scope").Scope | import("effect/unstable/sql/SqlClient").SqlClient | Cloudflare.WorkerEnvironment | Cloudflare.Worker<any>>, never, import("effect/FileSystem").FileSystem | import("effect/Scope").Scope | Cloudflare.WorkerEnvironment | Cloudflare.Worker<any>>;
51
+ }, never, Cloudflare.Providers | RegistryConfig | Cloudflare.WorkerEnvironment | Cloudflare.Worker<any>>;
52
+ export {};
53
+ //# sourceMappingURL=Handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Handler.d.ts","sourceRoot":"","sources":["../../src/Registry/Handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAKjD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAKxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,KAAK,kBAAkB,MAAM,yCAAyC,CAAC;AAc9E,OAAO,EAKL,cAAc,EAEf,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAKtC,oCAAoC;AACpC,QAAA,MAAM,GAAG;;;;;;;;EAMP,CAAC;AACH,KAAK,GAAG,GAAG,OAAO,GAAG,CAAC,IAAI,CAAC;AA6B3B;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,QAAS,GAAG,KAAG,MAAM,EAQxC,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,UAAU,QAAS,GAAG,WACyB,CAAC;AA2P7D;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,aACjB,MAAM,SACT,MAAM,GAAG,SAAS,KAEvB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACjD,SA0BH,CAAC;AA4EF;;;;GAIG;AACH,eAAO,MAAM,OAAO;;wGA+Ea,CAAC"}