@github-tools/sdk 1.19.0 → 1.21.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.
- package/README.md +97 -30
- package/dist/approval-policy-CEMMPq92.mjs +17 -0
- package/dist/approval-policy-CEMMPq92.mjs.map +1 -0
- package/dist/connect/eve.d.mts +2 -2
- package/dist/connect/eve.d.mts.map +1 -1
- package/dist/connect/eve.mjs +1 -1
- package/dist/connect.d.mts +15 -24
- package/dist/connect.d.mts.map +1 -1
- package/dist/connect.mjs +2 -2
- package/dist/{cores-BeLZwcde.mjs → cores-meFAMt2D.mjs} +41 -2
- package/dist/cores-meFAMt2D.mjs.map +1 -0
- package/dist/{tool-types-CrC80SIL.d.mts → dry-run-DXckOam2.d.mts} +437 -54
- package/dist/dry-run-DXckOam2.d.mts.map +1 -0
- package/dist/evaluation-DJHINyAu.mjs +311 -0
- package/dist/evaluation-DJHINyAu.mjs.map +1 -0
- package/dist/{eve-runtime-DRh2QJI7.d.mts → eve-runtime-B_CJE9JV.d.mts} +21 -7
- package/dist/eve-runtime-B_CJE9JV.d.mts.map +1 -0
- package/dist/{eve-runtime-YTxfrWP-.mjs → eve-runtime-DPzMPCLt.mjs} +49 -15
- package/dist/eve-runtime-DPzMPCLt.mjs.map +1 -0
- package/dist/eve-runtime.d.mts +5 -5
- package/dist/eve-runtime.mjs +4 -4
- package/dist/eve.d.mts +95 -4
- package/dist/eve.d.mts.map +1 -1
- package/dist/eve.mjs +94 -3
- package/dist/eve.mjs.map +1 -1
- package/dist/{index-DkZvveZP.d.mts → index-CzzrtCVj.d.mts} +119 -348
- package/dist/index-CzzrtCVj.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +4 -3
- package/dist/{interrupts-C_lUXMdd.d.mts → interrupts-BSDPwdJ2.d.mts} +2 -2
- package/dist/interrupts-BSDPwdJ2.d.mts.map +1 -0
- package/dist/{src-Bx5p1Unc.mjs → src-BlhrSieS.mjs} +491 -23
- package/dist/src-BlhrSieS.mjs.map +1 -0
- package/dist/tanstack/interrupts.d.mts +1 -1
- package/dist/tanstack.d.mts +1705 -204
- package/dist/tanstack.d.mts.map +1 -1
- package/dist/tanstack.mjs +53 -19
- package/dist/tanstack.mjs.map +1 -1
- package/dist/{token-Bh8nPj66.mjs → token-BLps09gm.mjs} +36 -116
- package/dist/token-BLps09gm.mjs.map +1 -0
- package/dist/{types-BmwOpI5-.d.mts → types-Bln8U42J.d.mts} +3 -3
- package/dist/{types-BmwOpI5-.d.mts.map → types-Bln8U42J.d.mts.map} +1 -1
- package/dist/{types-CPAsEMzx.d.mts → types-C7O2lwwz.d.mts} +14 -2
- package/dist/{types-CPAsEMzx.d.mts.map → types-C7O2lwwz.d.mts.map} +1 -1
- package/dist/workflow.d.mts +41 -40
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +20 -47
- package/dist/workflow.mjs.map +1 -1
- package/dist/{write-tools-BaoTUCg7.mjs → write-tools-w-8tjnDQ.mjs} +1360 -124
- package/dist/write-tools-w-8tjnDQ.mjs.map +1 -0
- package/package.json +4 -6
- package/dist/cores-BeLZwcde.mjs.map +0 -1
- package/dist/evaluation-f-2QwBid.mjs +0 -210
- package/dist/evaluation-f-2QwBid.mjs.map +0 -1
- package/dist/eve-runtime-DRh2QJI7.d.mts.map +0 -1
- package/dist/eve-runtime-YTxfrWP-.mjs.map +0 -1
- package/dist/index-DkZvveZP.d.mts.map +0 -1
- package/dist/instructions-BuypoY0x.mjs +0 -148
- package/dist/instructions-BuypoY0x.mjs.map +0 -1
- package/dist/interrupts-C_lUXMdd.d.mts.map +0 -1
- package/dist/src-Bx5p1Unc.mjs.map +0 -1
- package/dist/token-Bh8nPj66.mjs.map +0 -1
- package/dist/tool-types-CrC80SIL.d.mts.map +0 -1
- package/dist/write-tools-BaoTUCg7.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as GITHUB_TOOL_CATALOG, Za as githubToolsErrors, v as PRESET_TOOLS, w as ALL_GITHUB_TOOL_NAMES, y as resolvePresetTools } from "./write-tools-w-8tjnDQ.mjs";
|
|
2
2
|
import { ConnectError, ConnectorInstallationRequiredError, UserAuthorizationRequiredError, getToken } from "@vercel/connect";
|
|
3
3
|
//#region src/connect/connector.ts
|
|
4
4
|
/** Resolves a {@link GithubConnectorInput} to a connector name string. */
|
|
@@ -7,119 +7,6 @@ async function resolveGithubConnector(connector) {
|
|
|
7
7
|
}
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/connect/scopes.ts
|
|
10
|
-
/**
|
|
11
|
-
* Vercel Connect scope strings mapped to each {@link GithubToolPreset}.
|
|
12
|
-
*
|
|
13
|
-
* Scopes mirror GitHub App permissions (`contents`, `pull_requests`, `issues`,
|
|
14
|
-
* `discussions`, `actions`, `checks`, `statuses`, `administration`, `metadata`)
|
|
15
|
-
* and must cover every read/write family a preset's tools touch, not just its
|
|
16
|
-
* primary domain. Release tools fall under the `contents` permission on GitHub
|
|
17
|
-
* Apps, and reaction tools under `issues`, so neither needs a scope of its own.
|
|
18
|
-
*
|
|
19
|
-
* Gist tools in `repo-explorer` and `maintainer` are intentionally left
|
|
20
|
-
* unscoped: the Gists API only accepts GitHub App *user* access tokens, never
|
|
21
|
-
* installation tokens, and Connect mints `subject: { type: 'app' }`
|
|
22
|
-
* installation tokens by default. Gist calls made with an app-subject token
|
|
23
|
-
* 403 regardless of requested scopes — use a `{ type: 'user' }` subject or a
|
|
24
|
-
* fine-grained PAT with the "Gists" account permission for those tools instead.
|
|
25
|
-
*
|
|
26
|
-
* Notification tools in `maintainer` and `notification-inbox` are unscoped for
|
|
27
|
-
* the same reason: `notifications` is an account-level GitHub App permission
|
|
28
|
-
* that only applies to user access tokens, so `listNotifications` /
|
|
29
|
-
* `markNotificationRead` need a PAT with the "Notifications" account permission.
|
|
30
|
-
*/
|
|
31
|
-
const PRESET_CONNECT_SCOPES = {
|
|
32
|
-
"repo-explorer": [
|
|
33
|
-
"contents:read",
|
|
34
|
-
"metadata:read",
|
|
35
|
-
"pull_requests:read",
|
|
36
|
-
"issues:read",
|
|
37
|
-
"discussions:read",
|
|
38
|
-
"actions:read",
|
|
39
|
-
"checks:read",
|
|
40
|
-
"statuses:read"
|
|
41
|
-
],
|
|
42
|
-
"code-review": [
|
|
43
|
-
"contents:read",
|
|
44
|
-
"metadata:read",
|
|
45
|
-
"pull_requests:read",
|
|
46
|
-
"pull_requests:write",
|
|
47
|
-
"checks:read",
|
|
48
|
-
"statuses:read"
|
|
49
|
-
],
|
|
50
|
-
"issue-triage": [
|
|
51
|
-
"contents:read",
|
|
52
|
-
"metadata:read",
|
|
53
|
-
"issues:read",
|
|
54
|
-
"issues:write"
|
|
55
|
-
],
|
|
56
|
-
"ci-ops": [
|
|
57
|
-
"contents:read",
|
|
58
|
-
"metadata:read",
|
|
59
|
-
"actions:read",
|
|
60
|
-
"actions:write",
|
|
61
|
-
"checks:read",
|
|
62
|
-
"statuses:read"
|
|
63
|
-
],
|
|
64
|
-
"security-audit": [
|
|
65
|
-
"contents:read",
|
|
66
|
-
"metadata:read",
|
|
67
|
-
"pull_requests:read",
|
|
68
|
-
"issues:read",
|
|
69
|
-
"issues:write",
|
|
70
|
-
"actions:read",
|
|
71
|
-
"checks:read",
|
|
72
|
-
"statuses:read"
|
|
73
|
-
],
|
|
74
|
-
"release-manager": [
|
|
75
|
-
"contents:read",
|
|
76
|
-
"contents:write",
|
|
77
|
-
"metadata:read",
|
|
78
|
-
"pull_requests:read",
|
|
79
|
-
"actions:read",
|
|
80
|
-
"actions:write"
|
|
81
|
-
],
|
|
82
|
-
"discussion-moderator": [
|
|
83
|
-
"contents:read",
|
|
84
|
-
"metadata:read",
|
|
85
|
-
"issues:read",
|
|
86
|
-
"issues:write",
|
|
87
|
-
"discussions:read",
|
|
88
|
-
"discussions:write"
|
|
89
|
-
],
|
|
90
|
-
"notification-inbox": [
|
|
91
|
-
"contents:read",
|
|
92
|
-
"metadata:read",
|
|
93
|
-
"pull_requests:read",
|
|
94
|
-
"issues:read"
|
|
95
|
-
],
|
|
96
|
-
"pr-author": [
|
|
97
|
-
"contents:read",
|
|
98
|
-
"contents:write",
|
|
99
|
-
"metadata:read",
|
|
100
|
-
"pull_requests:read",
|
|
101
|
-
"pull_requests:write"
|
|
102
|
-
],
|
|
103
|
-
"maintainer": [
|
|
104
|
-
"contents:read",
|
|
105
|
-
"contents:write",
|
|
106
|
-
"metadata:read",
|
|
107
|
-
"pull_requests:read",
|
|
108
|
-
"pull_requests:write",
|
|
109
|
-
"issues:read",
|
|
110
|
-
"issues:write",
|
|
111
|
-
"discussions:read",
|
|
112
|
-
"discussions:write",
|
|
113
|
-
"actions:read",
|
|
114
|
-
"actions:write",
|
|
115
|
-
"checks:read",
|
|
116
|
-
"statuses:read",
|
|
117
|
-
"administration:read",
|
|
118
|
-
"administration:write"
|
|
119
|
-
]
|
|
120
|
-
};
|
|
121
|
-
/** Default scopes when no preset is specified — union of all preset scopes. */
|
|
122
|
-
const ALL_CONNECT_SCOPES = [...new Set(Object.values(PRESET_CONNECT_SCOPES).flat())];
|
|
123
10
|
/** Stable scope order for tool-derived unions (tests + Connect payloads). */
|
|
124
11
|
const SCOPE_ORDER = [
|
|
125
12
|
"contents:read",
|
|
@@ -135,8 +22,12 @@ const SCOPE_ORDER = [
|
|
|
135
22
|
"actions:write",
|
|
136
23
|
"checks:read",
|
|
137
24
|
"statuses:read",
|
|
25
|
+
"statuses:write",
|
|
138
26
|
"administration:read",
|
|
139
|
-
"administration:write"
|
|
27
|
+
"administration:write",
|
|
28
|
+
"security_events:read",
|
|
29
|
+
"vulnerability_alerts:read",
|
|
30
|
+
"secret_scanning_alerts:read"
|
|
140
31
|
];
|
|
141
32
|
/**
|
|
142
33
|
* Per-tool Connect scopes, derived from `GITHUB_TOOL_CATALOG`. Empty arrays are
|
|
@@ -151,6 +42,35 @@ function orderScopes(scopes) {
|
|
|
151
42
|
return SCOPE_ORDER.filter((scope) => scopes.has(scope));
|
|
152
43
|
}
|
|
153
44
|
/**
|
|
45
|
+
* Vercel Connect scope strings mapped to each {@link GithubToolPreset}, derived
|
|
46
|
+
* from the preset's tools so a tool added to a preset brings its scopes along.
|
|
47
|
+
*
|
|
48
|
+
* Scopes mirror GitHub App permissions (`contents`, `pull_requests`, `issues`,
|
|
49
|
+
* `discussions`, `actions`, `checks`, `statuses`, `administration`, `metadata`,
|
|
50
|
+
* and `security_events`, `vulnerability_alerts`, `secret_scanning_alerts` for the alert tools)
|
|
51
|
+
* and must cover every read/write family a preset's tools touch, not just its
|
|
52
|
+
* primary domain. Release tools fall under the `contents` permission on GitHub
|
|
53
|
+
* Apps, and reaction tools under `issues`, so neither needs a scope of its own.
|
|
54
|
+
*
|
|
55
|
+
* Gist tools in `repo-explorer` and `maintainer` are intentionally left
|
|
56
|
+
* unscoped: the Gists API only accepts GitHub App *user* access tokens, never
|
|
57
|
+
* installation tokens, and Connect mints `subject: { type: 'app' }`
|
|
58
|
+
* installation tokens by default. Gist calls made with an app-subject token
|
|
59
|
+
* 403 regardless of requested scopes — use a `{ type: 'user' }` subject or a
|
|
60
|
+
* fine-grained PAT with the "Gists" account permission for those tools instead.
|
|
61
|
+
*
|
|
62
|
+
* Notification tools in `maintainer` and `notification-inbox` are unscoped for
|
|
63
|
+
* the same reason: `notifications` is an account-level GitHub App permission
|
|
64
|
+
* that only applies to user access tokens, so `listNotifications` /
|
|
65
|
+
* `markNotificationRead` need a PAT with the "Notifications" account permission.
|
|
66
|
+
*/
|
|
67
|
+
const PRESET_CONNECT_SCOPES = Object.keys(PRESET_TOOLS).reduce((map, preset) => {
|
|
68
|
+
map[preset] = connectGithubScopesForTools(PRESET_TOOLS[preset]);
|
|
69
|
+
return map;
|
|
70
|
+
}, {});
|
|
71
|
+
/** Default scopes when no preset is specified: every tool's scopes. */
|
|
72
|
+
const ALL_CONNECT_SCOPES = connectGithubScopesForTools(ALL_GITHUB_TOOL_NAMES);
|
|
73
|
+
/**
|
|
154
74
|
* Returns Vercel Connect scopes for a preset or combined presets.
|
|
155
75
|
* Without a preset, returns the union of all preset scopes (full tool set).
|
|
156
76
|
*/
|
|
@@ -349,4 +269,4 @@ function resolveConnectOptions(connectOptions) {
|
|
|
349
269
|
//#endregion
|
|
350
270
|
export { connectGithubScopesForSelection as a, connectGithubScopesForPreset as i, PRESET_CONNECT_SCOPES as n, connectGithubScopesForTools as o, TOOL_CONNECT_SCOPES as r, resolveGithubConnector as s, connectGithubToken as t };
|
|
351
271
|
|
|
352
|
-
//# sourceMappingURL=token-
|
|
272
|
+
//# sourceMappingURL=token-BLps09gm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-BLps09gm.mjs","names":[],"sources":["../src/connect/connector.ts","../src/connect/scopes.ts","../src/connect/params.ts","../src/connect/token.ts"],"sourcesContent":["/**\n * A Vercel Connect connector name, or a resolver that returns one.\n *\n * Use a function to pick the connector dynamically — e.g. a different\n * connector per environment (`production` vs. `preview`) or per tenant.\n * It's resolved lazily, on every token request, alongside the token itself.\n */\nexport type GithubConnectorInput = string | (() => string | Promise<string>)\n\n/** Resolves a {@link GithubConnectorInput} to a connector name string. */\nexport async function resolveGithubConnector(connector: GithubConnectorInput): Promise<string> {\n return typeof connector === 'function' ? await connector() : connector\n}\n","import { PRESET_TOOLS, resolvePresetTools, type GithubToolPreset } from '../core/presets'\nimport { GITHUB_TOOL_CATALOG } from '../core/catalog'\nimport { ALL_GITHUB_TOOL_NAMES, type GithubToolName } from '../core/tool-names'\n\n/** Stable scope order for tool-derived unions (tests + Connect payloads). */\nconst SCOPE_ORDER = [\n 'contents:read',\n 'contents:write',\n 'metadata:read',\n 'pull_requests:read',\n 'pull_requests:write',\n 'issues:read',\n 'issues:write',\n 'discussions:read',\n 'discussions:write',\n 'actions:read',\n 'actions:write',\n 'checks:read',\n 'statuses:read',\n 'statuses:write',\n 'administration:read',\n 'administration:write',\n 'security_events:read',\n 'vulnerability_alerts:read',\n 'secret_scanning_alerts:read',\n] as const\n\n/**\n * Per-tool Connect scopes, derived from `GITHUB_TOOL_CATALOG`. Empty arrays are\n * intentional for gist and notification tools (installation tokens cannot\n * satisfy those APIs).\n */\nexport const TOOL_CONNECT_SCOPES = ALL_GITHUB_TOOL_NAMES.reduce(\n (map, name) => {\n map[name] = GITHUB_TOOL_CATALOG[name].connectScopes\n return map\n },\n {} as Record<GithubToolName, readonly string[]>,\n)\n\nfunction orderScopes(scopes: Set<string>): string[] {\n return SCOPE_ORDER.filter(scope => scopes.has(scope))\n}\n\n/**\n * Vercel Connect scope strings mapped to each {@link GithubToolPreset}, derived\n * from the preset's tools so a tool added to a preset brings its scopes along.\n *\n * Scopes mirror GitHub App permissions (`contents`, `pull_requests`, `issues`,\n * `discussions`, `actions`, `checks`, `statuses`, `administration`, `metadata`,\n * and `security_events`, `vulnerability_alerts`, `secret_scanning_alerts` for the alert tools)\n * and must cover every read/write family a preset's tools touch, not just its\n * primary domain. Release tools fall under the `contents` permission on GitHub\n * Apps, and reaction tools under `issues`, so neither needs a scope of its own.\n *\n * Gist tools in `repo-explorer` and `maintainer` are intentionally left\n * unscoped: the Gists API only accepts GitHub App *user* access tokens, never\n * installation tokens, and Connect mints `subject: { type: 'app' }`\n * installation tokens by default. Gist calls made with an app-subject token\n * 403 regardless of requested scopes — use a `{ type: 'user' }` subject or a\n * fine-grained PAT with the \"Gists\" account permission for those tools instead.\n *\n * Notification tools in `maintainer` and `notification-inbox` are unscoped for\n * the same reason: `notifications` is an account-level GitHub App permission\n * that only applies to user access tokens, so `listNotifications` /\n * `markNotificationRead` need a PAT with the \"Notifications\" account permission.\n */\nexport const PRESET_CONNECT_SCOPES = (Object.keys(PRESET_TOOLS) as GithubToolPreset[]).reduce(\n (map, preset) => {\n map[preset] = connectGithubScopesForTools(PRESET_TOOLS[preset])\n return map\n },\n {} as Record<GithubToolPreset, readonly string[]>,\n)\n\n/** Default scopes when no preset is specified: every tool's scopes. */\nconst ALL_CONNECT_SCOPES = connectGithubScopesForTools(ALL_GITHUB_TOOL_NAMES)\n\n/**\n * Returns Vercel Connect scopes for a preset or combined presets.\n * Without a preset, returns the union of all preset scopes (full tool set).\n */\nexport function connectGithubScopesForPreset(\n preset?: GithubToolPreset | GithubToolPreset[],\n): string[] {\n if (!preset) return [...ALL_CONNECT_SCOPES]\n\n const presets = Array.isArray(preset) ? preset : [preset]\n return [\n ...new Set(presets.flatMap(p => PRESET_CONNECT_SCOPES[p])),\n ]\n}\n\n/**\n * Returns Connect scopes covering exactly the given tools.\n * Always includes `metadata:read`. Gist and notification tools contribute nothing.\n */\nexport function connectGithubScopesForTools(names: readonly GithubToolName[]): string[] {\n const scopes = new Set<string>(['metadata:read'])\n for (const name of names) {\n for (const scope of TOOL_CONNECT_SCOPES[name]) {\n scopes.add(scope)\n }\n }\n return orderScopes(scopes)\n}\n\nexport type ConnectScopeSelection = {\n preset?: GithubToolPreset | GithubToolPreset[]\n include?: readonly GithubToolName[]\n exclude?: readonly GithubToolName[]\n}\n\nfunction resolveSelectedToolNames({\n preset,\n include,\n exclude,\n}: ConnectScopeSelection): GithubToolName[] {\n const presetAllowed = preset ? resolvePresetTools(preset) : null\n const includeAllowed = include ? new Set(include) : null\n const excluded = exclude ? new Set(exclude) : null\n\n const allowed = presetAllowed && includeAllowed\n ? new Set([...presetAllowed, ...includeAllowed])\n : presetAllowed ?? includeAllowed\n\n return ALL_GITHUB_TOOL_NAMES.filter(\n name => (!allowed || allowed.has(name)) && !excluded?.has(name),\n )\n}\n\n/**\n * Resolves Connect scopes for the effective tool set.\n *\n * - No `include` / `exclude`: same as {@link connectGithubScopesForPreset}\n * (omitted preset → full union, including `administration:write`).\n * - With `include` and/or `exclude`: scopes are derived from the resolved tools\n * so a hand-picked `include` list does not mint the full admin surface.\n */\nexport function connectGithubScopesForSelection(selection: ConnectScopeSelection = {}): string[] {\n const { preset, include, exclude } = selection\n if (!include && !exclude) {\n return connectGithubScopesForPreset(preset)\n }\n return connectGithubScopesForTools(resolveSelectedToolNames(selection))\n}\n","import type { ConnectTokenParams } from '@vercel/connect'\nimport { connectGithubScopesForSelection } from './scopes'\nimport type { ConnectGithubTokenOptions, GithubConnectParams } from './types'\n\nexport function resolveGithubConnectTokenParams(\n options: Omit<ConnectGithubTokenOptions, 'params'> & { params?: GithubConnectParams } = {},\n): ConnectTokenParams {\n const { preset, include, exclude, params } = options\n const scopes = params?.scopes ?? connectGithubScopesForSelection({ preset, include, exclude })\n return buildConnectTokenParams(scopes, params)\n}\n\nfunction buildConnectTokenParams(\n scopes: string[],\n params?: GithubConnectParams,\n): ConnectTokenParams {\n const { repositories, subject, ...rest } = params ?? {}\n\n const authorizationDetails = rest.authorizationDetails\n ?? (repositories?.length\n ? [{ type: 'github_app_installation' as const, repositories }]\n : undefined)\n\n return {\n subject: subject ?? { type: 'app' },\n ...rest,\n scopes,\n ...(authorizationDetails && { authorizationDetails }),\n }\n}\n","import {\n ConnectError,\n ConnectorInstallationRequiredError,\n getToken,\n UserAuthorizationRequiredError,\n type ConnectOptions,\n type ConnectTokenParams,\n} from '@vercel/connect'\nimport { githubToolsErrors } from '../core/errors'\nimport type { GithubTokenCall, GithubTokenInput } from '../core/token'\nimport { resolveGithubConnector, type GithubConnectorInput } from './connector'\nimport { resolveGithubConnectTokenParams } from './params'\nimport type { ConnectGithubTokenOptions, GithubConnectParams } from './types'\n\n/**\n * Returns a lazy GitHub token provider backed by a Vercel Connect connector.\n * Scopes are derived from `preset`, or from the resolved `include`/`exclude`\n * tool set when those are set, unless overridden in `params.scopes`.\n *\n * `connector` may be a static name or a resolver function — e.g. to pick a\n * different connector per environment (production vs. preview) or tenant.\n * It's re-resolved on every call, alongside the token itself.\n *\n * App-subject tokens are minted for the GitHub App installation that owns the\n * call's target repository, so one App installed on several accounts works\n * with no configuration; an explicit `installationId`, `authorizationDetails`\n * or `repositories` in `params` pins the installation instead. `params` may\n * also be a resolver called with the tool call on every token request.\n * Connect caches tokens per `(connector, params)`, so repeated calls on the\n * same repository reuse one token.\n */\nexport function connectGithubToken(\n connector: GithubConnectorInput,\n options: ConnectGithubTokenOptions = {},\n): GithubTokenInput {\n const { connectOptions } = options\n const tokenParamsFor = createTokenParamsResolver(options)\n\n return async (call) => {\n const tokenParams = await tokenParamsFor(call)\n try {\n return await getToken(\n await resolveGithubConnector(connector),\n tokenParams,\n resolveConnectOptions(connectOptions),\n )\n }\n catch (error) {\n throw toConnectCatalogError(error, tokenParams, call)\n }\n }\n}\n\n/**\n * Static and resolved params go through the same repository targeting and\n * scope derivation, so per-call params keep the preset/include/exclude scope\n * narrowing unless they set `scopes` explicitly.\n */\nfunction createTokenParamsResolver(\n options: ConnectGithubTokenOptions,\n): (call?: GithubTokenCall) => Promise<ConnectTokenParams> {\n const { params } = options\n return async (call) => {\n const resolved = typeof params === 'function' ? await params(call) : params\n return resolveGithubConnectTokenParams({ ...options, params: withRepositoryTarget(resolved, call) })\n }\n}\n\n/**\n * Target the installation that owns the call's repository. Only app subjects\n * are installation-scoped, and an explicit installation choice in `params`\n * always wins.\n */\nexport function withRepositoryTarget(params: GithubConnectParams | undefined, call: GithubTokenCall | undefined): GithubConnectParams | undefined {\n if (!call?.owner || !call.repo) return params\n if (params?.subject !== undefined && params.subject.type !== 'app') return params\n if (params?.installationId !== undefined || params?.authorizationDetails !== undefined || params?.repositories !== undefined) return params\n return {\n ...params,\n authorizationDetails: [{ type: 'github_app_installation', org: call.owner, repositories: [call.repo] }],\n }\n}\n\n/** Account Connect selects the installation for: the detail's `org`, else the owner of a qualified repository. */\nfunction installationTarget(tokenParams: ConnectTokenParams): string | undefined {\n for (const detail of tokenParams.authorizationDetails ?? []) {\n if (detail.type !== 'github_app_installation') continue\n if (typeof detail.org === 'string') return detail.org\n const repositories = [detail.repositories].flat()\n const qualified = repositories.find((repository): repository is string => typeof repository === 'string' && repository.includes('/'))\n if (qualified) return qualified.split('/')[0]\n }\n return undefined\n}\n\n/**\n * Map @vercel/connect failures to catalog errors so models get the actual\n * cause (process identity, missing user connection, missing installation)\n * instead of a bare \"Not authorized\" they misread as GitHub permissions.\n */\nfunction toConnectCatalogError(error: unknown, tokenParams: ConnectTokenParams, call: GithubTokenCall | undefined): unknown {\n if (error instanceof UserAuthorizationRequiredError) {\n const { subject } = tokenParams\n const subjectId = subject.type === 'user' ? subject.id : subject.type ?? 'token'\n return githubToolsErrors.CONNECT_USER_NOT_CONNECTED({ subjectId, cause: error })\n }\n if (error instanceof ConnectorInstallationRequiredError) {\n const owner = installationTarget(tokenParams) ?? call?.owner\n return githubToolsErrors.CONNECT_INSTALLATION_REQUIRED({ detail: error.message, ...(owner && { owner }), cause: error })\n }\n if (error instanceof ConnectError && error.status === 403) {\n return githubToolsErrors.CONNECT_NOT_AUTHORIZED({ detail: error.message, cause: error })\n }\n return error\n}\n\n/**\n * Best-effort JWT `exp` claim, in epoch seconds. Returns undefined for\n * malformed tokens — Connect then rejects them with its own error.\n */\nfunction oidcTokenExpiry(token: string): number | undefined {\n const payload = token.split('.')[1]\n if (!payload) return undefined\n try {\n const claims: unknown = JSON.parse(Buffer.from(payload, 'base64url').toString())\n if (claims == null || typeof claims !== 'object' || !('exp' in claims)) return undefined\n return typeof claims.exp === 'number' ? claims.exp : undefined\n }\n catch {\n return undefined\n }\n}\n\n/**\n * Prefer an explicit `vercelToken`, then `VERCEL_OIDC_TOKEN` from the environment.\n * Passing the env token into `getToken` skips `@vercel/oidc`'s project-root walk,\n * which fails inside eve/workflow snapshots that have no `.vercel` directory.\n *\n * Pinning also disables refresh, so an expired token fails loudly here instead\n * of surfacing as an opaque Connect 403 the model misreads as GitHub permissions.\n */\nfunction resolveConnectOptions(connectOptions?: ConnectOptions): ConnectOptions | undefined {\n const vercelToken = connectOptions?.vercelToken ?? process.env.VERCEL_OIDC_TOKEN\n if (vercelToken) {\n const exp = oidcTokenExpiry(vercelToken)\n if (exp !== undefined && exp * 1000 <= Date.now()) {\n throw githubToolsErrors.OIDC_TOKEN_EXPIRED({ expiredAt: new Date(exp * 1000).toISOString() })\n }\n }\n if (!vercelToken && !connectOptions) return undefined\n return {\n ...vercelToken ? { vercelToken } : {},\n ...connectOptions,\n }\n}\n\nexport type { ConnectOptions }\n"],"mappings":"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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as EveGithubToolsOptions } from "./types-
|
|
1
|
+
import { M as GithubTokenCall, W as GithubToolName, i as GithubToolsBaseOptions, z as GithubToolPreset } from "./dry-run-DXckOam2.mjs";
|
|
2
|
+
import { r as EveGithubToolsOptions } from "./types-C7O2lwwz.mjs";
|
|
3
3
|
import { ConnectOptions, ConnectTokenParams } from "@vercel/connect";
|
|
4
4
|
//#region src/connect/connector.d.ts
|
|
5
5
|
/**
|
|
@@ -60,4 +60,4 @@ type ConnectGithubTokenOptions = {
|
|
|
60
60
|
};
|
|
61
61
|
//#endregion
|
|
62
62
|
export { GithubConnectParamsInput as a, resolveGithubConnector as c, GithubConnectParams as i, ConnectGithubTokenOptions as n, GithubConnectParamsResolver as o, ConnectGithubToolsOptions as r, GithubConnectorInput as s, ConnectGithubEveToolsOptions as t };
|
|
63
|
-
//# sourceMappingURL=types-
|
|
63
|
+
//# sourceMappingURL=types-Bln8U42J.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-Bln8U42J.d.mts","names":[],"sources":["../src/connect/connector.ts","../src/connect/types.ts"],"mappings":";;;;;;;;;;;KAOY,gDAAgD;;iBAGtC,uBAAuB,WAAW,uBAAuB;;;;;;;;;;KCInE,sBAAsB,KAAK;;;;;;;;EAQrC,UAAU;;EAEV;;;;;;;;KASU,+BACV,OAAO,oBACJ,sBAAsB,QAAQ;;KAGvB,2BAA2B,sBAAsB;KAEjD,4BAA4B;EACtC,SAAS,mBAAmB;EAC5B,UAAU;;KAGA,+BAA+B,KAAK;EAC9C,UAAU;;KAGA;EACV,SAAS,mBAAmB;;EAE5B,mBAAmB;;EAEnB,mBAAmB;EACnB,SAAS;EACT,iBAAiB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as GithubWriteToolName, I as GithubGuardrails, N as GithubTokenInput, W as GithubToolName, c as CommitIdentity, s as GithubToolsContext, t as GithubDryRunApproval, z as GithubToolPreset } from "./dry-run-DXckOam2.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { ToolModelOutput } from "eve/tools";
|
|
4
4
|
import { Approval } from "eve/tools/approval";
|
|
@@ -59,6 +59,18 @@ type EveGithubToolsOptions = {
|
|
|
59
59
|
committer?: CommitIdentity;
|
|
60
60
|
/** Co-authors to attribute on all commits created by tools. */
|
|
61
61
|
coAuthors?: CommitIdentity[];
|
|
62
|
+
/**
|
|
63
|
+
* Repositories and branches the tools may act on, checked before each call reaches GitHub.
|
|
64
|
+
* A blocked call returns a `github_tools.GUARDRAIL_BLOCKED` error, whoever approved it.
|
|
65
|
+
*/
|
|
66
|
+
guardrails?: GithubGuardrails;
|
|
67
|
+
/**
|
|
68
|
+
* Run reads as usual but send no write to GitHub: each write returns a `GithubDryRunResult`
|
|
69
|
+
* instead, after the approval and guardrail checks.
|
|
70
|
+
*/
|
|
71
|
+
dryRun?: boolean;
|
|
72
|
+
/** What approval would have decided for this call, reported in its dry-run result. Set per call by the eve extension. */
|
|
73
|
+
dryRunApproval?: GithubDryRunApproval;
|
|
62
74
|
/**
|
|
63
75
|
* Default owner / repo / PR / issue / ref values.
|
|
64
76
|
* Softens matching tool input fields and fills them when omitted.
|
|
@@ -68,4 +80,4 @@ type EveGithubToolsOptions = {
|
|
|
68
80
|
type EveToolFactoryOptions = Omit<EveGithubToolsOptions, 'preset' | 'include' | 'exclude'>;
|
|
69
81
|
//#endregion
|
|
70
82
|
export { EveToolOverrides as a, EveToolFactoryOptions as i, EveApprovalValue as n, EveGithubToolsOptions as r, EveApprovalConfig as t };
|
|
71
|
-
//# sourceMappingURL=types-
|
|
83
|
+
//# sourceMappingURL=types-C7O2lwwz.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-C7O2lwwz.d.mts","names":[],"sources":["../src/eve/types.ts"],"mappings":";;;;;;;;;;;;;KAoBY,2DAKR;KAEQ,8BAER,QAAQ,OAAO,qBAAqB;KAE5B,mBAAmB,QAAQ,OAAO;EAC5C;EACA,WAAW;EACX,iBAAiB,oBAAoB,kBAAkB,QAAQ;;EAE/D,eAAe,EAAE;;KAGP;;EAEV,QAAQ;;;;;;EAMR,SAAS,mBAAmB;;;;;;EAM5B,UAAU;;;;;;EAMV,UAAU;;;;;;EAMV,kBAAkB;;;;;;EAMlB,YAAY;;EAEZ,SAAS;;EAET,YAAY;;EAEZ,YAAY;;;;;EAKZ,aAAa;;;;;EAKb;;EAEA,iBAAiB;;;;;EAKjB,UAAU;;KAGA,wBAAwB,KAAK"}
|
package/dist/workflow.d.mts
CHANGED
|
@@ -1,56 +1,45 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { WorkflowAgentOptions, WorkflowAgentStreamOptions, WorkflowAgentStreamResult } from "@ai-sdk/workflow";
|
|
1
|
+
import { B as PRESET_TOOLS, G as GithubWriteToolName, H as GITHUB_TOOL_NAMES, N as GithubTokenInput, O as GITHUB_WRITE_TOOLS, P as resolveGithubToken, R as CombinedPresetToolNames, V as PresetToolName, W as GithubToolName, a as GithubToolsForPreset, c as CommitIdentity, h as StaticApprovalConfig, i as GithubToolsBaseOptions, l as CommitToolOptions, m as ApprovalConfig, o as PickGithubTools, p as ToolOverrides, r as AllGithubTools, s as GithubToolsContext, z as GithubToolPreset } from "./dry-run-DXckOam2.mjs";
|
|
2
|
+
import { Qt as createGithubAgent, Zt as CreateGithubAgentOptions, n as GithubToolsOptions, r as createGithubTools, t as GithubTools } from "./index-CzzrtCVj.mjs";
|
|
3
|
+
import { LanguageModel, Output, ToolSet } from "ai";
|
|
4
|
+
import { WorkflowAgent, WorkflowAgentOptions, WorkflowAgentStreamOptions, WorkflowAgentStreamResult } from "@ai-sdk/workflow";
|
|
5
5
|
import { Context } from "@ai-sdk/provider-utils";
|
|
6
6
|
//#region src/workflow.d.ts
|
|
7
|
+
type WorkflowGenerate<TTools extends ToolSet> = WorkflowAgent<TTools> extends {
|
|
8
|
+
generate: infer Generate;
|
|
9
|
+
} ? Generate : never;
|
|
10
|
+
/** Options of {@link DurableGithubAgent.generate}: those of `WorkflowAgent.generate()`. */
|
|
11
|
+
export type DurableGithubAgentGenerateOptions<TTools extends ToolSet = ToolSet> = WorkflowGenerate<TTools> extends ((options: infer Options) => unknown) ? Options : never;
|
|
7
12
|
/**
|
|
8
|
-
* Result of {@link DurableGithubAgent.generate}.
|
|
13
|
+
* Result of {@link DurableGithubAgent.generate}: the `WorkflowAgent` generation result. Read the
|
|
14
|
+
* fields you need inside the workflow and return those, since the result itself is not serializable.
|
|
9
15
|
*/
|
|
10
|
-
export
|
|
11
|
-
text: string;
|
|
12
|
-
finishReason: FinishReason;
|
|
13
|
-
usage: LanguageModelUsage;
|
|
14
|
-
steps: StepResult<TTools>[];
|
|
15
|
-
response: LanguageModelResponseMetadata & {
|
|
16
|
-
messages: ModelMessage[];
|
|
17
|
-
};
|
|
18
|
-
}
|
|
16
|
+
export type DurableGithubAgentGenerateResult<TTools extends ToolSet = ToolSet> = WorkflowGenerate<TTools> extends ((options: never) => Promise<infer Result>) ? Result : never;
|
|
19
17
|
/**
|
|
20
|
-
* A
|
|
21
|
-
*
|
|
18
|
+
* A GitHub agent built on {@link WorkflowAgent}. Call both methods from a `"use workflow"`
|
|
19
|
+
* function: each model call and each tool call runs as its own retriable workflow step, and
|
|
20
|
+
* tools with `needsApproval` pause the run until the user answers.
|
|
22
21
|
*
|
|
23
|
-
* - `.stream()`
|
|
24
|
-
*
|
|
25
|
-
* - `.generate()` — uses `generateText` from the AI SDK for non-streaming
|
|
26
|
-
* execution. Must be called from within a `"use step"` function in
|
|
27
|
-
* workflow context (the Workflow runtime blocks raw I/O in workflow scope).
|
|
22
|
+
* - `.stream()` writes the response to a `writable` for chat UIs.
|
|
23
|
+
* - `.generate()` returns the finished result, for bots, webhooks, and background jobs.
|
|
28
24
|
*/
|
|
29
25
|
export declare class DurableGithubAgent<TTools extends ToolSet = ToolSet> {
|
|
30
26
|
private agent;
|
|
31
|
-
private _model;
|
|
32
|
-
private _instructions?;
|
|
33
|
-
private _telemetry?;
|
|
34
|
-
private _tools;
|
|
35
27
|
constructor(options: WorkflowAgentOptions<TTools>);
|
|
36
28
|
/** The tool set configured for this agent. */
|
|
37
29
|
get tools(): TTools;
|
|
38
|
-
/**
|
|
39
|
-
* Stream the agent's response. Delegates directly to `WorkflowAgent.stream()`.
|
|
40
|
-
* Works in workflow context — each tool call is a durable step.
|
|
41
|
-
*/
|
|
30
|
+
/** Stream the agent's response. Delegates to `WorkflowAgent.stream()`. */
|
|
42
31
|
stream<TStreamTools extends TTools = TTools, OUTPUT = never, PARTIAL_OUTPUT = never>(options: WorkflowAgentStreamOptions<TStreamTools, Context, OUTPUT, PARTIAL_OUTPUT>): Promise<WorkflowAgentStreamResult<TStreamTools, OUTPUT>>;
|
|
43
32
|
/**
|
|
44
|
-
* Generate
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* at the workflow scope level.
|
|
33
|
+
* Generate the full response without streaming. Delegates to `WorkflowAgent.generate()`, which
|
|
34
|
+
* needs `@ai-sdk/workflow` 2.0.59 or later. Stops after 20 steps unless `stopWhen` says otherwise.
|
|
35
|
+
* A write that needs approval ends the call with a `tool-approval-request` in
|
|
36
|
+
* `responseMessages`; append the user's `tool-approval-response` and call `generate()` again.
|
|
49
37
|
*/
|
|
50
|
-
generate(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
generate<OUTPUT = string>(options: DurableGithubAgentGenerateOptions<TTools> & {
|
|
39
|
+
output?: Output.Output<OUTPUT>;
|
|
40
|
+
}): Promise<Omit<DurableGithubAgentGenerateResult<TTools>, 'output'> & {
|
|
41
|
+
readonly output: OUTPUT;
|
|
42
|
+
}>;
|
|
54
43
|
}
|
|
55
44
|
/**
|
|
56
45
|
* Options for creating a durable GitHub agent via {@link createDurableGithubAgent}.
|
|
@@ -68,8 +57,8 @@ export type CreateDurableGithubAgentOptions = Omit<WorkflowAgentOptions, 'model'
|
|
|
68
57
|
/**
|
|
69
58
|
* Restrict tools and system prompt to a predefined preset.
|
|
70
59
|
*
|
|
71
|
-
* Selects a subset of tools and
|
|
72
|
-
*
|
|
60
|
+
* Selects a subset of tools and sets the preset's system prompt. Combine presets with an array
|
|
61
|
+
* to merge their tool sets and system prompts.
|
|
73
62
|
*
|
|
74
63
|
* @see {@link GithubToolPreset} for available presets and included tools.
|
|
75
64
|
*/
|
|
@@ -82,6 +71,18 @@ export type CreateDurableGithubAgentOptions = Omit<WorkflowAgentOptions, 'model'
|
|
|
82
71
|
* @see {@link StaticApprovalConfig} for global and per-tool options.
|
|
83
72
|
*/
|
|
84
73
|
requireApproval?: StaticApprovalConfig;
|
|
74
|
+
/**
|
|
75
|
+
* Per-tool overrides (`description`, `title`, `needsApproval`, …), as on `createGithubTools`.
|
|
76
|
+
* `execute`, `inputSchema`, and `outputSchema` cannot be overridden.
|
|
77
|
+
*/
|
|
78
|
+
overrides?: GithubToolsBaseOptions['overrides'];
|
|
79
|
+
/**
|
|
80
|
+
* Repositories and branches the tools may act on, checked before each call reaches GitHub,
|
|
81
|
+
* as on `createGithubTools`.
|
|
82
|
+
*/
|
|
83
|
+
guardrails?: GithubToolsBaseOptions['guardrails'];
|
|
84
|
+
/** Send no write to GitHub, as on `createGithubTools`. */
|
|
85
|
+
dryRun?: boolean;
|
|
85
86
|
/**
|
|
86
87
|
* Fully replace the default system prompt.
|
|
87
88
|
* When set, `preset` system prompts and `additionalInstructions` are ignored.
|
package/dist/workflow.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.mts","names":[],"sources":["../src/workflow.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow.d.mts","names":[],"sources":["../src/workflow.ts"],"mappings":";;;;;;KAuBK,iBAAiB,eAAe,WAAW,cAAc;EAAkB,gBAAgB;IAAa;;YAGjG,kCAAkC,eAAe,UAAU,WAAW,iBAAiB,kBAAiB,eAAe,uBAAsB;;;;;YAM7I,iCAAiC,eAAe,UAAU,WAAW,iBAAiB,kBAAiB,mBAAmB,cAAc,WAAU;;;;;;;;;qBAUjJ,mBAAmB,eAAe,UAAU;UAC/C;EAEI,YAAA,SAAS,qBAAqB;;MAKtC,SAAS;;EAKb,OAAO,qBAAqB,SAAS,QAAQ,gBAAgB,wBAC3D,SAAS,2BAA2B,cAAc,SAAS,QAAQ,kBAClE,QAAQ,0BAA0B,cAAc;;;;;;;EAUnD,SAAS,iBACP,SAAS,kCAAkC;IAAY,SAAS,OAAO,OAAO;MAC7E,QAAQ,KAAK,iCAAiC;aAAgC,QAAQ;;;;;;;;;YAY/E,kCACV,KAAK;EACH,gBAAgB;;;;;EAKhB,QAAQ;;;;;;;;;EASR,SAAS,mBAAmB;;;;;;;;EAQ5B,kBAAkB;;;;;EAKlB,YAAY;;;;;EAKZ,aAAa;;EAEb;;;;;EAKA;;;;;EAKA;;;;EAIA,UAAU;;;;;EAKV,SAAS;;;;;EAKT,YAAY;;;;;EAKZ,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiCA,yBACd,SAAS;EAAoC;IAC5C,mBAAmB;wBACN,yBAAyB,UAAU,kBACjD,SAAS;EAAoC,QAAQ;IACpD,mBAAmB,KAAK,gBAAgB,eAAe;wBAC1C,yBAAyB,mBAAmB,oBAC1D,SAAS;EAAoC,QAAQ;IACpD,mBAAmB,KAAK,gBAAgB,wBAAwB"}
|
package/dist/workflow.mjs
CHANGED
|
@@ -1,78 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as resolveInstructions } from "./instructions-BuypoY0x.mjs";
|
|
1
|
+
import { S as resolveGithubToken, Za as githubToolsErrors, g as GITHUB_TOOL_NAMES, n as resolveInstructions, t as GITHUB_WRITE_TOOLS, v as PRESET_TOOLS } from "./write-tools-w-8tjnDQ.mjs";
|
|
2
|
+
import { r as createGithubAgent, t as createGithubTools } from "./src-BlhrSieS.mjs";
|
|
4
3
|
import { WorkflowAgent } from "@ai-sdk/workflow";
|
|
5
4
|
//#region src/workflow.ts
|
|
6
5
|
/**
|
|
7
|
-
* A
|
|
8
|
-
*
|
|
6
|
+
* A GitHub agent built on {@link WorkflowAgent}. Call both methods from a `"use workflow"`
|
|
7
|
+
* function: each model call and each tool call runs as its own retriable workflow step, and
|
|
8
|
+
* tools with `needsApproval` pause the run until the user answers.
|
|
9
9
|
*
|
|
10
|
-
* - `.stream()`
|
|
11
|
-
*
|
|
12
|
-
* - `.generate()` — uses `generateText` from the AI SDK for non-streaming
|
|
13
|
-
* execution. Must be called from within a `"use step"` function in
|
|
14
|
-
* workflow context (the Workflow runtime blocks raw I/O in workflow scope).
|
|
10
|
+
* - `.stream()` writes the response to a `writable` for chat UIs.
|
|
11
|
+
* - `.generate()` returns the finished result, for bots, webhooks, and background jobs.
|
|
15
12
|
*/
|
|
16
13
|
var DurableGithubAgent = class {
|
|
17
14
|
agent;
|
|
18
|
-
_model;
|
|
19
|
-
_instructions;
|
|
20
|
-
_telemetry;
|
|
21
|
-
_tools;
|
|
22
15
|
constructor(options) {
|
|
23
16
|
this.agent = new WorkflowAgent(options);
|
|
24
|
-
this._model = options.model;
|
|
25
|
-
this._instructions = typeof options.instructions === "string" ? options.instructions : void 0;
|
|
26
|
-
this._telemetry = options.telemetry;
|
|
27
|
-
this._tools = options.tools ?? {};
|
|
28
17
|
}
|
|
29
18
|
/** The tool set configured for this agent. */
|
|
30
19
|
get tools() {
|
|
31
20
|
return this.agent.tools;
|
|
32
21
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Stream the agent's response. Delegates directly to `WorkflowAgent.stream()`.
|
|
35
|
-
* Works in workflow context — each tool call is a durable step.
|
|
36
|
-
*/
|
|
22
|
+
/** Stream the agent's response. Delegates to `WorkflowAgent.stream()`. */
|
|
37
23
|
stream(options) {
|
|
38
24
|
return this.agent.stream(options);
|
|
39
25
|
}
|
|
40
26
|
/**
|
|
41
|
-
* Generate
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* at the workflow scope level.
|
|
27
|
+
* Generate the full response without streaming. Delegates to `WorkflowAgent.generate()`, which
|
|
28
|
+
* needs `@ai-sdk/workflow` 2.0.59 or later. Stops after 20 steps unless `stopWhen` says otherwise.
|
|
29
|
+
* A write that needs approval ends the call with a `tool-approval-request` in
|
|
30
|
+
* `responseMessages`; append the user's `tool-approval-response` and call `generate()` again.
|
|
46
31
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const result = await generateText({
|
|
51
|
-
model: this._model,
|
|
52
|
-
tools: this._tools,
|
|
53
|
-
system,
|
|
54
|
-
prompt,
|
|
55
|
-
stopWhen,
|
|
56
|
-
experimental_telemetry: this._telemetry
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
text: result.text,
|
|
60
|
-
finishReason: result.finishReason,
|
|
61
|
-
usage: result.usage,
|
|
62
|
-
steps: result.steps,
|
|
63
|
-
response: result.response
|
|
64
|
-
};
|
|
32
|
+
generate(options) {
|
|
33
|
+
if (typeof this.agent.generate !== "function") throw githubToolsErrors.DURABLE_GENERATE_UNAVAILABLE();
|
|
34
|
+
return this.agent.generate(options);
|
|
65
35
|
}
|
|
66
36
|
};
|
|
67
|
-
function createDurableGithubAgent({ model, token, preset, requireApproval, context, instructions, additionalInstructions, author, committer, coAuthors, ...agentOptions }) {
|
|
37
|
+
function createDurableGithubAgent({ model, token, preset, requireApproval, overrides, context, instructions, additionalInstructions, author, committer, coAuthors, guardrails, dryRun, ...agentOptions }) {
|
|
68
38
|
const tools = createGithubTools({
|
|
69
39
|
token,
|
|
70
40
|
requireApproval,
|
|
71
41
|
preset,
|
|
42
|
+
overrides,
|
|
72
43
|
context,
|
|
73
44
|
author,
|
|
74
45
|
committer,
|
|
75
|
-
coAuthors
|
|
46
|
+
coAuthors,
|
|
47
|
+
guardrails,
|
|
48
|
+
dryRun
|
|
76
49
|
});
|
|
77
50
|
return new DurableGithubAgent({
|
|
78
51
|
...agentOptions,
|
package/dist/workflow.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.mjs","names":[],"sources":["../src/workflow.ts"],"sourcesContent":["import { WorkflowAgent } from '@ai-sdk/workflow'\nimport type {\n WorkflowAgentOptions,\n WorkflowAgentStreamOptions,\n WorkflowAgentStreamResult,\n TelemetryOptions,\n} from '@ai-sdk/workflow'\nimport type {\n LanguageModel,\n ToolSet,\n StepResult,\n FinishReason,\n LanguageModelUsage,\n LanguageModelResponseMetadata,\n ModelMessage,\n StopCondition,\n} from 'ai'\nimport { createGithubTools } from './index'\nimport { resolveInstructions } from './agents'\nimport type { AllGithubTools } from './core/tool-types'\nimport type { CombinedPresetToolNames, GithubToolPreset, PresetToolName } from './core/presets'\nimport type { GithubToolName } from './core/tool-names'\nimport type { StaticApprovalConfig } from './index'\nimport type { CommitIdentity } from './types'\nimport type { GithubTokenInput } from './core/token'\nimport type { GithubToolsContext } from './core/context'\nimport type { Context } from '@ai-sdk/provider-utils'\n\n/**\n * Result of {@link DurableGithubAgent.generate}.\n */\nexport interface DurableGithubAgentGenerateResult<TTools extends ToolSet = ToolSet> {\n text: string\n finishReason: FinishReason\n usage: LanguageModelUsage\n steps: StepResult<TTools>[]\n response: LanguageModelResponseMetadata & { messages: ModelMessage[] }\n}\n\n/**\n * A wrapper around {@link WorkflowAgent} that adds a non-streaming\n * `.generate()` method alongside the existing `.stream()`.\n *\n * - `.stream()` — delegates to `WorkflowAgent.stream()`. Each tool call is\n * an individually retriable workflow step. Supports `needsApproval` on tools.\n * - `.generate()` — uses `generateText` from the AI SDK for non-streaming\n * execution. Must be called from within a `\"use step\"` function in\n * workflow context (the Workflow runtime blocks raw I/O in workflow scope).\n */\nexport class DurableGithubAgent<TTools extends ToolSet = ToolSet> {\n private agent: WorkflowAgent<TTools>\n private _model: LanguageModel\n private _instructions?: string\n private _telemetry?: TelemetryOptions\n private _tools: TTools\n\n constructor(options: WorkflowAgentOptions<TTools>) {\n this.agent = new WorkflowAgent(options)\n this._model = options.model\n this._instructions = typeof options.instructions === 'string' ? options.instructions : undefined\n this._telemetry = options.telemetry\n this._tools = options.tools ?? {} as TTools\n }\n\n /** The tool set configured for this agent. */\n get tools(): TTools {\n return this.agent.tools\n }\n\n /**\n * Stream the agent's response. Delegates directly to `WorkflowAgent.stream()`.\n * Works in workflow context — each tool call is a durable step.\n */\n stream<TStreamTools extends TTools = TTools, OUTPUT = never, PARTIAL_OUTPUT = never>(\n options: WorkflowAgentStreamOptions<TStreamTools, Context, OUTPUT, PARTIAL_OUTPUT>,\n ): Promise<WorkflowAgentStreamResult<TStreamTools, OUTPUT>> {\n return this.agent.stream(options)\n }\n\n /**\n * Generate a non-streaming response using `generateText` from the AI SDK.\n *\n * In workflow context this **must** be called from within a `\"use step\"`\n * function, because the Workflow runtime blocks direct I/O (HTTP calls)\n * at the workflow scope level.\n */\n async generate({ prompt, stopWhen }: { prompt: string, stopWhen?: StopCondition<TTools> | Array<StopCondition<TTools>> }): Promise<DurableGithubAgentGenerateResult<TTools>> {\n const { generateText } = await import('ai')\n\n const system = this._instructions\n\n const result = await generateText({\n model: this._model,\n tools: this._tools,\n system,\n prompt,\n stopWhen,\n experimental_telemetry: this._telemetry as Parameters<typeof generateText>[0]['experimental_telemetry'],\n })\n\n return {\n text: result.text,\n finishReason: result.finishReason,\n usage: result.usage,\n steps: result.steps as StepResult<TTools>[],\n response: result.response,\n }\n }\n}\n\n/**\n * Options for creating a durable GitHub agent via {@link createDurableGithubAgent}.\n *\n * Extends all `WorkflowAgentOptions` (temperature, telemetry, callbacks, etc.)\n * and adds GitHub-specific fields (token, preset, approval config).\n */\nexport type CreateDurableGithubAgentOptions =\n Omit<WorkflowAgentOptions, 'model' | 'tools' | 'instructions'> & {\n model: string | LanguageModel\n /**\n * GitHub personal access token or async token provider.\n * Falls back to `process.env.GITHUB_TOKEN` when omitted.\n */\n token?: GithubTokenInput\n /**\n * Restrict tools and system prompt to a predefined preset.\n *\n * Selects a subset of tools and, when a single preset is passed,\n * sets a matching system prompt. Combine presets with an array to merge tool sets.\n *\n * @see {@link GithubToolPreset} for available presets and included tools.\n */\n preset?: GithubToolPreset | GithubToolPreset[]\n /**\n * Control whether write operations require user approval before execution.\n *\n * `'auto'` is not supported: the evaluation call cannot run inside a workflow function.\n *\n * @see {@link StaticApprovalConfig} for global and per-tool options.\n */\n requireApproval?: StaticApprovalConfig\n /**\n * Fully replace the default system prompt.\n * When set, `preset` system prompts and `additionalInstructions` are ignored.\n */\n instructions?: string\n /**\n * Append text to the preset-specific (or default) system prompt.\n * Ignored when `instructions` is set.\n */\n additionalInstructions?: string\n /**\n * Default owner / repo / PR / issue / ref values for tools and the system prompt.\n */\n context?: GithubToolsContext\n /**\n * Default author for commit-creating tools.\n * Falls back to the authenticated user when omitted.\n */\n author?: CommitIdentity\n /**\n * Default committer for commit-creating tools.\n * Falls back to the authenticated user when omitted.\n */\n committer?: CommitIdentity\n /**\n * Co-authors to attribute on all commits.\n * Added as \"Co-authored-by\" trailers to commit messages.\n */\n coAuthors?: CommitIdentity[]\n }\n\n/**\n * Create a pre-configured durable GitHub agent powered by `WorkflowAgent`\n * from `@ai-sdk/workflow`.\n *\n * Returns a {@link DurableGithubAgent} with two interaction modes:\n *\n * - `.stream()` — works directly in workflow scope; each tool call is a durable step.\n * Write tools honor `requireApproval` via `needsApproval` and pause the workflow\n * until the user approves or denies.\n * - `.generate()` — uses `generateText` from the AI SDK; must be called from\n * within a `\"use step\"` function when running inside a workflow.\n *\n * @example Streaming (chat UI — works in workflow scope)\n * ```ts\n * import { createDurableGithubAgent } from '@github-tools/sdk/workflow'\n * import { getWritable } from 'workflow'\n * import type { ModelMessage, ModelCallStreamPart } from 'ai'\n *\n * async function chatWorkflow(messages: ModelMessage[], token: string) {\n * \"use workflow\"\n * const agent = createDurableGithubAgent({\n * model: 'anthropic/claude-opus-5.5',\n * token,\n * preset: 'code-review',\n * })\n * const writable = getWritable<ModelCallStreamPart>()\n * await agent.stream({ messages, writable })\n * }\n * ```\n */\nexport function createDurableGithubAgent(\n options: CreateDurableGithubAgentOptions & { preset?: undefined },\n): DurableGithubAgent<AllGithubTools>\nexport function createDurableGithubAgent<P extends GithubToolPreset>(\n options: CreateDurableGithubAgentOptions & { preset: P },\n): DurableGithubAgent<Pick<AllGithubTools, PresetToolName<P>>>\nexport function createDurableGithubAgent<P extends readonly GithubToolPreset[]>(\n options: CreateDurableGithubAgentOptions & { preset: P },\n): DurableGithubAgent<Pick<AllGithubTools, CombinedPresetToolNames<P>>>\nexport function createDurableGithubAgent({\n model,\n token,\n preset,\n requireApproval,\n context,\n instructions,\n additionalInstructions,\n author,\n committer,\n coAuthors,\n ...agentOptions\n}: CreateDurableGithubAgentOptions): DurableGithubAgent<AllGithubTools | Pick<AllGithubTools, GithubToolName>> {\n const tools = createGithubTools({ token, requireApproval, preset, context, author, committer, coAuthors })\n\n return new DurableGithubAgent({\n ...agentOptions,\n model,\n tools,\n instructions: resolveInstructions({ preset, instructions, additionalInstructions, context }),\n }) as DurableGithubAgent<typeof tools>\n}\n\nexport { createGithubTools, createGithubAgent } from './index'\nexport type { CommitIdentity, CommitToolOptions, GithubTools, GithubToolsOptions, GithubToolPreset, GithubToolName, GithubWriteToolName, ApprovalConfig, ToolOverrides, AllGithubTools, PresetToolName, CombinedPresetToolNames, GithubToolsForPreset, PickGithubTools, GithubTokenInput, GithubToolsContext } from './index'\nexport { PRESET_TOOLS, GITHUB_TOOL_NAMES, GITHUB_WRITE_TOOLS, resolveGithubToken } from './index'\nexport type { CreateGithubAgentOptions } from './agents'\n"],"mappings":";;;;;;;;;;;;;;;AAiDA,IAAa,qBAAb,MAAkE;CAChE;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAuC;EACjD,KAAK,QAAQ,IAAI,cAAc,OAAO;EACtC,KAAK,SAAS,QAAQ;EACtB,KAAK,gBAAgB,OAAO,QAAQ,iBAAiB,WAAW,QAAQ,eAAe,KAAA;EACvF,KAAK,aAAa,QAAQ;EAC1B,KAAK,SAAS,QAAQ,SAAS,CAAC;CAClC;;CAGA,IAAI,QAAgB;EAClB,OAAO,KAAK,MAAM;CACpB;;;;;CAMA,OACE,SAC0D;EAC1D,OAAO,KAAK,MAAM,OAAO,OAAO;CAClC;;;;;;;;CASA,MAAM,SAAS,EAAE,QAAQ,YAAoJ;EAC3K,MAAM,EAAE,iBAAiB,MAAM,OAAO;EAEtC,MAAM,SAAS,KAAK;EAEpB,MAAM,SAAS,MAAM,aAAa;GAChC,OAAO,KAAK;GACZ,OAAO,KAAK;GACZ;GACA;GACA;GACA,wBAAwB,KAAK;EAC/B,CAAC;EAED,OAAO;GACL,MAAM,OAAO;GACb,cAAc,OAAO;GACrB,OAAO,OAAO;GACd,OAAO,OAAO;GACd,UAAU,OAAO;EACnB;CACF;AACF;AAuGA,SAAgB,yBAAyB,EACvC,OACA,OACA,QACA,iBACA,SACA,cACA,wBACA,QACA,WACA,WACA,GAAG,gBAC0G;CAC7G,MAAM,QAAQ,kBAAkB;EAAE;EAAO;EAAiB;EAAQ;EAAS;EAAQ;EAAW;CAAU,CAAC;CAEzG,OAAO,IAAI,mBAAmB;EAC5B,GAAG;EACH;EACA;EACA,cAAc,oBAAoB;GAAE;GAAQ;GAAc;GAAwB;EAAQ,CAAC;CAC7F,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"workflow.mjs","names":[],"sources":["../src/workflow.ts"],"sourcesContent":["import { WorkflowAgent } from '@ai-sdk/workflow'\nimport type {\n WorkflowAgentOptions,\n WorkflowAgentStreamOptions,\n WorkflowAgentStreamResult,\n} from '@ai-sdk/workflow'\nimport type { LanguageModel, Output, ToolSet } from 'ai'\nimport { createGithubTools } from './index'\nimport { resolveInstructions } from './agents'\nimport { githubToolsErrors } from './core/errors'\nimport type { AllGithubTools } from './core/tool-types'\nimport type { CombinedPresetToolNames, GithubToolPreset, PresetToolName } from './core/presets'\nimport type { GithubToolName } from './core/tool-names'\nimport type { GithubToolsBaseOptions } from './core/tool-types'\nimport type { StaticApprovalConfig } from './index'\nimport type { CommitIdentity } from './types'\nimport type { GithubTokenInput } from './core/token'\nimport type { GithubToolsContext } from './core/context'\nimport type { Context } from '@ai-sdk/provider-utils'\n\n// Read from `WorkflowAgent` instead of importing `WorkflowAgentGenerateOptions` and\n// `WorkflowAgentGenerateResult`, which `@ai-sdk/workflow` only exports from 2.0.59: importing them\n// would break type checking for `.stream()` users on older supported versions.\ntype WorkflowGenerate<TTools extends ToolSet> = WorkflowAgent<TTools> extends { generate: infer Generate } ? Generate : never\n\n/** Options of {@link DurableGithubAgent.generate}: those of `WorkflowAgent.generate()`. */\nexport type DurableGithubAgentGenerateOptions<TTools extends ToolSet = ToolSet> = WorkflowGenerate<TTools> extends (options: infer Options) => unknown ? Options : never\n\n/**\n * Result of {@link DurableGithubAgent.generate}: the `WorkflowAgent` generation result. Read the\n * fields you need inside the workflow and return those, since the result itself is not serializable.\n */\nexport type DurableGithubAgentGenerateResult<TTools extends ToolSet = ToolSet> = WorkflowGenerate<TTools> extends (options: never) => Promise<infer Result> ? Result : never\n\n/**\n * A GitHub agent built on {@link WorkflowAgent}. Call both methods from a `\"use workflow\"`\n * function: each model call and each tool call runs as its own retriable workflow step, and\n * tools with `needsApproval` pause the run until the user answers.\n *\n * - `.stream()` writes the response to a `writable` for chat UIs.\n * - `.generate()` returns the finished result, for bots, webhooks, and background jobs.\n */\nexport class DurableGithubAgent<TTools extends ToolSet = ToolSet> {\n private agent: WorkflowAgent<TTools>\n\n constructor(options: WorkflowAgentOptions<TTools>) {\n this.agent = new WorkflowAgent(options)\n }\n\n /** The tool set configured for this agent. */\n get tools(): TTools {\n return this.agent.tools\n }\n\n /** Stream the agent's response. Delegates to `WorkflowAgent.stream()`. */\n stream<TStreamTools extends TTools = TTools, OUTPUT = never, PARTIAL_OUTPUT = never>(\n options: WorkflowAgentStreamOptions<TStreamTools, Context, OUTPUT, PARTIAL_OUTPUT>,\n ): Promise<WorkflowAgentStreamResult<TStreamTools, OUTPUT>> {\n return this.agent.stream(options)\n }\n\n /**\n * Generate the full response without streaming. Delegates to `WorkflowAgent.generate()`, which\n * needs `@ai-sdk/workflow` 2.0.59 or later. Stops after 20 steps unless `stopWhen` says otherwise.\n * A write that needs approval ends the call with a `tool-approval-request` in\n * `responseMessages`; append the user's `tool-approval-response` and call `generate()` again.\n */\n generate<OUTPUT = string>(\n options: DurableGithubAgentGenerateOptions<TTools> & { output?: Output.Output<OUTPUT> },\n ): Promise<Omit<DurableGithubAgentGenerateResult<TTools>, 'output'> & { readonly output: OUTPUT }> {\n if (typeof this.agent.generate !== 'function') throw githubToolsErrors.DURABLE_GENERATE_UNAVAILABLE()\n return this.agent.generate(options)\n }\n}\n\n/**\n * Options for creating a durable GitHub agent via {@link createDurableGithubAgent}.\n *\n * Extends all `WorkflowAgentOptions` (temperature, telemetry, callbacks, etc.)\n * and adds GitHub-specific fields (token, preset, approval config).\n */\nexport type CreateDurableGithubAgentOptions =\n Omit<WorkflowAgentOptions, 'model' | 'tools' | 'instructions'> & {\n model: string | LanguageModel\n /**\n * GitHub personal access token or async token provider.\n * Falls back to `process.env.GITHUB_TOKEN` when omitted.\n */\n token?: GithubTokenInput\n /**\n * Restrict tools and system prompt to a predefined preset.\n *\n * Selects a subset of tools and sets the preset's system prompt. Combine presets with an array\n * to merge their tool sets and system prompts.\n *\n * @see {@link GithubToolPreset} for available presets and included tools.\n */\n preset?: GithubToolPreset | GithubToolPreset[]\n /**\n * Control whether write operations require user approval before execution.\n *\n * `'auto'` is not supported: the evaluation call cannot run inside a workflow function.\n *\n * @see {@link StaticApprovalConfig} for global and per-tool options.\n */\n requireApproval?: StaticApprovalConfig\n /**\n * Per-tool overrides (`description`, `title`, `needsApproval`, …), as on `createGithubTools`.\n * `execute`, `inputSchema`, and `outputSchema` cannot be overridden.\n */\n overrides?: GithubToolsBaseOptions['overrides']\n /**\n * Repositories and branches the tools may act on, checked before each call reaches GitHub,\n * as on `createGithubTools`.\n */\n guardrails?: GithubToolsBaseOptions['guardrails']\n /** Send no write to GitHub, as on `createGithubTools`. */\n dryRun?: boolean\n /**\n * Fully replace the default system prompt.\n * When set, `preset` system prompts and `additionalInstructions` are ignored.\n */\n instructions?: string\n /**\n * Append text to the preset-specific (or default) system prompt.\n * Ignored when `instructions` is set.\n */\n additionalInstructions?: string\n /**\n * Default owner / repo / PR / issue / ref values for tools and the system prompt.\n */\n context?: GithubToolsContext\n /**\n * Default author for commit-creating tools.\n * Falls back to the authenticated user when omitted.\n */\n author?: CommitIdentity\n /**\n * Default committer for commit-creating tools.\n * Falls back to the authenticated user when omitted.\n */\n committer?: CommitIdentity\n /**\n * Co-authors to attribute on all commits.\n * Added as \"Co-authored-by\" trailers to commit messages.\n */\n coAuthors?: CommitIdentity[]\n }\n\n/**\n * Create a pre-configured durable GitHub agent powered by `WorkflowAgent`\n * from `@ai-sdk/workflow`.\n *\n * Returns a {@link DurableGithubAgent} with two interaction modes:\n *\n * - `.stream()` — works directly in workflow scope; each tool call is a durable step.\n * Write tools honor `requireApproval` via `needsApproval` and pause the workflow\n * until the user approves or denies.\n * - `.generate()` — uses `generateText` from the AI SDK; must be called from\n * within a `\"use step\"` function when running inside a workflow.\n *\n * @example Streaming (chat UI — works in workflow scope)\n * ```ts\n * import { createDurableGithubAgent } from '@github-tools/sdk/workflow'\n * import { getWritable } from 'workflow'\n * import type { ModelMessage, ModelCallStreamPart } from 'ai'\n *\n * async function chatWorkflow(messages: ModelMessage[], token: string) {\n * \"use workflow\"\n * const agent = createDurableGithubAgent({\n * model: 'anthropic/claude-opus-5.5',\n * token,\n * preset: 'code-review',\n * })\n * const writable = getWritable<ModelCallStreamPart>()\n * await agent.stream({ messages, writable })\n * }\n * ```\n */\nexport function createDurableGithubAgent(\n options: CreateDurableGithubAgentOptions & { preset?: undefined },\n): DurableGithubAgent<AllGithubTools>\nexport function createDurableGithubAgent<P extends GithubToolPreset>(\n options: CreateDurableGithubAgentOptions & { preset: P },\n): DurableGithubAgent<Pick<AllGithubTools, PresetToolName<P>>>\nexport function createDurableGithubAgent<P extends readonly GithubToolPreset[]>(\n options: CreateDurableGithubAgentOptions & { preset: P },\n): DurableGithubAgent<Pick<AllGithubTools, CombinedPresetToolNames<P>>>\nexport function createDurableGithubAgent({\n model,\n token,\n preset,\n requireApproval,\n overrides,\n context,\n instructions,\n additionalInstructions,\n author,\n committer,\n coAuthors,\n guardrails,\n dryRun,\n ...agentOptions\n}: CreateDurableGithubAgentOptions): DurableGithubAgent<AllGithubTools | Pick<AllGithubTools, GithubToolName>> {\n const tools = createGithubTools({ token, requireApproval, preset, overrides, context, author, committer, coAuthors, guardrails, dryRun })\n\n return new DurableGithubAgent({\n ...agentOptions,\n model,\n tools,\n instructions: resolveInstructions({ preset, instructions, additionalInstructions, context }),\n }) as DurableGithubAgent<typeof tools>\n}\n\nexport { createGithubTools, createGithubAgent } from './index'\nexport type { CommitIdentity, CommitToolOptions, GithubTools, GithubToolsOptions, GithubToolPreset, GithubToolName, GithubWriteToolName, ApprovalConfig, ToolOverrides, AllGithubTools, PresetToolName, CombinedPresetToolNames, GithubToolsForPreset, PickGithubTools, GithubTokenInput, GithubToolsContext } from './index'\nexport { PRESET_TOOLS, GITHUB_TOOL_NAMES, GITHUB_WRITE_TOOLS, resolveGithubToken } from './index'\nexport type { CreateGithubAgentOptions } from './agents'\n"],"mappings":";;;;;;;;;;;;AA0CA,IAAa,qBAAb,MAAkE;CAChE;CAEA,YAAY,SAAuC;EACjD,KAAK,QAAQ,IAAI,cAAc,OAAO;CACxC;;CAGA,IAAI,QAAgB;EAClB,OAAO,KAAK,MAAM;CACpB;;CAGA,OACE,SAC0D;EAC1D,OAAO,KAAK,MAAM,OAAO,OAAO;CAClC;;;;;;;CAQA,SACE,SACiG;EACjG,IAAI,OAAO,KAAK,MAAM,aAAa,YAAY,MAAM,kBAAkB,6BAA6B;EACpG,OAAO,KAAK,MAAM,SAAS,OAAO;CACpC;AACF;AAmHA,SAAgB,yBAAyB,EACvC,OACA,OACA,QACA,iBACA,WACA,SACA,cACA,wBACA,QACA,WACA,WACA,YACA,QACA,GAAG,gBAC0G;CAC7G,MAAM,QAAQ,kBAAkB;EAAE;EAAO;EAAiB;EAAQ;EAAW;EAAS;EAAQ;EAAW;EAAW;EAAY;CAAO,CAAC;CAExI,OAAO,IAAI,mBAAmB;EAC5B,GAAG;EACH;EACA;EACA,cAAc,oBAAoB;GAAE;GAAQ;GAAc;GAAwB;EAAQ,CAAC;CAC7F,CAAC;AACH"}
|