@vercel/factory 0.0.9 → 0.0.11

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.
@@ -1,5 +1,5 @@
1
- import { c as Finding, k as FactoryStores, t as ApprovalPolicy } from "../approval-MoiwGpkh.mjs";
2
- import { d as GitHubReviewComment } from "../github-DMOypeIu.mjs";
1
+ import { A as FactoryStores, P as Task, c as Finding, t as ApprovalPolicy } from "../approval-CDiBco2V.mjs";
2
+ import { T as PullRequestReviewComment, b as GitHubReviewComment, j as SubmittedPullRequestReview } from "../github-wThBfbm-.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/eve/fetch.d.ts
5
5
  /** The subset of the eve sandbox handle a credentialed git operation needs. */
@@ -341,7 +341,7 @@ interface InvokeAgentOptions {
341
341
  /** Bearer token for the target agent's eve channel, when it requires auth. */
342
342
  token?: () => Promise<string | undefined>;
343
343
  /** Extra headers for the session request, e.g. a deployment protection bypass. */
344
- headers?: () => Record<string, string> | Promise<Record<string, string>>;
344
+ headers?: (task: Task) => Record<string, string> | Promise<Record<string, string>>;
345
345
  fetch?: typeof fetch;
346
346
  }
347
347
  /**
@@ -378,6 +378,76 @@ declare function invokeAgentTool(stores: FactoryStores, options: InvokeAgentOpti
378
378
  }>;
379
379
  };
380
380
  //#endregion
381
+ //#region src/eve/post-review.d.ts
382
+ interface PublishedReview {
383
+ taskId: string;
384
+ changeId: string;
385
+ repository: string;
386
+ headSha: string;
387
+ verdict: "approve" | "request_changes" | "comment";
388
+ summary: string;
389
+ comments: readonly PullRequestReviewComment[];
390
+ review: SubmittedPullRequestReview;
391
+ }
392
+ interface PostReviewToolOptions {
393
+ tokenForRepository: (repository: string) => Promise<string>;
394
+ onPublished?: (published: PublishedReview) => Promise<void>;
395
+ fetch?: typeof globalThis.fetch;
396
+ }
397
+ /**
398
+ * Publish an independent review of an existing pull request and finish the
399
+ * review task without changing the pull request's factory lifecycle.
400
+ */
401
+ declare function postReviewTool(stores: FactoryStores, options: PostReviewToolOptions): import("eve/tools").ToolDefinition<{
402
+ taskId: string;
403
+ changeId: string;
404
+ verdict: "approve" | "request_changes" | "comment";
405
+ headSha: string;
406
+ summary: string;
407
+ comments: {
408
+ path: string;
409
+ line: number;
410
+ body: string;
411
+ }[];
412
+ }, {
413
+ recorded: false;
414
+ reason: string;
415
+ verdict?: undefined;
416
+ review?: undefined;
417
+ taskState?: undefined;
418
+ } | {
419
+ recorded: true;
420
+ verdict: "approve" | "request_changes" | "comment";
421
+ review: SubmittedPullRequestReview;
422
+ taskState: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
423
+ reason?: undefined;
424
+ }> & {
425
+ execute(input: {
426
+ taskId: string;
427
+ changeId: string;
428
+ verdict: "approve" | "request_changes" | "comment";
429
+ headSha: string;
430
+ summary: string;
431
+ comments: {
432
+ path: string;
433
+ line: number;
434
+ body: string;
435
+ }[];
436
+ }, ctx: import("eve/tools").ToolContext): Promise<{
437
+ recorded: false;
438
+ reason: string;
439
+ verdict?: undefined;
440
+ review?: undefined;
441
+ taskState?: undefined;
442
+ } | {
443
+ recorded: true;
444
+ verdict: "approve" | "request_changes" | "comment";
445
+ review: SubmittedPullRequestReview;
446
+ taskState: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
447
+ reason?: undefined;
448
+ }>;
449
+ };
450
+ //#endregion
381
451
  //#region src/eve/review.d.ts
