@morphllm/morphsdk 0.2.93 → 0.2.94

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 (86) hide show
  1. package/dist/{chunk-IJ54DTJ3.js → chunk-4WO7PJNT.js} +11 -11
  2. package/dist/{chunk-EYGBUH2R.js → chunk-AV6YV2MH.js} +2 -2
  3. package/dist/{chunk-LMUZ3NGC.js → chunk-BVVDDTI7.js} +2 -2
  4. package/dist/chunk-ESRZJRTQ.js +359 -0
  5. package/dist/chunk-ESRZJRTQ.js.map +1 -0
  6. package/dist/{chunk-GU6DACME.js → chunk-FIA6LBW2.js} +2 -2
  7. package/dist/{chunk-4WLGDYWQ.js → chunk-FMWNVTJJ.js} +2 -2
  8. package/dist/{chunk-PBLPZ6AU.js → chunk-IH3KN4AT.js} +2 -2
  9. package/dist/{chunk-MIIJWDOQ.js → chunk-M7GFXRKL.js} +13 -3
  10. package/dist/chunk-M7GFXRKL.js.map +1 -0
  11. package/dist/{chunk-4KMBU6T3.js → chunk-R7WN43L2.js} +4 -4
  12. package/dist/{chunk-PUGIOVSP.js → chunk-TXYCM4NP.js} +2 -2
  13. package/dist/chunk-UJ7LVT5G.js +177 -0
  14. package/dist/chunk-UJ7LVT5G.js.map +1 -0
  15. package/dist/{chunk-FNLNDMIX.js → chunk-WSQMWVSD.js} +2 -2
  16. package/dist/chunk-YJ354BA2.js +46 -0
  17. package/dist/chunk-YJ354BA2.js.map +1 -0
  18. package/dist/client.cjs +546 -4
  19. package/dist/client.cjs.map +1 -1
  20. package/dist/client.d.ts +2 -0
  21. package/dist/client.js +12 -9
  22. package/dist/index.cjs +546 -4
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +12 -9
  26. package/dist/tools/browser/anthropic.cjs +5 -1
  27. package/dist/tools/browser/anthropic.cjs.map +1 -1
  28. package/dist/tools/browser/anthropic.js +5 -2
  29. package/dist/tools/browser/core.cjs +544 -2
  30. package/dist/tools/browser/core.cjs.map +1 -1
  31. package/dist/tools/browser/core.d.ts +6 -0
  32. package/dist/tools/browser/core.js +4 -1
  33. package/dist/tools/browser/errors.cjs +208 -0
  34. package/dist/tools/browser/errors.cjs.map +1 -0
  35. package/dist/tools/browser/errors.d.ts +158 -0
  36. package/dist/tools/browser/errors.js +22 -0
  37. package/dist/tools/browser/errors.js.map +1 -0
  38. package/dist/tools/browser/index.cjs +562 -2
  39. package/dist/tools/browser/index.cjs.map +1 -1
  40. package/dist/tools/browser/index.d.ts +3 -0
  41. package/dist/tools/browser/index.js +27 -4
  42. package/dist/tools/browser/index.js.map +1 -1
  43. package/dist/tools/browser/openai.cjs +5 -1
  44. package/dist/tools/browser/openai.cjs.map +1 -1
  45. package/dist/tools/browser/openai.js +5 -2
  46. package/dist/tools/browser/profiles/core.cjs +639 -0
  47. package/dist/tools/browser/profiles/core.cjs.map +1 -0
  48. package/dist/tools/browser/profiles/core.d.ts +179 -0
  49. package/dist/tools/browser/profiles/core.js +27 -0
  50. package/dist/tools/browser/profiles/core.js.map +1 -0
  51. package/dist/tools/browser/profiles/index.cjs +639 -0
  52. package/dist/tools/browser/profiles/index.cjs.map +1 -0
  53. package/dist/tools/browser/profiles/index.d.ts +4 -0
  54. package/dist/tools/browser/profiles/index.js +27 -0
  55. package/dist/tools/browser/profiles/index.js.map +1 -0
  56. package/dist/tools/browser/profiles/types.cjs +74 -0
  57. package/dist/tools/browser/profiles/types.cjs.map +1 -0
  58. package/dist/tools/browser/profiles/types.d.ts +176 -0
  59. package/dist/tools/browser/profiles/types.js +16 -0
  60. package/dist/tools/browser/profiles/types.js.map +1 -0
  61. package/dist/tools/browser/types.cjs.map +1 -1
  62. package/dist/tools/browser/types.d.ts +2 -0
  63. package/dist/tools/browser/vercel.cjs +5 -1
  64. package/dist/tools/browser/vercel.cjs.map +1 -1
  65. package/dist/tools/browser/vercel.js +5 -2
  66. package/dist/tools/fastapply/index.js +3 -3
  67. package/dist/tools/index.js +3 -3
  68. package/dist/tools/warp_grep/anthropic.js +4 -4
  69. package/dist/tools/warp_grep/client.js +3 -3
  70. package/dist/tools/warp_grep/gemini.js +3 -3
  71. package/dist/tools/warp_grep/harness.js +2 -2
  72. package/dist/tools/warp_grep/index.js +3 -3
  73. package/dist/tools/warp_grep/openai.js +4 -4
  74. package/dist/tools/warp_grep/providers/local.js +2 -2
  75. package/dist/tools/warp_grep/vercel.js +4 -4
  76. package/package.json +7 -2
  77. package/dist/chunk-MIIJWDOQ.js.map +0 -1
  78. /package/dist/{chunk-IJ54DTJ3.js.map → chunk-4WO7PJNT.js.map} +0 -0
  79. /package/dist/{chunk-EYGBUH2R.js.map → chunk-AV6YV2MH.js.map} +0 -0
  80. /package/dist/{chunk-LMUZ3NGC.js.map → chunk-BVVDDTI7.js.map} +0 -0
  81. /package/dist/{chunk-GU6DACME.js.map → chunk-FIA6LBW2.js.map} +0 -0
  82. /package/dist/{chunk-4WLGDYWQ.js.map → chunk-FMWNVTJJ.js.map} +0 -0
  83. /package/dist/{chunk-PBLPZ6AU.js.map → chunk-IH3KN4AT.js.map} +0 -0
  84. /package/dist/{chunk-4KMBU6T3.js.map → chunk-R7WN43L2.js.map} +0 -0
  85. /package/dist/{chunk-PUGIOVSP.js.map → chunk-TXYCM4NP.js.map} +0 -0
  86. /package/dist/{chunk-FNLNDMIX.js.map → chunk-WSQMWVSD.js.map} +0 -0
