@vite-hub/forge 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +43 -7
  2. package/dist/{association-Cm0dUTDU-CDDhJnIh.js → association-Ds6Tgs0W-Cu9_YCGq.js} +1 -1
  3. package/dist/build/node.d.ts +12 -0
  4. package/dist/build/node.js +106 -0
  5. package/dist/build.d.ts +2 -0
  6. package/dist/build.js +2 -0
  7. package/dist/{events-saDWbqbf-VX_k8jtr.js → events-C6C7lk1x-J8VCAjEX.js} +4 -4
  8. package/dist/{events-DudKM7vq-Cj_PCDdt.js → events-DW3SFUDA-D2rhS9D-.js} +4 -4
  9. package/dist/{events-CeChclTf-CX-gD8oy.js → events-DjRw3KSr-C72gY7Vu.js} +4 -4
  10. package/dist/{events-CRaLy7U3-3PNNp5WZ.js → events-DmSWTdpS-BdJBABfI.js} +4 -4
  11. package/dist/{events-7EBoeIPd-A2RUkJi5.js → events-uCMi3LHU-Bz79PQtq.js} +4 -4
  12. package/dist/{feed-Dyf730Ys-D0HgBba6.js → feed-BlzdKdNv-DbxuSgsx.js} +4 -4
  13. package/dist/{feed-DsC7Vws1-M_de2nSK.js → feed-BwdcTgZq-Bm_c8br8.js} +4 -4
  14. package/dist/{feed-CmBoYS3Z-CuC4i0fH.js → feed-CIaAZINm-Dpe9DxwK.js} +4 -4
  15. package/dist/{forgejo-BN8ItCfl.js → forgejo-UNPc42cY.js} +50 -8
  16. package/dist/{gitee-DExkQP6X-BxJS2dRY.js → gitee-BXyl2_3W-dQOAjWqr.js} +2 -2
  17. package/dist/{github-DtncTfmv.js → github-CUiEF2FK.js} +65 -40
  18. package/dist/{gitlab-BoDm8-BC.js → gitlab-zvWb9zOi.js} +65 -8
  19. package/dist/{graphql-DG5aJBT3-DceyFYdM.js → graphql-BDhuP5jN-BSpB8lWf.js} +59 -7
  20. package/dist/identity-CNTWZZuv.d.ts +27 -0
  21. package/dist/identity-CmVEBLP5.js +38 -0
  22. package/dist/index.d.ts +332 -110
  23. package/dist/index.js +815 -313
  24. package/dist/{knot-BpyTK9D7-CVIsX4I2.js → knot-bGebBK_B-CeDHcJUz.js} +16 -9
  25. package/dist/{tangled-DPt_0u21-zS41xdG5.js → tangled-8lg_73Wi-bSufNXiN.js} +1 -1
  26. package/dist/{templates-Bn8a-pd2-D9DhJEVD.js → templates-BGDqQMu4-PSB43E1j.js} +2 -2
  27. package/dist/{utils-CA_4WJhJ-DNgT61X2.js → utils-DC7MBR65-B7Vr2hFm.js} +3 -306
  28. package/dist/{webhooks-DgHwxxYz-D1V2LOr1.js → webhooks-Bc6QhmI8-CNgCERCq.js} +326 -5
  29. package/package.json +19 -8
package/dist/index.d.ts CHANGED
@@ -1,31 +1,6 @@
1
- //#region src/env.d.ts
2
- /** One Server Env value of a Forge. */
3
- interface ForgeEnvField {
4
- /** Host variable names in lookup order. The `VITEHUB_` name comes first, then the `forges` name. */
5
- names: readonly [string, ...string[]];
6
- secret?: true;
7
- }
8
- /** Server Env fields of each Forge. */
9
- type ForgeEnv = {
10
- github: Record<"appId" | "installationId" | "appOwner" | "appInstallations" | "privateKey" | "privateKeyPath" | "token" | "webhookSecret", ForgeEnvField>;
11
- gitlab: Record<"baseUrl" | "token" | "webhookSecret", ForgeEnvField>;
12
- forgejo: Record<"baseUrl" | "token" | "webhookSecret", ForgeEnvField>;
13
- };
14
- /**
15
- * Server Env of each Forge, keyed by the `env.server.<forge>.<field>` path.
16
- * Channels, Capabilities, Workspaces and Sources read the same names.
17
- * `FORGES_*` names are the ones that `forgesFromEnv()` in the `forges` library reads.
18
- * Fields without a `forges` equivalent have only a `VITEHUB_` name.
19
- */
20
- export declare const forgeEnv: ForgeEnv;
21
- /**
22
- * The first value of `field` that is set, in its lookup order.
23
- * `env` is a record, such as `process.env`, or a reader, such as a Cloudflare binding lookup. Default: `process.env`.
24
- */
25
- export declare function readForgeEnv(field: ForgeEnvField, env?: Record<string, unknown> | ((name: string) => unknown)): string | undefined;
26
- //#endregion
27
- //#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/model-C_dXr71E.d.mts
28
- //#region src/model.d.ts
1
+ import { Result } from "@vite-hub/runtime";
2
+ import { Diagnostic } from "nostics";
3
+ //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/model-tYVNrXXO.d.mts
29
4
  /**
30
5
  * Every public type in this module is JSON-serialisable except `Date`, which
31
6
  * serialises to an ISO 8601 string through `JSON.stringify`, and the bytes of
@@ -80,6 +55,12 @@ interface RepoRef extends ForgeOrigin {
80
55
  * `owner` and `name`.
81
56
  */
