@opengeni/worker-bundle 0.20.3 → 0.22.1-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/dist/activities/agent-turn/admission.d.ts +52 -0
  2. package/dist/activities/agent-turn/agent-build.d.ts +89 -0
  3. package/dist/activities/agent-turn/claim.d.ts +67 -0
  4. package/dist/activities/agent-turn/codex-capacity.d.ts +40 -0
  5. package/dist/activities/agent-turn/codex.d.ts +32 -0
  6. package/dist/activities/agent-turn/compaction-prep.d.ts +88 -0
  7. package/dist/activities/agent-turn/credential-leases.d.ts +56 -0
  8. package/dist/activities/agent-turn/errors.d.ts +253 -0
  9. package/dist/activities/agent-turn/failure-settlement.d.ts +33 -0
  10. package/dist/activities/agent-turn/file-resources.d.ts +37 -0
  11. package/dist/activities/agent-turn/finalization.d.ts +42 -0
  12. package/dist/activities/agent-turn/github-repository-bindings.d.ts +105 -0
  13. package/dist/activities/agent-turn/governance-model.d.ts +66 -0
  14. package/dist/activities/agent-turn/history-sink.d.ts +52 -0
  15. package/dist/activities/agent-turn/history.d.ts +63 -0
  16. package/dist/activities/agent-turn/media-artifacts.d.ts +145 -0
  17. package/dist/activities/agent-turn/model-usage.d.ts +218 -0
  18. package/dist/activities/agent-turn/quiescence.d.ts +135 -0
  19. package/dist/activities/agent-turn/run-credentials.d.ts +84 -0
  20. package/dist/activities/agent-turn/run.d.ts +3 -0
  21. package/dist/activities/agent-turn/sandbox-establish.d.ts +93 -0
  22. package/dist/activities/agent-turn/sandbox-provision.d.ts +89 -0
  23. package/dist/activities/agent-turn/sandbox-route.d.ts +151 -0
  24. package/dist/activities/agent-turn/sandbox-runtime.d.ts +44 -0
  25. package/dist/activities/agent-turn/stream-attempt.d.ts +107 -0
  26. package/dist/activities/agent-turn/tool-environment.d.ts +142 -0
  27. package/dist/activities/agent-turn/tool-policy.d.ts +127 -0
  28. package/dist/activities/agent-turn/tool-result-spill.d.ts +59 -0
  29. package/dist/activities/agent-turn/turn-context.d.ts +144 -0
  30. package/dist/activities/agent-turn/xai-capacity.d.ts +2 -0
  31. package/dist/activities/agent-turn.d.ts +12 -954
  32. package/dist/activities/automations.d.ts +16 -0
  33. package/dist/activities/common.d.ts +1 -1
  34. package/dist/activities/connector-attachments.d.ts +13 -0
  35. package/dist/activities/documents.d.ts +1 -0
  36. package/dist/activities/environment.d.ts +26 -15
  37. package/dist/activities/generated-images.d.ts +1 -1
  38. package/dist/activities/git-credential-renewal.d.ts +3 -1
  39. package/dist/activities/goals.d.ts +4 -1
  40. package/dist/activities/google-drive-provider.d.ts +29 -0
  41. package/dist/activities/google-drive-publication.d.ts +17 -4
  42. package/dist/activities/incident-telemetry-authority.d.ts +52 -0
  43. package/dist/activities/incident-telemetry-preflight.d.ts +71 -0
  44. package/dist/activities/knowledge-source-sync.d.ts +4 -0
  45. package/dist/activities/mcp-credentials.d.ts +9 -3
  46. package/dist/activities/open-suffix-resume.d.ts +77 -0
  47. package/dist/activities/packs.d.ts +3 -11
  48. package/dist/activities/parent-wake.d.ts +19 -0
  49. package/dist/activities/retained-screenshot-reaper.d.ts +1 -1
  50. package/dist/activities/retained-screenshots.d.ts +1 -1
  51. package/dist/activities/rig-verification.d.ts +1 -1
  52. package/dist/activities/run-input.d.ts +9 -10
  53. package/dist/activities/sandbox-images.d.ts +1 -14
  54. package/dist/activities/sandbox-lease.d.ts +21 -3
  55. package/dist/activities/scheduled-tasks.d.ts +47 -0
  56. package/dist/activities/types.d.ts +23 -2
  57. package/dist/activities/video-media-validation.d.ts +1 -1
  58. package/dist/activities/video-output-retention.d.ts +1 -2
  59. package/dist/activities/xai-auth.d.ts +3 -0
  60. package/dist/{activities-control-BJSDRSIP.js → activities-control-DKG22ONJ.js} +2646 -551
  61. package/dist/activities-control-DKG22ONJ.js.map +1 -0
  62. package/dist/activities-control.d.ts +6 -2
  63. package/dist/activities-turn-4IMC3MAA.js +21326 -0
  64. package/dist/activities-turn-4IMC3MAA.js.map +1 -0
  65. package/dist/activities.d.ts +7 -3
  66. package/dist/artifact-materializer-entry.js +41 -22
  67. package/dist/artifact-materializer-entry.js.map +1 -1
  68. package/dist/{chunk-N5TJIFCE.js → chunk-CE7TPKBS.js} +468 -1
  69. package/dist/chunk-CE7TPKBS.js.map +1 -0
  70. package/dist/chunk-CNYGVRKF.js +4698 -0
  71. package/dist/chunk-CNYGVRKF.js.map +1 -0
  72. package/dist/connection-provider-use.d.ts +18 -0
  73. package/dist/editable-artifact-materializer.d.ts +4 -3
  74. package/dist/github-rest-mcp.d.ts +26 -0
  75. package/dist/index.d.ts +10 -2
  76. package/dist/index.js +58 -14
  77. package/dist/index.js.map +1 -1
  78. package/dist/knowledge-source-sync-activity-policy.d.ts +2 -0
  79. package/dist/model-context-contributions.d.ts +8 -4
  80. package/dist/observability-metrics.d.ts +63 -4
  81. package/dist/opensandbox-kubernetes-inventory.d.ts +21 -0
  82. package/dist/personal-github-git-credentials.d.ts +9 -0
  83. package/dist/pr-review-credentials.d.ts +6 -0
  84. package/dist/sandbox-archive-storage.d.ts +45 -0
  85. package/dist/sandbox-resume.d.ts +65 -6
  86. package/dist/sandbox-routing.d.ts +38 -2
  87. package/dist/scheduled-alert-occurrence.d.ts +33 -0
  88. package/dist/workflow-bundle.js +87 -28
  89. package/dist/workflows/activities.d.ts +1 -0
  90. package/dist/workflows/automations.d.ts +6 -0
  91. package/dist/workflows/document-index.d.ts +1 -0
  92. package/dist/workflows.d.ts +1 -0
  93. package/package.json +17 -17
  94. package/src/activities/agent-turn/admission.ts +292 -0
  95. package/src/activities/agent-turn/agent-build.ts +802 -0
  96. package/src/activities/agent-turn/claim.ts +590 -0
  97. package/src/activities/agent-turn/codex-capacity.ts +720 -0
  98. package/src/activities/agent-turn/codex.ts +94 -0
  99. package/src/activities/agent-turn/compaction-prep.ts +722 -0
  100. package/src/activities/agent-turn/credential-leases.ts +240 -0
  101. package/src/activities/agent-turn/errors.ts +1068 -0
  102. package/src/activities/agent-turn/failure-settlement.ts +1436 -0
  103. package/src/activities/agent-turn/file-resources.ts +227 -0
  104. package/src/activities/agent-turn/finalization.ts +754 -0
  105. package/src/activities/agent-turn/github-repository-bindings.ts +300 -0
  106. package/src/activities/agent-turn/governance-model.ts +465 -0
  107. package/src/activities/agent-turn/history-sink.ts +139 -0
  108. package/src/activities/agent-turn/history.ts +200 -0
  109. package/src/activities/agent-turn/media-artifacts.ts +359 -0
  110. package/src/activities/agent-turn/model-usage.ts +823 -0
  111. package/src/activities/agent-turn/quiescence.ts +353 -0
  112. package/src/activities/agent-turn/run-credentials.ts +761 -0
  113. package/src/activities/agent-turn/run.ts +1530 -0
  114. package/src/activities/agent-turn/sandbox-establish.ts +1207 -0
  115. package/src/activities/agent-turn/sandbox-provision.ts +569 -0
  116. package/src/activities/agent-turn/sandbox-route.ts +358 -0
  117. package/src/activities/agent-turn/sandbox-runtime.ts +731 -0
  118. package/src/activities/agent-turn/stream-attempt.ts +1670 -0
  119. package/src/activities/agent-turn/tool-environment.ts +729 -0
  120. package/src/activities/agent-turn/tool-policy.ts +216 -0
  121. package/src/activities/agent-turn/tool-result-spill.ts +265 -0
  122. package/src/activities/agent-turn/turn-context.ts +281 -0
  123. package/src/activities/agent-turn/xai-capacity.ts +229 -0
  124. package/src/activities/agent-turn.ts +12 -12701
  125. package/src/activities/api-integrations.ts +3 -0
  126. package/src/activities/automations.ts +214 -0
  127. package/src/activities/codemode-dispatcher.ts +12 -1
  128. package/src/activities/common.ts +1 -5
  129. package/src/activities/connector-attachments.ts +168 -0
  130. package/src/activities/context-compaction.ts +18 -0
  131. package/src/activities/environment.ts +151 -55
  132. package/src/activities/generated-images.ts +26 -11
  133. package/src/activities/git-credential-renewal.ts +13 -3
  134. package/src/activities/goals.ts +85 -19
  135. package/src/activities/google-drive-provider.ts +178 -0
  136. package/src/activities/google-drive-publication.ts +147 -49
  137. package/src/activities/incident-telemetry-authority.ts +327 -0
  138. package/src/activities/incident-telemetry-preflight.ts +317 -0
  139. package/src/activities/knowledge-source-sync.ts +178 -37
  140. package/src/activities/mcp-credentials.ts +191 -17
  141. package/src/activities/open-suffix-resume.ts +422 -0
  142. package/src/activities/packs.ts +12 -60
  143. package/src/activities/parent-wake.ts +64 -14
  144. package/src/activities/retained-screenshot-reaper.ts +6 -3
  145. package/src/activities/retained-screenshots.ts +15 -47
  146. package/src/activities/rig-verification.ts +1 -1
  147. package/src/activities/run-input.ts +102 -142
  148. package/src/activities/sandbox-images.ts +7 -166
  149. package/src/activities/sandbox-lease.ts +406 -15
  150. package/src/activities/scheduled-tasks.ts +2103 -411
  151. package/src/activities/session-state.ts +10 -2
  152. package/src/activities/types.ts +32 -2
  153. package/src/activities/video-media-validation.ts +3 -3
  154. package/src/activities/video-output-retention.ts +2 -57
  155. package/src/activities/xai-auth.ts +8 -0
  156. package/src/activities-control.ts +2 -0
  157. package/src/activities.ts +3 -0
  158. package/src/activity-services.ts +13 -4
  159. package/src/connection-provider-use.ts +36 -0
  160. package/src/editable-artifact-materializer-subprocess.ts +25 -14
  161. package/src/editable-artifact-materializer.ts +29 -18
  162. package/src/github-rest-mcp.ts +713 -0
  163. package/src/http.ts +16 -6
  164. package/src/index.ts +40 -5
  165. package/src/knowledge-source-sync-activity-policy.ts +2 -0
  166. package/src/model-context-contributions.ts +33 -10
  167. package/src/observability-metrics.ts +357 -0
  168. package/src/opensandbox-kubernetes-inventory.ts +292 -0
  169. package/src/personal-github-git-credentials.ts +331 -0
  170. package/src/pr-review-credentials.ts +163 -0
  171. package/src/sandbox-archive-storage.ts +159 -0
  172. package/src/sandbox-resume.ts +449 -63
  173. package/src/sandbox-routing.ts +314 -16
  174. package/src/scheduled-alert-occurrence.ts +176 -0
  175. package/src/workflows/activities.ts +18 -2
  176. package/src/workflows/automations.ts +11 -0
  177. package/src/workflows/session.ts +13 -3
  178. package/src/workflows.ts +1 -0
  179. package/dist/activities-control-BJSDRSIP.js.map +0 -1
  180. package/dist/activities-turn-J5YO7XXX.js +0 -17243
  181. package/dist/activities-turn-J5YO7XXX.js.map +0 -1
  182. package/dist/chunk-N5TJIFCE.js.map +0 -1
  183. package/dist/chunk-P6Z2SLAA.js +0 -3092
  184. package/dist/chunk-P6Z2SLAA.js.map +0 -1
