11import type { GoogleVaultCreateMattersHoldsParams } from '@/tools/google_vault/types'
2+ import { enhanceGoogleVaultError } from '@/tools/google_vault/utils'
23import type { ToolConfig } from '@/tools/types'
34
4- // matters.holds.create
5- // POST https://vault.googleapis.com/v1/matters/{matterId}/holds
65export const createMattersHoldsTool : ToolConfig < GoogleVaultCreateMattersHoldsParams > = {
76 id : 'create_matters_holds' ,
87 name : 'Vault Create Hold (by Matter)' ,
@@ -36,7 +35,6 @@ export const createMattersHoldsTool: ToolConfig<GoogleVaultCreateMattersHoldsPar
3635 visibility : 'user-only' ,
3736 description : 'Organization unit ID to put on hold (alternative to accounts)' ,
3837 } ,
39- // Query parameters for MAIL and GROUPS corpus (date filtering)
4038 terms : {
4139 type : 'string' ,
4240 required : false ,
@@ -55,7 +53,6 @@ export const createMattersHoldsTool: ToolConfig<GoogleVaultCreateMattersHoldsPar
5553 visibility : 'user-only' ,
5654 description : 'End time for date filtering (ISO 8601 format, for MAIL and GROUPS corpus)' ,
5755 } ,
58- // Drive-specific option
5956 includeSharedDrives : {
6057 type : 'boolean' ,
6158 required : false ,
@@ -72,13 +69,11 @@ export const createMattersHoldsTool: ToolConfig<GoogleVaultCreateMattersHoldsPar
7269 'Content-Type' : 'application/json' ,
7370 } ) ,
7471 body : ( params ) => {
75- // Build Hold body. One of accounts or orgUnit must be provided.
7672 const body : any = {
7773 name : params . holdName ,
7874 corpus : params . corpus ,
7975 }
8076
81- // Handle accountEmails - can be string (comma-separated) or array
8277 let emails : string [ ] = [ ]
8378 if ( params . accountEmails ) {
8479 if ( Array . isArray ( params . accountEmails ) ) {
@@ -92,13 +87,11 @@ export const createMattersHoldsTool: ToolConfig<GoogleVaultCreateMattersHoldsPar
9287 }
9388
9489 if ( emails . length > 0 ) {
95- // Google Vault expects HeldAccount objects with 'email' or 'accountId'. Use 'email' here.
9690 body . accounts = emails . map ( ( email : string ) => ( { email } ) )
9791 } else if ( params . orgUnitId ) {
9892 body . orgUnit = { orgUnitId : params . orgUnitId }
9993 }
10094
101- // Build corpus-specific query for date filtering
10295 if ( params . corpus === 'MAIL' || params . corpus === 'GROUPS' ) {
10396 const hasQueryParams = params . terms || params . startTime || params . endTime
10497 if ( hasQueryParams ) {
@@ -124,7 +117,8 @@ export const createMattersHoldsTool: ToolConfig<GoogleVaultCreateMattersHoldsPar
124117 transformResponse : async ( response : Response ) => {
125118 const data = await response . json ( )
126119 if ( ! response . ok ) {
127- throw new Error ( data . error ?. message || 'Failed to create hold' )
120+ const errorMessage = data . error ?. message || 'Failed to create hold'
121+ throw new Error ( enhanceGoogleVaultError ( errorMessage ) )
128122 }
129123 return { success : true , output : { hold : data } }
130124 } ,
0 commit comments