382
452
  interface ReviewCommentToolOptions<S extends CommandSandbox = CommandSandbox> {
383
453
  tokenForRepository: (repository: string) => Promise<string>;
@@ -562,6 +632,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
562
632
  }, {
563
633
  schemaVersion: 1;
564
634
  id: string;
635
+ repositoryIds: string[];
565
636
  kind: string;
566
637
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
567
638
  origin: {
@@ -576,7 +647,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
576
647
  attempt: number;
577
648
  createdAt: string;
578
649
  updatedAt: string;
579
- repositoryIds?: string[] | undefined;
580
650
  area?: string | undefined;
581
651
  approval?: "required" | "granted" | "denied" | undefined;
582
652
  dependsOn?: string[] | undefined;
@@ -604,6 +674,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
604
674
  }, ctx: import("eve/tools").ToolContext): Promise<{
605
675
  schemaVersion: 1;
606
676
  id: string;
677
+ repositoryIds: string[];
607
678
  kind: string;
608
679
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
609
680
  origin: {
@@ -618,7 +689,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
618
689
  attempt: number;
619
690
  createdAt: string;
620
691
  updatedAt: string;
621
- repositoryIds?: string[] | undefined;
622
692
  area?: string | undefined;
623
693
  approval?: "required" | "granted" | "denied" | undefined;
624
694
  dependsOn?: string[] | undefined;
@@ -724,6 +794,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
724
794
  task: {
725
795
  schemaVersion: 1;
726
796
  id: string;
797
+ repositoryIds: string[];
727
798
  kind: string;
728
799
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
729
800
  origin: {
@@ -738,7 +809,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
738
809
  attempt: number;
739
810
  createdAt: string;
740
811
  updatedAt: string;
741
- repositoryIds?: string[] | undefined;
742
812
  area?: string | undefined;
743
813
  approval?: "required" | "granted" | "denied" | undefined;
744
814
  dependsOn?: string[] | undefined;
@@ -796,6 +866,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
796
866
  task: {
797
867
  schemaVersion: 1;
798
868
  id: string;
869
+ repositoryIds: string[];
799
870
  kind: string;
800
871
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
801
872
  origin: {
@@ -810,7 +881,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
810
881
  attempt: number;
811
882
  createdAt: string;
812
883
  updatedAt: string;
813
- repositoryIds?: string[] | undefined;
814
884
  area?: string | undefined;
815
885
  approval?: "required" | "granted" | "denied" | undefined;
816
886
  dependsOn?: string[] | undefined;
@@ -863,6 +933,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
863
933
  }, {
864
934
  schemaVersion: 1;
865
935
  id: string;
936
+ repositoryIds: string[];
866
937
  kind: string;
867
938
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
868
939
  origin: {
@@ -877,7 +948,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
877
948
  attempt: number;
878
949
  createdAt: string;
879
950
  updatedAt: string;
880
- repositoryIds?: string[] | undefined;
881
951
  area?: string | undefined;
882
952
  approval?: "required" | "granted" | "denied" | undefined;
883
953
  dependsOn?: string[] | undefined;
@@ -903,6 +973,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
903
973
  }, ctx: import("eve/tools").ToolContext): Promise<{
904
974
  schemaVersion: 1;
905
975
  id: string;
976
+ repositoryIds: string[];
906
977
  kind: string;
907
978
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
908
979
  origin: {
@@ -917,7 +988,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
917
988
  attempt: number;
918
989
  createdAt: string;
919
990
  updatedAt: string;
920
- repositoryIds?: string[] | undefined;
921
991
  area?: string | undefined;
922
992
  approval?: "required" | "granted" | "denied" | undefined;
923
993
  dependsOn?: string[] | undefined;
@@ -950,6 +1020,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
950
1020
  }, {
951
1021
  schemaVersion: 1;
952
1022
  id: string;
1023
+ repositoryIds: string[];
953
1024
  kind: string;
954
1025
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
955
1026
  origin: {
@@ -964,7 +1035,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
964
1035
  attempt: number;
965
1036
  createdAt: string;
966
1037
  updatedAt: string;
967
- repositoryIds?: string[] | undefined;
968
1038
  area?: string | undefined;
969
1039
  approval?: "required" | "granted" | "denied" | undefined;
970
1040
  dependsOn?: string[] | undefined;
@@ -996,6 +1066,7 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
996
1066
  }, ctx: import("eve/tools").ToolContext): Promise<{
997
1067
  schemaVersion: 1;
998
1068
  id: string;
1069
+ repositoryIds: string[];
999
1070
  kind: string;
1000
1071
  state: "queued" | "running" | "verifying" | "succeeded" | "failed" | "needs_human" | "cancelled";
1001
1072
  origin: {
@@ -1010,7 +1081,6 @@ declare function factoryTools(stores: FactoryStores, options?: FactoryToolsOptio
1010
1081
  attempt: number;
1011
1082
  createdAt: string;
1012
1083
  updatedAt: string;
1013
- repositoryIds?: string[] | undefined;
1014
1084
  area?: string | undefined;
1015
1085
  approval?: "required" | "granted" | "denied" | undefined;
1016
1086
  dependsOn?: string[] | undefined;
@@ -1099,5 +1169,5 @@ declare function factoryHooks(stores: FactoryStores): {
1099
1169
  };
1100
1170
  type FactoryHooks = ReturnType<typeof factoryHooks>;
1101
1171
  //#endregion
1102
- export { type CommandSandbox, type DeepsecScanOptions, FactoryHooks, FactoryTools, FactoryToolsOptions, type FetchPullRequestOptions, type FetchPullRequestResult, GateVerdict, type InvokeAgentOptions, type MergeConflictPayload, type MergeConflictToolOptions, RecordChangeInput, type RecordFindingOptions, type RecordFindingResult, type ReviewCommentToolOptions, deepsecScanTool, factoryHooks, factoryTools, fetchPullRequestTool, findingFromDeepsec, invokeAgentTool, mergeConflictPayloadSchema, mergeConflictTools, recordFinding, recordFindingTool, recordVerificationTool, reviewCommentTools };
1172
+ export { type CommandSandbox, type DeepsecScanOptions, FactoryHooks, FactoryTools, FactoryToolsOptions, type FetchPullRequestOptions, type FetchPullRequestResult, GateVerdict, type InvokeAgentOptions, type MergeConflictPayload, type MergeConflictToolOptions, type PostReviewToolOptions, type PublishedReview, RecordChangeInput, type RecordFindingOptions, type RecordFindingResult, type ReviewCommentToolOptions, deepsecScanTool, factoryHooks, factoryTools, fetchPullRequestTool, findingFromDeepsec, invokeAgentTool, mergeConflictPayloadSchema, mergeConflictTools, postReviewTool, recordFinding, recordFindingTool, recordVerificationTool, reviewCommentTools };
1103
1173
  //# sourceMappingURL=index.d.mts.map
@@ -1,7 +1,7 @@
1
1
  import { i as repositoryIdSchema, o as signalIdSchema, p as vocabularySchema, s as taskIdSchema, t as changeIdSchema } from "../id-DwCihQr4.mjs";
2
2
  import { c as findingSchema, i as requiresApproval, o as findingFingerprint, r as defaultApprovalPolicy } from "../approval-DdvEKLiE.mjs";
3
- import { g as dispatchTask, p as levelSchema, s as taskQuestionSchema, u as changeEvidenceSchema } from "../task-DMHuvBI0.mjs";
4
- import { answerReviewComment, readPullRequestHead, readReviewComment } from "../github.mjs";
3
+ import { g as taskQuestionSchema, i as levelSchema, s as dispatchTask, t as changeEvidenceSchema } from "../change-BPYhWKuL.mjs";
4
+ import { answerReviewComment, readPullRequestHead, readReviewComment, submitPullRequestReview } from "../github.mjs";
5
5
  import { z } from "zod";
6
6
  import { defineHook } from "eve/hooks";
7
7
  import { defineTool } from "eve/tools";
@@ -442,7 +442,7 @@ function invokeAgentTool(stores, options) {
442
442
  launch: async (dispatched) => {
443
443
  const headers = {
444
444
  "content-type": "application/json",
445
- ...await options.headers?.()
445
+ ...await options.headers?.(dispatched)
446
446
  };
447
447
  const token = await options.token?.();
448
448
  if (token !== void 0) headers.authorization = `Bearer ${token}`;
@@ -475,6 +475,86 @@ function invokeAgentTool(stores, options) {
475
475
  });
476
476
  }
477
477
  //#endregion
478
+ //#region src/eve/post-review.ts
479
+ const reviewCommentSchema = z.strictObject({
480
+ path: z.string().min(1).max(500).describe("Repository-relative file path."),
481
+ line: z.number().int().min(1).describe("Line in the pull request's new version."),
482
+ body: z.string().min(1).max(5e3).describe("Markdown explaining the finding and a concrete fix.")
483
+ });
484
+ /**
485
+ * Publish an independent review of an existing pull request and finish the
486
+ * review task without changing the pull request's factory lifecycle.
487
+ */
488
+ function postReviewTool(stores, options) {
489
+ return defineTool({
490
+ description: "Publish a completed code review to the existing pull request and finish your code_review task. Use request_changes only for blocking findings.",
491
+ inputSchema: z.object({
492
+ taskId: taskIdSchema.describe("Your code_review task."),
493
+ changeId: changeIdSchema.describe("The pull request change from your starting message."),
494
+ verdict: z.enum([
495
+ "approve",
496
+ "request_changes",
497
+ "comment"
498
+ ]),
499
+ headSha: z.string().regex(/^[0-9a-f]{40}$/).describe("Commit returned by fetch_pull_request."),
500
+ summary: z.string().min(1).max(5e3).describe("Markdown summary of what you reviewed and found."),
501
+ comments: z.array(reviewCommentSchema).max(50).default([])
502
+ }),
503
+ async execute({ taskId, changeId, verdict, headSha, summary, comments }) {
504
+ const task = await stores.tasks.get(taskId);
505
+ if (task === null || task.kind !== "code_review") return {
506
+ recorded: false,
507
+ reason: `${taskId} is not a code_review task`
508
+ };
509
+ if (task.state !== "running") return {
510
+ recorded: false,
511
+ reason: `task is ${task.state}, not running`
512
+ };
513
+ const change = await stores.changes.get(changeId);
514
+ if (change === null) return {
515
+ recorded: false,
516
+ reason: `change ${changeId} does not exist`
517
+ };
518
+ if (change.state !== "verifying" && change.state !== "ready") return {
519
+ recorded: false,
520
+ reason: `change is ${change.state}, not open for review`
521
+ };
522
+ const repository = await stores.repositories.get(change.repositoryId);
523
+ if (repository === null) return {
524
+ recorded: false,
525
+ reason: `repository ${change.repositoryId} does not exist`
526
+ };
527
+ const review = await submitPullRequestReview({
528
+ repository: repository.slug,
529
+ token: await options.tokenForRepository(repository.slug),
530
+ fetch: options.fetch,
531
+ pullRequestNumber: change.prNumber,
532
+ commitId: headSha,
533
+ event: verdict === "approve" ? "APPROVE" : verdict === "request_changes" ? "REQUEST_CHANGES" : "COMMENT",
534
+ body: summary,
535
+ comments
536
+ });
537
+ await options.onPublished?.({
538
+ taskId,
539
+ changeId,
540
+ repository: repository.slug,
541
+ headSha,
542
+ verdict,
543
+ summary,
544
+ comments,
545
+ review
546
+ });
547
+ await stores.tasks.transition(taskId, "verifying", { reason: summary });
548
+ return {
549
+ recorded: true,
550
+ verdict,
551
+ review,
552
+ taskState: (await stores.tasks.transition(taskId, "succeeded")).state
553
+ };
554
+ }
555
+ });
556
+ }
557
+ //#endregion
478
558
  //#region src/eve/review.ts
479
559
  function reviewCommentTools(stores, options) {
480
560
  const repoPath = options.repoPath ?? "repo";
@@ -849,6 +929,6 @@ function factoryHooks(stores) {
849
929
  } } }) };
850
930
  }
851
931
  //#endregion
852
- export { deepsecScanTool, factoryHooks, factoryTools, fetchPullRequestTool, findingFromDeepsec, invokeAgentTool, mergeConflictPayloadSchema, mergeConflictTools, recordFinding, recordFindingTool, recordVerificationTool, reviewCommentTools };
932
+ export { deepsecScanTool, factoryHooks, factoryTools, fetchPullRequestTool, findingFromDeepsec, invokeAgentTool, mergeConflictPayloadSchema, mergeConflictTools, postReviewTool, recordFinding, recordFindingTool, recordVerificationTool, reviewCommentTools };
853
933
 
854
934
  //# sourceMappingURL=index.mjs.map