package/dist/client.cjs CHANGED
@@ -501,6 +501,541 @@ function resolvePreset(optionsOrPreset) {
501
501
  return optionsOrPreset;
502
502
  }
503
503
 
504
+ // tools/browser/errors.ts
505
+ var MorphError = class extends Error {
506
+ /** Error code for programmatic handling */
507
+ code;
508
+ /** Original cause of the error, if any */
509
+ cause;
510
+ constructor(message, code, cause) {
511
+ super(message);
512
+ this.name = "MorphError";
513
+ this.code = code;
514
+ this.cause = cause;
515
+ if (Error.captureStackTrace) {
516
+ Error.captureStackTrace(this, this.constructor);
517
+ }
518
+ }
519
+ /**
520
+ * Returns a JSON representation of the error for logging.
521
+ */
522
+ toJSON() {
523
+ return {
524
+ name: this.name,
525
+ message: this.message,
526
+ code: this.code,
527
+ cause: this.cause?.message
528
+ };
529
+ }
530
+ };
531
+ var MorphValidationError = class extends MorphError {
532
+ /** The field that failed validation */
533
+ field;
534
+ constructor(message, field) {
535
+ super(message, "validation_error");
536
+ this.name = "MorphValidationError";
537
+ this.field = field;
538
+ }
539
+ toJSON() {
540
+ return {
541
+ ...super.toJSON(),
542
+ field: this.field
543
+ };
544
+ }
545
+ };
546
+ var MorphAPIError = class extends MorphError {
547
+ /** HTTP status code */
548
+ statusCode;
549
+ /** Request ID for debugging (if available) */
550
+ requestId;
551
+ /** Raw response body */
552
+ rawResponse;
553
+ constructor(message, code, statusCode, options) {
554
+ super(message, code, options?.cause);
555
+ this.name = "MorphAPIError";
556
+ this.statusCode = statusCode;
557
+ this.requestId = options?.requestId;
558
+ this.rawResponse = options?.rawResponse;
559
+ }
560
+ toJSON() {
561
+ return {
562
+ ...super.toJSON(),
563
+ statusCode: this.statusCode,
564
+ requestId: this.requestId
565
+ };
566
+ }
567
+ };
568
+ var MorphAuthenticationError = class extends MorphAPIError {
569
+ constructor(message = "Authentication required. Please provide a valid API key.") {
570
+ super(message, "authentication_required", 401);
571
+ this.name = "MorphAuthenticationError";
572
+ }
573
+ };
574
+ var MorphRateLimitError = class extends MorphAPIError {
575
+ /** When the rate limit resets (Unix timestamp) */
576
+ resetAt;
577
+ /** Number of seconds until reset */
578
+ retryAfter;
579
+ constructor(message = "Rate limit exceeded. Please retry later.", options) {
580
+ super(message, "rate_limit_exceeded", 429, { requestId: options?.requestId });
581
+ this.name = "MorphRateLimitError";
582
+ this.resetAt = options?.resetAt;
583
+ this.retryAfter = options?.retryAfter;
584
+ }
585
+ toJSON() {
586
+ return {
587
+ ...super.toJSON(),
588
+ resetAt: this.resetAt,
589
+ retryAfter: this.retryAfter
590
+ };
591
+ }
592
+ };
593
+ var MorphNotFoundError = class extends MorphAPIError {
594
+ /** The type of resource that was not found */
595
+ resourceType;
596
+ /** The ID of the resource that was not found */
597
+ resourceId;
598
+ constructor(resourceType, resourceId) {
599
+ const message = resourceId ? `${resourceType} '${resourceId}' not found` : `${resourceType} not found`;
600
+ super(message, "resource_not_found", 404);
601
+ this.name = "MorphNotFoundError";
602
+ this.resourceType = resourceType;
603
+ this.resourceId = resourceId;
604
+ }
605
+ toJSON() {
606
+ return {
607
+ ...super.toJSON(),
608
+ resourceType: this.resourceType,
609
+ resourceId: this.resourceId
610
+ };
611
+ }
612
+ };
613
+ var MorphProfileLimitError = class extends MorphAPIError {
614
+ /** Current number of profiles */
615
+ currentCount;
616
+ /** Maximum allowed profiles for the plan */
617
+ maxAllowed;
618
+ constructor(message = "Profile limit exceeded for your plan.", options) {
619
+ super(message, "profile_limit_exceeded", 403, { requestId: options?.requestId });
620
+ this.name = "MorphProfileLimitError";
621
+ this.currentCount = options?.currentCount;
622
+ this.maxAllowed = options?.maxAllowed;
623
+ }
624
+ toJSON() {
625
+ return {
626
+ ...super.toJSON(),
627
+ currentCount: this.currentCount,
628
+ maxAllowed: this.maxAllowed
629
+ };
630
+ }
631
+ };
632
+ function parseAPIError(statusCode, responseText, requestId) {
633
+ let errorData = {};
634
+ try {
635
+ errorData = JSON.parse(responseText);
636
+ } catch {
637
+ }
638
+ const message = errorData.detail || errorData.message || responseText || "Unknown error";
639
+ const code = errorData.code;
640
+ switch (statusCode) {
641
+ case 401:
642
+ return new MorphAuthenticationError(message);
643
+ case 403:
644
+ if (code === "profile_limit_exceeded" || message.toLowerCase().includes("limit")) {
645
+ return new MorphProfileLimitError(message, { requestId });
646
+ }
647
+ return new MorphAPIError(message, "insufficient_permissions", statusCode, { requestId, rawResponse: responseText });
648
+ case 404:
649
+ if (message.toLowerCase().includes("profile")) {
650
+ return new MorphNotFoundError("Profile", void 0);
651
+ }
652
+ if (message.toLowerCase().includes("session")) {
653
+ return new MorphNotFoundError("Session", void 0);
654
+ }
655
+ return new MorphAPIError(message, "resource_not_found", statusCode, { requestId, rawResponse: responseText });
656
+ case 429:
657
+ return new MorphRateLimitError(message, { requestId });
658
+ case 422:
659
+ return new MorphAPIError(message, "validation_error", statusCode, { requestId, rawResponse: responseText });
660
+ case 500:
661
+ case 502:
662
+ case 503:
663
+ case 504:
664
+ return new MorphAPIError(message, "service_unavailable", statusCode, { requestId, rawResponse: responseText });
665
+ default:
666
+ return new MorphAPIError(message, "network_error", statusCode, { requestId, rawResponse: responseText });
667
+ }
668
+ }
669
+
670
+ // tools/browser/profiles/types.ts
671
+ function transformProfile(api) {
672
+ return {
673
+ id: api.id,
674
+ name: api.name,
675
+ repoId: api.repo_id,
676
+ cookieDomains: api.cookie_domains,
677
+ lastUsedAt: api.last_used_at,
678
+ createdAt: api.created_at,
679
+ updatedAt: api.updated_at
680
+ };
681
+ }
682
+ function transformCreateInput(input) {
683
+ return {
684
+ name: input.name,
685
+ repo_id: input.repoId
686
+ };
687
+ }
688
+ function transformSession(api) {
689
+ return {
690
+ sessionId: api.session_id,
691
+ debugUrl: api.debug_url || api.debugUrl || ""
692
+ };
693
+ }
694
+ function transformSaveInput(input) {
695
+ return {
696
+ session_id: input.sessionId,
697
+ profile_id: input.profileId
698
+ };
699
+ }
700
+ function transformStateResponse(api) {
701
+ return {
702
+ profileId: api.profile_id,
703
+ stateUrl: api.state_url,
704
+ expiresIn: api.expires_in
705
+ };
706
+ }
707
+
708
+ // tools/browser/profiles/core.ts
709
+ var DEFAULT_API_URL = process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com";
710
+ var ProfilesClient = class {
711
+ config;
712
+ constructor(config) {
713
+ this.config = config;
714
+ }
715
+ /**
716
+ * Create a new browser profile.
717
+ *
718
+ * @param input - Profile creation parameters
719
+ * @returns The created profile
720
+ * @throws {MorphValidationError} If input validation fails
721
+ * @throws {MorphProfileLimitError} If profile limit is exceeded
722
+ * @throws {MorphAuthenticationError} If API key is missing or invalid
723
+ *
724
+ * @example
725
+ * ```typescript
726
+ * const profile = await morph.browser.profiles.createProfile({
727
+ * name: 'LinkedIn Production',
728
+ * repoId: 'repo-uuid-here'
729
+ * });
730
+ * ```
731
+ */
732
+ async createProfile(input) {
733
+ return createProfile(input, this.config);
734
+ }
735
+ /**
736
+ * List all profiles for the authenticated user.
737
+ *
738
+ * @param repoId - Optional repository ID to filter by
739
+ * @returns Array of profiles
740
+ *
741
+ * @example
742
+ * ```typescript
743
+ * // List all profiles
744
+ * const allProfiles = await morph.browser.profiles.listProfiles();
745
+ *
746
+ * // List profiles for a specific repo
747
+ * const repoProfiles = await morph.browser.profiles.listProfiles('repo-uuid');
748
+ * ```
749
+ */
750
+ async listProfiles(repoId) {
751
+ return listProfiles(this.config, repoId);
752
+ }
753
+ /**
754
+ * Get a profile by ID with convenience methods.
755
+ *
756
+ * @param id - Profile ID
757
+ * @returns Profile with attached methods
758
+ * @throws {MorphNotFoundError} If profile is not found
759
+ *
760
+ * @example
761
+ * ```typescript
762
+ * const profile = await morph.browser.profiles.getProfile('profile-id');
763
+ * const state = await profile.getState();
764
+ * await profile.delete();
765
+ * ```
766
+ */
767
+ async getProfile(id) {
768
+ return getProfile(id, this.config);
769
+ }
770
+ /**
771
+ * Update a profile's name.
772
+ *
773
+ * @param id - Profile ID
774
+ * @param input - Update parameters
775
+ * @returns Updated profile
776
+ */
777
+ async updateProfile(id, input) {
778
+ return updateProfile(id, input, this.config);
779
+ }
780
+ /**
781
+ * Delete a profile.
782
+ *
783
+ * @param id - Profile ID
784
+ * @throws {MorphNotFoundError} If profile is not found
785
+ */
786
+ async deleteProfile(id) {
787
+ return deleteProfile(id, this.config);
788
+ }
789
+ /**
790
+ * Start a browser session for profile setup.
791
+ *
792
+ * Returns a live URL where the user can sign into accounts.
793
+ * After signing in, call `saveSession` to persist the state.
794
+ *
795
+ * @param input - Optional session parameters
796
+ * @returns Session with debug URL
797
+ *
798
+ * @example
799
+ * ```typescript
800
+ * const session = await morph.browser.profiles.startSession();
801
+ * console.log('Sign in at:', session.debugUrl);
802
+ * // Open debugUrl in browser, user signs in...
803
+ * await morph.browser.profiles.saveSession(session.sessionId, profile.id);
804
+ * ```
805
+ */
806
+ async startSession(input) {
807
+ return startProfileSession(this.config, input);
808
+ }
809
+ /**
810
+ * Save browser state from a session to a profile.
811
+ *
812
+ * Call this after the user is done signing into accounts.
813
+ * Extracts cookies, localStorage, and sessionStorage.
814
+ *
815
+ * @param sessionId - Browser session ID from startSession
816
+ * @param profileId - Profile ID to save state to
817
+ * @returns Updated profile with cookie domains
818
+ */
819
+ async saveSession(sessionId, profileId) {
820
+ return saveProfileSession({ sessionId, profileId }, this.config);
821
+ }
822
+ /**
823
+ * Get the presigned URL for a profile's state.
824
+ *
825
+ * Use this to download the raw state JSON for debugging
826
+ * or to restore state manually.
827
+ *
828
+ * @param profileId - Profile ID
829
+ * @returns State URL with expiry information
830
+ */
831
+ async getProfileState(profileId) {
832
+ return getProfileState(profileId, this.config);
833
+ }
834
+ };
835
+ function validateCreateInput(input) {
836
+ if (!input.name || typeof input.name !== "string") {
837
+ throw new MorphValidationError("name is required", "name");
838
+ }
839
+ const trimmedName = input.name.trim();
840
+ if (trimmedName.length === 0) {
841
+ throw new MorphValidationError("name cannot be empty", "name");
842
+ }
843
+ if (trimmedName.length > 100) {
844
+ throw new MorphValidationError("name must be 100 characters or less", "name");
845
+ }
846
+ if (!input.repoId || typeof input.repoId !== "string") {
847
+ throw new MorphValidationError("repoId is required", "repoId");
848
+ }
849
+ if (input.repoId.trim().length === 0) {
850
+ throw new MorphValidationError("repoId cannot be empty", "repoId");
851
+ }
852
+ }
853
+ function validateId(id, fieldName) {
854
+ if (!id || typeof id !== "string") {
855
+ throw new MorphValidationError(`${fieldName} is required`, fieldName);
856
+ }
857
+ if (id.trim().length === 0) {
858
+ throw new MorphValidationError(`${fieldName} cannot be empty`, fieldName);
859
+ }
860
+ }
861
+ async function createProfile(input, config = {}) {
862
+ validateCreateInput(input);
863
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
864
+ const headers = buildHeaders(config);
865
+ const response = await fetchWithRetry(
866
+ `${apiUrl}/profiles`,
867
+ {
868
+ method: "POST",
869
+ headers,
870
+ body: JSON.stringify(transformCreateInput(input))
871
+ },
872
+ config.retryConfig
873
+ );
874
+ if (!response.ok) {
875
+ const errorText = await response.text().catch(() => response.statusText);
876
+ const requestId = response.headers.get("x-request-id") || void 0;
877
+ throw parseAPIError(response.status, errorText, requestId);
878
+ }
879
+ const apiProfile = await response.json();
880
+ return transformProfile(apiProfile);
881
+ }
882
+ async function listProfiles(config = {}, repoId) {
883
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
884
+ const headers = buildHeaders(config);
885
+ const url = repoId ? `${apiUrl}/profiles?repo_id=${encodeURIComponent(repoId)}` : `${apiUrl}/profiles`;
886
+ const response = await fetchWithRetry(
887
+ url,
888
+ { method: "GET", headers },
889
+ config.retryConfig
890
+ );
891
+ if (!response.ok) {
892
+ const errorText = await response.text().catch(() => response.statusText);
893
+ const requestId = response.headers.get("x-request-id") || void 0;
894
+ throw parseAPIError(response.status, errorText, requestId);
895
+ }
896
+ const data = await response.json();
897
+ return data.profiles.map(transformProfile);
898
+ }
899
+ async function getProfile(id, config = {}) {
900
+ validateId(id, "id");
901
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
902
+ const headers = buildHeaders(config);
903
+ const response = await fetchWithRetry(
904
+ `${apiUrl}/profiles/${encodeURIComponent(id)}`,
905
+ { method: "GET", headers },
906
+ config.retryConfig
907
+ );
908
+ if (!response.ok) {
909
+ const errorText = await response.text().catch(() => response.statusText);
910
+ const requestId = response.headers.get("x-request-id") || void 0;
911
+ throw parseAPIError(response.status, errorText, requestId);
912
+ }
913
+ const apiProfile = await response.json();
914
+ const profile = transformProfile(apiProfile);
915
+ return {
916
+ ...profile,
917
+ getState: () => getProfileState(id, config),
918
+ delete: () => deleteProfile(id, config)
919
+ };
920
+ }
921
+ async function updateProfile(id, input, config = {}) {
922
+ validateId(id, "id");
923
+ if (input.name !== void 0) {
924
+ if (typeof input.name !== "string") {
925
+ throw new MorphValidationError("name must be a string", "name");
926
+ }
927
+ if (input.name.trim().length === 0) {
928
+ throw new MorphValidationError("name cannot be empty", "name");
929
+ }
930
+ if (input.name.length > 100) {
931
+ throw new MorphValidationError("name must be 100 characters or less", "name");
932
+ }
933
+ }
934
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
935
+ const headers = buildHeaders(config);
936
+ const response = await fetchWithRetry(
937
+ `${apiUrl}/profiles/${encodeURIComponent(id)}`,
938
+ {
939
+ method: "PATCH",
940
+ headers,
941
+ body: JSON.stringify(input)
942
+ },
943
+ config.retryConfig
944
+ );
945
+ if (!response.ok) {
946
+ const errorText = await response.text().catch(() => response.statusText);
947
+ const requestId = response.headers.get("x-request-id") || void 0;
948
+ throw parseAPIError(response.status, errorText, requestId);
949
+ }
950
+ const apiProfile = await response.json();
951
+ return transformProfile(apiProfile);
952
+ }
953
+ async function deleteProfile(id, config = {}) {
954
+ validateId(id, "id");
955
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
956
+ const headers = buildHeaders(config);
957
+ const response = await fetchWithRetry(
958
+ `${apiUrl}/profiles/${encodeURIComponent(id)}`,
959
+ { method: "DELETE", headers },
960
+ config.retryConfig
961
+ );
962
+ if (!response.ok) {
963
+ const errorText = await response.text().catch(() => response.statusText);
964
+ const requestId = response.headers.get("x-request-id") || void 0;
965
+ throw parseAPIError(response.status, errorText, requestId);
966
+ }
967
+ }
968
+ async function startProfileSession(config = {}, input) {
969
+ if (!config.apiKey) {
970
+ throw new MorphAuthenticationError();
971
+ }
972
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
973
+ const headers = buildHeaders(config);
974
+ const body = input?.profileId ? { profile_id: input.profileId } : {};
975
+ const response = await fetchWithRetry(
976
+ `${apiUrl}/profiles/session/start`,
977
+ {
978
+ method: "POST",
979
+ headers,
980
+ body: JSON.stringify(body)
981
+ },
982
+ config.retryConfig
983
+ );
984
+ if (!response.ok) {
985
+ const errorText = await response.text().catch(() => response.statusText);
986
+ const requestId = response.headers.get("x-request-id") || void 0;
987
+ throw parseAPIError(response.status, errorText, requestId);
988
+ }
989
+ const apiSession = await response.json();
990
+ return transformSession(apiSession);
991
+ }
992
+ async function saveProfileSession(input, config = {}) {
993
+ validateId(input.sessionId, "sessionId");
994
+ validateId(input.profileId, "profileId");
995
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
996
+ const headers = buildHeaders(config);
997
+ const response = await fetchWithRetry(
998
+ `${apiUrl}/profiles/session/save`,
999
+ {
1000
+ method: "POST",
1001
+ headers,
1002
+ body: JSON.stringify(transformSaveInput(input))
1003
+ },
1004
+ config.retryConfig
1005
+ );
1006
+ if (!response.ok) {
1007
+ const errorText = await response.text().catch(() => response.statusText);
1008
+ const requestId = response.headers.get("x-request-id") || void 0;
1009
+ throw parseAPIError(response.status, errorText, requestId);
1010
+ }
1011
+ const apiProfile = await response.json();
1012
+ return transformProfile(apiProfile);
1013
+ }
1014
+ async function getProfileState(profileId, config = {}) {
1015
+ validateId(profileId, "profileId");
1016
+ const apiUrl = config.apiUrl || DEFAULT_API_URL;
1017
+ const headers = buildHeaders(config);
1018
+ const response = await fetchWithRetry(
1019
+ `${apiUrl}/profiles/${encodeURIComponent(profileId)}/state`,
1020
+ { method: "GET", headers },
1021
+ config.retryConfig
1022
+ );
1023
+ if (!response.ok) {
1024
+ const errorText = await response.text().catch(() => response.statusText);
1025
+ const requestId = response.headers.get("x-request-id") || void 0;
1026
+ throw parseAPIError(response.status, errorText, requestId);
1027
+ }
1028
+ const apiState = await response.json();
1029
+ return transformStateResponse(apiState);
1030
+ }
1031
+ function buildHeaders(config) {
1032
+ const headers = { "Content-Type": "application/json" };
1033
+ if (config.apiKey) {
1034
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
1035
+ }
1036
+ return headers;
1037
+ }
1038
+
504
1039
  // tools/browser/core.ts