82
57
  externalId?: string;
58
+ /**
59
+ * The owner's handle, where the forge identifies accounts by DID but
60
+ * addresses them by handle in its web URLs (Tangled). The `owner` stays the
61
+ * DID, so that a repository is found the same way whichever is known.
62
+ */
63
+ ownerHandle?: string;
83
64
  }
84
65
  /** Who can see a repository. */
85
66
  type RepoVisibility = "public" | "private" | "internal";
@@ -570,6 +551,24 @@ interface ReviewComment {
570
551
  url?: string;
571
552
  raw: unknown;
572
553
  }
554
+ /** A review conversation on a pull request: comments that are resolved together, usually on one line of the diff. */
555
+ interface ReviewThread {
556
+ /** Forge-native id; `resolveReviewThread()` takes it where the forge can resolve a conversation. */
557
+ id: string;
558
+ resolved: boolean;
559
+ /** Whether the code under the conversation has changed since. Absent where the forge doesn't say. */
560
+ outdated?: boolean;
561
+ path?: string;
562
+ /** Line the conversation is anchored to, in `side`; the last line of a multi-line conversation. */
563
+ line?: number;
564
+ /** First line of a multi-line conversation. */
565
+ startLine?: number;
566
+ /** `'left'` is the base of the diff, `'right'` the head. */
567
+ side?: "left" | "right";
568
+ /** The comments in the conversation, oldest first. */
569
+ comments: ReviewComment[];
570
+ raw: unknown;
571
+ }
573
572
  /** A review of a pull request. */