@@ -0,0 +1,300 @@
1
+ import type { Settings } from "@opengeni/config";
2
+ import type { CredentialAuthNeededPayload, ResourceRef } from "@opengeni/contracts";
3
+ import {
4
+ applyGitHubRepositoryBindings,
5
+ listGitHubRepositoryBindingCandidates,
6
+ resolveGitHubRepositoryBindings,
7
+ unboundGitHubRepositoryResources,
8
+ type GitHubRepositoryBinding,
9
+ type GitHubRepositoryBindingCandidate,
10
+ type GitHubRepositoryBindingLookup,
11
+ type GitHubRepositoryBindingResolution,
12
+ } from "@opengeni/core";
13
+ import type { Database } from "@opengeni/db";
14
+ import {
15
+ createGitHubAppInstallationRepositoryLookup,
16
+ githubAppMissingSettings,
17
+ } from "@opengeni/github";
18
+
19
+ /**
20
+ * Turn-time GitHub App binding resolution for bare repository URIs.
21
+ *
22
+ * The web composer and the MCP repository catalog stamp
23
+ * `githubInstallationId`/`githubRepositoryId` on every bound repository, but an
24
+ * API caller, an older session, or an agent-spawned child may still carry a
25
+ * bare `https://github.com/<owner>/<repo>` resource. The workspace allowlist
26
+ * stores repository ids only, so the worker (which already talks to GitHub to
27
+ * mint the sandbox token) resolves the URI here: the owner selects the
28
+ * workspace's auditable installation(s) from Postgres, one server-side
29
+ * metadata-read supplies GitHub's repository id, and the allowlist decides.
30
+ * Exactly one allowlisted match stamps the ids for this turn's in-memory
31
+ * resources; every other case keeps the resource bare (anonymous clone, as
32
+ * before) and reports a visible warning. Nothing here is durable and nothing
33
+ * can fail the turn.
34
+ */
35
+
36
+ /** Process-local lookup memo: recovered turns and sibling children reuse it. */
37
+ export const GITHUB_REPOSITORY_LOOKUP_CACHE_TTL_MS = 10 * 60_000;
38
+ const GITHUB_REPOSITORY_LOOKUP_CACHE_MAX_ENTRIES = 4_096;
39
+
40
+ type LookupCacheEntry = { value: { id: number } | null; expiresAt: number };
41
+
42
+ export type GitHubRepositoryLookupCache = {
43
+ get: (key: string, now: number) => LookupCacheEntry | undefined;
44
+ set: (key: string, entry: LookupCacheEntry) => void;
45
+ clear: () => void;
46
+ };
47
+
48
+ export function createGitHubRepositoryLookupCache(
49
+ maxEntries = GITHUB_REPOSITORY_LOOKUP_CACHE_MAX_ENTRIES,
50
+ ): GitHubRepositoryLookupCache {
51
+ const entries = new Map<string, LookupCacheEntry>();
52
+ return {
53
+ get(key, now) {
54
+ const entry = entries.get(key);
55
+ if (!entry) return undefined;
56
+ if (entry.expiresAt <= now) {
57
+ entries.delete(key);
58
+ return undefined;
59
+ }
60
+ return entry;
61
+ },
62
+ set(key, entry) {
63
+ entries.delete(key);
64
+ entries.set(key, entry);
65
+ while (entries.size > maxEntries) {
66
+ const oldest = entries.keys().next().value;
67
+ if (oldest === undefined) break;
68
+ entries.delete(oldest);
69
+ }
70
+ },
71
+ clear() {
72
+ entries.clear();
73
+ },
74
+ };
75
+ }
76
+
77
+ const defaultLookupCache = createGitHubRepositoryLookupCache();
78
+ const defaultWarningCache = createGitHubRepositoryLookupCache();
79
+
80
+ function lookupCacheKey(
81
+ workspaceId: string,
82
+ input: { installationId: number; owner: string; name: string },
83
+ ): string {
84
+ return `${workspaceId}\u0000${input.installationId}\u0000${input.owner.toLowerCase()}/${input.name.toLowerCase()}`;
85
+ }
86
+
87
+ /**
88
+ * Wrap a live lookup with the process-local TTL memo. Successful ids and
89
+ * negative (not visible through this installation) answers are both cached;
90
+ * failures are not, so a GitHub blip is retried on the next turn.
91
+ */
92
+ export function cachedGitHubRepositoryBindingLookup(input: {
93
+ workspaceId: string;
94
+ lookup: GitHubRepositoryBindingLookup;
95
+ cache?: GitHubRepositoryLookupCache;
96
+ now?: () => number;
97
+ ttlMs?: number;
98
+ }): GitHubRepositoryBindingLookup {
99
+ const cache = input.cache ?? defaultLookupCache;
100
+ const now = input.now ?? Date.now;
101
+ const ttlMs = input.ttlMs ?? GITHUB_REPOSITORY_LOOKUP_CACHE_TTL_MS;
102
+ return async (request) => {
103
+ const key = lookupCacheKey(input.workspaceId, request);
104
+ const cached = cache.get(key, now());
105
+ if (cached) return cached.value;
106
+ const value = await input.lookup(request);
107
+ cache.set(key, { value: value ? { id: value.id } : null, expiresAt: now() + ttlMs });
108
+ return value;
109
+ };
110
+ }
111
+
112
+ export type TurnGitHubRepositoryBindings = {
113
+ resources: ResourceRef[];
114
+ bindings: Map<string, GitHubRepositoryBinding>;
115
+ resolutions: GitHubRepositoryBindingResolution[];
116
+ warnings: CredentialAuthNeededPayload[];
117
+ /** Apply the same bindings to a sibling resource list (runtime resources). */
118
+ apply: (resources: readonly ResourceRef[]) => ResourceRef[];
119
+ };
120
+
121
+ export async function resolveTurnGitHubRepositoryBindings(input: {
122
+ db: Database;
123
+ settings: Settings;
124
+ workspaceId: string;
125
+ resources: readonly ResourceRef[];
126
+ /** Test seam; defaults to the workspace's auditable bindings under RLS. */
127
+ listCandidates?: (
128
+ db: Database,
129
+ workspaceId: string,
130
+ ) => Promise<GitHubRepositoryBindingCandidate[]>;
131
+ /** Test seam; defaults to one live GitHub App lookup client per call. */
132
+ lookup?: GitHubRepositoryBindingLookup;
133
+ /** Test seam; defaults to the process-local TTL memo. */
134
+ lookupCache?: GitHubRepositoryLookupCache;
135
+ }): Promise<TurnGitHubRepositoryBindings> {
136
+ const passthrough = (): TurnGitHubRepositoryBindings => ({
137
+ resources: [...input.resources],
138
+ bindings: new Map(),
139
+ resolutions: [],
140
+ warnings: [],
141
+ apply: (resources) => [...resources],
142
+ });
143
+ if (unboundGitHubRepositoryResources(input.resources).length === 0) {
144
+ return passthrough();
145
+ }
146
+ let lookup = input.lookup;
147
+ if (!lookup) {
148
+ // Without App signing credentials no installation token could be minted
149
+ // for a resolved id anyway, so a bare repository stays anonymous.
150
+ if (githubAppMissingSettings(input.settings).length > 0) {
151
+ return passthrough();
152
+ }
153
+ const live = createGitHubAppInstallationRepositoryLookup(input.settings);
154
+ lookup = async (request) => {
155
+ const repository = await live(request);
156
+ return repository ? { id: repository.id } : null;
157
+ };
158
+ }
159
+ const candidates = await (input.listCandidates ?? listGitHubRepositoryBindingCandidates)(
160
+ input.db,
161
+ input.workspaceId,
162
+ );
163
+ if (candidates.length === 0) {
164
+ return passthrough();
165
+ }
166
+ const resolved = await resolveGitHubRepositoryBindings({
167
+ resources: input.resources,
168
+ candidates,
169
+ lookup: cachedGitHubRepositoryBindingLookup({
170
+ workspaceId: input.workspaceId,
171
+ lookup,
172
+ ...(input.lookupCache ? { cache: input.lookupCache } : {}),
173
+ }),
174
+ });
175
+ return {
176
+ resources: resolved.resources,
177
+ bindings: resolved.bindings,
178
+ resolutions: resolved.resolutions,
179
+ warnings: resolved.resolutions.flatMap(
180
+ (resolution) => gitHubRepositoryBindingWarning(resolution) ?? [],
181
+ ),
182
+ apply: (resources) => applyGitHubRepositoryBindings(resources, resolved.bindings),
183
+ };
184
+ }
185
+
186
+ /**
187
+ * The visible warning for a bound-but-unusable repository. An unbound owner
188
+ * is the ordinary anonymous public clone and produces no warning; a resolved
189
+ * repository needs none.
190
+ */
191
+ export function gitHubRepositoryBindingWarning(
192
+ resolution: GitHubRepositoryBindingResolution,
193
+ ): CredentialAuthNeededPayload | null {
194
+ const repository = `${resolution.owner}/${resolution.name}`;
195
+ switch (resolution.outcome.status) {
196
+ case "resolved":
197
+ case "unbound":
198
+ return null;
199
+ case "not_allowlisted":
200
+ return {
201
+ credentialClass: "run",
202
+ providerDomain: "github.com",
203
+ reason: "insufficient_scope",
204
+ resource: resolution.uri,
205
+ message: `GitHub repository ${repository} is not in the repository allowlist of the workspace's GitHub App installation for ${resolution.owner}. The sandbox clones it anonymously and cannot push or use gh until the repository is added to that installation.`,
206
+ };
207
+ case "ambiguous":
208
+ return {
209
+ credentialClass: "run",
210
+ providerDomain: "github.com",
211
+ reason: "insufficient_scope",
212
+ resource: resolution.uri,
213
+ message: `GitHub repository ${repository} is allowlisted by more than one GitHub App installation in this workspace (${resolution.outcome.installationIds.join(", ")}). Select it with an explicit installation, or unlink the duplicate binding, to receive a scoped token.`,
214
+ };
215
+ case "unavailable":
216
+ return {
217
+ credentialClass: "run",
218
+ providerDomain: "github.com",
219
+ reason: "refresh_failed",
220
+ resource: resolution.uri,
221
+ message: `GitHub repository ${repository} could not be resolved against the workspace's GitHub App installation (${resolution.outcome.message}). The sandbox clones it anonymously for this turn.`,
222
+ };
223
+ }
224
+ }
225
+
226
+ export type ApplyTurnGitHubRepositoryBindingsInput = {
227
+ db: Database;
228
+ settings: Settings;
229
+ workspaceId: string;
230
+ sessionId: string;
231
+ activeSandboxBackend: Settings["sandboxBackend"] | undefined;
232
+ claimedTurnResources: readonly ResourceRef[];
233
+ claimedRuntimeResources: readonly ResourceRef[];
234
+ /** Publishes one attempt-fenced session event batch. */
235
+ publish: (
236
+ events: Array<{ type: "credential.auth_needed"; payload: CredentialAuthNeededPayload }>,
237
+ ) => Promise<void>;
238
+ /** Operational log for a resolution that threw; the turn proceeds bare. */
239
+ warn: (message: string, fields: Record<string, string>) => void;
240
+ /** Test seam for the resolver itself. */
241
+ resolve?: typeof resolveTurnGitHubRepositoryBindings;
242
+ /** Test seam for the per-session warning dedupe memo. */
243
+ warningCache?: GitHubRepositoryLookupCache;
244
+ now?: () => number;
245
+ };
246
+
247
+ /**
248
+ * The run.ts wiring in one testable seam: skip for a Connected Machine,
249
+ * proceed bare when resolution throws, stamp both the turn and runtime
250
+ * resource lists from one resolution, and publish a bound-but-unusable
251
+ * warning once per session and URI within the memo window (the resolution
252
+ * itself already runs once per attempt).
253
+ */
254
+ export async function applyTurnGitHubRepositoryBindings(
255
+ input: ApplyTurnGitHubRepositoryBindingsInput,
256
+ ): Promise<{ turnResources: ResourceRef[]; runtimeResources: ResourceRef[] }> {
257
+ const passthrough = {
258
+ turnResources: [...input.claimedTurnResources],
259
+ runtimeResources: [...input.claimedRuntimeResources],
260
+ };
261
+ if (input.activeSandboxBackend === "selfhosted") {
262
+ return passthrough;
263
+ }
264
+ let resolved: TurnGitHubRepositoryBindings;
265
+ try {
266
+ resolved = await (input.resolve ?? resolveTurnGitHubRepositoryBindings)({
267
+ db: input.db,
268
+ settings: input.settings,
269
+ workspaceId: input.workspaceId,
270
+ resources: input.claimedTurnResources,
271
+ });
272
+ } catch (error) {
273
+ input.warn("GitHub repository binding resolution skipped", {
274
+ errorClass: error instanceof Error ? error.name : "Error",
275
+ errorCode: "github_repository_binding_resolution_failed",
276
+ origin: "worker",
277
+ });
278
+ return passthrough;
279
+ }
280
+ const now = input.now ?? Date.now;
281
+ const warningCache = input.warningCache ?? defaultWarningCache;
282
+ const warnings = resolved.warnings.filter((payload) => {
283
+ const key = `${input.sessionId}\u0000${payload.resource ?? ""}\u0000${payload.reason}`;
284
+ if (warningCache.get(key, now())) return false;
285
+ warningCache.set(key, {
286
+ value: null,
287
+ expiresAt: now() + GITHUB_REPOSITORY_LOOKUP_CACHE_TTL_MS,
288
+ });
289
+ return true;
290
+ });
291
+ if (warnings.length > 0) {
292
+ await input.publish(
293
+ warnings.map((payload) => ({ type: "credential.auth_needed" as const, payload })),
294
+ );
295
+ }
296
+ return {
297
+ turnResources: resolved.resources,
298
+ runtimeResources: resolved.apply(input.claimedRuntimeResources),
299
+ };
300
+ }