505
1040
  var DEFAULT_CONFIG2 = {
506
1041
  apiUrl: process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com",
@@ -510,11 +1045,16 @@ var DEFAULT_CONFIG2 = {
510
1045
  };
511
1046
  var BrowserClient = class {
512
1047
  config;
1048
+ /**
1049
+ * Profile management - create and manage browser profiles for storing login state.
1050
+ */
1051
+ profiles;
513
1052
  constructor(config = {}) {
514
1053
  this.config = {
515
1054
  ...DEFAULT_CONFIG2,
516
1055
  ...config
517
1056
  };
1057
+ this.profiles = new ProfilesClient(this.config);
518
1058
  }
519
1059
  /**
520
1060
  * Execute a browser automation task
@@ -549,7 +1089,8 @@ var BrowserClient = class {
549
1089
  video_height: input.video_height ?? input.viewport_height ?? 720,
550
1090
  allow_resizing: input.allow_resizing ?? false,
551
1091
  structured_output: "schema" in input ? stringifyStructuredOutput(input.schema) : void 0,
552
- auth: input.auth
1092
+ auth: input.auth,
1093
+ profile_id: input.profile_id
553
1094
  })
554
1095
  });
555
1096
  if (!response.ok) {
@@ -648,7 +1189,8 @@ async function executeBrowserTask(input, config = {}) {
648
1189
  video_height: input.video_height ?? input.viewport_height ?? 720,
649
1190
  allow_resizing: input.allow_resizing ?? false,
650
1191
  structured_output: input.structured_output,
651
- auth: input.auth
1192
+ auth: input.auth,
1193
+ profile_id: input.profile_id
652
1194
  })
653
1195
  },
654
1196
  config.retryConfig
@@ -1853,9 +2395,9 @@ function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS
1853
2395
  // tools/warp_grep/agent/runner.ts
1854
2396
  var import_path3 = __toESM(require("path"), 1);
1855
2397
  var parser = new LLMResponseParser();
1856
- var DEFAULT_API_URL = "https://api.morphllm.com";
2398
+ var DEFAULT_API_URL2 = "https://api.morphllm.com";
1857
2399
  async function callModel(messages, model, options = {}) {
1858
- const baseUrl = options.morphApiUrl || DEFAULT_API_URL;
2400
+ const baseUrl = options.morphApiUrl || DEFAULT_API_URL2;
1859
2401
  const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
1860
2402
  const fetchPromise = fetchWithRetry(
1861
2403
  `${baseUrl}/v1/chat/completions`,