@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 649 lines 28.6 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda";
2 import * as Rekognition from "@alchemy.run/aws/Rekognition";
3 import * as Duration from "effect/Duration";
4 import * as Effect from "effect/Effect";
5 import { HttpServerRequest } from "effect/http/HttpServerRequest";
6 import * as HttpServerResponse from "effect/http/HttpServerResponse";
7 import * as Layer from "effect/Layer";
8 import path from "pathe";
9
10 const main = path.resolve(import.meta.dirname, "handler.ts");
11
12 // Deterministic collection id — this suite owns it in the testing account and
13 // the lifecycle route deletes it on entry and exit, so reruns self-heal.
14 export const TEST_COLLECTION_ID = "alchemy-test-rekognition-bindings";
15
16 // A 100x100 RGB PNG (blue sky, green ground, yellow sun disc) generated once
17 // and checked in — big enough for Rekognition's 80px minimum dimension. It
18 // contains no faces, which the face routes exploit: IndexFaces succeeds with
19 // zero face records and SearchFacesByImage surfaces the typed
20 // InvalidParameterException ("no faces in image"), both proving IAM + call
21 // plumbing end-to-end.
22 const TEST_IMAGE_B64 =
23 "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAABNElEQVR4nO3YUQ3CMABF0cpBBN/IQc5EoGkOcMAXCkjK2u6l60n6v+Tsvo5Qnq+3UylQSNULwII15m5RFixlxb9FZghLWWaYJ3BnwVJWnGC5GX72268Dq4qpO1lZQaqXV1lEqotXWUeq3assJdXoBevSWI1ZtcQFC5ayzNCd5YKPfwfNEJayLrPEw8+d70cprPO8Wl7SlGUd9mp84sRY/ikd5dXl3cxdVg1Zx6dcBOucAwuWsswwT+DOgqWsOIEZwlJWnMAMYSkrTmCGsJQVJzBDWMqKE5ghLGXNNMP79nAqBWD90QosWGPuFmXBUlb8q22GsJRlhnkCdxYsZcUJzBCWsuIEZghLWXECM4SlrDiBGcJSVpzADGEpK05ghrCUFScwQ1jKihOYISxlxQnMENYWLusLBGA4iOtydmQAAAAASUVORK5CYII=";
24 const imageBytes = Buffer.from(TEST_IMAGE_B64, "base64");
25
26 // Well-formed-but-nonexistent identifiers used to drive the typed not-found
27 // paths. An IAM gap would surface AccessDeniedException (a 500 through the
28 // handler's orDie), so a typed not-found/validation tag proves the grant
29 // end-to-end.
30 const BOGUS_JOB_ID = "0".repeat(64);
31 const BOGUS_FACE_ID = "00000000-0000-0000-0000-000000000000";
32 const BOGUS_SESSION_ID = "00000000-0000-0000-0000-000000000000";
33 const BOGUS_BUCKET = "alchemy-nonexistent-rekognition-test-bucket";
34 const BOGUS_VIDEO = {
35 S3Object: { Bucket: BOGUS_BUCKET, Name: "video.mp4" },
36 };
37
38 export class RekognitionTestFunction extends Lambda.Function<Lambda.Function>()(
39 "RekognitionTestFunction",
40 ) {}
41
42 export default RekognitionTestFunction.make(
43 {
44 main,
45 functionUrl: true,
46 // The image-analysis route runs seven sequential inferences and the
47 // collection route ~15 sequential data-plane calls.
48 timeout: Duration.seconds(120),
49 // The bundled Rekognition schema graph is large — the 128 MB default
50 // leaves almost no headroom (observed Max Memory Used: 118 MB on the
51 // cheap routes alone).
52 memorySize: 512,
53 },
54 Effect.gen(function* () {
55 // --- image analysis ---
56 const compareFaces = yield* Rekognition.CompareFaces();
57 const detectFaces = yield* Rekognition.DetectFaces();
58 const detectLabels = yield* Rekognition.DetectLabels();
59 const detectModerationLabels = yield* Rekognition.DetectModerationLabels();
60 const detectProtectiveEquipment = yield* Rekognition.DetectProtectiveEquipment();
61 const detectText = yield* Rekognition.DetectText();
62 const recognizeCelebrities = yield* Rekognition.RecognizeCelebrities();
63 const getCelebrityInfo = yield* Rekognition.GetCelebrityInfo();
64
65 // --- face collections ---
66 const createCollection = yield* Rekognition.CreateCollection();
67 const deleteCollection = yield* Rekognition.DeleteCollection();
68 const describeCollection = yield* Rekognition.DescribeCollection();
69 const listCollections = yield* Rekognition.ListCollections();
70 const indexFaces = yield* Rekognition.IndexFaces();
71 const listFaces = yield* Rekognition.ListFaces();
72 const deleteFaces = yield* Rekognition.DeleteFaces();
73 const searchFaces = yield* Rekognition.SearchFaces();
74 const searchFacesByImage = yield* Rekognition.SearchFacesByImage();
75
76 // --- user search ---
77 const createUser = yield* Rekognition.CreateUser();
78 const deleteUser = yield* Rekognition.DeleteUser();
79 const listUsers = yield* Rekognition.ListUsers();
80 const associateFaces = yield* Rekognition.AssociateFaces();
81 const disassociateFaces = yield* Rekognition.DisassociateFaces();
82 const searchUsers = yield* Rekognition.SearchUsers();
83 const searchUsersByImage = yield* Rekognition.SearchUsersByImage();
84
85 // --- face liveness ---
86 const createFaceLivenessSession = yield* Rekognition.CreateFaceLivenessSession();
87 const getFaceLivenessSessionResults = yield* Rekognition.GetFaceLivenessSessionResults();
88
89 // --- video analysis ---
90 const startCelebrityRecognition = yield* Rekognition.StartCelebrityRecognition();
91 const getCelebrityRecognition = yield* Rekognition.GetCelebrityRecognition();
92 const startContentModeration = yield* Rekognition.StartContentModeration();
93 const getContentModeration = yield* Rekognition.GetContentModeration();
94 const startFaceDetection = yield* Rekognition.StartFaceDetection();
95 const getFaceDetection = yield* Rekognition.GetFaceDetection();
96 const startFaceSearch = yield* Rekognition.StartFaceSearch();
97 const getFaceSearch = yield* Rekognition.GetFaceSearch();
98 const startLabelDetection = yield* Rekognition.StartLabelDetection();
99 const getLabelDetection = yield* Rekognition.GetLabelDetection();
100 const startPersonTracking = yield* Rekognition.StartPersonTracking();
101 const getPersonTracking = yield* Rekognition.GetPersonTracking();
102 const startSegmentDetection = yield* Rekognition.StartSegmentDetection();
103 const getSegmentDetection = yield* Rekognition.GetSegmentDetection();
104 const startTextDetection = yield* Rekognition.StartTextDetection();
105 const getTextDetection = yield* Rekognition.GetTextDetection();
106
107 // --- media analysis jobs ---
108 const startMediaAnalysisJob = yield* Rekognition.StartMediaAnalysisJob();
109 const getMediaAnalysisJob = yield* Rekognition.GetMediaAnalysisJob();
110 const listMediaAnalysisJobs = yield* Rekognition.ListMediaAnalysisJobs();
111
112 // --- stream processors ---
113 const startStreamProcessor = yield* Rekognition.StartStreamProcessor();
114 const stopStreamProcessor = yield* Rekognition.StopStreamProcessor();
115 const describeStreamProcessor = yield* Rekognition.DescribeStreamProcessor();
116 const listStreamProcessors = yield* Rekognition.ListStreamProcessors();
117
118 // --- custom labels ---
119 const detectCustomLabels = yield* Rekognition.DetectCustomLabels();
120 const describeProjects = yield* Rekognition.DescribeProjects();
121 const describeProjectVersions = yield* Rekognition.DescribeProjectVersions();
122 const startProjectVersion = yield* Rekognition.StartProjectVersion();
123 const stopProjectVersion = yield* Rekognition.StopProjectVersion();
124
125 return {
126 fetch: Effect.gen(function* () {
127 const request = yield* HttpServerRequest;
128 const url = new URL(request.originalUrl);
129 const pathname = url.pathname;
130
131 // Cheap readiness route — no Rekognition call.
132 if (request.method === "GET" && pathname === "/ping") {
133 return yield* HttpServerResponse.json({ ok: true });
134 }
135
136 // One route drives every synchronous image-analysis binding against
137 // the embedded test image (real inferences; the image has no faces,
138 // so CompareFaces surfaces its typed InvalidParameterException).
139 if (request.method === "GET" && pathname === "/analyze-image") {
140 const labels = yield* detectLabels({
141 Image: { Bytes: imageBytes },
142 MaxLabels: 10,
143 });
144 const faces = yield* detectFaces({ Image: { Bytes: imageBytes } });
145 const moderation = yield* detectModerationLabels({
146 Image: { Bytes: imageBytes },
147 });
148 const text = yield* detectText({ Image: { Bytes: imageBytes } });
149 const ppe = yield* detectProtectiveEquipment({
150 Image: { Bytes: imageBytes },
151 });
152 const celebrities = yield* recognizeCelebrities({
153 Image: { Bytes: imageBytes },
154 });
155 const compareTag = yield* compareFaces({
156 SourceImage: { Bytes: imageBytes },
157 TargetImage: { Bytes: imageBytes },
158 }).pipe(
159 Effect.map(() => "Success"),
160 Effect.catchTag("InvalidParameterException", (e) => Effect.succeed(e._tag)),
161 );
162 const celebrityInfoTag = yield* getCelebrityInfo({
163 Id: "0000000000",
164 }).pipe(
165 Effect.map(() => "Success"),
166 Effect.catchTag(["ResourceNotFoundException", "InvalidParameterException"], (e) =>
167 Effect.succeed(e._tag),
168 ),
169 );
170 return yield* HttpServerResponse.json({
171 labelNames: (labels.Labels ?? []).map((l) => l.Name),
172 faceCount: (faces.FaceDetails ?? []).length,
173 moderationCount: (moderation.ModerationLabels ?? []).length,
174 textCount: (text.TextDetections ?? []).length,
175 ppePersons: (ppe.Persons ?? []).length,
176 celebrityCount: (celebrities.CelebrityFaces ?? []).length,
177 compareTag,
178 celebrityInfoTag,
179 });
180 }
181
182 // Full real lifecycle of the collection + user data plane: create a
183 // collection, describe/list it, index a (faceless) image, create and
184 // list a user, drive the face-id ops through their typed not-found
185 // paths, then tear everything down.
186 if (request.method === "POST" && pathname === "/collections") {
187 // Self-heal from a previous crashed run.
188 yield* deleteCollection({ CollectionId: TEST_COLLECTION_ID }).pipe(
189 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
190 );
191 const created = yield* createCollection({
192 CollectionId: TEST_COLLECTION_ID,
193 }).pipe(
194 Effect.map((r) => r.StatusCode ?? 200),
195 Effect.catchTag("ResourceAlreadyExistsException", () => Effect.succeed(200)),
196 );
197 const described = yield* describeCollection({
198 CollectionId: TEST_COLLECTION_ID,
199 });
200 const collections = yield* listCollections({ MaxResults: 100 });
201 const indexed = yield* indexFaces({
202 CollectionId: TEST_COLLECTION_ID,
203 Image: { Bytes: imageBytes },
204 });
205 const faces = yield* listFaces({
206 CollectionId: TEST_COLLECTION_ID,
207 });
208 yield* createUser({
209 CollectionId: TEST_COLLECTION_ID,
210 UserId: "test-user",
211 }).pipe(Effect.catchTag("ConflictException", () => Effect.void));
212 const users = yield* listUsers({
213 CollectionId: TEST_COLLECTION_ID,
214 });
215 const searchUsersTag = yield* searchUsers({
216 CollectionId: TEST_COLLECTION_ID,
217 UserId: "test-user",
218 }).pipe(
219 Effect.map(() => "Success"),
220 Effect.catchTag(["InvalidParameterException", "ResourceNotFoundException"], (e) =>
221 Effect.succeed(e._tag),
222 ),
223 );
224 const associateTag = yield* associateFaces({
225 CollectionId: TEST_COLLECTION_ID,
226 UserId: "test-user",
227 FaceIds: [BOGUS_FACE_ID],
228 }).pipe(
229 Effect.map(() => "Success"),
230 Effect.catchTag(["InvalidParameterException", "ResourceNotFoundException"], (e) =>
231 Effect.succeed(e._tag),
232 ),
233 );
234 const disassociateTag = yield* disassociateFaces({
235 CollectionId: TEST_COLLECTION_ID,
236 UserId: "test-user",
237 FaceIds: [BOGUS_FACE_ID],
238 }).pipe(
239 Effect.map(() => "Success"),
240 Effect.catchTag(["InvalidParameterException", "ResourceNotFoundException"], (e) =>
241 Effect.succeed(e._tag),
242 ),
243 );
244 const searchFacesTag = yield* searchFaces({
245 CollectionId: TEST_COLLECTION_ID,
246 FaceId: BOGUS_FACE_ID,
247 }).pipe(
248 Effect.map(() => "Success"),
249 Effect.catchTag(["InvalidParameterException", "ResourceNotFoundException"], (e) =>
250 Effect.succeed(e._tag),
251 ),
252 );
253 const searchFacesByImageTag = yield* searchFacesByImage({
254 CollectionId: TEST_COLLECTION_ID,
255 Image: { Bytes: imageBytes },
256 }).pipe(
257 Effect.map(() => "Success"),
258 Effect.catchTag("InvalidParameterException", (e) => Effect.succeed(e._tag)),
259 );
260 const searchUsersByImageTag = yield* searchUsersByImage({
261 CollectionId: TEST_COLLECTION_ID,
262 Image: { Bytes: imageBytes },
263 }).pipe(
264 Effect.map(() => "Success"),
265 Effect.catchTag("InvalidParameterException", (e) => Effect.succeed(e._tag)),
266 );
267 const deleteFacesTag = yield* deleteFaces({
268 CollectionId: TEST_COLLECTION_ID,
269 FaceIds: [BOGUS_FACE_ID],
270 }).pipe(
271 Effect.map(() => "Success"),
272 Effect.catchTag("InvalidParameterException", (e) => Effect.succeed(e._tag)),
273 );
274 yield* deleteUser({
275 CollectionId: TEST_COLLECTION_ID,
276 UserId: "test-user",
277 }).pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.void));
278 yield* deleteCollection({ CollectionId: TEST_COLLECTION_ID });
279 return yield* HttpServerResponse.json({
280 createStatus: created,
281 faceCountAtCreate: described.FaceCount ?? 0,
282 listedCollection: (collections.CollectionIds ?? []).includes(TEST_COLLECTION_ID),
283 indexedFaceRecords: (indexed.FaceRecords ?? []).length,
284 listedFaces: (faces.Faces ?? []).length,
285 listedUsers: (users.Users ?? []).map((u) => u.UserId),
286 searchUsersTag,
287 associateTag,
288 disassociateTag,
289 searchFacesTag,
290 searchFacesByImageTag,
291 searchUsersByImageTag,
292 deleteFacesTag,
293 });
294 }
295
296 // Real Face Liveness lifecycle: create a session, read its CREATED
297 // status back, and drive the typed SessionNotFoundException path.
298 if (request.method === "POST" && pathname === "/liveness") {
299 const session = yield* createFaceLivenessSession();
300 const results = yield* getFaceLivenessSessionResults({
301 SessionId: session.SessionId,
302 });
303 const notFoundTag = yield* getFaceLivenessSessionResults({
304 SessionId: BOGUS_SESSION_ID,
305 }).pipe(
306 Effect.map(() => "Found"),
307 Effect.catchTag("SessionNotFoundException", (e) => Effect.succeed(e._tag)),
308 );
309 return yield* HttpServerResponse.json({
310 sessionId: session.SessionId,
311 status: results.Status,
312 notFoundTag,
313 });
314 }
315
316 // Drives all eight Start* video bindings through Rekognition's typed
317 // server-side S3 validation (nonexistent bucket) — real runtime calls
318 // proving IAM without paying for eight async video jobs.
319 if (request.method === "POST" && pathname === "/video/start-all") {
320 const tags = {
321 celebrityRecognition: yield* startCelebrityRecognition({
322 Video: BOGUS_VIDEO,
323 }).pipe(
324 Effect.map(() => "Started"),
325 Effect.catch((e) => Effect.succeed(e._tag)),
326 ),
327 contentModeration: yield* startContentModeration({
328 Video: BOGUS_VIDEO,
329 }).pipe(
330 Effect.map(() => "Started"),
331 Effect.catch((e) => Effect.succeed(e._tag)),
332 ),
333 faceDetection: yield* startFaceDetection({
334 Video: BOGUS_VIDEO,
335 }).pipe(
336 Effect.map(() => "Started"),
337 Effect.catch((e) => Effect.succeed(e._tag)),
338 ),
339 // FaceSearch also validates the collection — it may surface
340 // ResourceNotFoundException before the S3 check.
341 faceSearch: yield* startFaceSearch({
342 Video: BOGUS_VIDEO,
343 CollectionId: "alchemy-nonexistent-collection",
344 }).pipe(
345 Effect.map(() => "Started"),
346 Effect.catch((e) => Effect.succeed(e._tag)),
347 ),
348 labelDetection: yield* startLabelDetection({
349 Video: BOGUS_VIDEO,
350 }).pipe(
351 Effect.map(() => "Started"),
352 Effect.catch((e) => Effect.succeed(e._tag)),
353 ),
354 personTracking: yield* startPersonTracking({
355 Video: BOGUS_VIDEO,
356 }).pipe(
357 Effect.map(() => "Started"),
358 Effect.catch((e) => Effect.succeed(e._tag)),
359 ),
360 segmentDetection: yield* startSegmentDetection({
361 Video: BOGUS_VIDEO,
362 SegmentTypes: ["SHOT"],
363 }).pipe(
364 Effect.map(() => "Started"),
365 Effect.catch((e) => Effect.succeed(e._tag)),
366 ),
367 textDetection: yield* startTextDetection({
368 Video: BOGUS_VIDEO,
369 }).pipe(
370 Effect.map(() => "Started"),
371 Effect.catch((e) => Effect.succeed(e._tag)),
372 ),
373 };
374 return yield* HttpServerResponse.json(tags);
375 }
376
377 // Drives all eight Get* video bindings through their typed
378 // ResourceNotFoundException path with a well-formed bogus JobId.
379 if (request.method === "GET" && pathname === "/video/get-all") {
380 const probe = { JobId: BOGUS_JOB_ID };
381 const tags = {
382 celebrityRecognition: yield* getCelebrityRecognition(probe).pipe(
383 Effect.map(() => "Found"),
384 Effect.catchTag(
385 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
386 (e) => Effect.succeed(e._tag),
387 ),
388 ),
389 contentModeration: yield* getContentModeration(probe).pipe(
390 Effect.map(() => "Found"),
391 Effect.catchTag(
392 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
393 (e) => Effect.succeed(e._tag),
394 ),
395 ),
396 faceDetection: yield* getFaceDetection(probe).pipe(
397 Effect.map(() => "Found"),
398 Effect.catchTag(
399 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
400 (e) => Effect.succeed(e._tag),
401 ),
402 ),
403 faceSearch: yield* getFaceSearch(probe).pipe(
404 Effect.map(() => "Found"),
405 Effect.catchTag(
406 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
407 (e) => Effect.succeed(e._tag),
408 ),
409 ),
410 labelDetection: yield* getLabelDetection(probe).pipe(
411 Effect.map(() => "Found"),
412 Effect.catchTag(
413 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
414 (e) => Effect.succeed(e._tag),
415 ),
416 ),
417 personTracking: yield* getPersonTracking(probe).pipe(
418 Effect.map(() => "Found"),
419 Effect.catchTag(
420 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
421 (e) => Effect.succeed(e._tag),
422 ),
423 ),
424 segmentDetection: yield* getSegmentDetection(probe).pipe(
425 Effect.map(() => "Found"),
426 Effect.catchTag(
427 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
428 (e) => Effect.succeed(e._tag),
429 ),
430 ),
431 textDetection: yield* getTextDetection(probe).pipe(
432 Effect.map(() => "Found"),
433 Effect.catchTag(
434 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
435 (e) => Effect.succeed(e._tag),
436 ),
437 ),
438 };
439 return yield* HttpServerResponse.json(tags);
440 }
441
442 // Media analysis: list for real, start/get through typed error paths.
443 if (request.method === "POST" && pathname === "/media-analysis") {
444 const jobCount = (
445 (yield* listMediaAnalysisJobs({ MaxResults: 10 })).MediaAnalysisJobs ?? []
446 ).length;
447 const startTag = yield* startMediaAnalysisJob({
448 OperationsConfig: {
449 DetectModerationLabels: { MinConfidence: 60 },
450 },
451 Input: {
452 S3Object: { Bucket: BOGUS_BUCKET, Name: "manifest.jsonl" },
453 },
454 OutputConfig: { S3Bucket: BOGUS_BUCKET, S3KeyPrefix: "out/" },
455 }).pipe(
456 Effect.map(() => "Started"),
457 Effect.catchTag(
458 [
459 "InvalidS3ObjectException",
460 "InvalidManifestException",
461 "InvalidParameterException",
462 "ResourceNotFoundException",
463 ],
464 (e) => Effect.succeed(e._tag),
465 ),
466 );
467 const getTag = yield* getMediaAnalysisJob({
468 JobId: BOGUS_JOB_ID,
469 }).pipe(
470 Effect.map(() => "Found"),
471 Effect.catchTag(["ResourceNotFoundException", "InvalidParameterException"], (e) =>
472 Effect.succeed(e._tag),
473 ),
474 );
475 return yield* HttpServerResponse.json({ jobCount, startTag, getTag });
476 }
477
478 // Stream processors: list for real, control plane through the typed
479 // ResourceNotFoundException path. Rekognition Video stream processors
480 // are allow-listed per account: an unentitled account gets the typed
481 // AccessDeniedException from every op (the list included), which
482 // still proves the binding reached the service.
483 if (request.method === "GET" && pathname === "/stream-processors") {
484 const listed = yield* listStreamProcessors({ MaxResults: 10 }).pipe(
485 Effect.map((r) => ({ count: (r.StreamProcessors ?? []).length }) as const),
486 Effect.catchTag("AccessDeniedException", (e) =>
487 Effect.succeed({ count: -1, listTag: e._tag } as const),
488 ),
489 );
490 const describeTag = yield* describeStreamProcessor({
491 Name: "alchemy-nonexistent-processor",
492 }).pipe(
493 Effect.map(() => "Found"),
494 Effect.catchTag(["ResourceNotFoundException", "AccessDeniedException"], (e) =>
495 Effect.succeed(e._tag),
496 ),
497 );
498 const startTag = yield* startStreamProcessor({
499 Name: "alchemy-nonexistent-processor",
500 }).pipe(
501 Effect.map(() => "Started"),
502 Effect.catchTag(["ResourceNotFoundException", "AccessDeniedException"], (e) =>
503 Effect.succeed(e._tag),
504 ),
505 );
506 const stopTag = yield* stopStreamProcessor({
507 Name: "alchemy-nonexistent-processor",
508 }).pipe(
509 Effect.map(() => "Stopped"),
510 Effect.catchTag(["ResourceNotFoundException", "AccessDeniedException"], (e) =>
511 Effect.succeed(e._tag),
512 ),
513 );
514 return yield* HttpServerResponse.json({
515 ...listed,
516 describeTag,
517 startTag,
518 stopTag,
519 });
520 }
521
522 // Custom Labels: DescribeProjects for real; the model-scoped ops run
523 // through their typed ResourceNotFoundException path with well-formed
524 // same-account ARNs (?account=… is passed by the test, parsed from the
525 // deployed function's ARN). Custom Labels is closed to new customers,
526 // so entitlement-gated accounts may surface the typed
527 // AccessDeniedException instead — the test accepts both.
528 if (request.method === "GET" && pathname === "/custom-labels") {
529 const account = url.searchParams.get("account") ?? "123456789012";
530 const region = yield* Effect.sync(() => process.env.AWS_REGION ?? "us-east-1");
531 const projectArn = `arn:aws:rekognition:${region}:${account}:project/alchemy-nonexistent/1700000000000`;
532 const projectVersionArn = `arn:aws:rekognition:${region}:${account}:project/alchemy-nonexistent/version/alchemy-nonexistent/1700000000000`;
533 const projectCount = (
534 (yield* describeProjects({ MaxResults: 10 })).ProjectDescriptions ?? []
535 ).length;
536 const describeVersionsTag = yield* describeProjectVersions({
537 ProjectArn: projectArn,
538 }).pipe(
539 Effect.map(() => "Found"),
540 Effect.catchTag(
541 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
542 (e) => Effect.succeed(e._tag),
543 ),
544 );
545 const detectTag = yield* detectCustomLabels({
546 ProjectVersionArn: projectVersionArn,
547 Image: { Bytes: imageBytes },
548 }).pipe(
549 Effect.map(() => "Detected"),
550 Effect.catchTag(
551 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
552 (e) => Effect.succeed(e._tag),
553 ),
554 );
555 const startTag = yield* startProjectVersion({
556 ProjectVersionArn: projectVersionArn,
557 MinInferenceUnits: 1,
558 }).pipe(
559 Effect.map(() => "Started"),
560 Effect.catchTag(
561 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
562 (e) => Effect.succeed(e._tag),
563 ),
564 );
565 const stopTag = yield* stopProjectVersion({
566 ProjectVersionArn: projectVersionArn,
567 }).pipe(
568 Effect.map(() => "Stopped"),
569 Effect.catchTag(
570 ["ResourceNotFoundException", "InvalidParameterException", "AccessDeniedException"],
571 (e) => Effect.succeed(e._tag),
572 ),
573 );
574 return yield* HttpServerResponse.json({
575 projectCount,
576 describeVersionsTag,
577 detectTag,
578 startTag,
579 stopTag,
580 });
581 }
582
583 return yield* HttpServerResponse.json(
584 { error: "Not found", method: request.method, pathname },
585 { status: 404 },
586 );
587 }).pipe(Effect.orDie),
588 };
589 }).pipe(
590 Effect.provide(
591 Layer.mergeAll(
592 Rekognition.CompareFacesHttp,
593 Rekognition.DetectFacesHttp,
594 Rekognition.DetectLabelsHttp,
595 Rekognition.DetectModerationLabelsHttp,
596 Rekognition.DetectProtectiveEquipmentHttp,
597 Rekognition.DetectTextHttp,
598 Rekognition.RecognizeCelebritiesHttp,
599 Rekognition.GetCelebrityInfoHttp,
600 Rekognition.CreateCollectionHttp,
601 Rekognition.DeleteCollectionHttp,
602 Rekognition.DescribeCollectionHttp,
603 Rekognition.ListCollectionsHttp,
604 Rekognition.IndexFacesHttp,
605 Rekognition.ListFacesHttp,
606 Rekognition.DeleteFacesHttp,
607 Rekognition.SearchFacesHttp,
608 Rekognition.SearchFacesByImageHttp,
609 Rekognition.CreateUserHttp,
610 Rekognition.DeleteUserHttp,
611 Rekognition.ListUsersHttp,
612 Rekognition.AssociateFacesHttp,
613 Rekognition.DisassociateFacesHttp,
614 Rekognition.SearchUsersHttp,
615 Rekognition.SearchUsersByImageHttp,
616 Rekognition.CreateFaceLivenessSessionHttp,
617 Rekognition.GetFaceLivenessSessionResultsHttp,
618 Rekognition.StartCelebrityRecognitionHttp,
619 Rekognition.GetCelebrityRecognitionHttp,
620 Rekognition.StartContentModerationHttp,
621 Rekognition.GetContentModerationHttp,
622 Rekognition.StartFaceDetectionHttp,
623 Rekognition.GetFaceDetectionHttp,
624 Rekognition.StartFaceSearchHttp,
625 Rekognition.GetFaceSearchHttp,
626 Rekognition.StartLabelDetectionHttp,
627 Rekognition.GetLabelDetectionHttp,
628 Rekognition.StartPersonTrackingHttp,
629 Rekognition.GetPersonTrackingHttp,
630 Rekognition.StartSegmentDetectionHttp,
631 Rekognition.GetSegmentDetectionHttp,
632 Rekognition.StartTextDetectionHttp,
633 Rekognition.GetTextDetectionHttp,
634 Rekognition.StartMediaAnalysisJobHttp,
635 Rekognition.GetMediaAnalysisJobHttp,
636 Rekognition.ListMediaAnalysisJobsHttp,
637 Rekognition.StartStreamProcessorHttp,
638 Rekognition.StopStreamProcessorHttp,
639 Rekognition.DescribeStreamProcessorHttp,
640 Rekognition.ListStreamProcessorsHttp,
641 Rekognition.DetectCustomLabelsHttp,
642 Rekognition.DescribeProjectsHttp,
643 Rekognition.DescribeProjectVersionsHttp,
644 Rekognition.StartProjectVersionHttp,
645 Rekognition.StopProjectVersionHttp,
646 ),
647 ),
648 ),
649 );