574
573
  interface Review {
575
574
  ref: ResolvedReviewRef;
@@ -1493,6 +1492,11 @@ interface ListOptions extends PageOptions {
1493
1492
  /** Only items updated at or after this time. */
1494
1493
  since?: Date;
1495
1494
  }
1495
+ /** Options for `threads.reviewThreads()`. */
1496
+ interface ReviewThreadListOptions extends PageOptions {
1497
+ /** Only resolved or only unresolved conversations; `'all'` by default. */
1498
+ state?: "resolved" | "unresolved" | "all";
1499
+ }
1496
1500
  /** Options for `repos.events()` and `users.events()`. */
1497
1501
  interface EventFeedOptions extends PageOptions {
1498
1502
  /**
@@ -1844,8 +1848,7 @@ interface Installation extends ForgeOrigin {
1844
1848
  raw: unknown;
1845
1849
  }
1846
1850
  //#endregion
1847
- //#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/fetch-BmQltM0Y.d.mts
1848
- //#region src/errors.d.ts
1851
+ //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/fetch-BUdyK5-h.d.mts
1849
1852
  /** Where an error happened: the forge, the instance and the request. */
1850
1853
  interface ForgeErrorContext {
1851
1854
  forge?: ForgeKind$1;
@@ -1956,13 +1959,13 @@ interface ForgeRequest {
1956
1959
  <T = unknown>(method: string, path: string, options?: ForgeRequestOptions): Promise<ForgeResponse<T>>;
1957
1960
  }
1958
1961
  //#endregion
1959
- //#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/web-BB1at9UM.d.mts
1960
- //#region src/web.d.ts
1962
+ //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/web-DhBCh_Iq.d.mts
1961
1963
  /** A repository's section, for linking to the section itself rather than one entry in it. */
1962
1964
  type RepoSection = "issues" | "pullRequests" | "compare" | "releases" | "stargazers" | "forks" | "watchers";
1963
1965
  /**
1964
1966
  * Something with a web page. A revision (`at`, `base` or `head`) is a branch,
1965
- * tag or commit sha; Azure DevOps reads anything but a full commit sha as a branch.
1967
+ * tag or commit sha; Azure DevOps takes a tag as its full ref, `refs/tags/NAME`.
1968
+ * A file's `at` is optional and defaults to the repository's default branch.
1966
1969
  */
1967
1970
  type UrlTarget = {
1968
1971
  repo: RepoRef;
@@ -1979,14 +1982,14 @@ type UrlTarget = {
1979
1982
  file: {
1980
1983
  repo: RepoRef;
1981
1984
  path: string;
1982
- at: string;
1985
+ at?: string;
1983
1986
  line?: number;
1984
1987
  };
1985
1988
  } | {
1986
1989
  raw: {
1987
1990
  repo: RepoRef;
1988
1991
  path: string;
1989
- at: string;
1992
+ at?: string;
1990
1993
  };
1991
1994
  } | {
1992
1995
  commit: {
@@ -2048,7 +2051,7 @@ interface ParsedReference {
2048
2051
  ref: ThreadRef | CommitRef;
2049
2052
  }
2050
2053
  //#endregion
2051
- //#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/provider-DLQInvPp.d.mts
2054
+ //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/provider-Dpahb8tR.d.mts
2052
2055
  /**
2053
2056
  * Rows omit what follows from the rest. `verbs` defaults to the capability,
2054
2057
  * and `spec` to the capability, or its page for a `listing` (`repos.labels`
@@ -2295,6 +2298,9 @@ declare const TABLE: readonly [{
2295
2298
  }, {
2296
2299
  readonly capability: "threads.replyToReviewComment";
2297
2300
  readonly write: true;
2301
+ }, {
2302
+ readonly capability: "threads.reviewThreads";
2303
+ readonly listing: true;
2298
2304
  }, {
2299
2305
  readonly capability: "threads.resolveReviewThread";
2300
2306
  readonly write: true;
@@ -2657,6 +2663,8 @@ interface ForgeCapabilities {
2657
2663
  approve: Support;
2658
2664
  /** Support for `threads.replyToReviewComment()`. */
2659
2665
  replyToReviewComment: Support;
2666
+ /** Support for `threads.reviewThreads()`. `'emulated'` where conversations are grouped from review comments. */
2667
+ reviewThreads: Support;
2660
2668
  /** Support for `threads.resolveReviewThread()`. */
2661
2669
  resolveReviewThread: Support;
2662
2670
  /** Support for `threads.unresolveReviewThread()`. */
@@ -3115,6 +3123,8 @@ interface ThreadsApi {
3115
3123
  * second reply.
3116
3124
  */
3117
3125
  replyToReviewComment: (ref: ThreadRef, comment: Pick<ReviewComment, "ref" | "thread" | "inReplyTo">, body: string, options?: BaseOptions) => Promise<ReviewComment>;
3126
+ /** Review conversations on a pull request with their comments; `state` keeps only the resolved or the unresolved ones. */
3127
+ reviewThreads: (ref: ThreadRef, options?: ReviewThreadListOptions) => ForgeListing<ReviewThread>;
3118
3128
  /** Resolves a review conversation, by the id on {@link ReviewComment.thread} or {@link Comment.thread}. */
3119
3129
  resolveReviewThread: (ref: ThreadRef, id: string, options?: BaseOptions) => Promise<void>;
3120
3130
  /** Reopens a resolved review conversation, by the id on `ReviewComment.thread` or `Comment.thread`. */
@@ -3637,6 +3647,7 @@ interface ForgeProvider<HasWeb extends boolean = boolean> {
3637
3647
  support: (verb: ForgeVerb, kind?: ThreadKind | SecurityAlertKind) => Support;
3638
3648
  /**
3639
3649
  * The web page for `target`, built without a request; `undefined` when the forge has no such page.
3650
+ * A file target's `at` defaults to the repository's default branch.
3640
3651
  * @param target What to link to: a repository or one of its sections (`issues`, `pullRequests`, `compare`, `releases`, `stargazers`, `forks` or `watchers`), thread, comment, release, file, raw file, commit or comparison.
3641
3652
  */
3642
3653
  urlFor: {
@@ -3685,7 +3696,7 @@ interface ForgeProvider<HasWeb extends boolean = boolean> {
3685
3696
  parseReferences: (text: string, options: ParseReferencesOptions) => ParsedReference[];
3686
3697
  }
3687
3698
  //#endregion
3688
- //#region ../../node_modules/.pnpm/forges@https+++pkg.pr.new+danielroe+forges@40d50b2f8bdc5585becfae405e1a3b8a325f7202/node_modules/forges/dist/index-DR1bBfMh.d.mts
3699
+ //#region ../../node_modules/.pnpm/forges@0.3.1/node_modules/forges/dist/index-DlB9rINi.d.mts
3689
3700
  /**
3690
3701
  * A GraphQL document that carries the types of its result and variables, such as a `TypedDocumentString`
3691
3702
  * from GraphQL Code Generator with `documentMode: 'string'`.
@@ -3718,6 +3729,198 @@ interface GitHubProvider extends ForgeProvider<true> {
3718
3729
  graphql: GitHubGraphQL;
3719
3730
  }
3720
3731
  //#endregion
3732
+ //#region src/conditional.d.ts
3733
+ /** A response body that a later request can revalidate with `If-None-Match`. */
3734
+ interface ForgeCachedResponse {
3735
+ etag: string;
3736
+ body: string;
3737
+ /** The headers that a `304` does not repeat, such as `content-type` and `link`. */
3738
+ headers: [string, string][];
3739
+ }
3740
+ /** Where conditional requests keep their validators and bodies. Keys are opaque hashes. */
3741
+ interface ForgeResponseCache {
3742
+ get(key: string): ForgeCachedResponse | undefined;
3743
+ set(key: string, value: ForgeCachedResponse): void;
3744
+ delete(key: string): void;
3745
+ }
3746
+ interface ForgeConditionalRequests {
3747
+ /**
3748
+ * Who may reuse an entry. Default: the request's `Authorization` header. Pass something stable such as
3749
+ * `app:<appId>:<installationId>` so a rotated installation token keeps the entries of the one before it.
3750
+ */
3751
+ identity?: string;
3752
+ /** Default: one in-memory cache shared by every provider in the process. */
3753
+ cache?: ForgeResponseCache;
3754
+ }
3755
+ interface ForgeMemoryCacheOptions {
3756
+ /** Default 32 MiB, counted in body characters. */
3757
+ maxSize?: number;
3758
+ /** Bodies larger than this are not kept. Default 1 MiB. */
3759
+ maxEntrySize?: number;
3760
+ }
3761
+ /** An in-memory LRU of Forge responses, bounded by the total size of the bodies it keeps. */
3762
+ export declare function forgeMemoryCache(options?: ForgeMemoryCacheOptions): ForgeResponseCache;
3763
+ /**
3764
+ * Wrap `fetch` so authenticated GETs send `If-None-Match` with the ETag of the last response, and a `304`
3765
+ * returns that response's body again. GitHub does not count a `304` against the primary rate limit.
3766
+ * Every read still reaches the Forge, so a cached body is only returned when the Forge says it is current.
3767
+ */
3768
+ export declare function conditionalFetch(fetcher: typeof fetch, options?: ForgeConditionalRequests): typeof fetch;
3769
+ //#endregion
3770
+ //#region ../internal/src/forge.d.ts
3771
+ /**
3772
+ * The Server Env names of each Forge, and the HTTP status of a failed Forge request. `@vite-hub/forge` exports them.
3773
+ * Channels and Workspaces import them from here, so an app without a Forge does not install or bundle `@vite-hub/forge`.
3774
+ */
3775
+ /** One Server Env value of a Forge. */
3776
+ interface ForgeEnvField {
3777
+ /** Host variable names in lookup order. The `VITEHUB_` name comes first, then the `forges` name. */
3778
+ names: readonly [string, ...string[]];
3779
+ secret?: true;
3780
+ }
3781
+ /** Server Env fields of each Forge. */
3782
+ type ForgeEnv = {
3783
+ github: Record<"appId" | "installationId" | "appOwner" | "appInstallations" | "privateKey" | "privateKeyPath" | "token" | "webhookSecret", ForgeEnvField>;
3784
+ gitlab: Record<"baseUrl" | "token" | "webhookSecret", ForgeEnvField>;
3785
+ forgejo: Record<"baseUrl" | "token" | "webhookSecret", ForgeEnvField>;
3786
+ };
3787
+ /**
3788
+ * Server Env of each Forge, keyed by the `env.server.<forge>.<field>` path.
3789
+ * Channels, Capabilities, Workspaces and Sources read the same names.
3790
+ * `FORGES_*` names are the ones that `forgesFromEnv()` in the `forges` library reads.
3791
+ * Fields without a `forges` equivalent have only a `VITEHUB_` name.
3792
+ */
3793
+ export declare const forgeEnv: ForgeEnv;
3794
+ /**
3795
+ * The first value of `field` that is set, in its lookup order.
3796
+ * `env` is a record, such as `process.env`, or a reader, such as a Cloudflare binding lookup. Default: `process.env`.
3797
+ */
3798
+ export declare function readForgeEnv(field: ForgeEnvField, env?: Record<string, unknown> | ((name: string) => unknown)): string | undefined;
3799
+ /** The HTTP status of a failed Forge request, or undefined for other errors. */
3800
+ export declare function forgeErrorStatus(error: unknown): number | undefined;
3801
+ //#endregion
3802
+ //#region src/provider.d.ts
3803
+ /** The Forges that ViteHub supports. */
3804
+ type ForgeKind = "github" | "gitlab" | "forgejo";
3805
+ interface ForgeConnection {
3806
+ forge: ForgeKind;
3807
+ /** GitHub: API base. GitLab and Forgejo: instance root. */
3808
+ baseUrl?: string;
3809
+ /** Omitted: anonymous public reads. */
3810
+ token?: string;
3811
+ readOnly?: boolean;
3812
+ fetch?: typeof fetch;
3813
+ /** Default "vitehub". */
3814
+ userAgent?: string;
3815
+ /** Request timeout in milliseconds. Default 30000. */
3816
+ timeout?: number;
3817
+ /**
3818
+ * Revalidate repeated authenticated GETs with `If-None-Match`, so an unchanged response comes back as a `304`
3819
+ * that GitHub does not count against the rate limit. Default: on for GitHub. `false` turns it off.
3820
+ */
3821
+ conditionalRequests?: boolean | ForgeConditionalRequests;
3822
+ }
3823
+ /**
3824
+ * Create the library provider for one Forge. Internal to ViteHub packages: return it from a public API only
3825
+ * where the API owns the Forge credentials, such as `GitHubHost.forge()` in `@vite-hub/agent`.
3826
+ * A GitHub provider also has `graphql()`.
3827
+ */
3828
+ export declare function forgeProvider(connection: ForgeConnection & {
3829
+ forge: "github";
3830
+ }): Promise<GitHubProvider>;
3831
+ export declare function forgeProvider(connection: ForgeConnection): Promise<ForgeProvider>;
3832
+ /** A Forge response that succeeded but did not include the expected data: `FORGE_RESPONSE_INVALID`. */
3833
+ export declare function forgeResponseError(problem: string): Diagnostic;
3834
+ /** Whether a Forge response did not include the expected data. */
3835
+ export declare function isForgeResponseError(error: unknown): boolean;
3836
+ /** The error that a cancelled Forge operation rejects with. */
3837
+ export declare function abortError(signal: AbortSignal): Error;
3838
+ /** Reject with the abort reason when `signal` aborts before `promise` settles. */
3839
+ export declare function withSignal<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
3840
+ //#endregion
3841
+ //#region src/use-forge.d.ts
3842
+ /** Where `useForge()` reads its env: a record such as `process.env`, or a lookup by variable name. */
3843
+ type ForgeEnvSource = Record<string, unknown> | ((name: string) => unknown);
3844
+ interface UseForgeOptions<TKind extends ForgeKind = "github"> {
3845
+ /** Default `"github"`. */
3846
+ forge?: TKind;
3847
+ /**
3848
+ * GitHub: the API base, for GitHub Enterprise Server. GitLab and Forgejo: the instance root.
3849
+ * Default for GitLab and Forgejo: `VITEHUB_GITLAB_BASE_URL` or `VITEHUB_FORGEJO_BASE_URL`.
3850
+ */
3851
+ baseUrl?: string;
3852
+ /** Default: the bindings of the active Cloudflare request, then `process.env`. */
3853
+ env?: ForgeEnvSource;
3854
+ fetch?: typeof fetch;
3855
+ /** Default `"vitehub"`. */
3856
+ userAgent?: string;
3857
+ /**
3858
+ * `false` stops providers from revalidating repeated GETs with `If-None-Match`. Default: on for GitHub.
3859
+ * With a GitHub App, a cached response survives token rotation within the same installation.
3860
+ */
3861
+ conditionalRequests?: boolean;
3862
+ }
3863
+ interface ForgeCallOptions {
3864
+ /**
3865
+ * `owner/name`. With a GitHub App, the token is for the installation of the repository owner in
3866
+ * `VITEHUB_GITHUB_APP_INSTALLATIONS`, or `VITEHUB_GITHUB_INSTALLATION_ID` when the owner is `VITEHUB_GITHUB_APP_OWNER`.
3867
+ * Otherwise GitHub finds the installation that can reach the repository.
3868
+ */
3869
+ repository?: string;
3870
+ /**
3871
+ * The GitHub App installation to use, such as `installation.id` of a webhook delivery.
3872
+ * It replaces the installation that `repository` selects.
3873
+ */
3874
+ installation?: number;
3875
+ /** Mint a new GitHub App installation token instead of the cached one. */
3876
+ refresh?: boolean;
3877
+ /** Milliseconds the token must stay valid. A cached installation token that expires sooner is replaced. Default 60000. */
3878
+ minLifetime?: number;
3879
+ signal?: AbortSignal;
3880
+ }
3881
+ interface ForgeToken {
3882
+ token: string;
3883
+ /** When a GitHub App installation token expires. `undefined` for a configured token. */
3884
+ expiresAt: Date | undefined;
3885
+ }
3886
+ /** The GitHub App that `useForge()` acts as. `login` is the bot user, such as `my-app[bot]`. */
3887
+ interface ForgeAppIdentity {
3888
+ id: number;
3889
+ slug: string;
3890
+ login: string;
3891
+ }
3892
+ /** The `forges` provider of one Forge. A GitHub provider also has `graphql()`. */
3893
+ type ForgeProviderOf<TKind extends ForgeKind> = [TKind] extends ["github"] ? GitHubProvider : ForgeProvider;
3894
+ /** Codes of the errors that `useForge()` returns or throws. */
3895
+ type ForgeErrorCode = "FORGE_APP_NOT_INSTALLED" | "FORGE_REQUEST_FAILED" | "FORGE_MISSING_ENV" | "FORGE_INVALID_ENV" | "FORGE_MISSING_INSTALLATION" | "FORGE_NOT_APP";
3896
+ /** Runtime errors of a token request. */
3897
+ type ForgeTokenErrorCode = "FORGE_APP_NOT_INSTALLED" | "FORGE_REQUEST_FAILED";
3898
+ /** One Forge identity, read from Server Env. */
3899
+ interface Forge$1<TKind extends ForgeKind = ForgeKind> {
3900
+ readonly kind: TKind;
3901
+ /** `"app"`: GitHub App installation tokens. `"token"`: the configured token. */
3902
+ readonly auth: "app" | "token";
3903
+ readonly baseUrl: string | undefined;
3904
+ /** A token for API calls, `git`, or `gh`. Installation tokens are cached until one minute before they expire. */
3905
+ token(options?: ForgeCallOptions): Promise<Result<ForgeToken, ForgeTokenErrorCode>>;
3906
+ /** A `forges` provider that uses `token()`. Get a new one for each job: an installation token expires after one hour. */
3907
+ provider(options?: ForgeCallOptions): Promise<Result<ForgeProviderOf<TKind>, ForgeTokenErrorCode>>;
3908
+ /** The GitHub App. Throws `FORGE_NOT_APP` when the Forge uses a token. */
3909
+ app(options?: {
3910
+ signal?: AbortSignal;
3911
+ }): Promise<Result<ForgeAppIdentity, "FORGE_REQUEST_FAILED">>;
3912
+ }
3913
+ /**
3914
+ * The Forge identity of this deployment, read from the same Server Env as Channels, Workspaces and Sources.
3915
+ * GitHub uses a GitHub App when `VITEHUB_GITHUB_APP_ID` is set, and `VITEHUB_GITHUB_TOKEN` otherwise.
3916
+ * Throws a config error when the env has no credentials. Runtime operations return `[error, data]`.
3917
+ *
3918
+ * ```ts
3919
+ * const [error, provider] = await useForge().provider({ repository: "acme/web" })
3920
+ * ```
3921
+ */
3922
+ export declare function useForge<TKind extends ForgeKind = "github">(options?: UseForgeOptions<TKind>): Forge$1<TKind>;
3923
+ //#endregion
3721
3924
  //#region src/gaps/archive.d.ts
3722
3925
  interface ForgeArchiveOptions {
3723
3926
  /** Branch, tag or commit sha. */
@@ -3728,7 +3931,8 @@ interface ForgeArchiveOptions {
3728
3931
  }
3729
3932
  /**
3730
3933
  * The repository tree at `ref` as a gzipped tarball stream.
3731
- * Gap: `forges` has no `contents.archive()`. Proposed upstream as `provider.contents.archive(repo, options)`.
3934
+ * Gap: `forges` has no `contents.archive()`. Proposed upstream as `provider.contents.archive(repo, options)`
3935
+ * (https://github.com/danielroe/forges/issues/191).
3732
3936
  */
3733
3937
  export declare function forgeArchive(provider: ForgeProvider, repo: RepoRef, options: ForgeArchiveOptions): Promise<ReadableStream<Uint8Array>>;
3734
3938
  //#endregion
@@ -3736,7 +3940,7 @@ export declare function forgeArchive(provider: ForgeProvider, repo: RepoRef, opt
3736
3940
  /**
3737
3941
  * The bytes of one Git blob, by its sha. The blob of a symlink holds the link target.
3738
3942
  * Gap: `forges` reads files by path only, and GitHub follows a symlink path to its target.
3739
- * Proposed upstream as `provider.contents.blob(repo, sha, options)`.
3943
+ * Proposed upstream as `provider.contents.blob(repo, sha, options)` (https://github.com/danielroe/forges/issues/295).
3740
3944
  */
3741
3945
  export declare function forgeBlob(provider: ForgeProvider, repo: RepoRef, sha: string, options?: {
3742
3946
  signal?: AbortSignal;
@@ -3760,6 +3964,12 @@ interface GitHubBranchRuleDetails {
3760
3964
  * when the answer is not complete GitHub branch rules, so a caller never mistakes unknown rules for no rules.
3761
3965
  */
3762
3966
  export declare function githubBranchRuleDetails(rules: BranchRules): GitHubBranchRuleDetails;
3967
+ /**
3968
+ * Read branch rules with `provider.repos.branchRules()`. GitHub answers 403 for the rules of a private repository
3969
+ * on a plan without rulesets or branch protection. When it gives that reason and the branch summary reports the
3970
+ * branch unprotected, this returns no rules. Any other 403 still rejects, so a missing permission never reads as no rules.
3971
+ */
3972
+ export declare function forgeBranchRules(provider: ForgeProvider, repo: RepoRef, branch: string, options?: BaseOptions): Promise<BranchRules>;
3763
3973
  //#endregion
3764
3974
  //#region src/gaps/commit-files.d.ts
3765
3975
  /** Git file modes: a regular file, an executable file and a symlink. The content of a symlink is its target. */
@@ -3772,49 +3982,13 @@ interface ForgeCommitFilesInput extends Omit<CommitFilesInput, "changes"> {
3772
3982
  }
3773
3983
  /**
3774
3984
  * `provider.contents.commitFiles()` with Git file modes, and the sha of the new commit.
3775
- * Without a `mode`, the call goes to `commitFiles()`. When one change has a `mode`, every write without one is `100644`.
3985
+ * Without a `mode` or a GitHub author, the call goes to `commitFiles()`. Every write without a mode is `100644`.
3776
3986
  * Rejects with `BranchMovedError` when the branch no longer points at `expectedHead`, as `commitFiles()` does.
3777
3987
  * Gap: `FileChange` has no mode, so `commitFiles()` cannot write a symlink or an executable file.
3778
- * Proposed upstream as `FileChange.mode`.
3988
+ * Proposed upstream as `FileChange.mode` (https://github.com/danielroe/forges/issues/296).
3779
3989
  */
3780
3990
  export declare function forgeCommitFiles(provider: ForgeProvider, repo: RepoRef, input: ForgeCommitFilesInput, options?: BaseOptions): Promise<string>;
3781
3991
  //#endregion
3782
- //#region src/provider.d.ts
3783
- /** The Forges that ViteHub supports. */
3784
- type ForgeKind = "github" | "gitlab" | "forgejo";
3785
- interface ForgeConnection {
3786
- forge: ForgeKind;
3787
- /** GitHub: API base. GitLab and Forgejo: instance root. */
3788
- baseUrl?: string;
3789
- /** Omitted: anonymous public reads. */
3790
- token?: string;
3791
- readOnly?: boolean;
3792
- fetch?: typeof fetch;
3793
- /** Default "vitehub". */
3794
- userAgent?: string;
3795
- /** Request timeout in milliseconds. Default 30000. */
3796
- timeout?: number;
3797
- }
3798
- /**
3799
- * Create the library provider for one Forge. Internal to ViteHub packages: return it from a public API only
3800
- * where the API owns the Forge credentials, such as `GitHubHost.forge()` in `@vite-hub/agent`.
3801
- * A GitHub provider also has `graphql()`.
3802
- */
3803
- export declare function forgeProvider(connection: ForgeConnection & {
3804
- forge: "github";
3805
- }): Promise<GitHubProvider>;
3806
- export declare function forgeProvider(connection: ForgeConnection): Promise<ForgeProvider>;
3807
- /** A Forge response that succeeded but did not include the expected data. */
3808
- export declare class ForgeResponseError extends Error {
3809
- override name: string;
3810
- }
3811
- /** The HTTP status of a failed Forge request, or undefined for other errors. */
3812
- export declare function forgeErrorStatus(error: unknown): number | undefined;
3813
- /** The error that a cancelled Forge operation rejects with. */
3814
- export declare function abortError(signal: AbortSignal): Error;
3815
- /** Reject with the abort reason when `signal` aborts before `promise` settles. */
3816
- export declare function withSignal<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
3817
- //#endregion
3818
3992
  //#region src/gaps/git-credentials.d.ts
3819
3993
  interface ForgeGitCredentialsInput {
3820
3994
  forge: ForgeKind;
@@ -3834,6 +4008,7 @@ interface ForgeGitCredentials {
3834
4008
  /**
3835
4009
  * Git smart HTTP remote and credentials for one repository.
3836
4010
  * Gap: `forges` exposes `Repo.cloneUrls` but no transport credential.
4011
+ * Remove when forges releases it (https://github.com/danielroe/forges/issues/192).
3837
4012
  */
3838
4013
  export declare function forgeGitCredentials(input: ForgeGitCredentialsInput): ForgeGitCredentials;
3839
4014
  /**
@@ -3846,47 +4021,30 @@ export declare function forgeGitAuthHeader(credentials: ForgeGitCredentials): {
3846
4021
  value: string;
3847
4022
  } | undefined;
3848
4023
  //#endregion
4024
+ //#region src/gaps/merge.d.ts
4025
+ interface ForgeMergeOptions extends MergeOptions {
4026
+ /**
4027
+ * GitHub only. Merge past failing branch rules, such as a required check. GitHub accepts it only from an
4028
+ * actor that may bypass those rules: a repository admin, or a bypass actor of the ruleset.
4029
+ */
4030
+ bypassRules?: boolean;
4031
+ /** How long to wait for GitHub to finish the merge, in milliseconds. Default 30000. */
4032
+ timeout?: number;
4033
+ }
4034
+ /** `threads.merge()`, which can also bypass GitHub branch rules. */
4035
+ export declare function forgeMerge(provider: ForgeProvider, thread: ThreadRef, options?: ForgeMergeOptions): Promise<MergeResult>;
4036
+ //#endregion
3849
4037
  //#region src/gaps/retarget.d.ts
3850
4038
  /** Change the base branch of a GitHub pull request. */
3851
4039
  export declare function retargetPullRequest(provider: ForgeProvider, thread: ThreadRef, base: string, options?: BaseOptions): Promise<void>;
3852
4040
  //#endregion
3853
- //#region src/gaps/review-threads.d.ts
3854
- /** A resolvable review conversation on a pull request. */
3855
- interface ReviewThread {
3856
- /** The id that `threads.resolveReviewThread()` takes. */
3857
- id: string;
3858
- resolved: boolean;
3859
- outdated: boolean;
3860
- path?: string;
3861
- line?: number;
3862
- startLine?: number;
3863
- originalLine?: number;
3864
- originalStartLine?: number;
3865
- /** Every comment in the conversation: its GraphQL id and its REST id. */
3866
- comments: Array<{
3867
- id: string;
3868
- restId?: string;
3869
- }>;
3870
- /** The GraphQL node without its comment connection. */
3871
- raw: Record<string, unknown>;
3872
- }
3873
- /** A review conversation and the pull request it belongs to. */
3874
- interface ReviewThreadOwner {
3875
- id: string;
3876
- resolved: boolean;
3877
- /** The GraphQL id of the pull request. */
3878
- pullRequestId: string;
3879
- }
3880
- /** List every review conversation of a GitHub pull request, with the identity of every comment in it. */
3881
- export declare function listReviewThreads(provider: ForgeProvider, thread: ThreadRef, options?: BaseOptions): Promise<ReviewThread[]>;
3882
- /** Look up one review conversation by its id. Returns undefined when the id names no review conversation. */
3883
- export declare function getReviewThread(provider: ForgeProvider, id: string, options?: BaseOptions): Promise<ReviewThreadOwner | undefined>;
3884
- //#endregion
3885
4041
  //#region src/github-app.d.ts
3886
4042
  interface GitHubAppCredentials {
3887
4043
  installationToken(installationId: number | string, options?: {
3888
4044
  refresh?: boolean;
3889
4045
  signal?: AbortSignal;
4046
+ /** Mint a new token when the cached one expires within this many milliseconds. Default 60000. */
4047
+ minLifetime?: number;
3890
4048
  }): Promise<{
3891
4049
  token: string;
3892
4050
  expiresAt: Date;
@@ -3899,6 +4057,39 @@ interface GitHubAppCredentials {
3899
4057
  slug: string;
3900
4058
  login: string;
3901
4059
  }>;
4060
+ /**
4061
+ * Every repository that the App's installations can access, from `GET /app/installations` and
4062
+ * `GET /installation/repositories`, all pages. Suspended installations are skipped.
4063
+ */
4064
+ repositories(signal?: AbortSignal): Promise<GitHubAppRepository[]>;
4065
+ /**
4066
+ * Webhook deliveries of the App that failed since `since` (epoch milliseconds) and that no later
4067
+ * attempt delivered, oldest first, from `GET /app/hook/deliveries`. GitHub does not retry a failed
4068
+ * delivery by itself.
4069
+ */
4070
+ failedDeliveries(since: number, signal?: AbortSignal): Promise<GitHubAppDelivery[]>;
4071
+ /** Asks GitHub to send a delivery again: `POST /app/hook/deliveries/{id}/attempts`. */
4072
+ redeliver(id: string, signal?: AbortSignal): Promise<void>;
4073
+ }
4074
+ /** One webhook delivery of a GitHub App. */
4075
+ interface GitHubAppDelivery {
4076
+ /** A decimal string: delivery IDs are larger than `Number.MAX_SAFE_INTEGER`. */
4077
+ id: string;
4078
+ /** Shared by every attempt of the same event; the receiver's `X-GitHub-Delivery`. */
4079
+ guid: string;
4080
+ event: string;
4081
+ action?: string;
4082
+ deliveredAt: number;
4083
+ statusCode: number;
4084
+ /** Attempts of this `guid` in the listed window. */
4085
+ attempts: number;
4086
+ }
4087
+ /** A repository that one App installation can access. */
4088
+ interface GitHubAppRepository {
4089
+ /** `owner/name`, as GitHub spells it. */
4090
+ repository: string;
4091
+ installationId: number;
4092
+ archived: boolean;
3902
4093
  }
3903
4094
  interface GitHubAppInput {
3904
4095
  appId: number | string;
@@ -3915,4 +4106,35 @@ export declare function githubAppCredentials(input: GitHubAppInput): GitHubAppCr
3915
4106
  /** Read a GitHub App private key from an inline value or a file path. Escaped "\\n" becomes a newline. */
3916
4107
  export declare function readGitHubAppPrivateKey(inline: string | undefined, path: string | undefined): Promise<string | undefined>;
3917
4108
  //#endregion
3918
- export { type BaseOptions, BranchMovedError, type BranchRules, type Check, type CiRun, type CiRunRef, type Commit, ForgeApiError, type ForgeArchiveOptions, type ForgeCommitFilesInput, type ForgeConnection, type ForgeEnv, type ForgeEnvField, type ForgeFileChange, type ForgeFileMode, type ForgeGitCredentials, type ForgeGitCredentialsInput, type ForgeKind, type ForgeProvider, ForgeTimeoutError, type GitHubAppCredentials, type GitHubAppInput, type GitHubBranchRuleDetails, type GitHubProvider, MergeBlockedError, type MergeMethod, NotFoundError, type Page, RateLimitedError, type RepoRef, type RequiredCheck, type ReviewThread, type ReviewThreadOwner, type Thread, type ThreadRef, type TreeEntry, repoRef };
4109
+ //#region src/github-installations.d.ts
4110
+ /**
4111
+ * Which GitHub App installation serves each repository owner. Every reader of the GitHub Server Env routes with it,
4112
+ * so `useForge()`, Capabilities, Comments, and presets pick the same installation.
4113
+ */
4114
+ interface GitHubInstallationRouting {
4115
+ /** The fixed installation of `owner`. */
4116
+ installationId?: number;
4117
+ /** The lowercase repository owner of `installationId`. */
4118
+ owner?: string;
4119
+ /** Installation IDs by lowercase repository owner. */
4120
+ installations: Readonly<Record<string, number>>;
4121
+ }
4122
+ /** The raw values of `github.installationId`, `github.appOwner`, and `github.appInstallations` in Server Env. */
4123
+ interface GitHubInstallationEnv {
4124
+ installationId?: string | undefined;
4125
+ appOwner?: string | undefined;
4126
+ appInstallations?: string | undefined;
4127
+ }
4128
+ /**
4129
+ * Reads the installation routing from Server Env values. Throws `FORGE_INVALID_ENV` when
4130
+ * `VITEHUB_GITHUB_INSTALLATION_ID` has no `VITEHUB_GITHUB_APP_OWNER`, because an installation belongs to one owner.
4131
+ */
4132
+ export declare function githubInstallationRouting(env: GitHubInstallationEnv): GitHubInstallationRouting;
4133
+ /**
4134
+ * The configured installation for `repository`: its owner in `installations`, else the fixed installation when the
4135
+ * owner matches. Without `repository`, the fixed installation. `undefined` means: ask GitHub which installation can
4136
+ * reach the repository.
4137
+ */
4138
+ export declare function githubInstallationFor(routing: GitHubInstallationRouting, repository: string | undefined): number | undefined;
4139
+ //#endregion
4140
+ export { type BaseOptions, BranchMovedError, type BranchRules, type Check, type CiRun, type CiRunRef, type Commit, type Forge$1 as Forge, ForgeApiError, type ForgeAppIdentity, type ForgeArchiveOptions, type ForgeCachedResponse, type ForgeCallOptions, type ForgeCommitFilesInput, type ForgeConditionalRequests, type ForgeConnection, type ForgeEnv, type ForgeEnvField, type ForgeEnvSource, type ForgeErrorCode, type ForgeFileChange, type ForgeFileMode, type ForgeGitCredentials, type ForgeGitCredentialsInput, type ForgeKind, type ForgeMemoryCacheOptions, type ForgeMergeOptions, type ForgeProvider, type ForgeProviderOf, type ForgeResponseCache, ForgeTimeoutError, type ForgeToken, type ForgeTokenErrorCode, type GitHubAppCredentials, type GitHubAppDelivery, type GitHubAppInput, type GitHubAppRepository, type GitHubBranchRuleDetails, type GitHubInstallationEnv, type GitHubInstallationRouting, type GitHubProvider, MergeBlockedError, type MergeMethod, type MergeOptions, type MergeResult, NotFoundError, type Page, RateLimitedError, type RepoRef, type RequiredCheck, type Thread, type ThreadRef, type TreeEntry, type UseForgeOptions, repoRef };